Allow clients to opt-out of default app link link actions
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Jul 2015 22:58:13 +0000 (22:58 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Jul 2015 22:58:13 +0000 (22:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146883
<rdar://problem/21221902>

Reviewed by Dan Bernstein.

* UIProcess/API/APIUIClient.h:
(API::UIClient::shouldIncludeAppLinkActionsForElement):
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::shouldIncludeAppLinkActionsForElement):
Plumbing for a new delegate message to ask the client if they
would like app link actions or not. Default is yes.

* UIProcess/ios/WKActionSheetAssistant.h:
* UIProcess/ios/WKActionSheetAssistant.mm:
(-[WKActionSheetAssistant showImageSheet]):
(-[WKActionSheetAssistant showLinkSheet]):
(-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
(-[WKActionSheetAssistant defaultActionsForImageSheet:]):
Pass elementInfo into methods generating default actions.

(-[WKActionSheetAssistant _appendOpenActionsForURL:actions:elementInfo:]):
When generating open actions, if the process has AppLink capabilities
ask the client if they want to include AppLink actions or fall back
to the basic Open action.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView actionSheetAssistant:shouldIncludeAppLinkActionsForElement:]):
(-[WKContentView previewViewControllerForPosition:inSourceView:]):
* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView actionSheetAssistant:shouldIncludeAppLinkActionsForElement:]):
Assistant delegate implementations forward to the UIDelegate.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/APIUIClient.h
Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit2/UIProcess/Cocoa/UIDelegate.h
Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h
Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit2/UIProcess/ios/WKPDFView.mm

index 96da940..c536343 100644 (file)
@@ -1,5 +1,43 @@
 2015-07-11  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Allow clients to opt-out of default app link link actions
+        https://bugs.webkit.org/show_bug.cgi?id=146883
+        <rdar://problem/21221902>
+
+        Reviewed by Dan Bernstein.
+
+        * UIProcess/API/APIUIClient.h:
+        (API::UIClient::shouldIncludeAppLinkActionsForElement):
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::setDelegate):
+        (WebKit::UIDelegate::UIClient::shouldIncludeAppLinkActionsForElement):
+        Plumbing for a new delegate message to ask the client if they
+        would like app link actions or not. Default is yes.
+
+        * UIProcess/ios/WKActionSheetAssistant.h:
+        * UIProcess/ios/WKActionSheetAssistant.mm:
+        (-[WKActionSheetAssistant showImageSheet]):
+        (-[WKActionSheetAssistant showLinkSheet]):
+        (-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
+        (-[WKActionSheetAssistant defaultActionsForImageSheet:]):
+        Pass elementInfo into methods generating default actions.
+        
+        (-[WKActionSheetAssistant _appendOpenActionsForURL:actions:elementInfo:]):
+        When generating open actions, if the process has AppLink capabilities
+        ask the client if they want to include AppLink actions or fall back
+        to the basic Open action.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView actionSheetAssistant:shouldIncludeAppLinkActionsForElement:]):
+        (-[WKContentView previewViewControllerForPosition:inSourceView:]):
+        * UIProcess/ios/WKPDFView.mm:
+        (-[WKPDFView actionSheetAssistant:shouldIncludeAppLinkActionsForElement:]):
+        Assistant delegate implementations forward to the UIDelegate.
+
+2015-07-11  Joseph Pecoraro  <pecoraro@apple.com>
+
         Update default link action sheets for app links
         https://bugs.webkit.org/show_bug.cgi?id=146658
         <rdar://problem/21221902>
index c21340a..d62f2da 100644 (file)
@@ -159,6 +159,9 @@ public:
 #endif
 
 #if PLATFORM(IOS)
+#if HAVE(APP_LINKS)
+    virtual bool shouldIncludeAppLinkActionsForElement(_WKActivatedElementInfo *) { return true; }
+#endif
     virtual RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) { return WTF::move(defaultActions); }
     virtual void didNotHandleTapAsClick(const WebCore::IntPoint&) { }
 #endif
index d16f98b..9392c3b 100644 (file)
@@ -55,6 +55,7 @@ struct UIEdgeInsets;
 - (void)_webViewDidExitFullscreen:(WKWebView *)webView WK_AVAILABLE(WK_MAC_TBA, 8_3);
 
 #if TARGET_OS_IPHONE
