Bug 99251 - Make subclassing of WKView safer by namespacing methods and eliminating its use as an observer and delegate
Summary: Make subclassing of WKView safer by namespacing methods and eliminating its u...
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac All
: P2 Normal
Assignee: Darin Adler
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-13 10:53 PDT by Darin Adler
Modified: 2013-05-09 18:11 PDT (History)
5 users (show)

See Also:


Attachments
Patch (87.56 KB, patch)
2012-10-13 11:08 PDT, Darin Adler
no flags Details | Formatted Diff | Diff
Patch, revised based on feedback from Anders and Maciej (88.40 KB, patch)
2012-10-15 09:44 PDT, Darin Adler
no flags Details | Formatted Diff | Diff
Patch, revised based on additional feedback from Anders (88.51 KB, patch)
2012-10-15 20:41 PDT, Darin Adler
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Adler 2012-10-13 10:53:37 PDT
Make subclassing of WKView safer by namespacing methods and eliminating its use as an observer and delegate
Comment 1 Darin Adler 2012-10-13 11:08:58 PDT
Created attachment 168558 [details]
Patch
Comment 2 Darin Adler 2012-10-13 11:31:44 PDT
One minus to this approach is that these prefixed method names won’t work well as getter/setter pairs for Objective-C properties.
Comment 3 Maciej Stachowiak 2012-10-13 12:29:47 PDT
Comment on attachment 168558 [details]
Patch

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

> Source/WebKit2/ChangeLog:9
> +        we chose to use internally in WKView's own implementation. Thus, it's a good idea to add a "wk_" prefix

I am not sure that wk_ as the prefix best aligns the advice Apple gives to third-party developers, which is that Cocoa frameworks reserve methods starting with "_". So Apple's advice is that application code should never use methods starting with "_" and should instead use a two-letter prefix on method names of the form "XX_". By using "wk_" in WebKit2, a Cocoa framework, we're stepping on what our guidelines say is Application namespace:

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingMethods.html

On the other hand, in practice many apps use underscore-prefixed names freely, which is presumably the reason for your change. If we want to be extra kind to apps that use WebKit, then perhaps an _wk_ prefix would be a good choice (or _WK_). That way we would both be using what is supposed to be the system framework namespace for private methods (start with underscore) but also using a unique prefix to reduce risk of collision from app developers not following the advice.
Comment 4 Darin Adler 2012-10-14 17:42:34 PDT
(In reply to comment #3)
> If we want to be extra kind to apps that use WebKit

We do.

> then perhaps an _wk_ prefix would be a good choice (or _WK_).

Sounds fine. Would be easy for me to change wk_ to _wk_.
Comment 5 Darin Adler 2012-10-15 09:27:04 PDT
(In reply to comment #3)
> Cocoa frameworks reserve methods starting with "_"

It’s kind of unfortunate that future additions to the public APIs for Cocoa frameworks effectively reserve methods with simple names that do not start with "_" and the internals of Cocoa frameworks reserve methods with names that do start with "_". Guess that means app developers do need to use a prefix.
Comment 6 Darin Adler 2012-10-15 09:44:11 PDT
Created attachment 168730 [details]
Patch, revised based on feedback from Anders and Maciej
Comment 7 Darin Adler 2012-10-15 16:07:04 PDT
Comment on attachment 168730 [details]
Patch, revised based on feedback from Anders and Maciej

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

> Source/WebKit2/UIProcess/API/mac/WKView.mm:1889
> +    #define ADD_OBSERVER(selectorName, notificationName, notificationObject) \
> +        [[NSNotificationCenter defaultCenter] addObserver:_data selector:@selector(selectorName:) \
> +            name:notificationName object:notificationObject]

Anders asked me to not use the WKViewData as the observer, because he plans to eliminate that object entirely in the future, once we can take advantage of the more modern Objective-C feature where we can add data without touching the header file. So I’ll use the block form of observer instead.

> Source/WebKit2/UIProcess/API/mac/WKView.mm:2538
> +        _data->_lastToolTipTag = [self addToolTipRect:wideOpenRect owner:_data userData:NULL];

Similarly, Anders asked me not to use the WKViewData as the owner of the tooltip, so I’ll create a separate object just for that.
Comment 8 Darin Adler 2012-10-15 20:41:03 PDT
Created attachment 168843 [details]
Patch, revised based on additional feedback from Anders
Comment 9 Darin Adler 2012-10-15 20:42:06 PDT
Anders, I made the changes you requested. Would you consider reviewing?
Comment 10 WebKit Review Bot 2012-10-17 18:27:14 PDT
Comment on attachment 168843 [details]
Patch, revised based on additional feedback from Anders

Clearing flags on attachment: 168843

Committed r131686: <http://trac.webkit.org/changeset/131686>
Comment 11 WebKit Review Bot 2012-10-17 18:27:18 PDT
All reviewed patches have been landed.  Closing bug.
Comment 12 Ryosuke Niwa 2012-10-18 00:49:48 PDT
This patch appears to have broken Lion builds:
http://build.webkit.org/builders/Apple%20Lion%20Debug%20%28Build%29/builds/6232
Comment 13 Ryosuke Niwa 2012-10-18 00:54:15 PDT
Reverted the part of the patch that was causing the build failure in http://trac.webkit.org/changeset/131711.
Comment 14 Sam Weinig 2012-10-27 13:31:36 PDT
I completely rolled this out in r132738 due to continued crashes.  Reopening.
Comment 15 Darin Adler 2013-05-09 18:11:27 PDT
I don’t think I want to do this.