Populate alternate URL for _WKActivatedElementInfo in UIContextMenu SPI.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Aug 2019 21:14:56 +0000 (21:14 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Aug 2019 21:14:56 +0000 (21:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=201165.
rdar://problem/54729648.

Patch by James Savage <james.savage@apple.com> on 2019-08-27
Reviewed by Dean Jackson.

* UIProcess/API/APIContextMenuElementInfo.h:
* UIProcess/API/APIContextMenuElementInfo.cpp:
(API::ContextMenuElementInfo::ContextMenuElementInfo): Initialize new memeber.

* UIProcess/API/Cocoa/WKContextMenuElementInfo.mm:
(-[WKContextMenuElementInfo _activatedElementInfo]): Use new initializer.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _requestActivatedElementAtPosition:completionBlock:]): Ditto.

* UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h:
* UIProcess/API/Cocoa/_WKActivatedElementInfo.mm:
(+[_WKActivatedElementInfo activatedElementInfoWithInteractionInformationAtPosition:userInfo:]):
    Ditto.
(-[_WKActivatedElementInfo _initWithInteractionInformationAtPosition:userInfo:]): Set new ivar.
(+[_WKActivatedElementInfo activatedElementInfoWithInteractionInformationAtPosition:]): Deleted.
(-[_WKActivatedElementInfo _initWithInteractionInformationAtPosition:]): Deleted.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView assignLegacyDataForContextMenuInteraction]): Use new initializer.
(-[WKContentView continueContextMenuInteraction:]): If the context menu is being generated for
    an image, and we do not have a URL associated with the position information, try to
    generate one using existing SPI. This change also passes through the userInfo via a new
    property on _WKActivatedElementInfo. We only do this for the SPI version of this delegate
    method, because the API is not called for image previews.
(-[WKContentView _contextMenuInteraction:overrideSuggestedActionsForConfiguration:]): Use new
    initializer.

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/APIContextMenuElementInfo.cpp
Source/WebKit/UIProcess/API/APIContextMenuElementInfo.h
Source/WebKit/UIProcess/API/Cocoa/WKContextMenuElementInfo.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm
Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

index 835dd1c..610297a 100644 (file)
@@ -1,3 +1,39 @@
+2019-08-27  James Savage  <james.savage@apple.com>
+
+        Populate alternate URL for _WKActivatedElementInfo in UIContextMenu SPI.
+        https://bugs.webkit.org/show_bug.cgi?id=201165.
+        rdar://problem/54729648.
+
+        Reviewed by Dean Jackson.
+
+        * UIProcess/API/APIContextMenuElementInfo.h:
+        * UIProcess/API/APIContextMenuElementInfo.cpp:
+        (API::ContextMenuElementInfo::ContextMenuElementInfo): Initialize new memeber.
+
+        * UIProcess/API/Cocoa/WKContextMenuElementInfo.mm:
+        (-[WKContextMenuElementInfo _activatedElementInfo]): Use new initializer.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _requestActivatedElementAtPosition:completionBlock:]): Ditto.
+
+        * UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h:
+        * UIProcess/API/Cocoa/_WKActivatedElementInfo.mm:
+        (+[_WKActivatedElementInfo activatedElementInfoWithInteractionInformationAtPosition:userInfo:]):
+            Ditto.
+        (-[_WKActivatedElementInfo _initWithInteractionInformationAtPosition:userInfo:]): Set new ivar.
+        (+[_WKActivatedElementInfo activatedElementInfoWithInteractionInformationAtPosition:]): Deleted.
+        (-[_WKActivatedElementInfo _initWithInteractionInformationAtPosition:]): Deleted.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView assignLegacyDataForContextMenuInteraction]): Use new initializer.
+        (-[WKContentView continueContextMenuInteraction:]): If the context menu is being generated for
+            an image, and we do not have a URL associated with the position information, try to
+            generate one using existing SPI. This change also passes through the userInfo via a new
+            property on _WKActivatedElementInfo. We only do this for the SPI version of this delegate
+            method, because the API is not called for image previews.
+        (-[WKContentView _contextMenuInteraction:overrideSuggestedActionsForConfiguration:]): Use new
+            initializer.
+
 2019-08-27  Basuke Suzuki  <Basuke.Suzuki@sony.com>
 
         [RemoteInspector][Socket] Restructuring the components of Socket implementation
