<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[211147] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/211147">211147</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2017-01-25 09:02:58 -0800 (Wed, 25 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] Icon Database should be in private browsing mode for ephemeral web views
https://bugs.webkit.org/show_bug.cgi?id=167414

Reviewed by Michael Catanzaro.

Source/WebKit2:

This is already done by WebProcessPool for the legacy private session setting, but only checking the setting and not
whether there are ephemeral web pages or not.

* UIProcess/API/gtk/WebKitWebContext.cpp:
(webkitWebContextEnableIconDatabasePrivateBrowsingIfNeeded): Enable icon database private browsing if there's
any ephemeral web view.
(webkitWebContextDisableIconDatabasePrivateBrowsingIfNeeded): Disable icon database private browsing if there
aren't ephemeral web views anymore.
(webkit_web_context_set_favicon_database_directory): Enable icon database private browsing if the web context is ephemeral.
(webkitWebContextCreatePageForWebView): Call webkitWebContextEnableIconDatabasePrivateBrowsingIfNeeded().
(webkitWebContextWebViewDestroyed): Call webkitWebContextDisableIconDatabasePrivateBrowsingIfNeeded().
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkitWebViewDispose): Ensure webkitWebContextWebViewDestroyed is called only once.

Tools:

Add a test case to check ephemeral web views don't write favicons to the database.

* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp:
(ephemeralViewLoadChanged):
(testPrivateBrowsing):
(testFaviconDatabase):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitWebContextcpp">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitWebViewcpp">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2GtkTestWebKitFaviconDatabasecpp">trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (211146 => 211147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-01-25 16:56:00 UTC (rev 211146)
+++ trunk/Source/WebKit2/ChangeLog        2017-01-25 17:02:58 UTC (rev 211147)
</span><span class="lines">@@ -1,5 +1,26 @@
</span><span class="cx"> 2017-01-25  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><ins>+        [GTK] Icon Database should be in private browsing mode for ephemeral web views
+        https://bugs.webkit.org/show_bug.cgi?id=167414
+
+        Reviewed by Michael Catanzaro.
+
+        This is already done by WebProcessPool for the legacy private session setting, but only checking the setting and not
+        whether there are ephemeral web pages or not.
+
+        * UIProcess/API/gtk/WebKitWebContext.cpp:
+        (webkitWebContextEnableIconDatabasePrivateBrowsingIfNeeded): Enable icon database private browsing if there's
+        any ephemeral web view.
+        (webkitWebContextDisableIconDatabasePrivateBrowsingIfNeeded): Disable icon database private browsing if there
+        aren't ephemeral web views anymore.
+        (webkit_web_context_set_favicon_database_directory): Enable icon database private browsing if the web context is ephemeral.
+        (webkitWebContextCreatePageForWebView): Call webkitWebContextEnableIconDatabasePrivateBrowsingIfNeeded().
+        (webkitWebContextWebViewDestroyed): Call webkitWebContextDisableIconDatabasePrivateBrowsingIfNeeded().
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (webkitWebViewDispose): Ensure webkitWebContextWebViewDestroyed is called only once.
+
+2017-01-25  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
</ins><span class="cx">         [GTK] UIProcess from WebKitGtk+ 2.15.x SIGSEGVs because of X Error BadDamage in WebKit::AcceleratedBackingStoreX11::update(WebKit::LayerTreeContext const&amp;) () at Source/WebKit2/UIProcess/gtk/AcceleratedBackingStoreX11.cpp:145
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=165656
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitWebContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp (211146 => 211147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp        2017-01-25 16:56:00 UTC (rev 211146)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp        2017-01-25 17:02:58 UTC (rev 211147)
</span><span class="lines">@@ -176,6 +176,7 @@
</span><span class="cx">     unsigned processCountLimit;
</span><span class="cx"> 
</span><span class="cx">     HashMap&lt;uint64_t, WebKitWebView*&gt; webViews;
</span><ins>+    unsigned ephemeralPageCount;
</ins><span class="cx"> 
</span><span class="cx">     CString webExtensionsDirectory;
</span><span class="cx">     GRefPtr&lt;GVariant&gt; webExtensionsInitializationUserData;
</span><span class="lines">@@ -712,6 +713,31 @@
</span><span class="cx">     priv-&gt;faviconDatabase = adoptGRef(webkitFaviconDatabaseCreate(priv-&gt;processPool-&gt;iconDatabase()));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void webkitWebContextEnableIconDatabasePrivateBrowsingIfNeeded(WebKitWebContext* context, WebKitWebView* webView)
+{
+    if (webkit_web_context_is_ephemeral(context))
+        return;
+    if (!webkit_web_view_is_ephemeral(webView))
+        return;
+
+    if (!context-&gt;priv-&gt;ephemeralPageCount)
+        context-&gt;priv-&gt;processPool-&gt;iconDatabase()-&gt;setPrivateBrowsingEnabled(true);
+    context-&gt;priv-&gt;ephemeralPageCount++;
+}
+
+static void webkitWebContextDisableIconDatabasePrivateBrowsingIfNeeded(WebKitWebContext* context, WebKitWebView* webView)
+{
+    if (webkit_web_context_is_ephemeral(context))
+        return;
+    if (!webkit_web_view_is_ephemeral(webView))
+        return;
+
+    ASSERT(context-&gt;priv-&gt;ephemeralPageCount);
+    context-&gt;priv-&gt;ephemeralPageCount--;
+    if (!context-&gt;priv-&gt;ephemeralPageCount)
+        context-&gt;priv-&gt;processPool-&gt;iconDatabase()-&gt;setPrivateBrowsingEnabled(false);
+}
+
</ins><span class="cx"> /**
</span><span class="cx">  * webkit_web_context_set_favicon_database_directory:
</span><span class="cx">  * @context: a #WebKitWebContext
</span><span class="lines">@@ -750,6 +776,9 @@
</span><span class="cx"> 
</span><span class="cx">     // Setting the path will cause the icon database to be opened.
</span><span class="cx">     priv-&gt;processPool-&gt;setIconDatabasePath(WebCore::stringFromFileSystemRepresentation(faviconDatabasePath.get()));
</span><ins>+
+    if (webkit_web_context_is_ephemeral(context))
+        priv-&gt;processPool-&gt;iconDatabase()-&gt;setPrivateBrowsingEnabled(true);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -1458,6 +1487,10 @@
</span><span class="cx"> {
</span><span class="cx">     WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(webView);
</span><span class="cx"> 
</span><ins>+    // FIXME: icon database private mode is global, not per page, so while there are
+    // pages in private mode we need to enable the private mode in the icon database.
+    webkitWebContextEnableIconDatabasePrivateBrowsingIfNeeded(context, webView);
+
</ins><span class="cx">     auto pageConfiguration = API::PageConfiguration::create();
</span><span class="cx">     pageConfiguration-&gt;setProcessPool(context-&gt;priv-&gt;processPool.get());
</span><span class="cx">     pageConfiguration-&gt;setPreferences(webkitSettingsGetPreferences(webkit_web_view_get_settings(webView)));
</span><span class="lines">@@ -1477,6 +1510,7 @@
</span><span class="cx"> 
</span><span class="cx"> void webkitWebContextWebViewDestroyed(WebKitWebContext* context, WebKitWebView* webView)
</span><span class="cx"> {
</span><ins>+    webkitWebContextDisableIconDatabasePrivateBrowsingIfNeeded(context, webView);
</ins><span class="cx">     WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
</span><span class="cx">     context-&gt;priv-&gt;webViews.remove(page-&gt;pageID());
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitWebViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (211146 => 211147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp        2017-01-25 16:56:00 UTC (rev 211146)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp        2017-01-25 17:02:58 UTC (rev 211147)
</span><span class="lines">@@ -778,10 +778,13 @@
</span><span class="cx">     if (webView-&gt;priv-&gt;loadObserver) {
</span><span class="cx">         getPage(webView)-&gt;pageLoadState().removeObserver(*webView-&gt;priv-&gt;loadObserver);
</span><span class="cx">         webView-&gt;priv-&gt;loadObserver.reset();
</span><ins>+
+        // We notify the context here to ensure it's called only once. Ideally we should
+        // call this in finalize, not dispose, but finalize is used internally and we don't
+        // have access to the instance pointer from the private struct destructor.
+        webkitWebContextWebViewDestroyed(webView-&gt;priv-&gt;context.get(), webView);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    webkitWebContextWebViewDestroyed(webView-&gt;priv-&gt;context.get(), webView);
-
</del><span class="cx">     G_OBJECT_CLASS(webkit_web_view_parent_class)-&gt;dispose(object);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (211146 => 211147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-01-25 16:56:00 UTC (rev 211146)
+++ trunk/Tools/ChangeLog        2017-01-25 17:02:58 UTC (rev 211147)
</span><span class="lines">@@ -1,5 +1,19 @@
</span><span class="cx"> 2017-01-25  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><ins>+        [GTK] Icon Database should be in private browsing mode for ephemeral web views
+        https://bugs.webkit.org/show_bug.cgi?id=167414
+
+        Reviewed by Michael Catanzaro.
+
+        Add a test case to check ephemeral web views don't write favicons to the database.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp:
+        (ephemeralViewLoadChanged):
+        (testPrivateBrowsing):
+        (testFaviconDatabase):
+
+2017-01-25  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
</ins><span class="cx">         [GTK] Add a private browsing mode to MiniBrowser
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=167413
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2GtkTestWebKitFaviconDatabasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp (211146 => 211147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp        2017-01-25 16:56:00 UTC (rev 211146)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp        2017-01-25 17:02:58 UTC (rev 211147)
</span><span class="lines">@@ -152,6 +152,30 @@
</span><span class="cx">     g_assert(!iconURI);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void ephemeralViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebViewTest* test)
+{
+    if (loadEvent != WEBKIT_LOAD_FINISHED)
+        return;
+    g_signal_handlers_disconnect_by_func(webView, reinterpret_cast&lt;void*&gt;(ephemeralViewLoadChanged), test);
+    test-&gt;quitMainLoop();
+}
+
+static void testPrivateBrowsing(FaviconDatabaseTest* test)
+{
+    GRefPtr&lt;WebKitWebView&gt; webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+        &quot;web-context&quot;, test-&gt;m_webContext.get(),
+        &quot;is-ephemeral&quot;, TRUE,
+        nullptr));
+    g_signal_connect(webView.get(), &quot;load-changed&quot;, G_CALLBACK(ephemeralViewLoadChanged), test);
+    webkit_web_view_load_uri(webView.get(), kServer-&gt;getURIForPath(&quot;/foo&quot;).data());
+    g_main_loop_run(test-&gt;m_mainLoop);
+
+    // An ephemeral web view should not write to the database.
+    test-&gt;getFaviconForPageURIAndWaitUntilReady(kServer-&gt;getURIForPath(&quot;/foo&quot;).data());
+    g_assert(!test-&gt;m_favicon);
+    g_assert(test-&gt;m_error);
+}
+
</ins><span class="cx"> static void testGetFavicon(FaviconDatabaseTest* test)
</span><span class="cx"> {
</span><span class="cx">     // We need to load the page first to ensure the icon data will be
</span><span class="lines">@@ -228,6 +252,7 @@
</span><span class="cx">     // See https://bugs.webkit.org/show_bug.cgi?id=111434.
</span><span class="cx">     testNotInitialized(test);
</span><span class="cx">     testSetDirectory(test);
</span><ins>+    testPrivateBrowsing(test);
</ins><span class="cx">     testGetFavicon(test);
</span><span class="cx">     testGetFaviconURI(test);
</span><span class="cx">     testWebViewFavicon(test);
</span></span></pre>
</div>
</div>

</body>
</html>