Changeset 164666 in webkit
- Timestamp:
- Feb 25, 2014, 1:10:14 PM (11 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r164664 r164666 1 2014-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 1 33 2014-02-25 Michał Pakuła vel Rutka <m.pakula@samsung.com> 2 34 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.h
r164626 r164666 30 30 #import <Foundation/Foundation.h> 31 31 32 typedef NS_ENUM(NSInteger, _WKActivatedElementType) { 33 _WKActivatedElementTypeLink, 34 _WKActivatedElementTypeImage, 35 }; 36 32 37 WK_API_CLASS 33 38 @interface _WKActivatedElementInfo : NSObject … … 35 40 @property (nonatomic, readonly) NSURL *URL; 36 41 @property (nonatomic, readonly) NSString *title; 42 @property (nonatomic, readonly) _WKActivatedElementType type; 37 43 38 44 @end -
trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm
r164626 r164666 38 38 } 39 39 40 - (instancetype)_initWith URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect40 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect 41 41 { 42 42 if (!(self = [super init])) … … 47 47 _title = adoptNS([title copy]); 48 48 _boundingRect = rect; 49 _type = type; 49 50 50 51 return self; -
trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h
r164626 r164666 30 30 @interface _WKActivatedElementInfo () 31 31 32 - (instancetype)_initWith URL:(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; 33 33 34 34 @property (nonatomic, readonly) CGPoint _interactionLocation; -
trunk/Source/WebKit2/UIProcess/Cocoa/UIClient.h
r164460 r164666 35 35 #import <wtf/RetainPtr.h> 36 36 37 @class _WKActivatedElementInfo; 37 38 @class WKWebView; 38 39 @protocol WKUIDelegate; … … 47 48 RetainPtr<id <WKUIDelegate> > delegate(); 48 49 void setDelegate(id <WKUIDelegate>); 50 51 NSArray *actionsForElement(_WKActivatedElementInfo *, NSArray *defaultActions); 49 52 50 53 private: … … 61 64 bool webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1; 62 65 bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1; 66 #if PLATFORM(IOS) 67 bool webViewActionsForElementDefaultActions : 1; 68 #endif 63 69 } m_delegateMethods; 64 70 }; -
trunk/Source/WebKit2/UIProcess/Cocoa/UIClient.mm
r164460 r164666 30 30 31 31 #import "WKFrameInfoInternal.h" 32 #import "WKUIDelegate .h"32 #import "WKUIDelegatePrivate.h" 33 33 34 34 namespace WebKit { … … 55 55 m_delegateMethods.webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:)]; 56 56 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 62 NSArray *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; 57 75 } 58 76 -
trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm
r164626 r164666 29 29 #import "_WKActivatedElementInfoInternal.h" 30 30 #import "_WKElementActionInternal.h" 31 #import "UIClient.h" 31 32 #import "WKActionSheet.h" 32 33 #import "WKContentViewInteraction.h" … … 54 55 SOFT_LINK_CLASS(DataDetectorsUI, DDDetectionController) 55 56 57 using namespace WebKit; 58 56 59 @implementation WKActionSheetAssistant { 57 60 RetainPtr<WKActionSheet> _interactionSheet; 61 RetainPtr<_WKActivatedElementInfo> _elementInfo; 58 62 RetainPtr<NSArray> _elementActions; 59 63 WKContentView *_view; … … 155 159 return; 156 160 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]; 163 163 164 164 [self cleanupSheet]; … … 216 216 { 217 217 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]]; 223 226 if ([getSSReadingListClass() supportsURL:targetURL]) 224 [ actions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeAddToReadingList]];227 [defaultActions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeAddToReadingList]]; 225 228 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]; 233 242 if (!_interactionSheet) 234 243 return; 244 245 _elementInfo = std::move(elementInfo); 235 246 236 247 if (![_interactionSheet presentSheet]) … … 241 252 { 242 253 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]; 244 259 if (!targetURL) 245 260 return; 246 261 247 NSMutableArray * actions = [NSMutableArray array];248 [ actions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeOpen]];262 NSMutableArray *defaultActions = [NSMutableArray array]; 263 [defaultActions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeOpen]]; 249 264 if ([getSSReadingListClass() supportsURL:targetURL]) 250 [ actions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeAddToReadingList]];265 [defaultActions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeAddToReadingList]]; 251 266 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]; 257 278 if (!_interactionSheet) 258 279 return; 280 281 _elementInfo = std::move(elementInfo); 259 282 260 283 if (![_interactionSheet presentSheet]) … … 322 345 [_interactionSheet setDelegate:nil]; 323 346 _interactionSheet = nil; 347 _elementInfo = nil; 324 348 325 349 _elementActions = nil; -
trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
r164652 r164666 601 601 373D122718A473F60066D9CC /* WKFrameHandleInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 373D122618A473F60066D9CC /* WKFrameHandleInternal.h */; }; 602 602 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, ); }; }; 603 604 374436881820E7240049579F /* WKObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 374436871820E7240049579F /* WKObject.mm */; }; 604 605 3760881E150413E900FC82C7 /* WebRenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3760881C150413E900FC82C7 /* WebRenderObject.cpp */; }; … … 2334 2335 373D122618A473F60066D9CC /* WKFrameHandleInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFrameHandleInternal.h; sourceTree = "<group>"; }; 2335 2336 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>"; }; 2336 2338 374436871820E7240049579F /* WKObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKObject.mm; sourceTree = "<group>"; }; 2337 2339 375FB4731883415600BE34D4 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = "<group>"; }; … … 4449 4451 1A3CC16818907EB0001E6ED8 /* WKProcessPoolInternal.h */, 4450 4452 1AD8790918B6C38A006CAFD7 /* WKUIDelegate.h */, 4453 3743925718BC4C60001C8675 /* WKUIDelegatePrivate.h */, 4451 4454 1A3CC16518906ACF001E6ED8 /* WKWebView.h */, 4452 4455 1A3CC16418906ACF001E6ED8 /* WKWebView.mm */, … … 6542 6545 1A2BB6D114117B4D000F35D4 /* PluginProcessConnectionMessages.h in Headers */, 6543 6546 1A2D90D21281C966001EB962 /* PluginProcessCreationParameters.h in Headers */, 6547 3743925818BC4C60001C8675 /* WKUIDelegatePrivate.h in Headers */, 6544 6548 1A0EC603124A9F2C007EF4A5 /* PluginProcessManager.h in Headers */, 6545 6549 0FCB4E6618BBE3D9000FCFC9 /* WKPrintingView.h in Headers */,
Note:
See TracChangeset
for help on using the changeset viewer.