index 0c092e6..46bd991 100644 (file)
@@ -32,6 +32,13 @@ namespace API {
 
 ContextMenuElementInfo::ContextMenuElementInfo(const WebKit::InteractionInformationAtPosition& info)
     : m_interactionInformation(info)
+    , m_userInfo(nullptr)
+{
+}
+
+ContextMenuElementInfo::ContextMenuElementInfo(const WebKit::InteractionInformationAtPosition& info, NSDictionary *userInfo)
+    : m_interactionInformation(info)
+    , m_userInfo(userInfo)
 {
 }
 
index 3488ec5..edd1bfe 100644 (file)
@@ -43,10 +43,14 @@ public:
 
     const WebKit::InteractionInformationAtPosition& interactionInformation() const { return m_interactionInformation; }
 
+    const RetainPtr<NSDictionary> userInfo() const { return m_userInfo; }
+
 private:
     ContextMenuElementInfo(const WebKit::InteractionInformationAtPosition&);
+    ContextMenuElementInfo(const WebKit::InteractionInformationAtPosition&, NSDictionary *);
     
     WebKit::InteractionInformationAtPosition m_interactionInformation;
+    RetainPtr<NSDictionary> m_userInfo;
 };
 
 } // namespace API
index 730d068..21698b7 100644 (file)
@@ -48,7 +48,7 @@
 
 - (_WKActivatedElementInfo *)_activatedElementInfo
 {
-    return [_WKActivatedElementInfo activatedElementInfoWithInteractionInformationAtPosition:_elementInfo->interactionInformation()];
+    return [_WKActivatedElementInfo activatedElementInfoWithInteractionInformationAtPosition:_elementInfo->interactionInformation() userInfo:_elementInfo->userInfo().get()];
 }
 
 @end
index 4b4297f..5f44114 100644 (file)
@@ -6739,7 +6739,7 @@ static WebCore::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(UISe
     infoRequest.includeSnapshot = true;
 
     [_contentView doAfterPositionInformationUpdate:[capturedBlock = makeBlockPtr(block)] (WebKit::InteractionInformationAtPosition information) {
-        capturedBlock([_WKActivatedElementInfo activatedElementInfoWithInteractionInformationAtPosition:information]);
+        capturedBlock([_WKActivatedElementInfo activatedElementInfoWithInteractionInformationAtPosition:information userInfo:nil]);
     } forRequest:infoRequest];
 }
 
index 53321bb..9f39054 100644 (file)
 }
 
 #if PLATFORM(IOS_FAMILY)
-+ (instancetype)activatedElementInfoWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information
++ (instancetype)activatedElementInfoWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information userInfo:(NSDictionary *)userInfo
 {
-    return [[[self alloc] _initWithInteractionInformationAtPosition:information] autorelease];
+    return [[[self alloc] _initWithInteractionInformationAtPosition:information userInfo:userInfo] autorelease];
 }
 
-- (instancetype)_initWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information
+- (instancetype)_initWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information userInfo:(NSDictionary *)userInfo
 {
     if (!(self = [super init]))
         return nil;
@@ -83,6 +83,8 @@
     _image = information.image;
     _ID = information.idAttribute;
     _animatedImage = information.isAnimatedImage;
+
+    _userInfo = userInfo;
     
     return self;
 }