+- (BOOL)_webView:(WKWebView *)webView shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element WK_AVAILABLE(NA, WK_IOS_TBA);
 - (NSArray *)_webView:(WKWebView *)webView actionsForElement:(_WKActivatedElementInfo *)element defaultActions:(NSArray *)defaultActions;
 - (void)_webView:(WKWebView *)webView didNotHandleTapAsClickAtPoint:(CGPoint)point;
 - (BOOL)_webView:(WKWebView *)webView shouldRequestGeolocationAuthorizationForURL:(NSURL *)url isMainFrame:(BOOL)isMainFrame mainFrameURL:(NSURL *)mainFrameURL;
index 6f4ad67..fe1dd96 100644 (file)
@@ -69,10 +69,13 @@ private:
         virtual void exceededDatabaseQuota(WebPageProxy*, WebFrameProxy*, API::SecurityOrigin*, const WTF::String& databaseName, const WTF::String& displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentUsage, unsigned long long expectedUsage, std::function<void (unsigned long long)>) override;
         virtual void reachedApplicationCacheOriginQuota(WebPageProxy*, const WebCore::SecurityOrigin&, uint64_t currentQuota, uint64_t totalBytesNeeded, std::function<void (unsigned long long)> completionHandler) override;
         virtual void printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) override;
-    #if PLATFORM(IOS)
+#if PLATFORM(IOS)
+#if HAVE(APP_LINKS)
+        virtual bool shouldIncludeAppLinkActionsForElement(_WKActivatedElementInfo *) override;
+#endif
         virtual RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) override;
         virtual void didNotHandleTapAsClick(const WebCore::IntPoint&) override;
-    #endif
+#endif
 
         UIDelegate& m_uiDelegate;
     };
@@ -94,6 +97,9 @@ private:
         bool webViewDidEnterFullscreen : 1;
         bool webViewDidExitFullscreen : 1;
 #if PLATFORM(IOS)
+#if HAVE(APP_LINKS)
+        bool webViewShouldIncludeAppLinkActionsForElement : 1;
+#endif
         bool webViewActionsForElementDefaultActions : 1;
         bool webViewDidNotHandleTapAsClickAtPoint : 1;
 #endif
index e5b3c7f..78a5f0f 100644 (file)
@@ -78,6 +78,9 @@ void UIDelegate::setDelegate(id <WKUIDelegate> delegate)
     m_delegateMethods.webViewDidEnterFullscreen = [delegate respondsToSelector:@selector(_webViewDidEnterFullscreen:)];
     m_delegateMethods.webViewDidExitFullscreen = [delegate respondsToSelector:@selector(_webViewDidExitFullscreen:)];
 #if PLATFORM(IOS)
+#if HAVE(APP_LINKS)
+    m_delegateMethods.webViewShouldIncludeAppLinkActionsForElement = [delegate respondsToSelector:@selector(_webView:shouldIncludeAppLinkActionsForElement:)];
+#endif
     m_delegateMethods.webViewActionsForElementDefaultActions = [delegate respondsToSelector:@selector(_webView:actionsForElement:defaultActions:)];
     m_delegateMethods.webViewDidNotHandleTapAsClickAtPoint = [delegate respondsToSelector:@selector(_webView:didNotHandleTapAsClickAtPoint:)];
 #endif
@@ -293,6 +296,20 @@ void UIDelegate::UIClient::didExitFullscreen(WebKit::WebPageProxy*)
 }
     
 #if PLATFORM(IOS)
