Title: [115057] trunk/Source
Revision
115057
Author
carlo...@webkit.org
Date
2012-04-24 08:18:40 -0700 (Tue, 24 Apr 2012)

Log Message

[GTK] Add WebKitCookieManager::changed signal to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=82598

Reviewed by Philippe Normand.

Source/WebCore:

* GNUmakefile.list.am: Add new files to compilation.
* platform/gtk/TemporaryLinkStubs.cpp: Remove stubs for
setCookieStoragePrivateBrowsingEnabled,
startObservingCookieChanges and stopObservingCookieChanges.
* platform/network/soup/CookieStorageSoup.cpp: Added.
(WebCore::setCookieStoragePrivateBrowsingEnabled):
(WebCore::soupCookiesChanged): Notify cookies changes using
platform strategies.
(WebCore::startObservingCookieChanges): Connect to changed signal
of the soup cookie jar.
(WebCore::stopObservingCookieChanges): Disconnect signals handlers
for changed signals of the soup cookie jar.

Source/WebKit2:

* UIProcess/API/gtk/WebKitCookieManager.cpp:
(webkitCookieManagerFinalize): Stop observing cookie changes.
(webkit_cookie_manager_class_init): Add
WebKitCookieManager::changed signal.
(cookiesDidChange): Emit WebKitCookieManager::changed signal.
(webkitCookieManagerCreate): Implement WKCookieManagerClient and
start observing cookie changes.
* UIProcess/API/gtk/tests/TestCookieManager.cpp:
(testCookieManagerCookiesChanged):
(beforeAll):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (115056 => 115057)


--- trunk/Source/WebCore/ChangeLog	2012-04-24 15:16:27 UTC (rev 115056)
+++ trunk/Source/WebCore/ChangeLog	2012-04-24 15:18:40 UTC (rev 115057)
@@ -1,3 +1,23 @@
+2012-04-24  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add WebKitCookieManager::changed signal to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=82598
+
+        Reviewed by Philippe Normand.
+
+        * GNUmakefile.list.am: Add new files to compilation.
+        * platform/gtk/TemporaryLinkStubs.cpp: Remove stubs for
+        setCookieStoragePrivateBrowsingEnabled,
+        startObservingCookieChanges and stopObservingCookieChanges.
+        * platform/network/soup/CookieStorageSoup.cpp: Added.
+        (WebCore::setCookieStoragePrivateBrowsingEnabled):
+        (WebCore::soupCookiesChanged): Notify cookies changes using
+        platform strategies.
+        (WebCore::startObservingCookieChanges): Connect to changed signal
+        of the soup cookie jar.
+        (WebCore::stopObservingCookieChanges): Disconnect signals handlers
+        for changed signals of the soup cookie jar.
+
 2012-04-24  Alexis Menard  <alexis.men...@openbossa.org>
 
         Rename CSSStyleApplyProperty files to StyleBuilder.

Modified: trunk/Source/WebCore/GNUmakefile.list.am (115056 => 115057)


--- trunk/Source/WebCore/GNUmakefile.list.am	2012-04-24 15:16:27 UTC (rev 115056)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2012-04-24 15:18:40 UTC (rev 115057)
@@ -3484,6 +3484,7 @@
 	Source/WebCore/platform/network/soup/AuthenticationChallenge.h \
 	Source/WebCore/platform/network/soup/CookieJarSoup.cpp \
 	Source/WebCore/platform/network/soup/CookieJarSoup.h \
+	Source/WebCore/platform/network/soup/CookieStorageSoup.cpp \
 	Source/WebCore/platform/network/soup/CredentialStorageSoup.cpp \
 	Source/WebCore/platform/network/soup/DNSSoup.cpp \
 	Source/WebCore/platform/network/soup/GOwnPtrSoup.cpp \

Modified: trunk/Source/WebCore/platform/gtk/TemporaryLinkStubs.cpp (115056 => 115057)


--- trunk/Source/WebCore/platform/gtk/TemporaryLinkStubs.cpp	2012-04-24 15:16:27 UTC (rev 115056)
+++ trunk/Source/WebCore/platform/gtk/TemporaryLinkStubs.cpp	2012-04-24 15:18:40 UTC (rev 115057)
@@ -47,8 +47,5 @@
 void getSupportedKeySizes(Vector<String>&) { notImplemented(); }
 String signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String &challengeString, const KURL &url) { return String(); }
 float userIdleTime() { notImplemented(); return FLT_MAX; } // return an arbitrarily high userIdleTime so that releasing pages from the page cache isn't postponed
-void setCookieStoragePrivateBrowsingEnabled(bool) { notImplemented(); }
-void startObservingCookieChanges() { notImplemented(); }
-void stopObservingCookieChanges() { notImplemented(); }
 
 }