index ae57bb3..0799566 100644 (file)
@@ -37,8 +37,8 @@ namespace WebKit {
 @interface _WKActivatedElementInfo ()
 
 #if PLATFORM(IOS_FAMILY)
-+ (instancetype)activatedElementInfoWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information;
-- (instancetype)_initWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information;
++ (instancetype)activatedElementInfoWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information userInfo:(NSDictionary *)userInfo;
+- (instancetype)_initWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information userInfo:(NSDictionary *)userInfo;
 #endif
 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url imageURL:(NSURL *)imageURL location:(const WebCore::IntPoint&)location title:(NSString *)title ID:(NSString *)ID rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image;
 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url imageURL:(NSURL *)imageURL location:(const WebCore::IntPoint&)location title:(NSString *)title ID:(NSString *)ID rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image userInfo:(NSDictionary *)userInfo;
index 176bbe3..e4485a9 100644 (file)
@@ -45,6 +45,7 @@
 #import "VersionChecks.h"
 #import "WKActionSheetAssistant.h"
 #import "WKContextMenuElementInfoInternal.h"
+#import "WKContextMenuElementInfoPrivate.h"
 #import "WKDatePickerViewController.h"
 #import "WKDrawingCoordinator.h"
 #import "WKError.h"
@@ -7870,7 +7871,7 @@ static UIMenu *menuWithShowLinkPreviewAction(UIMenu *originalMenu)
 
     UIViewController *previewViewController = nil;
 
-    auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithInteractionInformationAtPosition:_positionInformation]);
+    auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithInteractionInformationAtPosition:_positionInformation userInfo:nil]);
 
     if (_positionInformation.isLink) {
         _longPressCanClick = NO;
@@ -8073,7 +8074,7 @@ static UIMenu *menuWithShowLinkPreviewAction(UIMenu *originalMenu)
 
             strongSelf->_contextMenuActionProviderDelegateNeedsOverride = NO;
 
-            auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithInteractionInformationAtPosition:strongSelf->_positionInformation]);
+            auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithInteractionInformationAtPosition:strongSelf->_positionInformation userInfo:nil]);
 
             UIContextMenuActionProvider actionMenuProvider = [weakSelf, elementInfo] (NSArray<UIMenuElement *> *) -> UIMenu * {
                 auto strongSelf = weakSelf.get();
@@ -8117,8 +8118,16 @@ static UIMenu *menuWithShowLinkPreviewAction(UIMenu *originalMenu)
     });
 
     _contextMenuActionProviderDelegateNeedsOverride = NO;
-    _contextMenuElementInfo = wrapper(API::ContextMenuElementInfo::create(_positionInformation));
+    _contextMenuElementInfo = wrapper(API::ContextMenuElementInfo::create(_positionInformation, nil));
     if ([uiDelegate respondsToSelector:@selector(_webView:contextMenuConfigurationForElement:completionHandler:)]) {
+        if (_positionInformation.isImage && _positionInformation.url.isNull() && [uiDelegate respondsToSelector:@selector(_webView:alternateURLFromImage:userInfo:)]) {
+            UIImage *uiImage = [[_contextMenuElementInfo _activatedElementInfo] image];
+            NSDictionary *userInfo = nil;
+            NSURL *nsURL = [uiDelegate _webView:_webView alternateURLFromImage:uiImage userInfo:&userInfo];
+            _positionInformation.url = nsURL;
+            _contextMenuElementInfo = wrapper(API::ContextMenuElementInfo::create(_positionInformation, userInfo));
+        }
+
         auto checker = WebKit::CompletionHandlerCallChecker::create(uiDelegate, @selector(_webView:contextMenuConfigurationForElement:completionHandler:));
         [uiDelegate _webView:_webView contextMenuConfigurationForElement:_contextMenuElementInfo.get() completionHandler:makeBlockPtr([completionBlock = WTFMove(completionBlock), checker = WTFMove(checker)] (UIContextMenuConfiguration *configuration) {
             if (checker->completionHandlerHasBeenCalled())
@@ -8161,7 +8170,7 @@ static UIMenu *menuWithShowLinkPreviewAction(UIMenu *originalMenu)
 - (NSArray<UIMenuElement *> *)_contextMenuInteraction:(UIContextMenuInteraction *)interaction overrideSuggestedActionsForConfiguration:(UIContextMenuConfiguration *)configuration
 {
     if (_contextMenuActionProviderDelegateNeedsOverride) {
-        auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithInteractionInformationAtPosition:_positionInformation]);
+        auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithInteractionInformationAtPosition:_positionInformation userInfo:nil]);
         RetainPtr<NSArray<_WKElementAction *>> defaultActionsFromAssistant = _positionInformation.isLink ? [_actionSheetAssistant defaultActionsForLinkSheet:elementInfo.get()] : [_actionSheetAssistant defaultActionsForImageSheet:elementInfo.get()];
         return menuElementsFromDefaultActions(defaultActionsFromAssistant, elementInfo);
     }