Changeset 164666 in webkit


Ignore:
Timestamp:
Feb 25, 2014, 1:10:14 PM (11 years ago)
Author:
mitz@apple.com
Message:

[Cocoa] Add delegate method for customizing actions on activated elements
https://bugs.webkit.org/show_bug.cgi?id=129290

Reviewed by Anders Carlsson.

  • UIProcess/API/Cocoa/WKUIDelegatePrivate.h: Added. Declared new delegate method.
  • UIProcess/API/Cocoa/_WKActivatedElementInfo.h:

(_WKActivatedElementType): Defined enum of element types.

  • UIProcess/API/Cocoa/_WKActivatedElementInfo.mm:

(-[_WKActivatedElementInfo _initWithType:URL:location:title:rect:]): Added type parameter
to the initializer, used to set the new type property.

  • UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h:
  • UIProcess/Cocoa/UIClient.h:
  • UIProcess/Cocoa/UIClient.mm:

(WebKit::UIClient::setDelegate): Initialize webViewActionsForElementDefaultActions member
of m_delegateMethods.
(WebKit::UIClient::actionsForElement): Added. Calls out to the new delegate method if
implemented. Otherwise returns the default actions.

  • UIProcess/ios/WKActionSheetAssistant.mm:

(-[WKActionSheetAssistant actionSheet:clickedButtonAtIndex:]): Use new _elementInfo ivar
instead of creating element info here.
(-[WKActionSheetAssistant showImageSheet]): Create element info here and assign it to
_elementInfo ivar if presenting a sheet. Call the UI client to get custom actions.
(-[WKActionSheetAssistant showLinkSheet]): Ditto.
(-[WKActionSheetAssistant cleanupSheet]): Clear _elementInfo ivar.

  • WebKit2.xcodeproj/project.pbxproj: Added reference to WKUIDelegatePrivate.h.
