Allow LaunchServices to handle URLs on link navigations
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Apr 2015 01:45:04 +0000 (01:45 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Apr 2015 01:45:04 +0000 (01:45 +0000)
<rdar://problem/19446826>
https://bugs.webkit.org/show_bug.cgi?id=143544

Reviewed by Anders Carlsson.

Source/WebCore:

* WebCore.xcodeproj/project.pbxproj:
* platform/spi/ios/LaunchServicesSPI.h: Added.
Add new SPI header.

Source/WebKit/mac:

* Configurations/WebKitLegacy.xcconfig:
Link MobileCoreServices.

* WebCoreSupport/WebFrameLoaderClient.h:
* WebCoreSupport/WebFrameLoaderClient.mm:
(shouldTryAppLink):
(WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction):
(WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction):
(WebFrameLoaderClient::setUpPolicyListener):
Only let LaunchServices have a crack at the URL if the navigation is:
    1) a main frame navigation
    2) a result of a user gesture

Source/WebKit2:

* UIProcess/Cocoa/NavigationState.mm:
(WebKit::tryAppLink):
(WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):
Only let LaunchServices have a crack at the URL if the navigation is:
    1) a main frame navigation
    2) a result of a user gesture

Source/WTF:

* wtf/Platform.h:
Add HAVE macro for this functionality.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182648 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/spi/ios/LaunchServicesSPI.h [new file with mode: 0644]
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Configurations/WebKitLegacy.xcconfig
Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h
Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Cocoa/NavigationState.mm

index 67e0bea..672c35e 100644 (file)
@@ -1,3 +1,14 @@
+2015-04-08  Sam Weinig  <sam@webkit.org>
+
+        Allow LaunchServices to handle URLs on link navigations
+        <rdar://problem/19446826>
+        https://bugs.webkit.org/show_bug.cgi?id=143544
+
+        Reviewed by Anders Carlsson.
+
+        * wtf/Platform.h:
+        Add HAVE macro for this functionality.
+
 2015-04-09  Andy Estes  <aestes@apple.com>
 
         [Cocoa] Add a HAVE(AVKIT) and use it
index ab9a665..fb26b17 100644 (file)
 #define WTF_USE_WEB_THREAD 1
 #define WTF_USE_QUICK_LOOK 1
 
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000
+#define HAVE_APP_LINKS 1
+#endif
+
 #if CPU(ARM64)
 #define ENABLE_JIT_CONSTANT_BLINDING 0
 #endif
index 83b1723..a2ff95b 100644 (file)
@@ -1,3 +1,15 @@
+2015-04-08  Sam Weinig  <sam@webkit.org>
+
+        Allow LaunchServices to handle URLs on link navigations
+        <rdar://problem/19446826>
+        https://bugs.webkit.org/show_bug.cgi?id=143544
+
+        Reviewed by Anders Carlsson.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/spi/ios/LaunchServicesSPI.h: Added.
+        Add new SPI header.
+
 2015-04-10  Bem Jones-Bey  <bjonesbe@adobe.com>
 
         Unreviewed, added CSS Shapes to features.json file.
index 2008c7d..a7db002 100644 (file)
                7C4C96DD1AD4483500365A50 /* JSReadableStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C4C96D91AD4483500365A50 /* JSReadableStream.h */; };
                7C4C96DE1AD4483500365A50 /* JSReadableStreamReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C4C96DA1AD4483500365A50 /* JSReadableStreamReader.cpp */; };
                7C4C96DF1AD4483500365A50 /* JSReadableStreamReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C4C96DB1AD4483500365A50 /* JSReadableStreamReader.h */; };
+               7C4C96E31AD44ABF00365A50 /* LaunchServicesSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C4C96E21AD44ABF00365A50 /* LaunchServicesSPI.h */; };
                7C4EDD741A7B607800198C4D /* FontCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7C4EDD731A7B607800198C4D /* FontCocoa.mm */; };
                7C522D4B15B477E8009B7C95 /* InspectorOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C522D4915B477E8009B7C95 /* InspectorOverlay.cpp */; };
                7C5343FC17B74B63004232F0 /* JSMediaQueryListListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C5343FA17B74B63004232F0 /* JSMediaQueryListListener.cpp */; };
                CE12523B1A16711000864480 /* NSFileManagerSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE12523A1A16711000864480 /* NSFileManagerSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CE12523D1A1676CD00864480 /* QuartzCoreSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE12523C1A1676CD00864480 /* QuartzCoreSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CE1252411A16B1B600864480 /* MediaPlayerSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1252401A16B1B600864480 /* MediaPlayerSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               CE1252431A16C01A00864480 /* CoreUISPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1252421A16C01A00864480 /* CoreUISPI.h */; };
