Changeset 225043 in webkit


Ignore:
Timestamp:
Nov 20, 2017 12:11:29 AM (6 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK][WPE] webkit_cookie_manager_delete_all_cookies doesn't delete the cookies if called before a web process is running
https://bugs.webkit.org/show_bug.cgi?id=175265

Reviewed by Michael Catanzaro.

Source/WebKit:

This is what happens:

1- We create our WebKitWebContext that creates its WebProcessPool.
2- We set a persistent cookies storage.
3- We ask the website data store to delete all cookies, but since website data store is a web process observer

and we haven't spawned any web process yet, it creates a new WebProcessPool with the default configuration
(no persistent cookies) and sends the message to delete the cookies there.

4- The network process of the second process pool does nothing because it doesn't have cookies at all.

We need to set the primary data store of the WebProcessPool when WebKitWebContext is constructed to ensure that
one is used before the web process is launched.

  • UIProcess/API/glib/WebKitWebContext.cpp:

(webkitWebContextConstructed):

Tools:

Add test case.

  • TestWebKitAPI/Tests/WebKitGLib/TestCookieManager.cpp:

(testCookieManagerPersistentStorageDeleteAll):
(serverCallback):
(beforeAll):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r225042 r225043  
     12017-11-20  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK][WPE] webkit_cookie_manager_delete_all_cookies doesn't delete the cookies if called before a web process is running
     4        https://bugs.webkit.org/show_bug.cgi?id=175265
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        This is what happens:
     9
     10        1- We create our WebKitWebContext that creates its WebProcessPool.
     11        2- We set a persistent cookies storage.
     12        3- We ask the website data store to delete all cookies, but since website data store is a web process observer
     13           and we haven't spawned any web process yet, it creates a new WebProcessPool with the default configuration
     14           (no persistent cookies) and sends the message to delete the cookies there.
     15        4- The network process of the second process pool does nothing because it doesn't have cookies at all.
     16
     17        We need to set the primary data store of the WebProcessPool when WebKitWebContext is constructed to ensure that
     18        one is used before the web process is launched.
     19
     20        * UIProcess/API/glib/WebKitWebContext.cpp:
     21        (webkitWebContextConstructed):
     22
    1232017-11-19  Tim Horton  <timothy_horton@apple.com>
    224
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitWebContext.cpp

    r224371 r225043  
    342342    if (!priv->websiteDataManager)
    343343        priv->websiteDataManager = adoptGRef(webkitWebsiteDataManagerCreate(websiteDataStoreConfigurationForWebProcessPoolConfiguration(configuration)));
     344    priv->processPool->setPrimaryDataStore(webkitWebsiteDataManagerGetDataStore(priv->websiteDataManager.get()));
    344345
    345346    webkitWebsiteDataManagerAddProcessPool(priv->websiteDataManager.get(), *priv->processPool);
  • trunk/Tools/ChangeLog

    r225042 r225043  
     12017-11-20  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK][WPE] webkit_cookie_manager_delete_all_cookies doesn't delete the cookies if called before a web process is running
     4        https://bugs.webkit.org/show_bug.cgi?id=175265
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Add test case.
     9
     10        * TestWebKitAPI/Tests/WebKitGLib/TestCookieManager.cpp:
     11        (testCookieManagerPersistentStorageDeleteAll):
     12        (serverCallback):
     13        (beforeAll):
     14
    1152017-11-19  Tim Horton  <timothy_horton@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestCookieManager.cpp

    r218686 r225043  
    4141    {
    4242        test->m_cookiesChanged = true;
    43         if (test->m_finishLoopWhenCookiesChange)
     43        if (test->m_finishLoopWhenCookiesChange && !(--test->m_cookiesExpectedToChangeCount))
    4444            g_main_loop_quit(test->m_mainLoop);
    4545    }
     
    4848        : WebViewTest()
    4949        , m_cookieManager(webkit_web_context_get_cookie_manager(webkit_web_view_get_context(m_webView)))
    50         , m_acceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY)
    51         , m_domains(0)
    52         , m_cookiesChanged(false)
    53         , m_finishLoopWhenCookiesChange(false)
    5450    {
    5551        g_assert(webkit_website_data_manager_get_cookie_manager(webkit_web_context_get_website_data_manager(webkit_web_view_get_context(m_webView))) == m_cookieManager);
     
    163159    }
    164160
    165     void waitUntilCookiesChanged()
     161    void waitUntilCookiesChanged(int cookiesExpectedToChangeCount = 1)
    166162    {
    167163        m_cookiesChanged = false;
     164        m_cookiesExpectedToChangeCount = cookiesExpectedToChangeCount;
    168165        m_finishLoopWhenCookiesChange = true;
    169166        g_main_loop_run(m_mainLoop);
     
    171168    }
    172169
    173     WebKitCookieManager* m_cookieManager;
    174     WebKitCookieAcceptPolicy m_acceptPolicy;
    175     char** m_domains;
    176     bool m_cookiesChanged;
    177     bool m_finishLoopWhenCookiesChange;
     170    WebKitCookieManager* m_cookieManager { nullptr };
     171    WebKitCookieAcceptPolicy m_acceptPolicy { WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY };
     172    char** m_domains { nullptr };
     173    bool m_cookiesChanged { false };
     174    int m_cookiesExpectedToChangeCount { 0 };
     175    bool m_finishLoopWhenCookiesChange { false };
    178176    GUniquePtr<char> m_cookiesTextFile;
    179177    GUniquePtr<char> m_cookiesSQLiteFile;
     
    299297    test->deleteAllCookies();
    300298    g_assert_cmpint(g_strv_length(test->getDomains()), ==, 0);
     299}
     300
     301static void testCookieManagerPersistentStorageDeleteAll(CookieManagerTest* test, gconstpointer)
     302{
     303    // This checks that we can remove all the cookies of an existing file before a web process is created.
     304    // See bug https://bugs.webkit.org/show_bug.cgi?id=175265.
     305    static const char cookiesFileFormat[] = "127.0.0.1\tFALSE\t/\tFALSE\t%ld\tfoo\tbar\nlocalhost\tFALSE\t/\tFALSE\t%ld\tbaz\tqux\n";
     306    time_t expires = time(nullptr) + 60;
     307    GUniquePtr<char> cookiesFileContents(g_strdup_printf(cookiesFileFormat, expires, expires));
     308    GUniquePtr<char> cookiesFile(g_build_filename(Test::dataDirectory(), "cookies.txt", nullptr));
     309    g_assert(g_file_set_contents(cookiesFile.get(), cookiesFileContents.get(), -1, nullptr));
     310
     311    test->setPersistentStorage(WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
     312    test->deleteAllCookies();
     313    // Changed signal is emitted for every deleted cookie, twice in this case.
     314    test->waitUntilCookiesChanged(2);
     315
     316    // Ensure the web process is created and load something without cookies.
     317    test->m_cookiesChanged = false;
     318    test->loadURI(kServer->getURIForPath("/no-cookies.html").data());
     319    test->waitUntilLoadFinished();
     320    g_assert(!test->m_cookiesChanged);
     321    char** domains = test->getDomains();
     322    g_assert(domains);
     323    g_assert_cmpint(g_strv_length(domains), ==, 0);
    301324}
    302325
     
    367390    } else if (g_str_equal(path, "/image.png"))
    368391        soup_message_headers_replace(message->response_headers, "Set-Cookie", "baz=qux; Max-Age=60");
    369     else
     392    else if (g_str_equal(path, "/no-cookies.html")) {
     393        static const char* indexHtml = "<html><body><p>No cookies</p></body></html>";
     394        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, indexHtml, strlen(indexHtml));
     395    } else
    370396        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
    371397    soup_message_body_complete(message->response_body);
     
    381407    CookieManagerTest::add("WebKitCookieManager", "cookies-changed", testCookieManagerCookiesChanged);
    382408    CookieManagerTest::add("WebKitCookieManager", "persistent-storage", testCookieManagerPersistentStorage);
     409    CookieManagerTest::add("WebKitCookieManager", "persistent-storage-delete-all", testCookieManagerPersistentStorageDeleteAll);
    383410    CookieManagerTest::add("WebKitCookieManager", "ephemeral", testCookieManagerEphemeral);
    384411}
Note: See TracChangeset for help on using the changeset viewer.