Title: [118801] trunk/Source/WebCore
Revision
118801
Author
[email protected]
Date
2012-05-29 10:14:19 -0700 (Tue, 29 May 2012)

Log Message

[BlackBerry] Refactoring http/proxy authentication to use authcallback mechanism introduced with libcurl
https://bugs.webkit.org/show_bug.cgi?id=87706

Patch by Jonathan Dong <[email protected]> on 2012-05-29
Reviewed by Antonio Gomes.

Because we use authentication callback mechanism of libcurl,
which will take care of all the authentication communication
between UA and server, so the only thing we need to do is to
provide credential information when authentication callback
is triggered. By using this we don't need to process
intermediate headers for each http authentication scheme.

Implemented interface function notifyAuthReceived() in
NetworkJob to handle the authentication notification from
networking thread.
When the authentication callback is triggered, we should
cancel the current loading request and restart a new one with
credential information attached which comes from
credentialStorage or user input.

Internally reviewed by Joe Mason <[email protected]>.

No new tests since there is no behavior change.

* platform/network/blackberry/NetworkJob.cpp:
(WebCore::NetworkJob::notifyAuthReceived):
(WebCore):
(WebCore::NetworkJob::handleNotifyHeaderReceived):
(WebCore::NetworkJob::sendRequestWithCredentials):
* platform/network/blackberry/NetworkJob.h:
(NetworkJob):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (118800 => 118801)


--- trunk/Source/WebCore/ChangeLog	2012-05-29 17:02:26 UTC (rev 118800)
+++ trunk/Source/WebCore/ChangeLog	2012-05-29 17:14:19 UTC (rev 118801)
@@ -1,5 +1,39 @@
 2012-05-29  Jonathan Dong  <[email protected]>
 
+        [BlackBerry] Refactoring http/proxy authentication to use authcallback mechanism introduced with libcurl
+        https://bugs.webkit.org/show_bug.cgi?id=87706
+
+        Reviewed by Antonio Gomes.
+
+        Because we use authentication callback mechanism of libcurl,
+        which will take care of all the authentication communication
+        between UA and server, so the only thing we need to do is to
+        provide credential information when authentication callback
+        is triggered. By using this we don't need to process
+        intermediate headers for each http authentication scheme.
+
+        Implemented interface function notifyAuthReceived() in
+        NetworkJob to handle the authentication notification from
+        networking thread.
+        When the authentication callback is triggered, we should
+        cancel the current loading request and restart a new one with
+        credential information attached which comes from
+        credentialStorage or user input.
+
+        Internally reviewed by Joe Mason <[email protected]>.
+
+        No new tests since there is no behavior change.
+
+        * platform/network/blackberry/NetworkJob.cpp:
+        (WebCore::NetworkJob::notifyAuthReceived):
+        (WebCore):
+        (WebCore::NetworkJob::handleNotifyHeaderReceived):
+        (WebCore::NetworkJob::sendRequestWithCredentials):
+        * platform/network/blackberry/NetworkJob.h:
+        (NetworkJob):
+
+2012-05-29  Jonathan Dong  <[email protected]>
+
         [BlackBerry] http authentication challenge issue when loading subresource
         https://bugs.webkit.org/show_bug.cgi?id=87660
 

Modified: trunk/Source/WebCore/platform/network/blackberry/NetworkJob.cpp (118800 => 118801)


--- trunk/Source/WebCore/platform/network/blackberry/NetworkJob.cpp	2012-05-29 17:02:26 UTC (rev 118800)
+++ trunk/Source/WebCore/platform/network/blackberry/NetworkJob.cpp	2012-05-29 17:14:19 UTC (rev 118801)
@@ -254,6 +254,36 @@
         handleNotifyMultipartHeaderReceived(key, value);
 }
 
+void NetworkJob::notifyAuthReceived(BlackBerry::Platform::NetworkRequest::AuthType authType, const char* realm)
+{
+    using BlackBerry::Platform::NetworkRequest;
+
+    ProtectionSpaceServerType serverType = ProtectionSpaceServerHTTP;
+    ProtectionSpaceAuthenticationScheme scheme = ProtectionSpaceAuthenticationSchemeDefault;
+    switch (authType) {
+    case NetworkRequest::AuthHTTPBasic:
+        scheme = ProtectionSpaceAuthenticationSchemeHTTPBasic;
+        break;
+    case NetworkRequest::AuthHTTPDigest:
+        scheme = ProtectionSpaceAuthenticationSchemeHTTPDigest;
+        break;
+    case NetworkRequest::AuthHTTPNTLM:
+        scheme = ProtectionSpaceAuthenticationSchemeNTLM;
+        break;
+    case NetworkRequest::AuthFTP:
+        serverType = ProtectionSpaceServerFTP;
+        break;
+    case NetworkRequest::AuthProxy:
+        serverType = ProtectionSpaceProxyHTTP;
+        break;
+    case NetworkRequest::AuthNone:
+    default:
+        return;
+    }
+
+    sendRequestWithCredentials(serverType, scheme, realm);
+}
+
 void NetworkJob::notifyStringHeaderReceived(const String& key, const String& value)
 {
     if (shouldDeferLoading())
@@ -286,11 +316,7 @@
             m_response.setHTTPHeaderField(key, m_response.httpHeaderField(key) + "\r\n" + value);
             return;
         }
