Title: [142150] trunk/Source/WebCore
Revision
142150
Author
[email protected]
Date
2013-02-07 10:24:09 -0800 (Thu, 07 Feb 2013)

Log Message

[BlackBerry] Cookie database isn't loaded into memory in some rare cases
https://bugs.webkit.org/show_bug.cgi?id=109202
PR 286189

Patch by Otto Derek Cheung <[email protected]> on 2013-02-07
Reviewed by Yong Li.
Internally Reviewed by Konrad Piascik.

If a get/setCookie call is made before the database is loaded, or if there's some
kind of error that causes the loading of the database to fail in the constructor
of CookieManager, the browser will get into a state where it seems like cookie is
permanenty disabled.

Instead of logging the errors and redispatching the setCookie, we should do a force sync
to load the cookie database before continuing.

Since the bug is so difficult to reproduce (I never did so myself), I did the follow test
to make sure the code path is correct:
1) Make sure original implementation is retained - open and loading done in the constructor
2) Removed opening and loading in constructor, the new calls in get/setcookies loaded the db just fine (although with
an initial lag because we are blocking WKT while performing SQLite options).
3) Removed loading in constructor, the new calls loaded the db just fine.

* platform/blackberry/CookieDatabaseBackingStore/CookieDatabaseBackingStore.cpp:
(WebCore::CookieDatabaseBackingStore::openAndLoadDatabaseSynchronously):
(WebCore):
* platform/blackberry/CookieDatabaseBackingStore/CookieDatabaseBackingStore.h:
(CookieDatabaseBackingStore):
* platform/blackberry/CookieManager.cpp:
(WebCore::CookieManager::setCookies):
(WebCore::CookieManager::getCookie):
(WebCore::CookieManager::generateHtmlFragmentForCookies):
(WebCore::CookieManager::getRawCookies):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (142149 => 142150)


--- trunk/Source/WebCore/ChangeLog	2013-02-07 18:21:12 UTC (rev 142149)
+++ trunk/Source/WebCore/ChangeLog	2013-02-07 18:24:09 UTC (rev 142150)
@@ -1,3 +1,38 @@
+2013-02-07  Otto Derek Cheung  <[email protected]>
+
+        [BlackBerry] Cookie database isn't loaded into memory in some rare cases
+        https://bugs.webkit.org/show_bug.cgi?id=109202
+        PR 286189
+
+        Reviewed by Yong Li.
+        Internally Reviewed by Konrad Piascik.
+
+        If a get/setCookie call is made before the database is loaded, or if there's some
+        kind of error that causes the loading of the database to fail in the constructor
+        of CookieManager, the browser will get into a state where it seems like cookie is
+        permanenty disabled.
+
+        Instead of logging the errors and redispatching the setCookie, we should do a force sync
+        to load the cookie database before continuing.
+
+        Since the bug is so difficult to reproduce (I never did so myself), I did the follow test
+        to make sure the code path is correct:
+        1) Make sure original implementation is retained - open and loading done in the constructor
+        2) Removed opening and loading in constructor, the new calls in get/setcookies loaded the db just fine (although with
+        an initial lag because we are blocking WKT while performing SQLite options).
+        3) Removed loading in constructor, the new calls loaded the db just fine.
+
+        * platform/blackberry/CookieDatabaseBackingStore/CookieDatabaseBackingStore.cpp:
+        (WebCore::CookieDatabaseBackingStore::openAndLoadDatabaseSynchronously):
+        (WebCore):
+        * platform/blackberry/CookieDatabaseBackingStore/CookieDatabaseBackingStore.h:
+        (CookieDatabaseBackingStore):
+        * platform/blackberry/CookieManager.cpp:
+        (WebCore::CookieManager::setCookies):
+        (WebCore::CookieManager::getCookie):
+        (WebCore::CookieManager::generateHtmlFragmentForCookies):
+        (WebCore::CookieManager::getRawCookies):
+
 2013-02-07  Max Vujovic  <[email protected]>
 
         [CSS Shaders] Add WebKitCSSFilterRule to DOMWindow.idl

Modified: trunk/Source/WebCore/platform/blackberry/CookieDatabaseBackingStore/CookieDatabaseBackingStore.cpp (142149 => 142150)


--- trunk/Source/WebCore/platform/blackberry/CookieDatabaseBackingStore/CookieDatabaseBackingStore.cpp	2013-02-07 18:21:12 UTC (rev 142149)
+++ trunk/Source/WebCore/platform/blackberry/CookieDatabaseBackingStore/CookieDatabaseBackingStore.cpp	2013-02-07 18:24:09 UTC (rev 142150)
@@ -311,6 +311,23 @@
     return cookies;
 }
 
+void CookieDatabaseBackingStore::openAndLoadDatabaseSynchronously(const String& cookieJar)
+{
+    CookieLog("CookieBackingStore - loading database into CookieManager immediately");
+
+    if (m_db.isOpen()) {
+        if (isCurrentThread())
+            BlackBerry::Platform::webKitThreadMessageClient()->dispatchSyncMessage(createMethodCallMessage(&CookieManager::getBackingStoreCookies, &cookieManager()));
+        else
+            cookieManager().getBackingStoreCookies();
+    } else {
+        if (isCurrentThread())
+            invokeOpen(cookieJar);
+        else
+            dispatchSyncMessage(createMethodCallMessage(&CookieDatabaseBackingStore::invokeOpen, this, cookieJar));
+    }
+}
+
 void CookieDatabaseBackingStore::sendChangesToDatabaseSynchronously()
 {
     CookieLog("CookieBackingStore - sending to database immediately");

Modified: trunk/Source/WebCore/platform/blackberry/CookieDatabaseBackingStore/CookieDatabaseBackingStore.h (142149 => 142150)


--- trunk/Source/WebCore/platform/blackberry/CookieDatabaseBackingStore/CookieDatabaseBackingStore.h	2013-02-07 18:21:12 UTC (rev 142149)
+++ trunk/Source/WebCore/platform/blackberry/CookieDatabaseBackingStore/CookieDatabaseBackingStore.h	2013-02-07 18:24:09 UTC (rev 142150)
@@ -59,6 +59,7 @@
     // If a limit is not set, the method will return all cookies in the database
     void getCookiesFromDatabase(Vector<ParsedCookie*>& stackOfCookies, unsigned int limit = 0);
 
+    void openAndLoadDatabaseSynchronously(const String& cookieJar);
     void sendChangesToDatabaseSynchronously();
 
     // MessageClient methods

Modified: trunk/Source/WebCore/platform/blackberry/CookieManager.cpp (142149 => 142150)


--- trunk/Source/WebCore/platform/blackberry/CookieManager.cpp	2013-02-07 18:21:12 UTC (rev 142149)
+++ trunk/Source/WebCore/platform/blackberry/CookieManager.cpp	2013-02-07 18:24:09 UTC (rev 142150)
@@ -126,16 +126,10 @@
 
 void CookieManager::setCookies(const KURL& url, const String& value, CookieFilter filter)
 {
-    // Dispatch the message because the database cookies are not loaded in memory yet.
-    if (!m_syncedWithDatabase && !m_privateMode) {
-        typedef void (WebCore::CookieManager::*FunctionType)(const KURL&, const String&, CookieFilter);
+    // If the database hasn't been sync-ed at this point, force a sync load
+    if (!m_syncedWithDatabase && !m_privateMode)
+        m_cookieBackingStore->openAndLoadDatabaseSynchronously(cookieJar());
 
-        BlackBerry::Platform::webKitThreadMessageClient()->dispatchMessage(
-            BlackBerry::Platform::createMethodCallMessage<FunctionType, CookieManager, const KURL, const String, CookieFilter>(
-                &CookieManager::setCookies, this, url, value, filter));
-        return;
-    }
-
     CookieLog("CookieManager - Setting cookies");
     CookieParser parser(url);
     Vector<ParsedCookie*> cookies = parser.parse(value);
@@ -148,14 +142,9 @@
 
 void CookieManager::setCookies(const KURL& url, const Vector<String>& cookies, CookieFilter filter)
 {
-    // Dispatch the message because the database cookies are not loaded in memory yet.
-    if (!m_syncedWithDatabase && !m_privateMode) {
-        typedef void (WebCore::CookieManager::*FunctionType)(const KURL&, const Vector<String>&, CookieFilter);
-        BlackBerry::Platform::webKitThreadMessageClient()->dispatchMessage(
-            BlackBerry::Platform::createMethodCallMessage<FunctionType, CookieManager, const KURL, const Vector<String>, CookieFilter>(
-                &CookieManager::setCookies, this, url, cookies, filter));
-        return;
-    }
+    // If the database hasn't been sync-ed at this point, force a sync load
+    if (!m_syncedWithDatabase && !m_privateMode)
+        m_cookieBackingStore->openAndLoadDatabaseSynchronously(cookieJar());
 
     CookieLog("CookieManager - Setting cookies");
     CookieParser parser(url);
@@ -168,10 +157,9 @@
 
 String CookieManager::getCookie(const KURL& url, CookieFilter filter) const
 {
-    if (!m_syncedWithDatabase && !m_privateMode) {
-        LOG_ERROR("CookieManager is calling getCookies before database values are loaded.");
-        return String();
-    }
+    // If the database hasn't been sync-ed at this point, force a sync load
+    if (!m_syncedWithDatabase && !m_privateMode)
+        m_cookieBackingStore->openAndLoadDatabaseSynchronously(cookieJar());
 
     Vector<ParsedCookie*> rawCookies;
     rawCookies.reserveInitialCapacity(s_maxCookieCountPerHost);
@@ -198,10 +186,9 @@
 
 String CookieManager::generateHtmlFragmentForCookies()
 {
-    if (!m_syncedWithDatabase && !m_privateMode) {
-        LOG_ERROR("CookieManager is calling generateHtmlFragmentForCookies before database values are loaded.");
-        return String();
-    }
+    // If the database hasn't been sync-ed at this point, force a sync load
+    if (!m_syncedWithDatabase && !m_privateMode)
+        m_cookieBackingStore->openAndLoadDatabaseSynchronously(cookieJar());
 
     CookieLog("CookieManager - generateHtmlFragmentForCookies\n");
 
@@ -238,10 +225,9 @@
 
 void CookieManager::getRawCookies(Vector<ParsedCookie*> &stackOfCookies, const KURL& requestURL, CookieFilter filter) const
 {
-    if (!m_syncedWithDatabase && !m_privateMode) {
-        LOG_ERROR("CookieManager is calling getRawCookies before database values are loaded.");
-        return;
-    }
+    // Force a sync load of the database
+    if (!m_syncedWithDatabase && !m_privateMode)
+        m_cookieBackingStore->openAndLoadDatabaseSynchronously(cookieJar());
 
     CookieLog("CookieManager - getRawCookies - processing url with domain - %s & protocol: %s & path: %s\n", requestURL.host().utf8().data(), requestURL.protocol().utf8().data(), requestURL.path().utf8().data());
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to