<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GTK] Update cookie manager API to properly work with ephemeral sessions"
   href="https://bugs.webkit.org/show_bug.cgi?id=168230#c4">Comment # 4</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GTK] Update cookie manager API to properly work with ephemeral sessions"
   href="https://bugs.webkit.org/show_bug.cgi?id=168230">bug 168230</a>
              from <span class="vcard"><a class="email" href="mailto:cgarcia&#64;igalia.com" title="Carlos Garcia Campos &lt;cgarcia&#64;igalia.com&gt;"> <span class="fn">Carlos Garcia Campos</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=168230#c2">comment #2</a>)
<span class="quote">&gt; Comment on <span class=""><a href="attachment.cgi?id=301345&amp;action=diff" name="attach_301345" title="Patch">attachment 301345</a> <a href="attachment.cgi?id=301345&amp;action=edit" title="Patch">[details]</a></span>
&gt; Patch
&gt; 
&gt; View in context:
&gt; <a href="https://bugs.webkit.org/attachment.cgi?id=301345&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=301345&amp;action=review</a>
&gt; 
&gt; It looks mostly good, but I'd like to review this one again after you answer
&gt; my questions about why you used the weak pointer, which I hope was just a
&gt; mistake.
&gt; 
&gt; &gt; Source/WebCore/platform/network/soup/CookieJarSoup.cpp:217
&gt; &gt; +    // FIXME: Add support for deleting cookies modified since the given timestamp. It should probably be added to libsoup.
&gt; &gt; +    if (timestamp == std::chrono::system_clock::from_time_t(0))
&gt; &gt; +        deleteAllCookies(session);
&gt; 
&gt; Are you planning to fix this soon? I don't think we should proceed with
&gt; these API changes if the API does not work properly. At least add a runtime
&gt; warning using g_warning().</span >

No, I don't have time, I'll add the warning.

<span class="quote">&gt; &gt; Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp:40
&gt; &gt; + * The WebKitCookieManager defines how to setup and handle cookies.
&gt; 
&gt; setup (noun) -&gt; set up (verb)
&gt; 
&gt; &gt; Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp:43
&gt; &gt;   * store cookies, with webkit_cookie_manager_set_persistent_storage(),
&gt; 
&gt; Remove the comma
&gt; 
&gt; &gt; Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp:144
&gt; &gt; +    g_object_add_weak_pointer(G_OBJECT(dataManager), reinterpret_cast&lt;void**&gt;(&amp;manager-&gt;priv-&gt;dataManager));
&gt; 
&gt; Why is the weak pointer needed? I would expect WebKitCookieManager to be
&gt; owned by the WebKitWebsiteDataManager, so WebKitWebsiteDataManager would
&gt; keep a ref to ensure the WebKitCookieManager is never destroyed first. Is
&gt; there some really good reason you don't do that? I think it should be a
&gt; normal raw pointer instead.</span >

The cookie manager can't be created by the user, it's always created and owned by the website data manager. However, nothing prevents the user from taking a ref to the returned cookie manager. It's a programmer error to use the cookie manager after the data manager is destroyed, that's why all methods are protected with g_return_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager-&gt;priv-&gt;dataManager)). I don't want to take a reference to the data manager. Maybe it isn't worth it just to handle a corner case, so I can simply remove the weak point and use a plan pointer. Users will get a crash sooner or layer in both cases I'm afraid.

<span class="quote">&gt; &gt; Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp:165
&gt; &gt;   * By default, &#64;cookie_manager doesn't store the cookies persistenly, so you need to call this
&gt; 
&gt; Preexisting problem, but let's fix it now: persistenly -&gt; persistently
&gt; 
&gt; &gt; Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp:176
&gt; &gt; +    for (auto* processPool : webkitWebsiteDataManagerGetProcessPools(manager-&gt;priv-&gt;dataManager)) {
&gt; 
&gt; This is a big problem. Either manager-&gt;priv-&gt;dataManager can be legitimately
&gt; null here, or you should not have used a weak pointer.
&gt; 
&gt; &gt; Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp:197
&gt; &gt; +    g_return_if_fail(WEBKIT_IS_WEBSITE_DATA_MANAGER(manager-&gt;priv-&gt;dataManager));
&gt; 
&gt; Ditto. If you're going to use the weak pointer, then the entire class needs
&gt; to be prepared to deal with the WebKitWebsiteDataManager being null. There's
&gt; no point to the weak pointer otherwise.</span >

It deals with that already, but using g_return macros.

<span class="quote">&gt; &gt; Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp:82
&gt; &gt;   * webkit_web_context_get_security_manager() for that.
&gt; 
&gt; Remove &quot;for that&quot;: the sentence works better without them.
&gt; 
&gt; &gt; Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp:698
&gt; &gt;  WebKitCookieManager* webkit_web_context_get_cookie_manager(WebKitWebContext* context)
&gt; 
&gt; I think you should document that this function returns the
&gt; WebKitCookieManager of this context's WebKitWebsiteDataManager. I know it's
&gt; an implementation detail, but otherwise I think it's kind of confusing why
&gt; both WebKitWebContext and WebKitWebsiteDataManager have a
&gt; WebKitCookieManager.
&gt; 
&gt; &gt; Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp:2286
&gt; &gt; + * Get the #WebKitWebsiteDataManager associated to &#64;web_view. If &#64;web_view is not ephemeral
&gt; 
&gt; Add a comma after &quot;ephemeral&quot;
&gt; 
&gt; &gt; Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp:2287
&gt; &gt; + * the returned #WebKitWebsiteDataManager will be the same as the #WebKitWebView:web-context one.
&gt; 
&gt; &quot;the #WebKitWebView:web-context one&quot; doesn't sound great. I would write:
&gt; &quot;will be the same as the #WebKitWebsiteDataManager of &#64;web_view's
&gt; #WebKitWebContext.&quot;
&gt; 
&gt; &gt; Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.cpp:103
&gt; &gt; +    GRefPtr&lt;WebKitCookieManager&gt; cookieManager;
&gt; 
&gt; Aha, so you do keep a ref! Good! Then you don't need the weak pointer in
&gt; WebKitCookieManager, right? Surely the WebKitCookieManager cannot outlive
&gt; the WebKitWebsiteDataManager due to this ref.</span >

Not surely, but I guess we should assume it, yes.

<span class="quote">&gt; &gt; Source/WebKit2/UIProcess/API/gtk/WebKitWebsiteDataManager.cpp:104
&gt; &gt; +    Vector&lt;WebProcessPool*&gt; processPools;
&gt; 
&gt; Is it possible to use Vector&lt;WebProcessPool&amp;&gt; to clarify that the process
&gt; pools are not null?</span >

No, I don't think Vector can contain references.

<span class="quote">&gt; &gt; Source/WebKit2/UIProcess/WebsiteData/WebsiteDataRecord.cpp:54
&gt; &gt; +#if PLATFORM(GTK)
&gt; &gt; +    if (hostName == &quot;localhost&quot;)
&gt; &gt; +        return hostName;
&gt; &gt; +#endif
&gt; 
&gt; I think this should be an #else condition, not a GTK-specific condition.</span ></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>