[BlackBerry] Handle Set-Cookie immediately even when loading is deferred
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Feb 2013 18:53:06 +0000 (18:53 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Feb 2013 18:53:06 +0000 (18:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=111083

Patch by Joe Mason <jmason@rim.com> on 2013-02-28
Reviewed by Yong Li.

Internal PR: 298805
Internally Reviewed By: Leo Yang

Handle Set-Cookie headers immediately, even if loading is being deferred, since any request
created while loading is deferred should include all cookies received. (This especially
affects Set-Cookie headers sent with a 401 response - often this causes an auth dialog to be
opened, which defers loading, but the followup request using the credentials from the dialog
needs to include the cookie.)

This is safe because handleSetCookieHeader only updates the cookiejar, it doesn't call back
into the loader.

* platform/network/blackberry/NetworkJob.cpp:
(WebCore::NetworkJob::notifyHeadersReceived):
(WebCore::NetworkJob::handleNotifyHeaderReceived):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@144326 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/network/blackberry/NetworkJob.cpp

index 1501a8e..5b20f99 100644 (file)
@@ -1,3 +1,26 @@
+2013-02-28  Joe Mason  <jmason@rim.com>
+
+        [BlackBerry] Handle Set-Cookie immediately even when loading is deferred
+        https://bugs.webkit.org/show_bug.cgi?id=111083
+
+        Reviewed by Yong Li.
+
+        Internal PR: 298805
+        Internally Reviewed By: Leo Yang
+
+        Handle Set-Cookie headers immediately, even if loading is being deferred, since any request
+        created while loading is deferred should include all cookies received. (This especially
+        affects Set-Cookie headers sent with a 401 response - often this causes an auth dialog to be
+        opened, which defers loading, but the followup request using the credentials from the dialog
+        needs to include the cookie.)
+
+        This is safe because handleSetCookieHeader only updates the cookiejar, it doesn't call back
+        into the loader.
+
+        * platform/network/blackberry/NetworkJob.cpp:
+        (WebCore::NetworkJob::notifyHeadersReceived):
+        (WebCore::NetworkJob::handleNotifyHeaderReceived):
+
 2013-02-28  David Grogan  <dgrogan@chromium.org>
 
         IndexedDB: IO error when checking schema should destroy LevelDB directory
index a6e07c1..1844045 100644 (file)
@@ -235,12 +235,27 @@ void NetworkJob::handleNotifyStatusReceived(int status, const String& message)
 
 void NetworkJob::notifyHeadersReceived(const BlackBerry::Platform::NetworkRequest::HeaderList& headers)
 {
+    bool cookiesEnabled = m_frame && m_frame->loader() && m_frame->loader()->client()
+        && static_cast<FrameLoaderClientBlackBerry*>(m_frame->loader()->client())->cookiesEnabled();
+
     BlackBerry::Platform::NetworkRequest::HeaderList::const_iterator endIt = headers.end();
     for (BlackBerry::Platform::NetworkRequest::HeaderList::const_iterator it = headers.begin(); it != endIt; ++it) {
+
+        // Handle Set-Cookie headers immediately, even if loading is being deferred, since any request
+        // created while loading is deferred should include all cookies received. (This especially
+        // affects Set-Cookie headers sent with a 401 response - often this causes an auth dialog to be
+        // opened, which defers loading, but the followup request using the credentials from the dialog
+        // needs to include the cookie.)
+        //
+        // This is safe because handleSetCookieHeader only updates the cookiejar, it doesn't call back
+        // into the loader.
+        String keyString(it->first);
+        if (cookiesEnabled && equalIgnoringCase(keyString, "set-cookie"))
+            handleSetCookieHeader(it->second);
+
         if (shouldDeferLoading())
             m_deferredData.deferHeaderReceived(it->first, it->second);
         else {
-            String keyString(it->first);
             String valueString;
             if (equalIgnoringCase(keyString, "Location")) {
                 // Location, like all headers, is supposed to be Latin-1. But some sites (wikipedia) send it in UTF-8.
@@ -388,9 +403,6 @@ void NetworkJob::handleNotifyHeaderReceived(const String& key, const String& val
         m_contentType = value.lower();
     else if (lowerKey == "content-disposition")
         m_contentDisposition = value;
-    else if (lowerKey == "set-cookie" && m_frame && m_frame->loader() && m_frame->loader()->client()
-        && static_cast<FrameLoaderClientBlackBerry*>(m_frame->loader()->client())->cookiesEnabled())
-        handleSetCookieHeader(value);
     else if (equalIgnoringCase(key, BlackBerry::Platform::NetworkRequest::HEADER_BLACKBERRY_FTP))
         handleFTPHeader(value);