+               CE1252431A16C01A00864480 /* CoreUISPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1252421A16C01A00864480 /* CoreUISPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CE1252451A16C22500864480 /* DynamicLinkerSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1252441A16C22500864480 /* DynamicLinkerSPI.h */; };
                CE1252471A16C2C200864480 /* NSPointerFunctionsSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1252461A16C2C200864480 /* NSPointerFunctionsSPI.h */; };
                CE1252491A16C3BC00864480 /* MobileGestaltSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1252481A16C3BC00864480 /* MobileGestaltSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7C4C96D91AD4483500365A50 /* JSReadableStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSReadableStream.h; sourceTree = "<group>"; };
                7C4C96DA1AD4483500365A50 /* JSReadableStreamReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSReadableStreamReader.cpp; sourceTree = "<group>"; };
                7C4C96DB1AD4483500365A50 /* JSReadableStreamReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSReadableStreamReader.h; sourceTree = "<group>"; };
+               7C4C96E21AD44ABF00365A50 /* LaunchServicesSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LaunchServicesSPI.h; path = ios/LaunchServicesSPI.h; sourceTree = "<group>"; };
                7C4EDD731A7B607800198C4D /* FontCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FontCocoa.mm; sourceTree = "<group>"; };
                7C522D4915B477E8009B7C95 /* InspectorOverlay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorOverlay.cpp; sourceTree = "<group>"; };
                7C522D4A15B478B2009B7C95 /* InspectorOverlay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorOverlay.h; sourceTree = "<group>"; };
                        children = (
                                CE1252421A16C01A00864480 /* CoreUISPI.h */,
                                CEC337AE1A46086D009B8523 /* GraphicsServicesSPI.h */,
-                               CE1252481A16C3BC00864480 /* MobileGestaltSPI.h */,
+                               7C4C96E21AD44ABF00365A50 /* LaunchServicesSPI.h */,
                                CE1252401A16B1B600864480 /* MediaPlayerSPI.h */,
-                               CE1252381A166FA000864480 /* QuickLookSPI.h */,
+                               CE1252481A16C3BC00864480 /* MobileGestaltSPI.h */,
                                6FAD4A561A9D0FAE009F7D3C /* OpenGLESSPI.h */,
+                               CE1252381A166FA000864480 /* QuickLookSPI.h */,
                        );
                        name = ios;
                        sourceTree = "<group>";
                                B2FA3DCF0AB75A6F000E5AC4 /* JSSVGPathSegLinetoAbs.h in Headers */,
                                B2FA3DD10AB75A6F000E5AC4 /* JSSVGPathSegLinetoHorizontalAbs.h in Headers */,
                                B2FA3DD30AB75A6F000E5AC4 /* JSSVGPathSegLinetoHorizontalRel.h in Headers */,
+                               7C4C96E31AD44ABF00365A50 /* LaunchServicesSPI.h in Headers */,
                                B2FA3DD50AB75A6F000E5AC4 /* JSSVGPathSegLinetoRel.h in Headers */,
                                B2FA3DD70AB75A6F000E5AC4 /* JSSVGPathSegLinetoVerticalAbs.h in Headers */,
                                B2FA3DD90AB75A6F000E5AC4 /* JSSVGPathSegLinetoVerticalRel.h in Headers */,
diff --git a/Source/WebCore/platform/spi/ios/LaunchServicesSPI.h b/Source/WebCore/platform/spi/ios/LaunchServicesSPI.h
new file mode 100644 (file)
index 0000000..0f4047b
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LaunchServicesSPI_h
+#define LaunchServicesSPI_h
+
+#import <Foundation/Foundation.h>
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000
+#import <MobileCoreServices/LSAppLinkPriv.h>
+#endif
+
+#endif
+
+typedef void (^LSAppLinkOpenCompletionHandler)(BOOL success, NSError *error);
+
+#if !USE(APPLE_INTERNAL_SDK)
+
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000
+@interface LSAppLink : NSObject <NSSecureCoding>
+@end
+
+@interface LSAppLink (Details)
++ (void)openWithURL:(NSURL *)aURL completionHandler:(LSAppLinkOpenCompletionHandler)completionHandler;
+@end
+#endif
+
+#endif
+
+#endif // LaunchServicesSPI_h
index 1be044c..4d80ed8 100644 (file)
@@ -1,3 +1,24 @@
+2015-04-08  Sam Weinig  <sam@webkit.org>
+
+        Allow LaunchServices to handle URLs on link navigations
+        <rdar://problem/19446826>
+        https://bugs.webkit.org/show_bug.cgi?id=143544
+
+        Reviewed by Anders Carlsson.
+
+        * Configurations/WebKitLegacy.xcconfig:
+        Link MobileCoreServices.
+
+        * WebCoreSupport/WebFrameLoaderClient.h:
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (shouldTryAppLink):
+        (WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction):
+        (WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction):
+        (WebFrameLoaderClient::setUpPolicyListener):
+        Only let LaunchServices have a crack at the URL if the navigation is:
+            1) a main frame navigation
+            2) a result of a user gesture
+
 2015-04-10  Alexey Proskuryakov  <ap@apple.com>
 
         Build fix.
