Changeset 211147 in webkit


Ignore:
Timestamp:
Jan 25, 2017 9:02:58 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

[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):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r211145 r211147  
     12017-01-25  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Icon Database should be in private browsing mode for ephemeral web views
     4        https://bugs.webkit.org/show_bug.cgi?id=167414
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        This is already done by WebProcessPool for the legacy private session setting, but only checking the setting and not
     9        whether there are ephemeral web pages or not.
     10
     11        * UIProcess/API/gtk/WebKitWebContext.cpp:
     12        (webkitWebContextEnableIconDatabasePrivateBrowsingIfNeeded): Enable icon database private browsing if there's
     13        any ephemeral web view.
     14        (webkitWebContextDisableIconDatabasePrivateBrowsingIfNeeded): Disable icon database private browsing if there
     15        aren't ephemeral web views anymore.
     16        (webkit_web_context_set_favicon_database_directory): Enable icon database private browsing if the web context is ephemeral.
     17        (webkitWebContextCreatePageForWebView): Call webkitWebContextEnableIconDatabasePrivateBrowsingIfNeeded().
     18        (webkitWebContextWebViewDestroyed): Call webkitWebContextDisableIconDatabasePrivateBrowsingIfNeeded().
     19        * UIProcess/API/gtk/WebKitWebView.cpp:
     20        (webkitWebViewDispose): Ensure webkitWebContextWebViewDestroyed is called only once.
     21
    1222017-01-25  Carlos Garcia Campos  <cgarcia@igalia.com>
    223
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp

    r211138 r211147  
    177177
    178178    HashMap<uint64_t, WebKitWebView*> webViews;
     179    unsigned ephemeralPageCount;
    179180
    180181    CString webExtensionsDirectory;
     
    713714}
    714715
     716static void webkitWebContextEnableIconDatabasePrivateBrowsingIfNeeded(WebKitWebContext* context, WebKitWebView* webView)
     717{
     718    if (webkit_web_context_is_ephemeral(context))
     719        return;
     720    if (!webkit_web_view_is_ephemeral(webView))
     721        return;
     722
     723    if (!context->priv->ephemeralPageCount)
     724        context->priv->processPool->iconDatabase()->setPrivateBrowsingEnabled(true);
     725    context->priv->ephemeralPageCount++;
     726}
     727
     728static void webkitWebContextDisableIconDatabasePrivateBrowsingIfNeeded(WebKitWebContext* context, WebKitWebView* webView)
     729{
     730    if (webkit_web_context_is_ephemeral(context))
     731        return;
     732    if (!webkit_web_view_is_ephemeral(webView))
     733        return;
     734
     735    ASSERT(context->priv->ephemeralPageCount);
     736    context->priv->ephemeralPageCount--;
     737    if (!context->priv->ephemeralPageCount)
     738        context->priv->processPool->iconDatabase()->setPrivateBrowsingEnabled(false);
     739}
     740
    715741/**
    716742 * webkit_web_context_set_favicon_database_directory:
     
    751777    // Setting the path will cause the icon database to be opened.
    752778    priv->processPool->setIconDatabasePath(WebCore::stringFromFileSystemRepresentation(faviconDatabasePath.get()));
     779
     780    if (webkit_web_context_is_ephemeral(context))
     781        priv->processPool->iconDatabase()->setPrivateBrowsingEnabled(true);
    753782}
    754783
     
    14591488    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(webView);
    14601489
     1490    // FIXME: icon database private mode is global, not per page, so while there are
     1491    // pages in private mode we need to enable the private mode in the icon database.
     1492    webkitWebContextEnableIconDatabasePrivateBrowsingIfNeeded(context, webView);
     1493
    14611494    auto pageConfiguration = API::PageConfiguration::create();
    14621495    pageConfiguration->setProcessPool(context->priv->processPool.get());
     
    14781511void webkitWebContextWebViewDestroyed(WebKitWebContext* context, WebKitWebView* webView)
    14791512{
     1513    webkitWebContextDisableIconDatabasePrivateBrowsingIfNeeded(context, webView);
    14801514    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
    14811515    context->priv->webViews.remove(page->pageID());
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r211138 r211147  
    779779        getPage(webView)->pageLoadState().removeObserver(*webView->priv->loadObserver);
    780780        webView->priv->loadObserver.reset();
     781
     782        // We notify the context here to ensure it's called only once. Ideally we should
     783        // call this in finalize, not dispose, but finalize is used internally and we don't
     784        // have access to the instance pointer from the private struct destructor.
     785        webkitWebContextWebViewDestroyed(webView->priv->context.get(), webView);
    781786    }
    782 
    783     webkitWebContextWebViewDestroyed(webView->priv->context.get(), webView);
    784787
    785788    G_OBJECT_CLASS(webkit_web_view_parent_class)->dispose(object);
  • trunk/Tools/ChangeLog

    r211146 r211147  
     12017-01-25  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Icon Database should be in private browsing mode for ephemeral web views
     4        https://bugs.webkit.org/show_bug.cgi?id=167414
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Add a test case to check ephemeral web views don't write favicons to the database.
     9
     10        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp:
     11        (ephemeralViewLoadChanged):
     12        (testPrivateBrowsing):
     13        (testFaviconDatabase):
     14
    1152017-01-25  Carlos Garcia Campos  <cgarcia@igalia.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp

    r185502 r211147  
    153153}
    154154
     155static void ephemeralViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebViewTest* test)
     156{
     157    if (loadEvent != WEBKIT_LOAD_FINISHED)
     158        return;
     159    g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(ephemeralViewLoadChanged), test);
     160    test->quitMainLoop();
     161}
     162
     163static void testPrivateBrowsing(FaviconDatabaseTest* test)
     164{
     165    GRefPtr<WebKitWebView> webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
     166        "web-context", test->m_webContext.get(),
     167        "is-ephemeral", TRUE,
     168        nullptr));
     169    g_signal_connect(webView.get(), "load-changed", G_CALLBACK(ephemeralViewLoadChanged), test);
     170    webkit_web_view_load_uri(webView.get(), kServer->getURIForPath("/foo").data());
     171    g_main_loop_run(test->m_mainLoop);
     172
     173    // An ephemeral web view should not write to the database.
     174    test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/foo").data());
     175    g_assert(!test->m_favicon);
     176    g_assert(test->m_error);
     177}
     178
    155179static void testGetFavicon(FaviconDatabaseTest* test)
    156180{
     
    229253    testNotInitialized(test);
    230254    testSetDirectory(test);
     255    testPrivateBrowsing(test);
    231256    testGetFavicon(test);
    232257    testGetFaviconURI(test);
Note: See TracChangeset for help on using the changeset viewer.