+#if HAVE(APP_LINKS)
+bool UIDelegate::UIClient::shouldIncludeAppLinkActionsForElement(_WKActivatedElementInfo *elementInfo)
+{
+    if (!m_uiDelegate.m_delegateMethods.webViewShouldIncludeAppLinkActionsForElement)
+        return true;
+
+    auto delegate = m_uiDelegate.m_delegate.get();
+    if (!delegate)
+        return true;
+
+    return [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView shouldIncludeAppLinkActionsForElement:elementInfo];
+}
+#endif
+
 RetainPtr<NSArray> UIDelegate::UIClient::actionsForElement(_WKActivatedElementInfo *elementInfo, RetainPtr<NSArray> defaultActions)
 {
     if (!m_uiDelegate.m_delegateMethods.webViewActionsForElementDefaultActions)
index 93b0496..5ae713c 100644 (file)
@@ -45,6 +45,9 @@ struct InteractionInformationAtPosition;
 - (const WebKit::InteractionInformationAtPosition&)positionInformationForActionSheetAssistant:(WKActionSheetAssistant *)assistant;
 - (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant performAction:(WebKit::SheetAction)action;
 - (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant openElementAtLocation:(CGPoint)location;
+#if HAVE(APP_LINKS)
+- (BOOL)actionSheetAssistant:(WKActionSheetAssistant *)assistant shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element;
+#endif
 - (RetainPtr<NSArray>)actionSheetAssistant:(WKActionSheetAssistant *)assistant decideActionsForElement:(_WKActivatedElementInfo *)element defaultActions:(RetainPtr<NSArray>)defaultActions;
 
 @optional
@@ -62,8 +65,8 @@ struct InteractionInformationAtPosition;
 - (void)showDataDetectorsSheet;
 - (void)cleanupSheet;
 - (void)updateSheetPosition;
-- (RetainPtr<NSArray>)defaultActionsForLinkSheet;
-- (RetainPtr<NSArray>)defaultActionsForImageSheet;
+- (RetainPtr<NSArray>)defaultActionsForLinkSheet:(_WKActivatedElementInfo *)elementInfo;
+- (RetainPtr<NSArray>)defaultActionsForImageSheet:(_WKActivatedElementInfo *)elementInfo;
 @end
 
 #endif // PLATFORM(IOS)
index 2e5b73c..935424f 100644 (file)
@@ -273,8 +273,8 @@ static LSAppLink *appLinkForURL(NSURL *url)
     const auto& positionInformation = [delegate positionInformationForActionSheetAssistant:self];
 
     NSURL *targetURL = [NSURL _web_URLWithWTFString:positionInformation.url];
-    auto defaultActions = [self defaultActionsForImageSheet];
     auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds image:positionInformation.image.get()]);
+    auto defaultActions = [self defaultActionsForImageSheet:elementInfo.get()];
 
     RetainPtr<NSArray> actions = [delegate actionSheetAssistant:self decideActionsForElement:elementInfo.get() defaultActions:WTF::move(defaultActions)];
 
@@ -291,10 +291,11 @@ static LSAppLink *appLinkForURL(NSURL *url)
         [self cleanupSheet];
 }
 
-- (void)_appendOpenActionsForURL:(NSURL *)url actions:(NSMutableArray *)defaultActions
+- (void)_appendOpenActionsForURL:(NSURL *)url actions:(NSMutableArray *)defaultActions elementInfo:(_WKActivatedElementInfo *)elementInfo
 {
 #if HAVE(APP_LINKS)
-    if (applicationHasAppLinkEntitlements()) {
+    ASSERT(_delegate);
+    if (applicationHasAppLinkEntitlements() && [_delegate.get() actionSheetAssistant:self shouldIncludeAppLinkActionsForElement:elementInfo]) {
         LSAppLink *appLink = appLinkForURL(url);
         if (appLink) {
             NSString *title = WEB_UI_STRING("Open in Safari", "Title for Open in Safari Link action button");
@@ -320,7 +321,7 @@ static LSAppLink *appLinkForURL(NSURL *url)
 #endif
 }
 
-- (RetainPtr<NSArray>)defaultActionsForLinkSheet
+- (RetainPtr<NSArray>)defaultActionsForLinkSheet:(_WKActivatedElementInfo *)elementInfo
 {
     auto delegate = _delegate.get();
     if (!delegate)
@@ -333,7 +334,7 @@ static LSAppLink *appLinkForURL(NSURL *url)
         return nil;
 
     auto defaultActions = adoptNS([[NSMutableArray alloc] init]);
-    [self _appendOpenActionsForURL:targetURL actions:defaultActions.get()];
+    [self _appendOpenActionsForURL:targetURL actions:defaultActions.get() elementInfo:elementInfo];
 
 #if HAVE(SAFARI_SERVICES_FRAMEWORK)
     if ([getSSReadingListClass() supportsURL:targetURL])
@@ -345,7 +346,7 @@ static LSAppLink *appLinkForURL(NSURL *url)
     return defaultActions;
 }
 
-- (RetainPtr<NSArray>)defaultActionsForImageSheet
+- (RetainPtr<NSArray>)defaultActionsForImageSheet:(_WKActivatedElementInfo *)elementInfo
 {
     auto delegate = _delegate.get();
     if (!delegate)
@@ -356,7 +357,7 @@ static LSAppLink *appLinkForURL(NSURL *url)
 
     auto defaultActions = adoptNS([[NSMutableArray alloc] init]);
     if (!positionInformation.url.isEmpty())
-        [self _appendOpenActionsForURL:targetURL actions:defaultActions.get()];
+        [self _appendOpenActionsForURL:targetURL actions:defaultActions.get() elementInfo:elementInfo];
 
 #if HAVE(SAFARI_SERVICES_FRAMEWORK)
     if ([getSSReadingListClass() supportsURL:targetURL])
@@ -385,9 +386,8 @@ static LSAppLink *appLinkForURL(NSURL *url)
     if (!targetURL)
         return;
 
-    auto defaultActions = [self defaultActionsForLinkSheet];
-    RetainPtr<_WKActivatedElementInfo> elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeLink
-        URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds image:positionInformation.image.get()]);
+    auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeLink URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds image:positionInformation.image.get()]);
+    auto defaultActions = [self defaultActionsForLinkSheet:elementInfo.get()];
 
     RetainPtr<NSArray> actions = [delegate actionSheetAssistant:self decideActionsForElement:elementInfo.get() defaultActions:WTF::move(defaultActions)];
 