Location:
trunk/Source/WebKit2
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r164664 r164666  
     12014-02-25  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Add delegate method for customizing actions on activated elements
     4        https://bugs.webkit.org/show_bug.cgi?id=129290
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: Added. Declared new delegate method.
     9
     10        * UIProcess/API/Cocoa/_WKActivatedElementInfo.h:
     11        (_WKActivatedElementType): Defined enum of element types.
     12        * UIProcess/API/Cocoa/_WKActivatedElementInfo.mm:
     13        (-[_WKActivatedElementInfo _initWithType:URL:location:title:rect:]): Added type parameter
     14        to the initializer, used to set the new type property.
     15        * UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h:
     16
     17        * UIProcess/Cocoa/UIClient.h:
     18        * UIProcess/Cocoa/UIClient.mm:
     19        (WebKit::UIClient::setDelegate): Initialize webViewActionsForElementDefaultActions member
     20        of m_delegateMethods.
     21        (WebKit::UIClient::actionsForElement): Added. Calls out to the new delegate method if
     22        implemented. Otherwise returns the default actions.
     23
     24        * UIProcess/ios/WKActionSheetAssistant.mm:
     25        (-[WKActionSheetAssistant actionSheet:clickedButtonAtIndex:]): Use new _elementInfo ivar
     26        instead of creating element info here.
     27        (-[WKActionSheetAssistant showImageSheet]): Create element info here and assign it to
     28        _elementInfo ivar if presenting a sheet. Call the UI client to get custom actions.
     29        (-[WKActionSheetAssistant showLinkSheet]): Ditto.
     30        (-[WKActionSheetAssistant cleanupSheet]): Clear _elementInfo ivar.
     31        * WebKit2.xcodeproj/project.pbxproj: Added reference to WKUIDelegatePrivate.h.
     32
    1332014-02-25  Michał Pakuła vel Rutka  <m.pakula@samsung.com>
    234
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.h

    r164626 r164666  
    3030#import <Foundation/Foundation.h>
    3131
     32typedef NS_ENUM(NSInteger, _WKActivatedElementType) {
     33    _WKActivatedElementTypeLink,
     34    _WKActivatedElementTypeImage,
     35};
     36
    3237WK_API_CLASS
    3338@interface _WKActivatedElementInfo : NSObject
     
    3540@property (nonatomic, readonly) NSURL *URL;
    3641@property (nonatomic, readonly) NSString *title;
     42@property (nonatomic, readonly) _WKActivatedElementType type;
    3743
    3844@end
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm

    r164626 r164666  
    3838}
    3939
    40 - (instancetype)_initWithURL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect
     40- (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect
    4141{
    4242    if (!(self = [super init]))
     
    4747    _title = adoptNS([title copy]);
    4848    _boundingRect = rect;
     49    _type = type;
    4950
    5051    return self;
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h

    r164626 r164666  
    3030@interface _WKActivatedElementInfo ()
    3131
    32 - (instancetype)_initWithURL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect;
     32- (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect;
    3333
    3434@property (nonatomic, readonly) CGPoint _interactionLocation;
  • trunk/Source/WebKit2/UIProcess/Cocoa/UIClient.h

    r164460 r164666  
    3535#import <wtf/RetainPtr.h>
    3636
     37@class _WKActivatedElementInfo;
    3738@class WKWebView;
    3839@protocol WKUIDelegate;
     
    4748    RetainPtr<id <WKUIDelegate> > delegate();
    4849    void setDelegate(id <WKUIDelegate>);
     50
     51    NSArray *actionsForElement(_WKActivatedElementInfo *, NSArray *defaultActions);
    4952
    5053private:
     
    6164        bool webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
    6265        bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1;
     66#if PLATFORM(IOS)
     67        bool webViewActionsForElementDefaultActions : 1;
     68#endif
    6369    } m_delegateMethods;
    6470};
  • trunk/Source/WebKit2/UIProcess/Cocoa/UIClient.mm

    r164460 r164666  
    3030
    3131#import "WKFrameInfoInternal.h"
    32 #import "WKUIDelegate.h"
     32#import "WKUIDelegatePrivate.h"
    3333
    3434namespace WebKit {
     
    5555    m_delegateMethods.webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:)];
    5656    m_delegateMethods.webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:)];
     57#if PLATFORM(IOS)
     58    m_delegateMethods.webViewActionsForElementDefaultActions = [delegate respondsToSelector:@selector(_webView:actionsForElement:defaultActions:)];
     59#endif
     60}
     61
     62NSArray *UIClient::actionsForElement(_WKActivatedElementInfo *elementInfo, NSArray *defaultActions)
     63{
     64#if PLATFORM(IOS)
     65    if (!m_delegateMethods.webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler)
     66        return defaultActions;
     67
     68    auto delegate = m_delegate.get();
     69    if (!delegate)
     70        return defaultActions;
     71
     72    return [(id <WKUIDelegatePrivate>)delegate _webView:m_webView actionsForElement:elementInfo defaultActions:defaultActions];
     73#endif
     74    return defaultActions;
    5775}
    5876
  • trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm

    r164626 r164666  
    2929#import "_WKActivatedElementInfoInternal.h"
    3030#import "_WKElementActionInternal.h"
     31#import "UIClient.h"
    3132#import "WKActionSheet.h"
    3233#import "WKContentViewInteraction.h"
     
    5455SOFT_LINK_CLASS(DataDetectorsUI, DDDetectionController)
    5556
     57using namespace WebKit;
     58
    5659@implementation WKActionSheetAssistant {
    5760    RetainPtr<WKActionSheet> _interactionSheet;
     61    RetainPtr<_WKActivatedElementInfo> _elementInfo;
    5862    RetainPtr<NSArray> _elementActions;
    5963    WKContentView *_view;
     
    155159        return;
    156160
    157     if (_elementActions && buttonIndex < (NSInteger)[_elementActions count]) {
    158         _WKActivatedElementInfo *actionInfo = [[_WKActivatedElementInfo alloc] _initWithURL:[NSURL URLWithString:_view.positionInformation.url]
    159             location:_view.positionInformation.point title:_view.positionInformation.title rect:_view.positionInformation.bounds];
    160         [[_elementActions objectAtIndex:buttonIndex] _runActionWithElementInfo:actionInfo view:_view];
    161         [actionInfo release];
    162     }
     161    if (_elementActions && buttonIndex < (NSInteger)[_elementActions count])
     162        [[_elementActions objectAtIndex:buttonIndex] _runActionWithElementInfo:_elementInfo.get() view:_view];
    163163
    164164    [self cleanupSheet];
     
    216216{
    217217    ASSERT(!_interactionSheet);
    218 
    219     NSURL *targetURL = [NSURL URLWithString:_view.positionInformation.url];
    220     NSMutableArray *actions = [NSMutableArray array];
    221     if (!_view.positionInformation.url.isEmpty())
    222         [actions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeOpen]];
     218    ASSERT(!_elementInfo);
     219
     220    const auto& positionInformation = _view.positionInformation;
     221
     222    NSURL *targetURL = [NSURL URLWithString:positionInformation.url];
     223    NSMutableArray *defaultActions = [NSMutableArray array];
     224    if (!positionInformation.url.isEmpty())
     225        [defaultActions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeOpen]];
    223226    if ([getSSReadingListClass() supportsURL:targetURL])
    224         [actions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeAddToReadingList]];
     227        [defaultActions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeAddToReadingList]];
    225228    if (TCCAccessPreflight(getkTCCServicePhotos(), NULL) != kTCCAccessPreflightDenied)
    226         [actions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeSaveImage]];
    227     if (![[targetURL scheme] length] || [[targetURL scheme] caseInsensitiveCompare:@"javascript"] != NSOrderedSame)
    228         [actions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeCopy]];
    229 
    230     // FIXME: Add call to delegate to add custom actions.
    231 
    232     [self _createSheetWithElementActions:actions showLinkTitle:YES];
     229        [defaultActions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeSaveImage]];
     230    if (!targetURL.scheme.length || [targetURL.scheme caseInsensitiveCompare:@"javascript"] != NSOrderedSame)
     231        [defaultActions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeCopy]];
     232
     233    RetainPtr<_WKActivatedElementInfo> elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage
     234        URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds]);
     235
     236    RetainPtr<NSArray> actions = static_cast<UIClient&>(_view.page->uiClient()).actionsForElement(elementInfo.get(), [[defaultActions copy] autorelease]);
     237
     238    if (![actions count])
     239        return;
     240
     241    [self _createSheetWithElementActions:actions.get() showLinkTitle:YES];
    233242    if (!_interactionSheet)
    234243        return;
     244
     245    _elementInfo = std::move(elementInfo);
    235246
    236247    if (![_interactionSheet presentSheet])
     
    241252{
    242253    ASSERT(!_interactionSheet);
    243     NSURL *targetURL = [NSURL URLWithString:_view.positionInformation.url];
     254    ASSERT(!_elementInfo);
     255
     256    const auto& positionInformation = _view.positionInformation;
     257
     258    NSURL *targetURL = [NSURL URLWithString:positionInformation.url];
    244259    if (!targetURL)
    245260        return;
    246261
    247     NSMutableArray *actions = [NSMutableArray array];
    248     [actions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeOpen]];
     262    NSMutableArray *defaultActions = [NSMutableArray array];
     263    [defaultActions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeOpen]];
    249264    if ([getSSReadingListClass() supportsURL:targetURL])
    250         [actions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeAddToReadingList]];
     265        [defaultActions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeAddToReadingList]];
    251266    if (![[targetURL scheme] length] || [[targetURL scheme] caseInsensitiveCompare:@"javascript"] != NSOrderedSame)
    252         [actions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeCopy]];
    253 
    254     // FIXME: Add call to delegate to add custom actions.
    255 
    256     [self _createSheetWithElementActions:actions showLinkTitle:YES];
     267        [defaultActions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeCopy]];
     268
     269    RetainPtr<_WKActivatedElementInfo> elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeLink
     270        URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds]);
     271
     272    RetainPtr<NSArray> actions = static_cast<UIClient&>(_view.page->uiClient()).actionsForElement(elementInfo.get(), [[defaultActions copy] autorelease]);
     273
     274    if (![actions count])
     275        return;
     276
     277    [self _createSheetWithElementActions:actions.get() showLinkTitle:YES];
    257278    if (!_interactionSheet)
    258279        return;
     280
     281    _elementInfo = std::move(elementInfo);
    259282
    260283    if (![_interactionSheet presentSheet])
     
    322345    [_interactionSheet setDelegate:nil];
    323346    _interactionSheet = nil;
     347    _elementInfo = nil;
    324348
    325349    _elementActions = nil;
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r164652 r164666  
    601601                373D122718A473F60066D9CC /* WKFrameHandleInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 373D122618A473F60066D9CC /* WKFrameHandleInternal.h */; };
    602602                373D122D18A4B6EB0066D9CC /* WKWebProcessPlugInFramePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 373D122C18A4B6A80066D9CC /* WKWebProcessPlugInFramePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
     603                3743925818BC4C60001C8675 /* WKUIDelegatePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 3743925718BC4C60001C8675 /* WKUIDelegatePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
    603604                374436881820E7240049579F /* WKObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 374436871820E7240049579F /* WKObject.mm */; };
    604605                3760881E150413E900FC82C7 /* WebRenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3760881C150413E900FC82C7 /* WebRenderObject.cpp */; };
     
    23342335                373D122618A473F60066D9CC /* WKFrameHandleInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFrameHandleInternal.h; sourceTree = "<group>"; };
    23352336                373D122C18A4B6A80066D9CC /* WKWebProcessPlugInFramePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebProcessPlugInFramePrivate.h; sourceTree = "<group>"; };
     2337                3743925718BC4C60001C8675 /* WKUIDelegatePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKUIDelegatePrivate.h; sourceTree = "<group>"; };
    23362338                374436871820E7240049579F /* WKObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKObject.mm; sourceTree = "<group>"; };
    23372339                375FB4731883415600BE34D4 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = "<group>"; };
     
    44494451                                1A3CC16818907EB0001E6ED8 /* WKProcessPoolInternal.h */,
    44504452                                1AD8790918B6C38A006CAFD7 /* WKUIDelegate.h */,
     4453                                3743925718BC4C60001C8675 /* WKUIDelegatePrivate.h */,
    44514454                                1A3CC16518906ACF001E6ED8 /* WKWebView.h */,
    44524455                                1A3CC16418906ACF001E6ED8 /* WKWebView.mm */,
     
    65426545                                1A2BB6D114117B4D000F35D4 /* PluginProcessConnectionMessages.h in Headers */,
    65436546                                1A2D90D21281C966001EB962 /* PluginProcessCreationParameters.h in Headers */,
     6547                                3743925818BC4C60001C8675 /* WKUIDelegatePrivate.h in Headers */,
    65446548                                1A0EC603124A9F2C007EF4A5 /* PluginProcessManager.h in Headers */,
    65456549                                0FCB4E6618BBE3D9000FCFC9 /* WKPrintingView.h in Headers */,
Note: See TracChangeset for help on using the changeset viewer.