Added: trunk/Source/WebCore/platform/network/soup/CookieStorageSoup.cpp (0 => 115057)


--- trunk/Source/WebCore/platform/network/soup/CookieStorageSoup.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/soup/CookieStorageSoup.cpp	2012-04-24 15:18:40 UTC (rev 115057)
@@ -0,0 +1,60 @@
+/*
+ *  Copyright (C) 2012 Igalia S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "CookieStorage.h"
+
+#include "CookieJarSoup.h"
+#include "NotImplemented.h"
+
+#if USE(PLATFORM_STRATEGIES)
+#include "CookiesStrategy.h"
+#include "PlatformStrategies.h"
+#endif
+
+#include <stdio.h>
+
+namespace WebCore {
+
+void setCookieStoragePrivateBrowsingEnabled(bool enabled)
+{
+    notImplemented();
+}
+
+#if USE(PLATFORM_STRATEGIES)
+static void soupCookiesChanged(SoupCookieJar*, SoupCookie*, SoupCookie*, gpointer)
+{
+    platformStrategies()->cookiesStrategy()->notifyCookiesChanged();
+}
+#endif
+
+void startObservingCookieChanges()
+{
+#if USE(PLATFORM_STRATEGIES)
+    g_signal_connect(soupCookieJar(), "changed", G_CALLBACK(soupCookiesChanged), 0);
+#endif
+}
+
+void stopObservingCookieChanges()
+{
+#if USE(PLATFORM_STRATEGIES)
+    g_signal_handlers_disconnect_by_func(soupCookieJar(), reinterpret_cast<void*>(soupCookiesChanged), 0);
+#endif
+}
+
+}

Modified: trunk/Source/WebKit2/ChangeLog (115056 => 115057)


--- trunk/Source/WebKit2/ChangeLog	2012-04-24 15:16:27 UTC (rev 115056)
+++ trunk/Source/WebKit2/ChangeLog	2012-04-24 15:18:40 UTC (rev 115057)
@@ -1,3 +1,21 @@
+2012-04-24  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add WebKitCookieManager::changed signal to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=82598
+
+        Reviewed by Philippe Normand.
+
+        * UIProcess/API/gtk/WebKitCookieManager.cpp:
+        (webkitCookieManagerFinalize): Stop observing cookie changes.
+        (webkit_cookie_manager_class_init): Add
+        WebKitCookieManager::changed signal.
+        (cookiesDidChange): Emit WebKitCookieManager::changed signal.
+        (webkitCookieManagerCreate): Implement WKCookieManagerClient and
+        start observing cookie changes.
+        * UIProcess/API/gtk/tests/TestCookieManager.cpp:
+        (testCookieManagerCookiesChanged):
+        (beforeAll):
+
 2012-04-24  Allan Sandfeld Jensen  <allan.jen...@nokia.com>
 
         [Qt] Restore x-position when restoring previous zoom-level.

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp (115056 => 115057)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp	2012-04-24 15:16:27 UTC (rev 115056)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp	2012-04-24 15:18:40 UTC (rev 115057)
@@ -27,10 +27,18 @@
 
 using namespace WebKit;
 
+enum {
+    CHANGED,
+
+    LAST_SIGNAL
+};
+
 struct _WebKitCookieManagerPrivate {
     WKRetainPtr<WKCookieManagerRef> wkCookieManager;
 };
 
+static guint signals[LAST_SIGNAL] = { 0, };
+
 G_DEFINE_TYPE(WebKitCookieManager, webkit_cookie_manager, G_TYPE_OBJECT)
 
 COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS, kWKHTTPCookieAcceptPolicyAlways);
@@ -46,7 +54,9 @@
 
 static void webkitCookieManagerFinalize(GObject* object)
 {
-    WEBKIT_COOKIE_MANAGER(object)->priv->~WebKitCookieManagerPrivate();
+    WebKitCookieManagerPrivate* priv = WEBKIT_COOKIE_MANAGER(object)->priv;
+    WKCookieManagerStopObservingCookieChanges(priv->wkCookieManager.get());
+    priv->~WebKitCookieManagerPrivate();
     G_OBJECT_CLASS(webkit_cookie_manager_parent_class)->finalize(object);
 }
 
@@ -56,12 +66,40 @@
     gObjectClass->finalize = webkitCookieManagerFinalize;
 
     g_type_class_add_private(findClass, sizeof(WebKitCookieManagerPrivate));
+
+    /**
+     * WebKitCookieManager::changed:
+     * @cookie_manager: the #WebKitCookieManager
+     *
+     * This signal is emitted when cookies are added, removed or modified.
+     */
+    signals[CHANGED] =
+        g_signal_new("changed",
+                     G_TYPE_FROM_CLASS(gObjectClass),
+                     G_SIGNAL_RUN_LAST,
+                     0, 0, 0,
+                     g_cclosure_marshal_VOID__VOID,
+                     G_TYPE_NONE, 0);
 }
 
