Changeset 247326 in webkit


Ignore:
Timestamp:
Jul 10, 2019 1:40:05 PM (5 years ago)
Author:
dino@apple.com
Message:

Share or Copy image from context menu does not share the correct data
https://bugs.webkit.org/show_bug.cgi?id=199681
<rdar://problem/50538771>

Reviewed by Tim Horton.

The UIContextMenuInteraction calls didEndInteraction before executing the
actions of a selected menu item. This means we were assuming the interaction
had finished before performing the action triggered in the interaction, ending
up in the state where we had forgotten which element we were working with.

Rather than ask for UIKit to change, I'm just starting the interaction again
as the action is run. Thankfully we already had the location of the interaction.
There is a small risk that the page has changed in the meantime, but I'm not
sure what to do about that.

While here, I moved a method only used by us into _WKElementActionInternal,
and changed the location stored by _WKActivatedElementInfo from a CGPoint
to an WebCore::IntPoint (since it doesn't escape WebKit).

  • UIProcess/API/Cocoa/_WKActivatedElementInfo.mm: Use a WebCore::IntPoint rather than a CGPoint.

(-[_WKActivatedElementInfo _initWithType:URL:imageURL:location:title:ID:rect:image:]):
(-[_WKActivatedElementInfo _initWithType:URL:imageURL:location:title:ID:rect:image:userInfo:]):
(-[_WKActivatedElementInfo _interactionLocation]):

  • UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h:
  • UIProcess/API/Cocoa/_WKElementAction.h: Move uiActionForElementInfo to Internal.
  • UIProcess/API/Cocoa/_WKElementActionInternal.h:
  • UIProcess/API/Cocoa/_WKElementAction.mm: When executing the handlers, restart the interaction

using the location in _WKActivatedElementInfo.
(+[_WKElementAction _elementActionWithType:customTitle:assistant:]):

  • UIProcess/ios/WKContentViewInteraction.mm: Explicitly start and stop interactions at

the appropriate points in the UIContextMenu flow. This isn't really needed since we're
doing it in the handlers, but it will be correct if the UIKit delegate order changes.
(-[WKContentView continueContextMenuInteraction:]):
(-[WKContentView contextMenuInteractionDidEnd:]):

Location:
trunk/Source/WebKit
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r247322 r247326  
     12019-07-10  Dean Jackson  <dino@apple.com>
     2
     3        Share or Copy image from context menu does not share the correct data
     4        https://bugs.webkit.org/show_bug.cgi?id=199681
     5        <rdar://problem/50538771>
     6
     7        Reviewed by Tim Horton.
     8
     9        The UIContextMenuInteraction calls didEndInteraction before executing the
     10        actions of a selected menu item. This means we were assuming the interaction
     11        had finished before performing the action triggered in the interaction, ending
     12        up in the state where we had forgotten which element we were working with.
     13
     14        Rather than ask for UIKit to change, I'm just starting the interaction again
     15        as the action is run. Thankfully we already had the location of the interaction.
     16        There is a small risk that the page has changed in the meantime, but I'm not
     17        sure what to do about that.
     18
     19        While here, I moved a method only used by us into _WKElementActionInternal,
     20        and changed the location stored by _WKActivatedElementInfo from a CGPoint
     21        to an WebCore::IntPoint (since it doesn't escape WebKit).
     22
     23        * UIProcess/API/Cocoa/_WKActivatedElementInfo.mm: Use a WebCore::IntPoint rather than a CGPoint.
     24        (-[_WKActivatedElementInfo _initWithType:URL:imageURL:location:title:ID:rect:image:]):
     25        (-[_WKActivatedElementInfo _initWithType:URL:imageURL:location:title:ID:rect:image:userInfo:]):
     26        (-[_WKActivatedElementInfo _interactionLocation]):
     27        * UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h:
     28
     29        * UIProcess/API/Cocoa/_WKElementAction.h: Move uiActionForElementInfo to Internal.
     30        * UIProcess/API/Cocoa/_WKElementActionInternal.h:
     31
     32        * UIProcess/API/Cocoa/_WKElementAction.mm: When executing the handlers, restart the interaction
     33        using the location in _WKActivatedElementInfo.
     34        (+[_WKElementAction _elementActionWithType:customTitle:assistant:]):
     35
     36        * UIProcess/ios/WKContentViewInteraction.mm: Explicitly start and stop interactions at
     37        the appropriate points in the UIContextMenu flow. This isn't really needed since we're
     38        doing it in the handlers, but it will be correct if the UIKit delegate order changes.
     39        (-[WKContentView continueContextMenuInteraction:]):
     40        (-[WKContentView contextMenuInteractionDidEnd:]):
     41
    1422019-07-10  Chris Dumez  <cdumez@apple.com>
    243
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm

    r246224 r247326  
    4242    RetainPtr<NSURL> _imageURL;
    4343    RetainPtr<NSString> _title;
    44     CGPoint _interactionLocation;
     44    WebCore::IntPoint _interactionLocation;
    4545    RetainPtr<NSString> _ID;
    4646    RefPtr<WebKit::ShareableBitmap> _image;
     
    8989#endif
    9090
    91 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url imageURL:(NSURL *)imageURL location:(CGPoint)location title:(NSString *)title ID:(NSString *)ID rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image
     91- (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
    9292{
    9393    return [self _initWithType:type URL:url imageURL:imageURL location:location title:title ID:ID rect:rect image:image userInfo:nil];
    9494}
    9595
    96 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url imageURL:(NSURL *)imageURL location:(CGPoint)location title:(NSString *)title ID:(NSString *)ID rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image userInfo:(NSDictionary *)userInfo
     96- (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
    9797{
    9898    if (!(self = [super init]))
     
    134134}
    135135
    136 - (CGPoint)_interactionLocation
     136- (WebCore::IntPoint)_interactionLocation
    137137{
    138138    return _interactionLocation;
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h

    r244368 r247326  
    2929#import "_WKActivatedElementInfo.h"
    3030
     31#import <WebCore/IntPoint.h>
     32
    3133namespace WebKit {
    3234    class ShareableBitmap;
     
    3941- (instancetype)_initWithInteractionInformationAtPosition:(const WebKit::InteractionInformationAtPosition&)information;
    4042#endif
    41 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url imageURL:(NSURL *)imageURL location:(CGPoint)location title:(NSString *)title ID:(NSString *)ID rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image;
    42 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url imageURL:(NSURL *)imageURL location:(CGPoint)location title:(NSString *)title ID:(NSString *)ID rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image userInfo:(NSDictionary *)userInfo;
     43- (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;
     44- (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;
    4345
    44 @property (nonatomic, readonly) CGPoint _interactionLocation;
     46@property (nonatomic, readonly) WebCore::IntPoint _interactionLocation;
    4547
    4648@end
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.h

    r246865 r247326  
    6868- (void)runActionWithElementInfo:(_WKActivatedElementInfo *)info WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(9.0));
    6969
    70 - (UIAction *)uiActionForElementInfo:(_WKActivatedElementInfo *)elementInfo WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(13.0));
    71 
    7270@property (nonatomic, readonly) _WKElementActionType type;
    7371@property (nonatomic, readonly) NSString* title;
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.mm

    r247185 r247326  
    124124        title = WEB_UI_STRING_KEY("Copy", "Copy (ActionSheet)", "Title for Copy Link or Image action button");
    125125        handler = ^(WKActionSheetAssistant *assistant, _WKActivatedElementInfo *actionInfo) {
     126            if ([assistant.delegate respondsToSelector:@selector(actionSheetAssistant:willStartInteractionWithElement:)])
     127                [assistant.delegate actionSheetAssistant:assistant willStartInteractionWithElement:actionInfo];
    126128            [assistant.delegate actionSheetAssistant:assistant performAction:WebKit::SheetAction::Copy];
     129            if ([assistant.delegate respondsToSelector:@selector(actionSheetAssistantDidStopInteraction:)])
     130                [assistant.delegate actionSheetAssistantDidStopInteraction:assistant];
    127131        };
    128132        break;
     
    136140        title = WEB_UI_STRING("Add to Photos", "Title for Add to Photos action button");
    137141        handler = ^(WKActionSheetAssistant *assistant, _WKActivatedElementInfo *actionInfo) {
     142            if ([assistant.delegate respondsToSelector:@selector(actionSheetAssistant:willStartInteractionWithElement:)])
     143                [assistant.delegate actionSheetAssistant:assistant willStartInteractionWithElement:actionInfo];
    138144            [assistant.delegate actionSheetAssistant:assistant performAction:WebKit::SheetAction::SaveImage];
     145            if ([assistant.delegate respondsToSelector:@selector(actionSheetAssistantDidStopInteraction:)])
     146                [assistant.delegate actionSheetAssistantDidStopInteraction:assistant];
    139147        };
    140148        break;
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKElementActionInternal.h

    r242339 r247326  
    3737- (void)_runActionWithElementInfo:(_WKActivatedElementInfo *)info forActionSheetAssistant:(WKActionSheetAssistant *)assistant;
    3838
     39- (UIAction *)uiActionForElementInfo:(_WKActivatedElementInfo *)elementInfo;
     40
    3941@end
    4042
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r247321 r247326  
    7777#import "_WKActivatedElementInfoInternal.h"
    7878#import "_WKElementAction.h"
     79#import "_WKElementActionInternal.h"
    7980#import "_WKFocusedElementInfo.h"
    8081#import "_WKInputDelegate.h"
     
    78627863        };
    78637864
     7865        _page->startInteractionWithElementAtPosition(_positionInformation.request.point);
     7866
    78647867        // FIXME: Should we provide an identifier and ASSERT in delegates if we don't match?
    78657868        return continueWithContextMenuConfiguration([UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:contentPreviewProvider actionProvider:actionMenuProvider]);
     
    78737876
    78747877        if (configurationFromWKUIDelegate) {
     7878            strongSelf->_page->startInteractionWithElementAtPosition(strongSelf->_positionInformation.request.point);
    78757879            strongSelf->_contextMenuActionProviderDelegateNeedsOverride = YES;
    78767880            continueWithContextMenuConfiguration(configurationFromWKUIDelegate);
     
    78957899            UIContextMenuConfiguration *configurationFromDD = [ddContextMenuActionClass contextMenuConfigurationForURL:linkURL identifier:strongSelf->_positionInformation.dataDetectorIdentifier selectedText:[strongSelf selectedText] results:strongSelf->_positionInformation.dataDetectorResults.get() inView:strongSelf.get() context:context menuIdentifier:nil];
    78967900            strongSelf->_contextMenuActionProviderDelegateNeedsOverride = YES;
     7901            strongSelf->_page->startInteractionWithElementAtPosition(strongSelf->_positionInformation.request.point);
    78977902            if (strongSelf->_showLinkPreviews)
    78987903                return continueWithContextMenuConfiguration(configurationFromDD);
     
    81218126        }
    81228127    }
     8128
     8129    _page->stopInteraction();
    81238130
    81248131    _contextMenuLegacyPreviewController = nullptr;
Note: See TracChangeset for help on using the changeset viewer.