Bug 97807 - [Chromium] Fix the find-in-page implementation for detaching frames.
Summary: [Chromium] Fix the find-in-page implementation for detaching frames.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Leandro Graciá Gil
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-27 11:45 PDT by Leandro Graciá Gil
Modified: 2012-09-28 09:37 PDT (History)
6 users (show)

See Also:


Attachments
Patch (20.78 KB, patch)
2012-09-27 11:50 PDT, Leandro Graciá Gil
no flags Details | Formatted Diff | Diff
Patch (20.09 KB, patch)
2012-09-27 12:36 PDT, Leandro Graciá Gil
no flags Details | Formatted Diff | Diff
Patch (19.51 KB, patch)
2012-09-28 05:01 PDT, Leandro Graciá Gil
no flags Details | Formatted Diff | Diff
Patch (19.85 KB, patch)
2012-09-28 09:06 PDT, Leandro Graciá Gil
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Leandro Graciá Gil 2012-09-27 11:45:49 PDT
Our current find-in-page implementation is not properly tested against detaching frames, as bug 97688 proved to be the case. We should introduce proper test coverage, fix any crashes and ensure that a final reply is always sent.
Comment 1 Leandro Graciá Gil 2012-09-27 11:50:08 PDT
Created attachment 166039 [details]
Patch
Comment 2 Leandro Graciá Gil 2012-09-27 11:51:07 PDT
(In reply to comment #1)
> Created an attachment (id=166039) [details]
> Patch

Tested against Chromium's Find* browser_tests.
Comment 3 Adam Barth 2012-09-27 11:59:04 PDT
Comment on attachment 166039 [details]
Patch

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

This is great.  A few minor comments.  The main issue is that the unit tests should go through the API rather than manually poking at WebCore internals and potentially putting WebCore into an inconsistent state.

> Source/WebKit/chromium/src/WebFrameImpl.cpp:581
> +    virtual void willDetachPage()

willDetachPage should always occur before frameDestroyed, so m_webFrameImpl will always be non-0 here.

> Source/WebKit/chromium/src/WebFrameImpl.cpp:1658
> +    // Detached frame case. Return no results.

We don't need this comment.  It just says what the code does, not why it does it.

> Source/WebKit/chromium/src/WebFrameImpl.cpp:1935
> +    // Do nothing on detached frames.

ditto

> Source/WebKit/chromium/src/WebFrameImpl.cpp:2726
> +    // Frame already detached.
> +    if (!frame() || !frame()->page())
> +        return;

Is this possible?  Also this comment is redundant.

> Source/WebKit/chromium/src/WebFrameImpl.h:427
> +    // Observes for any destruction / page detachment events that might occur
> +    // to the WebCore frame.
> +    OwnPtr<FrameDestructionHelper> m_frameDestructionHelper;

Why not just make WebFrameImpl inherit from FrameDestructionObserver?

> Source/WebKit/chromium/src/WebFrameImpl.h:471
> +    int m_findRequestIdentifier;

Should we initialize this value in the constructor?

> Source/WebKit/chromium/tests/WebFrameTest.cpp:1016
> +    // Detach the frame before finding.
> +    WebFrameImpl* secondFrame = static_cast<WebFrameImpl*>(mainFrame->traverseNext(false));
> +    secondFrame->frame()->willDetachPage();
> +    secondFrame->frame()->detachFromPage();

Rather than doing this manually, we should do this by manipulating the DOM via the API or via JavaScript.

> Source/WebKit/chromium/tests/WebFrameTest.cpp:1061
> +    // Detach the frame between finding and scoping.
> +    WebFrameImpl* secondFrame = static_cast<WebFrameImpl*>(mainFrame->traverseNext(false));
> +    secondFrame->frame()->willDetachPage();
> +    secondFrame->frame()->detachFromPage();

ditto
Comment 4 Leandro Graciá Gil 2012-09-27 12:36:41 PDT
Created attachment 166044 [details]
Patch
Comment 5 Leandro Graciá Gil 2012-09-27 12:37:03 PDT
Comment on attachment 166039 [details]
Patch

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

>> Source/WebKit/chromium/src/WebFrameImpl.cpp:581
>> +    virtual void willDetachPage()
> 
> willDetachPage should always occur before frameDestroyed, so m_webFrameImpl will always be non-0 here.

Fixed.

>> Source/WebKit/chromium/src/WebFrameImpl.cpp:1658
>> +    // Detached frame case. Return no results.
> 
> We don't need this comment.  It just says what the code does, not why it does it.

Removed.

>> Source/WebKit/chromium/src/WebFrameImpl.cpp:1935
>> +    // Do nothing on detached frames.
> 
> ditto

Removed.

>> Source/WebKit/chromium/src/WebFrameImpl.cpp:2726
>> +        return;
> 
> Is this possible?  Also this comment is redundant.

I was also expecting that willDetachPage would be called only once, but this is indeed being called again on detached frames during destruction.
Also comment removed.

>> Source/WebKit/chromium/src/WebFrameImpl.h:427
>> +    OwnPtr<FrameDestructionHelper> m_frameDestructionHelper;
> 
> Why not just make WebFrameImpl inherit from FrameDestructionObserver?

Done.

>> Source/WebKit/chromium/src/WebFrameImpl.h:471
>> +    int m_findRequestIdentifier;
> 
> Should we initialize this value in the constructor?

Good point, I missed this. Thanks.

>> Source/WebKit/chromium/tests/WebFrameTest.cpp:1016
>> +    secondFrame->frame()->detachFromPage();
> 
> Rather than doing this manually, we should do this by manipulating the DOM via the API or via JavaScript.

I'm open to suggestions. However, there is an important benefit of doing it this way: we can predict exactly when the willDetachPage method will be called and check all possible situations. Whatever the approach this is something we should keep.
Comment 6 Leandro Graciá Gil 2012-09-27 12:38:12 PDT
(In reply to comment #4)
> Created an attachment (id=166044) [details]
> Patch

Tested again against Chromium's Find* browser_tests.
Comment 7 Adam Barth 2012-09-27 12:44:30 PDT
Comment on attachment 166044 [details]
Patch

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

> Source/WebKit/chromium/tests/WebFrameTest.cpp:1016
> +    WebFrameImpl* secondFrame = static_cast<WebFrameImpl*>(mainFrame->traverseNext(false));
> +    secondFrame->frame()->willDetachPage();
> +    secondFrame->frame()->detachFromPage();

I would add WebNode::remove to the API and then call:

mainFrame->document().getElementById("some_id_that_you_like").remove();

You might need to throw in a webkit_support::RunAllPendingMessages() but I don't think you need that anymore.
Comment 8 Build Bot 2012-09-27 13:14:56 PDT
Comment on attachment 166044 [details]
Patch

Attachment 166044 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/14054031

New failing tests:
http/tests/workers/terminate-during-sync-operation.html
Comment 9 Leandro Graciá Gil 2012-09-27 14:01:02 PDT
(In reply to comment #7)
> (From update of attachment 166044 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=166044&action=review
> 
> > Source/WebKit/chromium/tests/WebFrameTest.cpp:1016
> > +    WebFrameImpl* secondFrame = static_cast<WebFrameImpl*>(mainFrame->traverseNext(false));
> > +    secondFrame->frame()->willDetachPage();
> > +    secondFrame->frame()->detachFromPage();
> 
> I would add WebNode::remove to the API and then call:
> 
> mainFrame->document().getElementById("some_id_that_you_like").remove();
> 
> You might need to throw in a webkit_support::RunAllPendingMessages() but I don't think you need that anymore.

Let's hope we don't need RunAllPendingMessages(), since that will trigger the scopeStringMatches operations and create issues for the cases where the frames are detached between the first call (the state reset) and the rest.

Is there any special considerations I should keep in mind in order to detach the main frame with that approach? In fact, how can I set an id for the main frame? The body, perhaps?
Comment 10 Adam Barth 2012-09-27 14:06:52 PDT
You won't be able to detach the main frame using this technique.  It's not clear to me whether you can actually detach the main frame in these scenarios.
Comment 11 Leandro Graciá Gil 2012-09-27 14:23:31 PDT
(In reply to comment #10)
> You won't be able to detach the main frame using this technique.  It's not clear to me whether you can actually detach the main frame in these scenarios.

Should we limit the testing to the other frames with your suggested approach, then?
Comment 12 Adam Barth 2012-09-27 14:33:47 PDT
Yeah, that's probably the thing to do.
Comment 13 Leandro Graciá Gil 2012-09-27 14:34:40 PDT
(In reply to comment #12)
> Yeah, that's probably the thing to do.

Ok. I'll upload a new patch tomorrow. Thanks for the feedback.
Comment 14 Leandro Graciá Gil 2012-09-28 05:01:53 PDT
Created attachment 166213 [details]
Patch
Comment 15 WebKit Review Bot 2012-09-28 05:04:07 PDT
Please wait for approval from abarth@webkit.org, dglazkov@chromium.org, fishd@chromium.org, jamesr@chromium.org or tkent@chromium.org before submitting, as this patch contains changes to the Chromium public API. See also https://trac.webkit.org/wiki/ChromiumWebKitAPI.
Comment 16 Adam Barth 2012-09-28 08:55:57 PDT
Comment on attachment 166213 [details]
Patch

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

Thanks for improving the test.

> Source/WebKit/chromium/src/WebFrameImpl.cpp:2332
> +    m_frame = frame;
> +    observeFrame(m_frame);

m_frame is now almost redundant.  FrameDestructionObserver also has a m_frame pointer.  It might be worth adding a FIXME comment about removing m_frame.
Comment 17 Leandro Graciá Gil 2012-09-28 09:06:03 PDT
Created attachment 166263 [details]
Patch
Comment 18 Leandro Graciá Gil 2012-09-28 09:07:06 PDT
(In reply to comment #17)
> Created an attachment (id=166263) [details]
> Patch

FIXME added to make sure we don't forget about this.  We should probably take a look again when rethinking the WebFrameImpl destruction.
Comment 19 WebKit Review Bot 2012-09-28 09:37:54 PDT
Comment on attachment 166263 [details]
Patch

Clearing flags on attachment: 166263

Committed r129910: <http://trac.webkit.org/changeset/129910>
Comment 20 WebKit Review Bot 2012-09-28 09:37:59 PDT
All reviewed patches have been landed.  Closing bug.