[BlackBerry] Notify platform layer of failing to get authentication credentials
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2013 23:14:45 +0000 (23:14 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2013 23:14:45 +0000 (23:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109751

Patch by Joe Mason <jmason@rim.com> on 2013-02-13
Reviewed by Yong Li.
Reviewed internally by Leo Yang
Internal PR: 181302

The BlackBerry platform network layer needs to know if a stream failed to get authentication credentials.
This patch is using newly added stream API to do it.

No functionality changed no new tests.

* platform/network/blackberry/NetworkJob.cpp:
(WebCore::NetworkJob::notifyAuthReceived):
(WebCore::NetworkJob::sendRequestWithCredentials):
(WebCore::NetworkJob::notifyChallengeResult):
* platform/network/blackberry/NetworkJob.h:
* platform/network/blackberry/NetworkManager.cpp:
(WebCore::protectionSpaceToPlatformAuth):
(WebCore):
(WebCore::setAuthCredentials):
* platform/network/blackberry/NetworkManager.h:
(WebCore):

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

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

index 443221cfb5c04e2b6254bb8e135abdd947cd25ca..6fd9c8af396bc5aa35a8e9639e854faf8f618173 100644 (file)
@@ -1,3 +1,29 @@
+2013-02-13 Joe Mason <jmason@rim.com>
+
+        [BlackBerry] Notify platform layer of failing to get authentication credentials
+        https://bugs.webkit.org/show_bug.cgi?id=109751
+
+        Reviewed by Yong Li.
+        Reviewed internally by Leo Yang
+        Internal PR: 181302
+
+        The BlackBerry platform network layer needs to know if a stream failed to get authentication credentials.
+        This patch is using newly added stream API to do it.
+
+        No functionality changed no new tests.
+
+        * platform/network/blackberry/NetworkJob.cpp:
+        (WebCore::NetworkJob::notifyAuthReceived):
+        (WebCore::NetworkJob::sendRequestWithCredentials):
+        (WebCore::NetworkJob::notifyChallengeResult):
+        * platform/network/blackberry/NetworkJob.h:
+        * platform/network/blackberry/NetworkManager.cpp:
+        (WebCore::protectionSpaceToPlatformAuth):
+        (WebCore):
+        (WebCore::setAuthCredentials):
+        * platform/network/blackberry/NetworkManager.h:
+        (WebCore):
+
 2013-02-14  Kondapally Kalyan  <kalyan.kondapally@intel.com>
 
         [GTK] Fix indentation in GNUmakefile.list.am.
index 2ea6bd8e7e8d4ec5f3c3b6e58b6f4865030b2a0b..973da355f5ba49eb9e383b1edec3be0cb1e91bce 100644 (file)
@@ -354,8 +354,19 @@ void NetworkJob::notifyAuthReceived(NetworkRequest::AuthType authType, NetworkRe
         }
         storeCredentials();
     }
-    if (result != AuthResultSuccess)
-        m_newJobWithCredentialsStarted = sendRequestWithCredentials(serverType, scheme, realm, requireCredentials);
+    if (result != AuthResultSuccess) {
+        switch (sendRequestWithCredentials(serverType, scheme, realm, requireCredentials)) {
+        case SendRequestSucceeded:
+            m_newJobWithCredentialsStarted = true;
+            break;
+        case SendRequestCancelled:
+            streamFailedToGetCredentials(authType, authProtocol, authScheme);
+            // fall through
+        case SendRequestWaiting:
+            m_newJobWithCredentialsStarted = false;
+            break;
+        }
+    }
 }
 
 void NetworkJob::notifyStringHeaderReceived(const String& key, const String& value)
@@ -778,15 +789,15 @@ bool NetworkJob::handleFTPHeader(const String& header)
     return true;
 }
 