-    } else if (m_extendedStatusCode == 401 && lowerKey == "www-authenticate")
-        handleAuthHeader(ProtectionSpaceServerHTTP, value);
-    else if (m_extendedStatusCode == 407 && lowerKey == "proxy-authenticate" && !BlackBerry::Platform::Client::get()->getProxyAddress().empty())
-        handleAuthHeader(ProtectionSpaceProxyHTTP, value);
-    else if (equalIgnoringCase(key, BlackBerry::Platform::NetworkRequest::HEADER_BLACKBERRY_FTP))
+    } else if (equalIgnoringCase(key, BlackBerry::Platform::NetworkRequest::HEADER_BLACKBERRY_FTP))
         handleFTPHeader(value);
 
     m_response.setHTTPHeaderField(key, value);
@@ -647,62 +673,6 @@
     }
 }
 
-bool NetworkJob::handleAuthHeader(const ProtectionSpaceServerType space, const String& header)
-{
-    if (!m_handle)
-        return false;
-
-    if (!m_handle->getInternal()->m_currentWebChallenge.isNull())
-        return false;
-
-    if (header.isEmpty())
-        return false;
-
-    if (equalIgnoringCase(header, "ntlm"))
-        sendRequestWithCredentials(space, ProtectionSpaceAuthenticationSchemeNTLM, "NTLM");
-
-    // Extract the auth scheme and realm from the header.
-    size_t spacePos = header.find(' ');
-    if (spacePos == notFound) {
-        LOG(Network, "%s-Authenticate field '%s' badly formatted: missing scheme.", space == ProtectionSpaceServerHTTP ? "WWW" : "Proxy", header.utf8().data());
-        return false;
-    }
-
-    String scheme = header.left(spacePos);
-
-    ProtectionSpaceAuthenticationScheme protectionSpaceScheme = ProtectionSpaceAuthenticationSchemeDefault;
-    if (equalIgnoringCase(scheme, "basic"))
-        protectionSpaceScheme = ProtectionSpaceAuthenticationSchemeHTTPBasic;
-    else if (equalIgnoringCase(scheme, "digest"))
-        protectionSpaceScheme = ProtectionSpaceAuthenticationSchemeHTTPDigest;
-    else {
-        notImplemented();
-        return false;
-    }
-
-    size_t realmPos = header.findIgnoringCase("realm=", spacePos);
-    if (realmPos == notFound) {
-        LOG(Network, "%s-Authenticate field '%s' badly formatted: missing realm.", space == ProtectionSpaceServerHTTP ? "WWW" : "Proxy", header.utf8().data());
-        return false;
-    }
-    size_t beginPos = realmPos + 6;
-    String realm  = header.right(header.length() - beginPos);
-    if (realm.startsWith("\"")) {
-        beginPos += 1;
-        size_t endPos = header.find("\"", beginPos);
-        if (endPos == notFound) {
-            LOG(Network, "%s-Authenticate field '%s' badly formatted: invalid realm.", space == ProtectionSpaceServerHTTP ? "WWW" : "Proxy", header.utf8().data());
-            return false;
-        }
-        realm = header.substring(beginPos, endPos - beginPos);
-    }
-
-    // Get the user's credentials and resend the request.
-    sendRequestWithCredentials(space, protectionSpaceScheme, realm);
-
-    return true;
-}
-
 bool NetworkJob::handleFTPHeader(const String& header)
 {
     size_t spacePos = header.find(' ');
@@ -800,8 +770,6 @@
         m_handle->getInternal()->m_currentWebChallenge = AuthenticationChallenge(protectionSpace, credential, 0, m_response, ResourceError());
     }
 
-    // FIXME: Resend the resource request. Cloned from handleRedirect(). Not sure
-    // if we need everything that follows...
     ResourceRequest newRequest = m_handle->firstRequest();
     newRequest.setURL(newURL);
     newRequest.setMustHandleInternally(true);

Modified: trunk/Source/WebCore/platform/network/blackberry/NetworkJob.h (118800 => 118801)


--- trunk/Source/WebCore/platform/network/blackberry/NetworkJob.h	2012-05-29 17:02:26 UTC (rev 118800)
+++ trunk/Source/WebCore/platform/network/blackberry/NetworkJob.h	2012-05-29 17:14:19 UTC (rev 118801)
@@ -69,6 +69,7 @@
     virtual void notifyHeadersReceived(BlackBerry::Platform::NetworkRequest::HeaderList& headers);
     virtual void notifyMultipartHeaderReceived(const char* key, const char* value);
     // Exists only to resolve ambiguity between char* and String parameters
+    virtual void notifyAuthReceived(BlackBerry::Platform::NetworkRequest::AuthType, const char* realm);
     void notifyStringHeaderReceived(const String& key, const String& value);
     void handleNotifyHeaderReceived(const String& key, const String& value);
     void handleNotifyMultipartHeaderReceived(const String& key, const String& value);
@@ -122,12 +123,10 @@
 
     void handleAbout();
 
-    // The server needs authentication credentials. Search in the
-    // CredentialStorage or prompt the user via dialog.
-    bool handleAuthHeader(const ProtectionSpaceServerType, const String& header);
-
     bool handleFTPHeader(const String& header);
 
+    // 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);
 
     void storeCredentials();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to