+static void cookiesDidChange(WKCookieManagerRef, const void* clientInfo)
+{
+    g_signal_emit(WEBKIT_COOKIE_MANAGER(clientInfo), signals[CHANGED], 0);
+}
+
 WebKitCookieManager* webkitCookieManagerCreate(WKCookieManagerRef wkCookieManager)
 {
     WebKitCookieManager* manager = WEBKIT_COOKIE_MANAGER(g_object_new(WEBKIT_TYPE_COOKIE_MANAGER, NULL));
     manager->priv->wkCookieManager = wkCookieManager;
+
+    WKCookieManagerClient wkCookieManagerClient = {
+        kWKCookieManagerClientCurrentVersion,
+        manager, // clientInfo
+        cookiesDidChange
+    };
+    WKCookieManagerSetClient(wkCookieManager, &wkCookieManagerClient);
+    WKCookieManagerStartObservingCookieChanges(wkCookieManager);
+
     return manager;
 }
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp (115056 => 115057)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp	2012-04-24 15:16:27 UTC (rev 115056)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp	2012-04-24 15:18:40 UTC (rev 115057)
@@ -36,17 +36,28 @@
 public:
     MAKE_GLIB_TEST_FIXTURE(CookieManagerTest);
 
+    static void cookiesChangedCallback(WebKitCookieManager*, CookieManagerTest* test)
+    {
+        test->m_cookiesChanged = true;
+        if (test->m_finishLoopWhenCookiesChange)
+            g_main_loop_quit(test->m_mainLoop);
+    }
+
     CookieManagerTest()
         : WebViewTest()
         , m_cookieManager(webkit_web_context_get_cookie_manager(webkit_web_view_get_context(m_webView)))
         , m_acceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY)
         , m_domains(0)
+        , m_cookiesChanged(false)
+        , m_finishLoopWhenCookiesChange(false)
     {
+        g_signal_connect(m_cookieManager, "changed", G_CALLBACK(cookiesChangedCallback), this);
     }
 
     ~CookieManagerTest()
     {
         g_strfreev(m_domains);
+        g_signal_handlers_disconnect_matched(m_cookieManager, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
     }
 
     static void getAcceptPolicyReadyCallback(GObject* object, GAsyncResult* result, gpointer userData)
@@ -105,9 +116,19 @@
         webkit_cookie_manager_delete_all_cookies(m_cookieManager);
     }
 
+    void waitUntilCookiesChanged()
+    {
+        m_cookiesChanged = false;
+        m_finishLoopWhenCookiesChange = true;
+        g_main_loop_run(m_mainLoop);
+        m_finishLoopWhenCookiesChange = false;
+    }
+
     WebKitCookieManager* m_cookieManager;
     WebKitCookieAcceptPolicy m_acceptPolicy;
     char** m_domains;
+    bool m_cookiesChanged;
+    bool m_finishLoopWhenCookiesChange;
 };
 
 static void testCookieManagerAcceptPolicy(CookieManagerTest* test, gconstpointer)
@@ -166,6 +187,23 @@
     g_assert_cmpint(g_strv_length(test->getDomains()), ==, 0);
 }
 
+static void testCookieManagerCookiesChanged(CookieManagerTest* test, gconstpointer)
+{
+    g_assert(!test->m_cookiesChanged);
+    test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
+    test->loadURI(kServer->getURIForPath("/index.html").data());
+    test->waitUntilLoadFinished();
+    g_assert(test->m_cookiesChanged);
+
+    test->deleteCookiesForDomain(kFirstPartyDomain);
+    test->waitUntilCookiesChanged();
+    g_assert(test->m_cookiesChanged);
+
+    test->deleteAllCookies();
+    test->waitUntilCookiesChanged();
+    g_assert(test->m_cookiesChanged);
+}
+
 static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
 {
     if (message->method != SOUP_METHOD_GET) {
@@ -192,6 +230,7 @@
 
     CookieManagerTest::add("WebKitCookieManager", "accept-policy", testCookieManagerAcceptPolicy);
     CookieManagerTest::add("WebKitCookieManager", "delete-cookies", testCookieManagerDeleteCookies);
+    CookieManagerTest::add("WebKitCookieManager", "cookies-changed", testCookieManagerCookiesChanged);
 }
 
 void afterAll()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to