Bug 54898 - InjectedBundleNodeHandle dies too early in WKBundleHitTestResultGetNodeHandle
Summary: InjectedBundleNodeHandle dies too early in WKBundleHitTestResultGetNodeHandle
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Alice Liu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-21 11:55 PST by Alice Liu
Modified: 2011-02-28 20:45 PST (History)
4 users (show)

See Also:


Attachments
patch (1.49 KB, patch)
2011-02-21 11:58 PST, Alice Liu
aroben: review-
Details | Formatted Diff | Diff
API test (16.51 KB, patch)
2011-02-22 15:40 PST, Alice Liu
aroben: review+
Details | Formatted Diff | Diff
all-in-one patch (19.10 KB, patch)
2011-02-28 17:43 PST, Alice Liu
no flags Details | Formatted Diff | Diff
same as above, but fixed whitespace style nit (19.10 KB, patch)
2011-02-28 17:49 PST, Alice Liu
barraclough: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alice Liu 2011-02-21 11:55:36 PST
When asking a WKBundleHitTestResultRef for its nodeHandle, the InjectedBundleNodeHandle dies too early in WKBundleHitTestResultGetNodeHandle.

 	WebKit.dll!WebKit::InjectedBundleNodeHandle::~InjectedBundleNodeHandle()  Line 90	C++
 	WebKit.dll!WebKit::InjectedBundleNodeHandle::`scalar deleting destructor'()  + 0x16 bytes	C++
 	WebKit.dll!WTF::RefCounted<WebKit::APIObject>::deref()  Line 141 + 0x3a bytes	C++
 	WebKit.dll!WTF::derefIfNotNull<WebKit::InjectedBundleNodeHandle>(WebKit::InjectedBundleNodeHandle * ptr=0x03194368)  Line 60	C++
 	WebKit.dll!WTF::RefPtr<WebKit::InjectedBundleNodeHandle>::~RefPtr<WebKit::InjectedBundleNodeHandle>()  Line 58 + 0x19 bytes	C++
>	WebKit.dll!WKBundleHitTestResultGetNodeHandle(const OpaqueWKBundleHitTestResult * hitTestResultRef=0x0323a848)  Line 44 + 0x1c bytes	C++
Comment 1 Alice Liu 2011-02-21 11:58:49 PST
Created attachment 83200 [details]
patch

I don't know if this is right... the other functions that use release().leakRef() or release.releaseRef() that return WKBundleNodeHandleRef seem to have "copy" in their function names, but not WKBundleHitTestResultGetNodeHandle.
Comment 2 Adam Roben (:aroben) 2011-02-21 12:05:36 PST
Comment on attachment 83200 [details]
patch

My guess is that you're fixing a crash. It would be good to have "crash" somewhere in the bug title (which would also get it into your ChangeLog).

As you suspected, this change makes WKBundleHitTestResultGetNodeHandle follow the Create or Copy pattern, so its name will have to be changed.

The actual code change seems fine. Is it possible to make a test for this? I'd imagine it is, by using TestWebKitAPI.
Comment 3 Alice Liu 2011-02-22 15:40:55 PST
Created attachment 83402 [details]
API test
Comment 4 WebKit Review Bot 2011-02-23 11:47:09 PST
Attachment 83402 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Tools/ChangeLog', u'Tools/TestWebKitAPI/In..." exit_code: 1

Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle.cpp:47:  Missing space after ,  [whitespace/comma] [3]
Total errors found: 1 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Adam Roben (:aroben) 2011-02-23 13:41:19 PST
Comment on attachment 83402 [details]
API test

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

Awesome that you got a test working!

> Tools/TestWebKitAPI/PlatformWebView.h:65
> +    void simulateRightClick(CGPoint pt);

No need for "pt" here. (If you did need an argument name, "point" would be better.) Maybe it should be a const CGPoint&?

It's slightly unfortunate to use CG types in cross-platform code, as this will make it harder for other ports to build TestWebKitAPI. Maybe two unsigneds would be better.

> Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle.cpp:70
> +    WKContextInjectedBundleClient injectedBundleClient;
> +    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
> +    injectedBundleClient.version = 0;
> +    injectedBundleClient.clientInfo = 0;
> +    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
> +    WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient);

A separate setInjectedBundleClient function would make the main test logic easier to follow.

> Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle.cpp:82
> +    TEST_ASSERT(done);

No need for this assertion, as it will never be reached if done is still false.

> Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle_Bundle.cpp:49
> +        WKRetainPtr<WKStringRef> doneMessageName(AdoptWK, WKStringCreateWithUTF8CString("HitTestResultNodeHandleTestDoneMessageName"));
> +        WKRetainPtr<WKStringRef> doneMessageBody(AdoptWK, WKStringCreateWithUTF8CString("HitTestResultNodeHandleTestDoneMessageBody"));

You can use the Util::toWK function here instead.

> Tools/TestWebKitAPI/win/PlatformWebViewWin.cpp:109
> +    ::SendMessage(window, WM_RBUTTONDOWN, 0, MAKELPARAM(pt.x, pt.y));
> +    ::SendMessage(window, WM_RBUTTONUP, 0, MAKELPARAM(pt.x, pt.y));

Please use ::SendMessageW.
Comment 6 Adam Roben (:aroben) 2011-02-23 14:30:14 PST
Comment on attachment 83402 [details]
API test

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

> Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle_Bundle.cpp:44
> +        WKBundleNodeHandleRef nodeHandle = WKBundleHitTestResultGetNodeHandle(hitTestResult);

Presumably you're leaking this nodeHandle, now that you've changed the API to a Copy-style API.
Comment 7 Alice Liu 2011-02-28 17:43:16 PST
Created attachment 84163 [details]
all-in-one patch

Made a tweak to the test.  changed to use a WKRetainPtr so that the object that is returned from the (fixed) API call is ref'ed, so that it will crash in builds where the API call is not fixed.  

also renamed function and other suggestions adam made.
Comment 8 WebKit Review Bot 2011-02-28 17:45:04 PST
Attachment 84163 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebKit2/ChangeLog', u'Source/WebKit..." exit_code: 1

Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle.cpp:47:  Missing space after ,  [whitespace/comma] [3]
Total errors found: 1 in 11 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Alice Liu 2011-02-28 17:49:03 PST
Created attachment 84164 [details]
same as above, but fixed whitespace style nit
Comment 10 Gavin Barraclough 2011-02-28 19:41:51 PST
Comment on attachment 84164 [details]
same as above, but fixed whitespace style nit

Looks great.
Comment 11 Alice Liu 2011-02-28 20:45:22 PST
committed http://trac.webkit.org/changeset/79966