index e7d250c..5769773 100644 (file)
@@ -3152,6 +3152,13 @@ static bool isAssistableInputType(InputType type)
     [self _attemptClickAtLocation:location];
 }
 
+#if HAVE(APP_LINKS)
+- (BOOL)actionSheetAssistant:(WKActionSheetAssistant *)assistant shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element
+{
+    return _page->uiClient().shouldIncludeAppLinkActionsForElement(element);
+}
+#endif
+
 - (RetainPtr<NSArray>)actionSheetAssistant:(WKActionSheetAssistant *)assistant decideActionsForElement:(_WKActivatedElementInfo *)element defaultActions:(RetainPtr<NSArray>)defaultActions
 {
     return _page->uiClient().actionsForElement(element, WTF::move(defaultActions));
@@ -3215,7 +3222,7 @@ static bool isAssistableInputType(InputType type)
             _highlightLongPressCanClick = NO;
             RetainPtr<_WKActivatedElementInfo> elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeLink URL:targetURL location:_positionInformation.point title:_positionInformation.title rect:_positionInformation.bounds image:_positionInformation.image.get()]);
             _page->startInteractionWithElementAtPosition(_positionInformation.point);
-            return [uiDelegate _webView:_webView previewViewControllerForURL:targetURL defaultActions:[_actionSheetAssistant defaultActionsForLinkSheet].get() elementInfo:elementInfo.get()];
+            return [uiDelegate _webView:_webView previewViewControllerForURL:targetURL defaultActions:[_actionSheetAssistant defaultActionsForLinkSheet:elementInfo.get()].get() elementInfo:elementInfo.get()];
         }
 
         if ([uiDelegate respondsToSelector:@selector(_webView:previewViewControllerForURL:)]) {
@@ -3245,7 +3252,7 @@ static bool isAssistableInputType(InputType type)
             [uiDelegate _webView:_webView willPreviewImageWithURL:targetURL];
         RetainPtr<_WKActivatedElementInfo> elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage URL:targetURL location:_positionInformation.point title:_positionInformation.title rect:_positionInformation.bounds image:_positionInformation.image.get()]);
         _page->startInteractionWithElementAtPosition(_positionInformation.point);
-        return [[[WKImagePreviewViewController alloc] initWithCGImage:_positionInformation.image->makeCGImageCopy() defaultActions:[_actionSheetAssistant defaultActionsForImageSheet] elementInfo:elementInfo] autorelease];
+        return [[[WKImagePreviewViewController alloc] initWithCGImage:_positionInformation.image->makeCGImageCopy() defaultActions:[_actionSheetAssistant defaultActionsForImageSheet:elementInfo.get()] elementInfo:elementInfo] autorelease];
     }
 
     return nil;
index 79cb23c..e8d8cc0 100644 (file)
@@ -718,6 +718,13 @@ static NSStringCompareOptions stringCompareOptions(_WKFindOptions options)
     _webView->_page->navigateToPDFLinkWithSimulatedClick(_positionInformation.url, roundedIntPoint(location), roundedIntPoint(screenPoint));
 }
 
+#if HAVE(APP_LINKS)
+- (BOOL)actionSheetAssistant:(WKActionSheetAssistant *)assistant shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element
+{
+    return _webView->_page->uiClient().shouldIncludeAppLinkActionsForElement(element);
+}
+#endif
+
 - (RetainPtr<NSArray>)actionSheetAssistant:(WKActionSheetAssistant *)assistant decideActionsForElement:(_WKActivatedElementInfo *)element defaultActions:(RetainPtr<NSArray>)defaultActions
 {
     return _webView->_page->uiClient().actionsForElement(element, WTF::move(defaultActions));