<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:mcatanzaro&#64;igalia.com" title="Michael Catanzaro &lt;mcatanzaro&#64;igalia.com&gt;"> <span class="fn">Michael Catanzaro</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GTK] Add webkit_context_menu_item_new_from_gaction"
   href="https://bugs.webkit.org/show_bug.cgi?id=159631">bug 159631</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Attachment #288043 Flags</td>
           <td>review?
           </td>
           <td>review+, commit-queue-
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GTK] Add webkit_context_menu_item_new_from_gaction"
   href="https://bugs.webkit.org/show_bug.cgi?id=159631#c3">Comment # 3</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GTK] Add webkit_context_menu_item_new_from_gaction"
   href="https://bugs.webkit.org/show_bug.cgi?id=159631">bug 159631</a>
              from <span class="vcard"><a class="email" href="mailto:mcatanzaro&#64;igalia.com" title="Michael Catanzaro &lt;mcatanzaro&#64;igalia.com&gt;"> <span class="fn">Michael Catanzaro</span></a>
</span></b>
        <pre>Comment on <span class=""><a href="attachment.cgi?id=288043&amp;action=diff" name="attach_288043" title="Patch">attachment 288043</a> <a href="attachment.cgi?id=288043&amp;action=edit" title="Patch">[details]</a></span>
Patch

View in context: <a href="https://bugs.webkit.org/attachment.cgi?id=288043&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=288043&amp;action=review</a>

Great job!

r+ means review pass, since my comments are all minor. cq- means commit-queue denied. You'll need to re-upload this patch to address my comments, but you can manually write &quot;Reviewed by Michael Catanzaro&quot; and don't need to set the r? flag again, just cq?. Still, since this patch adds new API, it needs to be approved by a second GTK+ reviewer before we can commit it. Carlos Garcia will look at it soon.

Also, I forgot to suggest this earlier, but we should also deprecate webkit_context_menu_item_new(), since it's impossible to use without using deprecated GtkAction. You can look at webkit_web_context_set_disk_cache_directory() for an example of how to deprecate a method; it would look like this:

Deprecated: 2.16. Use webkit_context_menu_item_new_from_gaction() instead.

<span class="quote">&gt; Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp:199
&gt; +static void actionDataFree(ActionData* actionData, GObject* object)</span >

I like the documented name of the second parameter: GObject* whereTheObjectWas. It makes it more clear that the object is being finalized and is not safe to use. But actually, you don't need this parameter at all (see my next comment), so you should leave it unnamed to avoid unused variable compiler warnings:

static void actionDataFree(ActionData* actionData, GObject*)

<span class="quote">&gt; Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp:202
&gt; +    g_return_if_fail(G_IS_OBJECT(object));</span >

Hm, I'm slightly surprised this check passes, since object is being finalized after all. I would remove it. You don't use object anywhere in this function, and you know it's being finalized, so why check to see if it's valid?

<span class="quote">&gt; Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp:205
&gt; +    if (actionData-&gt;parameter)
&gt; +        g_variant_unref(actionData-&gt;parameter);</span >

This works, but try something more idiomatic: use a GRefPtr&lt;GVariant&gt; in the ActionData struct. Then you can delete these lines. Since you're not allocating the ActionData struct with normal C++ new and the struct would no longer contain only plain-old-data (POD) types, you'll have to manually invoke ActionData's destructor right before freeing the memory:

actionData-&gt;~ActionData();
g_slice_free(ActionData, actionData); // or free it some other way as appropriate, see comments below

<span class="quote">&gt; Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp:234
&gt; + * Creates a new #WebKitContextMenuItem for the given action using the given &#64;label.</span >

I would write: Creates a new #WebKitContextMenuItem for &#64;action using the label &#64;label.

<span class="quote">&gt; Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp:240
&gt; +WebKitContextMenuItem* webkit_context_menu_item_new_from_gaction(GAction* action, GVariant* parameter, const gchar* label)</span >

OK, time for my only serious concern with this patch: what are the ownership semantics of the GAction parameter? Since you do not have any transfer annotation, the default is transfer full. Is that what you intended? Is it the best choice here? Since it is transfer full, you have to free it in actionDataFree, but it looks like you don't do that. If you intended it to be transfer none, you need to add the annotation.

<span class="quote">&gt; Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp:245
&gt; +    ActionData* actionData = g_slice_new(ActionData);</span >

Instead of using GLib's &quot;fast&quot; allocator, which isn't very good, it's better to use WebKit's faster one (bmalloc):

ActionData* actionData = static_cast&lt;ActionData*&gt;(fastMalloc(sizeof(ActionData)));

Then you would free it with fastFree(actionData).

<span class="quote">&gt; Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:542
&gt; +class ContextMenuCustomGActionTest: public ContextMenuTest {</span >

Leave a space before the colon. I see you matched the style of the rest of this file, which is normally the right thing to do, but in this case the other examples in this file were wrong. :)

<span class="quote">&gt; Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:549
&gt; +        : m_itemToActivateLabel(0)
&gt; +        , m_activated(false)
&gt; +        , m_toggled(false)</span >

In new code we initialize these inline-style instead of in the constructor. I'll show you down below.

(And be careful to use nullptr for pointers, not 0.)

<span class="quote">&gt; Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:571
&gt; +        return 0;</span >

Do you really need the return for it to compile? GCC isn't smart enough to see it's unreachable? If you have to keep it, return nullptr rather than 0, since the return value is a pointer type.

<span class="quote">&gt; Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:587
&gt; +        return FALSE;</span >

return G_SOURCE_REMOVE (readable alias for FALSE)

<span class="quote">&gt; Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:592
&gt; +        m_activated = m_toggled = false;</span >

I think I prefer to write this on two lines.

<span class="quote">&gt; Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:615
&gt; +    void setAction(GAction* action, GVariant *parameter, const char* label)
&gt; +    {
&gt; +        m_action = action;</span >

Add another check: assertObjectIsDeletedWhenTestFinishes(G_OBJECT(action)). Does it pass?

Also, careful to write GVariant* parameter rather than GVariant *parameter while we're in WebKit code rather than GNOME code.

<span class="quote">&gt; Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:629
&gt; +    const char* m_label;
&gt; +    const char* m_itemToActivateLabel;
&gt; +    bool m_activated;
&gt; +    bool m_toggled;</span >

const char* m_label { nullptr };
const char* m_itemToActivateLabel { nullptr };
bool m_activated { false };
bool m_toggled { false };

<span class="quote">&gt; Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:1146
&gt; +    ContextMenuCustomGActionTest::add(&quot;WebKitWebView&quot;, &quot;gaction-populate-menu&quot;, testContextMenuGActionPopulateMenu);</span >

Hm, how about &quot;populate-menu-with-gaction&quot; and &quot;testContextMenuPopulateMenuWithGAction&quot;?</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>