index 8eff41f..d07d59e 100644 (file)
@@ -71,7 +71,7 @@ INSTALLHDRS_SCRIPT_PHASE = YES;
 PRODUCT_NAME = WebKitLegacy;
 UMBRELLA_FRAMEWORKS_DIR = $(PRODUCTION_FRAMEWORKS_DIR)/WebKit.framework/Versions/A/Frameworks;
 
-OTHER_LDFLAGS[sdk=iphone*] = $(inherited) -lobjc -lsqlite3 -framework CFNetwork -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework Foundation -framework GraphicsServices -framework ImageIO -framework OpenGLES -lMobileGestalt;
+OTHER_LDFLAGS[sdk=iphone*] = $(inherited) -lobjc -lsqlite3 -framework CFNetwork -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework Foundation -framework GraphicsServices -framework ImageIO -framework OpenGLES -framework MobileCoreServices -lMobileGestalt;
 OTHER_LDFLAGS[sdk=macosx*] = $(inherited) -framework Carbon -framework Cocoa -framework DiskArbitration -framework IOKit -framework OpenGL;
 
 SECTORDER_FLAGS = $(SECTORDER_FLAGS_$(CONFIGURATION));
index 3c51ded..6268b03 100644 (file)
@@ -221,7 +221,7 @@ private:
 
     virtual RemoteAXObjectRef accessibilityRemoteObject() override { return 0; }
     
-    RetainPtr<WebFramePolicyListener> setUpPolicyListener(WebCore::FramePolicyFunction);
+    RetainPtr<WebFramePolicyListener> setUpPolicyListener(WebCore::FramePolicyFunction, NSURL *appLinkURL = nil);
 
     NSDictionary *actionDictionary(const WebCore::NavigationAction&, PassRefPtr<WebCore::FormState>) const;
     
index a381e50..04917fc 100644 (file)
 #import <WebCore/RuntimeApplicationChecksIOS.h>
 #endif
 
+#if HAVE(APP_LINKS)
+#import <WebCore/LaunchServicesSPI.h>
+#import <WebCore/WebCoreThreadRun.h>
+#endif
+
 #if ENABLE(CONTENT_FILTERING)
 #import <WebCore/PolicyChecker.h>
 #endif
@@ -172,9 +177,16 @@ NSString *WebPluginContainerKey = @"WebPluginContainer";
 @interface WebFramePolicyListener : NSObject <WebPolicyDecisionListener, WebFormSubmissionListener> {
     RefPtr<Frame> _frame;
     FramePolicyFunction _policyFunction;
+#if HAVE(APP_LINKS)
+    RetainPtr<NSURL> _appLinkURL;
+#endif
 }
 
 - (id)initWithFrame:(Frame*)frame policyFunction:(FramePolicyFunction)policyFunction;
+#if HAVE(APP_LINKS)
+- (id)initWithFrame:(Frame*)frame policyFunction:(FramePolicyFunction)policyFunction appLinkURL:(NSURL *)url;
+#endif
+
 - (void)invalidate;
 
 @end
@@ -871,24 +883,45 @@ void WebFrameLoaderClient::dispatchDecidePolicyForResponse(const ResourceRespons
                                decisionListener:setUpPolicyListener(WTF::move(function)).get()];
 }
 
+
+static BOOL shouldTryAppLink(WebView *webView, const NavigationAction& action, Frame* targetFrame)
+{
+#if HAVE(APP_LINKS)
+    BOOL mainFrameNavigation = !targetFrame || targetFrame->isMainFrame();
+    if (!mainFrameNavigation)
+        return NO;
+
+    if (!action.processingUserGesture())
+        return NO;
+
+    return YES;
+#else
+    return NO;
+#endif
+}
+
 void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName, FramePolicyFunction function)
 {
     WebView *webView = getWebView(m_webFrame.get());
+    BOOL tryAppLink = shouldTryAppLink(webView, action, nullptr);
+
     [[webView _policyDelegateForwarder] webView:webView
             decidePolicyForNewWindowAction:actionDictionary(action, formState)
                                    request:request.nsURLRequest(UpdateHTTPBody)
                               newFrameName:frameName
-                          decisionListener:setUpPolicyListener(WTF::move(function)).get()];
+                          decisionListener:setUpPolicyListener(WTF::move(function), tryAppLink ? (NSURL *)request.url() : nil).get()];
 }
 
 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState, FramePolicyFunction function)
 {
     WebView *webView = getWebView(m_webFrame.get());
+    BOOL tryAppLink = shouldTryAppLink(webView, action, core(m_webFrame.get()));
+
     [[webView _policyDelegateForwarder] webView:webView
                 decidePolicyForNavigationAction:actionDictionary(action, formState)
                                         request:request.nsURLRequest(UpdateHTTPBody)
                                           frame:m_webFrame.get()
-                               decisionListener:setUpPolicyListener(WTF::move(function)).get()];
+                               decisionListener:setUpPolicyListener(WTF::move(function), tryAppLink ? (NSURL *)request.url() : nil).get()];
 }
 
 void WebFrameLoaderClient::cancelPolicyCheck()
@@ -1472,12 +1505,17 @@ void WebFrameLoaderClient::dispatchDidBecomeFrameset(bool)
 {
 }
 
-RetainPtr<WebFramePolicyListener> WebFrameLoaderClient::setUpPolicyListener(FramePolicyFunction function)
+RetainPtr<WebFramePolicyListener> WebFrameLoaderClient::setUpPolicyListener(FramePolicyFunction function, NSURL *appLinkURL)
 {
     // FIXME: <rdar://5634381> We need to support multiple active policy listeners.
     [m_policyListener invalidate];
 
-    m_policyListener = adoptNS([[WebFramePolicyListener alloc] initWithFrame:core(m_webFrame.get()) policyFunction:function]);
+#if HAVE(APP_LINKS)
+    if (appLinkURL)
+        m_policyListener = adoptNS([[WebFramePolicyListener alloc] initWithFrame:core(m_webFrame.get()) policyFunction:function appLinkURL:appLinkURL]);
+    else
+#endif
+        m_policyListener = adoptNS([[WebFramePolicyListener alloc] initWithFrame:core(m_webFrame.get()) policyFunction:function]);
 
     return m_policyListener;
 }
@@ -2271,6 +2309,19 @@ void WebFrameLoaderClient::contentFilterDidBlockLoad(WebCore::ContentFilterUnblo
     return self;
 }
 
+#if HAVE(APP_LINKS)
+- (id)initWithFrame:(Frame*)frame policyFunction:(FramePolicyFunction)policyFunction appLinkURL:(NSURL *)appLinkURL
+{
+    self = [self initWithFrame:frame policyFunction:policyFunction];
+    if (!self)
+        return nil;
+
+    _appLinkURL = appLinkURL;
+
+    return self;
+}
+#endif
+
 - (void)invalidate
 {
     _frame = nullptr;
@@ -2309,6 +2360,20 @@ void WebFrameLoaderClient::contentFilterDidBlockLoad(WebCore::ContentFilterUnblo
 
 - (void)use
 {
+#if HAVE(APP_LINKS)
+    if (_appLinkURL && _frame) {
+        [LSAppLink openWithURL:_appLinkURL.get() completionHandler:^(BOOL success, NSError *) {
+            WebThreadRun(^{
+                if (success)
+                    [self receivedPolicyDecision:PolicyIgnore];
+                else
+                    [self receivedPolicyDecision:PolicyUse];
+            });
+        }];
+        return;
+    }
+#endif
+
     [self receivedPolicyDecision:PolicyUse];
 }
 
index f7c56cf..3880d50 100644 (file)
@@ -1,3 +1,18 @@
+2015-04-08  Sam Weinig  <sam@webkit.org>
+
+        Allow LaunchServices to handle URLs on link navigations
+        <rdar://problem/19446826>
+        https://bugs.webkit.org/show_bug.cgi?id=143544
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::tryAppLink):
+        (WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):
+        Only let LaunchServices have a crack at the URL if the navigation is:
+            1) a main frame navigation
+            2) a result of a user gesture
+
 2015-04-10  Tim Horton  <timothy_horton@apple.com>
 
         Replace setFixedLayoutSizeEnabled: with an enum of layout modes
index f0c8363..0b0bd75 100644 (file)
 #import <WebCore/Credential.h>
 #import <wtf/NeverDestroyed.h>
 