-bool NetworkJob::sendRequestWithCredentials(ProtectionSpaceServerType type, ProtectionSpaceAuthenticationScheme scheme, const String& realm, bool requireCredentials)
+NetworkJob::SendRequestResult NetworkJob::sendRequestWithCredentials(ProtectionSpaceServerType type, ProtectionSpaceAuthenticationScheme scheme, const String& realm, bool requireCredentials)
 {
     ASSERT(m_handle);
     if (!m_handle)
-        return false;
+        return SendRequestCancelled;
 
     KURL newURL = m_response.url();
     if (!newURL.isValid())
-        return false;
+        return SendRequestCancelled;
 
     // IMPORTANT: if a new source of credentials is added to this method, be sure to handle it in
     // purgeCredentials as well!
@@ -845,7 +856,7 @@ bool NetworkJob::sendRequestWithCredentials(ProtectionSpaceServerType type, Prot
             // and parsed, so if we cancel the authentication challenge when loading the main
             // resource, we should also cancel loading the favicon when it starts to
             // load. If not we will receive another challenge which may confuse the user.
-            return false;
+            return SendRequestCancelled;
         }
 
         // CredentialStore is empty. Ask the user via dialog.
@@ -863,10 +874,10 @@ bool NetworkJob::sendRequestWithCredentials(ProtectionSpaceServerType type, Prot
         // Before asking the user for credentials, we check if the URL contains that.
         if (username.isEmpty() && password.isEmpty()) {
             if (m_handle->firstRequest().targetType() != ResourceRequest::TargetIsMainFrame && BlackBerry::Platform::Settings::instance()->isChromeProcess())
-                return false;
+                return SendRequestCancelled;
 
             if (!m_frame || !m_frame->page())
-                return false;
+                return SendRequestCancelled;
 
             // DO overwrite any existing credentials with the empty credential
             updateCurrentWebChallenge(AuthenticationChallenge(protectionSpace, credential, 0, m_response, ResourceError()));
@@ -876,7 +887,7 @@ bool NetworkJob::sendRequestWithCredentials(ProtectionSpaceServerType type, Prot
 
             AuthenticationChallengeManager::instance()->authenticationChallenge(newURL, protectionSpace,
                 Credential(), this, m_frame->page()->chrome()->client()->platformPageClient());
-            return false;
+            return SendRequestWaiting;
         }
 
         credential = Credential(username, password, CredentialPersistenceForSession);
@@ -885,7 +896,7 @@ bool NetworkJob::sendRequestWithCredentials(ProtectionSpaceServerType type, Prot
     }
 
     notifyChallengeResult(newURL, protectionSpace, AuthenticationChallengeSuccess, credential);
-    return m_newJobWithCredentialsStarted;
+    return m_newJobWithCredentialsStarted ? SendRequestSucceeded : SendRequestCancelled;
 }
 
 void NetworkJob::storeCredentials()
@@ -999,8 +1010,14 @@ void NetworkJob::notifyChallengeResult(const KURL& url, const ProtectionSpace& p
         updateDeferLoadingCount(-1);
     }
 
-    if (result != AuthenticationChallengeSuccess)
+    if (result != AuthenticationChallengeSuccess) {
+        NetworkRequest::AuthType authType;
+        NetworkRequest::AuthProtocol authProtocol;
+        NetworkRequest::AuthScheme authScheme;
+        protectionSpaceToPlatformAuth(protectionSpace, authType, authProtocol, authScheme);
+        streamFailedToGetCredentials(authType, authProtocol, authScheme);
         return;
+    }
 
     updateCurrentWebChallenge(AuthenticationChallenge(protectionSpace, credential, 0, m_response, ResourceError()), /* allowOverwrite */ false);
 
index 9e5a9d26826dc11de2c4dc85c8c35853f8037e9e..bb5a1d4bd313ac4b907577e8702627cc1ea9d935 100644 (file)
@@ -138,7 +138,12 @@ private:
 
     // The server needs authentication credentials. Search in the CredentialStorage
     // or prompt the user via dialog, then resend the request with the credentials.
-    bool sendRequestWithCredentials(ProtectionSpaceServerType, ProtectionSpaceAuthenticationScheme, const String& realm, bool requireCredentials = true);
+    enum SendRequestResult {
+        SendRequestSucceeded,
+        SendRequestCancelled,
+        SendRequestWaiting
+    };
+    SendRequestResult sendRequestWithCredentials(ProtectionSpaceServerType, ProtectionSpaceAuthenticationScheme, const String& realm, bool requireCredentials = true);
 
     void storeCredentials();
     void storeCredentials(AuthenticationChallenge&);
index 64aaa7f262d9a43cdefb37431059ea52fba82090..980d72cd1975955a930281f6d594822e3b8fecc2 100644 (file)
@@ -57,18 +57,9 @@ bool NetworkManager::startJob(int playerId, PassRefPtr<ResourceHandle> job, cons
     return startJob(playerId, page->groupName(), job, request, streamFactory, frame, defersLoading ? 1 : 0);
 }
 
-static void setAuthCredentials(NetworkRequest& platformRequest, const AuthenticationChallenge& challenge)
+void protectionSpaceToPlatformAuth(const ProtectionSpace& protectionSpace, NetworkRequest::AuthType& authType, NetworkRequest::AuthProtocol& authProtocol, NetworkRequest::AuthScheme& authScheme)
 {
-    if (challenge.isNull())
-        return;
-
-    Credential credential = challenge.proposedCredential();
-    const ProtectionSpace& protectionSpace = challenge.protectionSpace();
-
-    String username = credential.user();
-    String password = credential.password();
-
-    NetworkRequest::AuthScheme authScheme = NetworkRequest::AuthSchemeNone;
+    authScheme = NetworkRequest::AuthSchemeNone;
     switch (protectionSpace.authenticationScheme()) {
     case ProtectionSpaceAuthenticationSchemeDefault:
         authScheme = NetworkRequest::AuthSchemeDefault;
@@ -90,8 +81,8 @@ static void setAuthCredentials(NetworkRequest& platformRequest, const Authentica
         break;
     }
 
-    NetworkRequest::AuthType authType = NetworkRequest::AuthTypeNone;
-    NetworkRequest::AuthProtocol authProtocol = NetworkRequest::AuthProtocolNone;
+    authType = NetworkRequest::AuthTypeNone;
+    authProtocol = NetworkRequest::AuthProtocolNone;
     switch (protectionSpace.serverType()) {
     case ProtectionSpaceServerHTTP:
         authType = NetworkRequest::AuthTypeHost;
@@ -125,6 +116,23 @@ static void setAuthCredentials(NetworkRequest& platformRequest, const Authentica
         ASSERT_NOT_REACHED();
         break;
     }
+}
+
+static void setAuthCredentials(NetworkRequest& platformRequest, const AuthenticationChallenge& challenge)
+{
+    if (challenge.isNull())
+        return;
+
+    Credential credential = challenge.proposedCredential();
+    const ProtectionSpace& protectionSpace = challenge.protectionSpace();
+
+    String username = credential.user();
+    String password = credential.password();
+
+    NetworkRequest::AuthType authType;
+    NetworkRequest::AuthProtocol authProtocol;
+    NetworkRequest::AuthScheme authScheme;
+    protectionSpaceToPlatformAuth(protectionSpace, authType, authProtocol, authScheme);
 
     if (authType != NetworkRequest::AuthTypeNone && authProtocol != NetworkRequest::AuthProtocolNone && authScheme != NetworkRequest::AuthSchemeNone)
         platformRequest.setCredentials(authType, authProtocol, authScheme, username.utf8().data(), password.utf8().data());
index 88833f092eebe2416c3812937c08e73189f0bbf6..f0c59d099d774d88c4cc5965baa6181f253e7a89 100644 (file)
@@ -23,6 +23,7 @@
 #include "ResourceHandle.h"
 
 #include <BlackBerryPlatformSingleton.h>
+#include <network/NetworkRequest.h>
 #include <wtf/Vector.h>
 
 namespace BlackBerry {
@@ -37,6 +38,8 @@ namespace WebCore {
 class Frame;
 class NetworkJob;
 
+void protectionSpaceToPlatformAuth(const ProtectionSpace&, BlackBerry::Platform::NetworkRequest::AuthType&, BlackBerry::Platform::NetworkRequest::AuthProtocol&, BlackBerry::Platform::NetworkRequest::AuthScheme&);
+
 class NetworkManager : public BlackBerry::Platform::ThreadUnsafeSingleton<NetworkManager> {
     SINGLETON_DEFINITION_THREADUNSAFE(NetworkManager)
 public: