Title: [137940] trunk/Source/WebCore
Revision
137940
Author
[email protected]
Date
2012-12-17 13:48:49 -0800 (Mon, 17 Dec 2012)

Log Message

[BlackBerry] Prevent CookieManager from blocking the WKT thread
https://bugs.webkit.org/show_bug.cgi?id=105111

Prevent CookieManager from blocking the WKT Thread.

PR 265603

Patch by Otto Derek Cheung <[email protected]> on 2012-12-17
Reviewed by Rob Buis.

Adding some guards to CookieManager so it will return immedately
if getCookie functions are called when the database isn't loaded yet.

setCookie functions will be redispatched until the database is ready.

* platform/blackberry/CookieManager.cpp:
(WebCore::CookieManager::CookieManager):
(WebCore::CookieManager::setCookies):
(WebCore::CookieManager::getCookie):
(WebCore::CookieManager::generateHtmlFragmentForCookies):
(WebCore::CookieManager::getRawCookies):
(WebCore::CookieManager::removeAllCookies):
(WebCore::CookieManager::getBackingStoreCookies):
(WebCore::CookieManager::setPrivateMode):
(WebCore::CookieManager::removeCookieWithName):
* platform/blackberry/CookieManager.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (137939 => 137940)


--- trunk/Source/WebCore/ChangeLog	2012-12-17 21:42:25 UTC (rev 137939)
+++ trunk/Source/WebCore/ChangeLog	2012-12-17 21:48:49 UTC (rev 137940)
@@ -1,3 +1,31 @@
+2012-12-17  Otto Derek Cheung  <[email protected]>
+
+        [BlackBerry] Prevent CookieManager from blocking the WKT thread
+        https://bugs.webkit.org/show_bug.cgi?id=105111
+
+        Prevent CookieManager from blocking the WKT Thread.
+
+        PR 265603
+
+        Reviewed by Rob Buis.
+
+        Adding some guards to CookieManager so it will return immedately
+        if getCookie functions are called when the database isn't loaded yet.
+
+        setCookie functions will be redispatched until the database is ready.
+
+        * platform/blackberry/CookieManager.cpp:
+        (WebCore::CookieManager::CookieManager):
+        (WebCore::CookieManager::setCookies):
+        (WebCore::CookieManager::getCookie):
+        (WebCore::CookieManager::generateHtmlFragmentForCookies):
+        (WebCore::CookieManager::getRawCookies):
+        (WebCore::CookieManager::removeAllCookies):
+        (WebCore::CookieManager::getBackingStoreCookies):
+        (WebCore::CookieManager::setPrivateMode):
+        (WebCore::CookieManager::removeCookieWithName):
+        * platform/blackberry/CookieManager.h:
+
 2012-12-17  Levi Weintraub  <[email protected]>
 
         Add support for tracking hit test rectangles to enable fast event rejection in the compositor

Modified: trunk/Source/WebCore/platform/blackberry/CookieManager.cpp (137939 => 137940)


--- trunk/Source/WebCore/platform/blackberry/CookieManager.cpp	2012-12-17 21:42:25 UTC (rev 137939)
+++ trunk/Source/WebCore/platform/blackberry/CookieManager.cpp	2012-12-17 21:48:49 UTC (rev 137940)
@@ -86,6 +86,7 @@
     : m_count(0)
     , m_privateMode(false)
     , m_shouldDumpAllCookies(false)
+    , m_syncedWithDatabase(false)
     , m_cookieJarFileName(pathByAppendingComponent(BlackBerry::Platform::Settings::instance()->applicationDataDirectory().c_str(), "/cookieCollection.db"))
     , m_policy(CookieStorageAcceptPolicyAlways)
     , m_cookieBackingStore(CookieDatabaseBackingStore::create())
@@ -125,6 +126,16 @@
 
 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);
+
+        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);
@@ -137,6 +148,15 @@
 
 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;
+    }
+
     CookieLog("CookieManager - Setting cookies");
     CookieParser parser(url);
     for (size_t i = 0; i < cookies.size(); ++i) {
@@ -148,6 +168,11 @@
 
 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();
+    }
+
     Vector<ParsedCookie*> rawCookies;
     rawCookies.reserveInitialCapacity(s_maxCookieCountPerHost);
 
@@ -173,6 +198,11 @@
 
 String CookieManager::generateHtmlFragmentForCookies()
 {
+    if (!m_syncedWithDatabase && !m_privateMode) {
+        LOG_ERROR("CookieManager is calling generateHtmlFragmentForCookies before database values are loaded.");
+        return String();
+    }
+
     CookieLog("CookieManager - generateHtmlFragmentForCookies\n");
 
     Vector<ParsedCookie*> cookieCandidates;
@@ -208,6 +238,11 @@
 
 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;
+    }
+
     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());
 
     const bool invalidScheme = shouldIgnoreScheme(requestURL.protocol());
@@ -487,6 +522,10 @@
 
 void CookieManager::getBackingStoreCookies()
 {
+    // Make sure private mode is off when the database thread calls this method
+    if (m_privateMode)
+        return;
+
     // This method should be called just after having created the cookieManager
     // NEVER afterwards!
     ASSERT(!m_count);
@@ -499,6 +538,8 @@
         checkAndTreatCookie(newCookie, BackingStoreCookieEntry);
     }
     CookieLog("CookieManager - Backingstore loading complete.");
+
+    m_syncedWithDatabase = true;
 }
 
 void CookieManager::setPrivateMode(bool privateMode)
@@ -508,6 +549,11 @@
 
     m_privateMode = privateMode;
 
+    // If we switched to private mode when the database cookies haven't loaded into memory yet
+    // we can return because there's nothing in memory anyway.
+    if (m_privateMode && !m_syncedWithDatabase)
+        return;
+
     removeAllCookies(DoNotRemoveFromBackingStore);
 
     // If we are switching back to public mode, reload the database to memory.
@@ -554,6 +600,15 @@
 
 void CookieManager::removeCookieWithName(const KURL& url, const String& cookieName)
 {
+    // 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&);
+        BlackBerry::Platform::webKitThreadMessageClient()->dispatchMessage(
+            BlackBerry::Platform::createMethodCallMessage<FunctionType, CookieManager, const KURL, const String>(
+                &CookieManager::removeCookieWithName, this, url, cookieName));
+        return;
+    }
+
     // We get all cookies from all domains that domain matches the request domain
     // and delete any cookies with the specified name that path matches the request path
     Vector<ParsedCookie*> results;

Modified: trunk/Source/WebCore/platform/blackberry/CookieManager.h (137939 => 137940)


--- trunk/Source/WebCore/platform/blackberry/CookieManager.h	2012-12-17 21:42:25 UTC (rev 137939)
+++ trunk/Source/WebCore/platform/blackberry/CookieManager.h	2012-12-17 21:48:49 UTC (rev 137940)
@@ -123,6 +123,7 @@
 
     bool m_privateMode;
     bool m_shouldDumpAllCookies;
+    bool m_syncedWithDatabase;
 
     String m_cookieJarFileName;
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to