Bug 138066

Summary: Provide a way for WebKit1 clients to override default action menu items
Product: WebKit Reporter: Beth Dakin <bdakin>
Component: WebKit APIAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, bdakin, commit-queue, mitz, thorton
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch that uses WebUIDelegate
none
Patch andersca: review+

Description Beth Dakin 2014-10-24 17:16:19 PDT
Provide a way for WebKit1 clients to override default action menu items

rdar://problem/18451638
Comment 1 Beth Dakin 2014-10-24 17:19:30 PDT
Created attachment 240447 [details]
Patch
Comment 2 mitz 2014-10-24 18:43:42 PDT
I know that the patch is similar to how we do things in WebKit2’s C SPI, but in WebKit1, could we do something more similar to how context menus are handled, with a delegate? Would that be significantly harder to implement or for clients to adopt?
Comment 3 mitz 2014-10-25 09:36:00 PDT
(In reply to comment #2)
> I know that the patch is similar to how we do things in WebKit2’s C SPI, but
> in WebKit1, could we do something more similar to how context menus are
> handled, with a delegate? Would that be significantly harder to implement or
> for clients to adopt?

For context menus, there is -webView:contextMenuItemsForElement:defaultMenuItems: in WebUIDelegate. It seems like something similar could work here (in WebUIDelegatePrivate), and will not require clients to subclass WebView if they want to implement this.
Comment 4 Beth Dakin 2014-10-25 12:13:53 PDT
(In reply to comment #3)
> (In reply to comment #2)
> > I know that the patch is similar to how we do things in WebKit2’s C SPI, but
> > in WebKit1, could we do something more similar to how context menus are
> > handled, with a delegate? Would that be significantly harder to implement or
> > for clients to adopt?
> 
> For context menus, there is
> -webView:contextMenuItemsForElement:defaultMenuItems: in WebUIDelegate. It
> seems like something similar could work here (in WebUIDelegatePrivate), and
> will not require clients to subclass WebView if they want to implement this.

I think that sounds very reasonable! Honestly, I was torn between the two spots since I took a look at the context menu stuff as well. Will move!
Comment 5 Beth Dakin 2014-10-27 12:51:07 PDT
Created attachment 240495 [details]
Patch that uses WebUIDelegate
Comment 6 WebKit Commit Bot 2014-10-27 12:53:51 PDT
Attachment 240495 [details] did not pass style-queue:


ERROR: Source/WebKit/mac/WebView/WebActionMenuController.mm:89:  The parameter name "]" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 1 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 Anders Carlsson 2014-10-27 12:55:48 PDT
Comment on attachment 240495 [details]
Patch that uses WebUIDelegate

View in context: https://bugs.webkit.org/attachment.cgi?id=240495&action=review

> Source/WebKit/mac/WebView/WebUIDelegatePrivate.h:208
> +- (NSArray *)webView:(WebView *)sender _actionMenuItemsForHitTestResult:(NSDictionary *)hitTestResult withType:(WebActionMenuType)type defaultActionMenuItems:(NSArray *)defaultMenuItems;

Underscore should be at the start of the method name, _webView:
Comment 8 Anders Carlsson 2014-10-27 12:56:38 PDT
Comment on attachment 240495 [details]
Patch that uses WebUIDelegate

View in context: https://bugs.webkit.org/attachment.cgi?id=240495&action=review

> Source/WebKit/mac/WebView/WebActionMenuController.mm:90
> +        menuItems = [[_webView _UIDelegateForwarder] webView:_webView _actionMenuItemsForHitTestResult:hitTestResult withType:_type defaultActionMenuItems:menuItems];

I don't think you need the UIDelegateForwarder here - you can just call the method directly since you check respondsToSelector already.
Comment 9 Beth Dakin 2014-10-27 13:06:11 PDT
Created attachment 240496 [details]
Patch
Comment 10 Beth Dakin 2014-10-27 13:08:47 PDT
Thank you! http://trac.webkit.org/changeset/175229