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;