Bug 54902

Summary: [Qt] [WK2] Improve the memory handling of the context menu for WebKit 2
Product: WebKit Reporter: Benjamin Poulain <benjamin>
Component: WebKit2Assignee: Benjamin Poulain <benjamin>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue
Priority: P2 Keywords: Qt, QtTriaged
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Patch none

Description Benjamin Poulain 2011-02-21 12:52:47 PST
Currently, the QWKPage emit a signal when the context menu should be shown, a pointer to the menu being passed as parameter. The memory is handled by the receiver of the signal.

I did the design that way because the WebKit 2 apis do not prevent showContextMenu() from being called multiple time.

I now think it was a mistake because that make memory handling unreliable, and couple QGraphicsWKView and QWKPage via signals, which is a terrible idea... For example, disconnecting the default signal-slot connexion leaks the menus.
Comment 1 Benjamin Poulain 2011-02-21 12:59:43 PST
Created attachment 83208 [details]
Patch
Comment 2 Kenneth Rohde Christiansen 2011-02-22 00:37:46 PST
Comment on attachment 83208 [details]
Patch

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

> Source/WebKit2/UIProcess/qt/WebContextMenuProxyQt.cpp:97
> +    OwnPtr<QMenu> menu(new QMenu);

Why not create this as a PassOwnPtr? like in the PassRefPtr example here? http://www.webkit.org/coding/RefPtr.html
Comment 3 Benjamin Poulain 2011-02-22 02:34:13 PST
(In reply to comment #2)
> Why not create this as a PassOwnPtr? like in the PassRefPtr example here? http://www.webkit.org/coding/RefPtr.html

I think the semantic of OwnPtr is better than PassPtr for this function.

In the doc you mention, on top of the example, there is 
// example, not preferred style; should use RefCounted and adoptRef (see below)

 there is "we recommend PassRefPtr only for function argument and result types" in the text.
Comment 4 Benjamin Poulain 2011-02-22 02:35:27 PST
Comment on attachment 83208 [details]
Patch

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

>> Source/WebKit2/UIProcess/qt/WebContextMenuProxyQt.cpp:97
>> +    OwnPtr<QMenu> menu(new QMenu);
> 
> Why not create this as a PassOwnPtr? like in the PassRefPtr example here? http://www.webkit.org/coding/RefPtr.html

This should use adoptPtr() or it won't build without LOOSE_PASS_OWN_PTR defined.
Comment 5 Benjamin Poulain 2011-02-22 04:33:16 PST
Created attachment 83299 [details]
Patch
Comment 6 WebKit Commit Bot 2011-02-22 05:25:30 PST
Comment on attachment 83299 [details]
Patch

Clearing flags on attachment: 83299

Committed r79316: <http://trac.webkit.org/changeset/79316>
Comment 7 WebKit Commit Bot 2011-02-22 05:25:35 PST
All reviewed patches have been landed.  Closing bug.