+#if HAVE(APP_LINKS)
+#import <WebCore/LaunchServicesSPI.h>
+#endif
+
 #if USE(QUICK_LOOK)
 #import "QuickLookDocumentData.h"
 #endif
@@ -224,28 +228,58 @@ NavigationState::NavigationClient::~NavigationClient()
 {
 }
 
+static void tryAppLink(RefPtr<API::NavigationAction> navigationAction, std::function<void (bool)> completionHandler)
+{
+#if HAVE(APP_LINKS)
+    bool mainFrameNavigation = !navigationAction->targetFrame() || navigationAction->targetFrame()->isMainFrame();
+    bool isProcessingUserGesture = navigationAction->isProcessingUserGesture();
+    if (mainFrameNavigation && isProcessingUserGesture) {
+        auto* localCompletionHandler = new std::function<void (bool)>(WTF::move(completionHandler));
+        [LSAppLink openWithURL:navigationAction->request().url() completionHandler:[localCompletionHandler](BOOL success, NSError *) {
+            dispatch_async(dispatch_get_main_queue(), [localCompletionHandler, success] {
+                (*localCompletionHandler)(success);
+                delete localCompletionHandler;
+            });
+        }];
+        return;
+    }
+#endif
+
+    completionHandler(false);
+}
+
 void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageProxy&, API::NavigationAction& navigationAction, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData)
 {
     if (!m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionDecisionHandler) {
-        RetainPtr<NSURLRequest> nsURLRequest = adoptNS(wrapper(*API::URLRequest::create(navigationAction.request()).leakRef()));
+        RefPtr<API::NavigationAction> localNavigationAction = &navigationAction;
+        RefPtr<WebFramePolicyListenerProxy> localListener = WTF::move(listener);
 
-        if (!navigationAction.targetFrame()) {
-            listener->use();
-            return;
-        }
+        tryAppLink(localNavigationAction, [localListener, localNavigationAction] (bool followedLinkToApp) {
+            if (followedLinkToApp) {
+                localListener->ignore();
+                return;
+            }
 
-        if ([NSURLConnection canHandleRequest:nsURLRequest.get()]) {
-            listener->use();
-            return;
-        }
+            if (!localNavigationAction->targetFrame()) {
+                localListener->use();
+                return;
+            }
+
+            RetainPtr<NSURLRequest> nsURLRequest = adoptNS(wrapper(*API::URLRequest::create(localNavigationAction->request()).leakRef()));
+            if ([NSURLConnection canHandleRequest:nsURLRequest.get()]) {
+                localListener->use();
+                return;
+            }
 
 #if PLATFORM(MAC)
-        // A file URL shouldn't fall through to here, but if it did,
-        // it would be a security risk to open it.
-        if (![[nsURLRequest URL] isFileURL])
-            [[NSWorkspace sharedWorkspace] openURL:[nsURLRequest URL]];
+            // A file URL shouldn't fall through to here, but if it did,
+            // it would be a security risk to open it.
+            if (![[nsURLRequest URL] isFileURL])
+                [[NSWorkspace sharedWorkspace] openURL:[nsURLRequest URL]];
 #endif
-        listener->ignore();
+            localListener->ignore();
+        });
+
         return;
     }
 
@@ -253,14 +287,23 @@ void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
     if (!navigationDelegate)
         return;
 
+    RefPtr<API::NavigationAction> localNavigationAction = &navigationAction;
     RefPtr<WebFramePolicyListenerProxy> localListener = WTF::move(listener);
     RefPtr<CompletionHandlerCallChecker> checker = CompletionHandlerCallChecker::create(navigationDelegate.get(), @selector(webView:decidePolicyForNavigationAction:decisionHandler:));
-    [navigationDelegate webView:m_navigationState.m_webView decidePolicyForNavigationAction:wrapper(navigationAction) decisionHandler:[localListener, checker](WKNavigationActionPolicy actionPolicy) {
+    [navigationDelegate webView:m_navigationState.m_webView decidePolicyForNavigationAction:wrapper(navigationAction) decisionHandler:[localListener, localNavigationAction, checker](WKNavigationActionPolicy actionPolicy) {
         checker->didCallCompletionHandler();
 
         switch (actionPolicy) {
         case WKNavigationActionPolicyAllow:
-            localListener->use();
+            tryAppLink(localNavigationAction, [localListener](bool followedLinkToApp) {
+                if (followedLinkToApp) {
+                    localListener->ignore();
+                    return;
+                }
+
+                localListener->use();
+            });
+        
             break;
 
         case WKNavigationActionPolicyCancel: