Diff
Modified: trunk/Source/WebCore/ChangeLog (152907 => 152908)
--- trunk/Source/WebCore/ChangeLog 2013-07-19 17:47:36 UTC (rev 152907)
+++ trunk/Source/WebCore/ChangeLog 2013-07-19 17:52:49 UTC (rev 152908)
@@ -1,3 +1,45 @@
+2013-07-19 [email protected] <[email protected]>
+
+ [Curl] Http response code 401 (Authentication required) is not handled.
+ https://bugs.webkit.org/show_bug.cgi?id=118849
+
+ Reviewed by Brent Fulgham.
+
+ The current Curl implementation does not handle a 401 response.
+ When receiving http code 401, we need to give a notification that authorization is required, by calling the appropriate notification method.
+ This gives a WebKit client the possibility to present a password dialog to the user.
+ In response to this, we should provide Curl with the given username and password, so another request can be sent with the given credentials.
+
+ * platform/network/ResourceHandle.h:
+ Added method to check if credential storage should be used.
+ * platform/network/ResourceHandleInternal.h:
+ Added member to keep track of number of authentication failures.
+ (WebCore::ResourceHandleInternal::ResourceHandleInternal):
+ * platform/network/curl/ResourceHandleCurl.cpp:
+ (WebCore::ResourceHandle::shouldUseCredentialStorage):
+ Added method to check if credential storage should be used.
+ (WebCore::ResourceHandle::didReceiveAuthenticationChallenge):
+ Implement method; notify client when authentication is required.
+ (WebCore::ResourceHandle::receivedCredential):
+ Implement method; provide Curl with password and username when available.
+ (WebCore::ResourceHandle::receivedRequestToContinueWithoutCredential):
+ Implement method; reset Curl username and password.
+ (WebCore::ResourceHandle::receivedCancellation):
+ Implement method; notify client that authorization has been cancelled.
+ * platform/network/curl/ResourceHandleManager.cpp:
+ (WebCore::isHttpAuthentication):
+ Added function to check if http code is an 'Authorization required' code.
+ (WebCore::getProtectionSpace):
+ Added function to initialize a protection space object from a Curl handle and a response object.
+ (WebCore::headerCallback):
+ Notify client when authorization is required.
+ (WebCore::ResourceHandleManager::applyAuthenticationToRequest):
+ Added method to set Curl username and password.
+ (WebCore::ResourceHandleManager::initializeHandle):
+ Use method to set Curl username and password.
+ * platform/network/curl/ResourceHandleManager.h:
+ Added method to set Curl username and password.
+
2013-07-19 Radu Stavila <[email protected]>
Hover doesn't work for block elements inside a href element
Modified: trunk/Source/WebCore/platform/network/ResourceHandle.h (152907 => 152908)
--- trunk/Source/WebCore/platform/network/ResourceHandle.h 2013-07-19 17:47:36 UTC (rev 152907)
+++ trunk/Source/WebCore/platform/network/ResourceHandle.h 2013-07-19 17:52:49 UTC (rev 152908)
@@ -107,9 +107,9 @@
#if PLATFORM(MAC) || USE(CFNETWORK)
void willSendRequest(ResourceRequest&, const ResourceResponse& redirectResponse);
- bool shouldUseCredentialStorage();
#endif
#if PLATFORM(MAC) || USE(CFNETWORK) || USE(CURL) || USE(SOUP)
+ bool shouldUseCredentialStorage();
void didReceiveAuthenticationChallenge(const AuthenticationChallenge&);
virtual void receivedCredential(const AuthenticationChallenge&, const Credential&);
virtual void receivedRequestToContinueWithoutCredential(const AuthenticationChallenge&);
@@ -165,7 +165,6 @@
#if USE(SOUP)
void continueDidReceiveAuthenticationChallenge(const Credential& credentialFromPersistentStorage);
void sendPendingRequest();
- bool shouldUseCredentialStorage();
bool cancelledOrClientless();
void ensureReadBuffer();
static SoupSession* defaultSession();
Modified: trunk/Source/WebCore/platform/network/ResourceHandleInternal.h (152907 => 152908)
--- trunk/Source/WebCore/platform/network/ResourceHandleInternal.h 2013-07-19 17:47:36 UTC (rev 152907)
+++ trunk/Source/WebCore/platform/network/ResourceHandleInternal.h 2013-07-19 17:52:49 UTC (rev 152908)
@@ -107,6 +107,7 @@
, m_url(0)
, m_customHeaders(0)
, m_cancelled(false)
+ , m_authFailureCount(0)
, m_formDataStream(loader)
#endif
#if USE(SOUP)
@@ -185,6 +186,7 @@
struct curl_slist* m_customHeaders;
ResourceResponse m_response;
bool m_cancelled;
+ unsigned short m_authFailureCount;
FormDataStream m_formDataStream;
Vector<char> m_postBytes;
Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp (152907 => 152908)
--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp 2013-07-19 17:47:36 UTC (rev 152907)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp 2013-07-19 17:52:49 UTC (rev 152908)
@@ -29,6 +29,7 @@
#include "ResourceHandle.h"
#include "CachedResourceLoader.h"
+#include "CredentialStorage.h"
#include "NetworkingContext.h"
#include "NotImplemented.h"
#include "ResourceHandleInternal.h"
@@ -168,6 +169,11 @@
return false;
}
+bool ResourceHandle::shouldUseCredentialStorage()
+{
+ return (!client() || client()->shouldUseCredentialStorage(this)) && firstRequest().url().protocolIsInHTTPFamily();
+}
+
void ResourceHandle::platformLoadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials storedCredentials, ResourceError& error, ResourceResponse& response, Vector<char>& data)
{
WebCoreSynchronousLoader syncLoader;
@@ -182,25 +188,78 @@
response = syncLoader.resourceResponse();
}
-//stubs needed for windows version
-void ResourceHandle::didReceiveAuthenticationChallenge(const AuthenticationChallenge&)
+void ResourceHandle::didReceiveAuthenticationChallenge(const AuthenticationChallenge& challenge)
{
- notImplemented();
+ if (shouldUseCredentialStorage()) {
+ if (!d->m_initialCredential.isEmpty() || challenge.previousFailureCount()) {
+ // The stored credential wasn't accepted, stop using it.
+ // There is a race condition here, since a different credential might have already been stored by another ResourceHandle,
+ // but the observable effect should be very minor, if any.
+ CredentialStorage::remove(challenge.protectionSpace());
+ }
+
+ if (!challenge.previousFailureCount()) {
+ Credential credential = CredentialStorage::get(challenge.protectionSpace());
+ if (!credential.isEmpty() && credential != d->m_initialCredential) {
+ ASSERT(credential.persistence() == CredentialPersistenceNone);
+ if (challenge.failureResponse().httpStatusCode() == 401) {
+ // Store the credential back, possibly adding it as a default for this directory.
+ CredentialStorage::set(credential, challenge.protectionSpace(), challenge.failureResponse().url());
+ }
+ String userpass = credential.user() + ":" + credential.password();
+ curl_easy_setopt(d->m_handle, CURLOPT_USERPWD, userpass.utf8().data());
+ return;
+ }
+ }
+ }
+
+ d->m_currentWebChallenge = challenge;
+
+ if (client())
+ client()->didReceiveAuthenticationChallenge(this, d->m_currentWebChallenge);
}
-void ResourceHandle::receivedCredential(const AuthenticationChallenge&, const Credential&)
+void ResourceHandle::receivedCredential(const AuthenticationChallenge& challenge, const Credential& credential)
{
- notImplemented();
+ if (challenge != d->m_currentWebChallenge)
+ return;
+
+ if (credential.isEmpty()) {
+ receivedRequestToContinueWithoutCredential(challenge);
+ return;
+ }
+
+ if (shouldUseCredentialStorage()) {
+ if (challenge.failureResponse().httpStatusCode() == 401) {
+ KURL urlToStore = challenge.failureResponse().url();
+ CredentialStorage::set(credential, challenge.protectionSpace(), urlToStore);
+ }
+ }
+
+ String userpass = credential.user() + ":" + credential.password();
+ curl_easy_setopt(d->m_handle, CURLOPT_USERPWD, userpass.utf8().data());
+
+ clearAuthentication();
}
-void ResourceHandle::receivedRequestToContinueWithoutCredential(const AuthenticationChallenge&)
+void ResourceHandle::receivedRequestToContinueWithoutCredential(const AuthenticationChallenge& challenge)
{
- notImplemented();
+ if (challenge != d->m_currentWebChallenge)
+ return;
+
+ String userpass = "";
+ curl_easy_setopt(d->m_handle, CURLOPT_USERPWD, userpass.utf8().data());
+
+ clearAuthentication();
}
-void ResourceHandle::receivedCancellation(const AuthenticationChallenge&)
+void ResourceHandle::receivedCancellation(const AuthenticationChallenge& challenge)
{
- notImplemented();
+ if (challenge != d->m_currentWebChallenge)
+ return;
+
+ if (client())
+ client()->receivedCancellation(this, challenge);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp (152907 => 152908)
--- trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp 2013-07-19 17:47:36 UTC (rev 152907)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp 2013-07-19 17:52:49 UTC (rev 152908)
@@ -35,6 +35,7 @@
#include "config.h"
#include "ResourceHandleManager.h"
+#include "CredentialStorage.h"
#include "DataURL.h"
#include "HTTPParsers.h"
#include "MIMETypeRegistry.h"
@@ -137,6 +138,11 @@
return 300 <= statusCode && statusCode < 400 && statusCode != 304;
}
+inline static bool isHttpAuthentication(int statusCode)
+{
+ return statusCode == 401;
+}
+
ResourceHandleManager::ResourceHandleManager()
: m_downloadTimer(this, &ResourceHandleManager::downloadTimerCallback)
, m_cookieJarFileName(cookieJarPath())
@@ -279,6 +285,58 @@
return false;
}
+static bool getProtectionSpace(CURL* h, const ResourceResponse& response, ProtectionSpace& protectionSpace)
+{
+ CURLcode err;
+
+ long port = 0;
+ err = curl_easy_getinfo(h, CURLINFO_PRIMARY_PORT, &port);
+ if (err != CURLE_OK)
+ return false;
+
+ long availableAuth = CURLAUTH_NONE;
+ err = curl_easy_getinfo(h, CURLINFO_HTTPAUTH_AVAIL, &availableAuth);
+ if (err != CURLE_OK)
+ return false;
+
+ const char* url = ""
+ err = curl_easy_getinfo(h, CURLINFO_EFFECTIVE_URL, &url);
+ if (err != CURLE_OK)
+ return false;
+
+ KURL kurl(ParsedURLString, url);
+
+ String host = kurl.host();
+ String protocol = kurl.protocol();
+
+ String realm;
+
+ String authHeader = response.httpHeaderField("WWW-Authenticate");
+ const String realmString = "realm=";
+ int realmPos = authHeader.find(realmString);
+ if (realmPos > 0)
+ realm = authHeader.substring(realmPos + realmString.length());
+
+ ProtectionSpaceServerType serverType = ProtectionSpaceServerHTTP;
+ if (protocol == "https")
+ serverType = ProtectionSpaceServerHTTPS;
+
+ ProtectionSpaceAuthenticationScheme authScheme = ProtectionSpaceAuthenticationSchemeUnknown;
+
+ if (availableAuth & CURLAUTH_BASIC)
+ authScheme = ProtectionSpaceAuthenticationSchemeHTTPBasic;
+ if (availableAuth & CURLAUTH_DIGEST)
+ authScheme = ProtectionSpaceAuthenticationSchemeHTTPDigest;
+ if (availableAuth & CURLAUTH_GSSNEGOTIATE)
+ authScheme = ProtectionSpaceAuthenticationSchemeNegotiate;
+ if (availableAuth & CURLAUTH_NTLM)
+ authScheme = ProtectionSpaceAuthenticationSchemeNTLM;
+
+ protectionSpace = ProtectionSpace(host, port, serverType, realm, authScheme);
+
+ return true;
+}
+
/*
* This is being called for each HTTP header in the response. This includes '\r\n'
* for the last line of the header.
@@ -350,6 +408,16 @@
return totalSize;
}
+ } else if (isHttpAuthentication(httpCode)) {
+ ProtectionSpace protectionSpace;
+ if (getProtectionSpace(d->m_handle, d->m_response, protectionSpace)) {
+ Credential credential;
+ AuthenticationChallenge challenge(protectionSpace, credential, d->m_authFailureCount, d->m_response, ResourceError());
+ challenge.setAuthenticationClient(job);
+ job->didReceiveAuthenticationChallenge(challenge);
+ d->m_authFailureCount++;
+ return totalSize;
+ }
}
if (client)
@@ -752,6 +820,41 @@
}
}
+void ResourceHandleManager::applyAuthenticationToRequest(ResourceHandle* handle, ResourceRequest& request)
+{
+ // m_user/m_pass are credentials given manually, for instance, by the arguments passed to XMLHttpRequest.open().
+ ResourceHandleInternal* d = handle->getInternal();
+
+ if (handle->shouldUseCredentialStorage()) {
+ if (d->m_user.isEmpty() && d->m_pass.isEmpty()) {
+ // <rdar://problem/7174050> - For URLs that match the paths of those previously challenged for HTTP Basic authentication,
+ // try and reuse the credential preemptively, as allowed by RFC 2617.
+ d->m_initialCredential = CredentialStorage::get(request.url());
+ } else {
+ // If there is already a protection space known for the URL, update stored credentials
+ // before sending a request. This makes it possible to implement logout by sending an
+ // XMLHttpRequest with known incorrect credentials, and aborting it immediately (so that
+ // an authentication dialog doesn't pop up).
+ CredentialStorage::set(Credential(d->m_user, d->m_pass, CredentialPersistenceNone), request.url());
+ }
+ }
+
+ String user = d->m_user;
+ String password = d->m_pass;
+
+ if (!d->m_initialCredential.isEmpty()) {
+ user = d->m_initialCredential.user();
+ password = d->m_initialCredential.password();
+ }
+
+ // It seems we need to set CURLOPT_USERPWD even if username and password is empty.
+ // Otherwise cURL will not automatically continue with a new request after a 401 response.
+
+ // curl CURLOPT_USERPWD expects username:password
+ String userpass = user + ":" + password;
+ curl_easy_setopt(d->m_handle, CURLOPT_USERPWD, userpass.utf8().data());
+}
+
void ResourceHandleManager::initializeHandle(ResourceHandle* job)
{
static const int allowedProtocols = CURLPROTO_FILE | CURLPROTO_FTP | CURLPROTO_FTPS | CURLPROTO_HTTP | CURLPROTO_HTTPS;
@@ -859,12 +962,9 @@
curl_easy_setopt(d->m_handle, CURLOPT_HTTPHEADER, headers);
d->m_customHeaders = headers;
}
- // curl CURLOPT_USERPWD expects username:password
- if (d->m_user.length() || d->m_pass.length()) {
- String userpass = d->m_user + ":" + d->m_pass;
- curl_easy_setopt(d->m_handle, CURLOPT_USERPWD, userpass.utf8().data());
- }
+ applyAuthenticationToRequest(job, job->firstRequest());
+
// Set proxy options if we have them.
if (m_proxy.length()) {
curl_easy_setopt(d->m_handle, CURLOPT_PROXY, m_proxy.utf8().data());
Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.h (152907 => 152908)
--- trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.h 2013-07-19 17:47:36 UTC (rev 152907)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.h 2013-07-19 17:52:49 UTC (rev 152908)
@@ -81,6 +81,7 @@
bool removeScheduledJob(ResourceHandle*);
void startJob(ResourceHandle*);
bool startScheduledJobs();
+ void applyAuthenticationToRequest(ResourceHandle*, ResourceRequest&);
void initializeHandle(ResourceHandle*);
Modified: trunk/Source/WebKit/win/ChangeLog (152907 => 152908)
--- trunk/Source/WebKit/win/ChangeLog 2013-07-19 17:47:36 UTC (rev 152907)
+++ trunk/Source/WebKit/win/ChangeLog 2013-07-19 17:52:49 UTC (rev 152908)
@@ -1,3 +1,27 @@
+2013-07-19 [email protected] <[email protected]>
+
+ [Curl] Http response code 401 (Authentication required) is not handled.
+ https://bugs.webkit.org/show_bug.cgi?id=118849
+
+ Reviewed by Brent Fulgham.
+
+ The current Curl implementation does not handle a 401 response.
+ When receiving http code 401, we need to give a notification that authorization is required, by calling the appropriate notification method.
+ This gives a WebKit client the possibility to present a password dialog to the user.
+ In response to this, we should provide Curl with the given username and password, so another request can be sent with the given credentials.
+
+ * WebCoreSupport/WebFrameLoaderClient.cpp:
+ (WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge):
+ Implement empty method; use the same implementation as the CFNetwork version does,
+ notify delegate when authorization is required.
+ * WebURLAuthenticationChallengeSenderCurl.cpp:
+ (WebURLAuthenticationChallengeSender::cancelAuthenticationChallenge):
+ Implement empty method; use the same implementation as the CFNetwork version does.
+ (WebURLAuthenticationChallengeSender::continueWithoutCredentialForAuthenticationChallenge):
+ Implement empty method; use the same implementation as the CFNetwork version does.
+ (WebURLAuthenticationChallengeSender::useCredential):
+ Implement empty method; use the same implementation as the CFNetwork version does.
+
2013-07-17 Kangil Han <[email protected]>
Use toHTMLMediaElement
Modified: trunk/Source/WebKit/win/WebCoreSupport/WebFrameLoaderClient.cpp (152907 => 152908)
--- trunk/Source/WebKit/win/WebCoreSupport/WebFrameLoaderClient.cpp 2013-07-19 17:47:36 UTC (rev 152907)
+++ trunk/Source/WebKit/win/WebCoreSupport/WebFrameLoaderClient.cpp 2013-07-19 17:52:49 UTC (rev 152908)
@@ -144,7 +144,6 @@
void WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(DocumentLoader* loader, unsigned long identifier, const AuthenticationChallenge& challenge)
{
-#if USE(CFNETWORK)
ASSERT(challenge.authenticationClient());
WebView* webView = m_webFrame->webView();
@@ -158,9 +157,6 @@
// If the ResourceLoadDelegate doesn't exist or fails to handle the call, we tell the ResourceHandle
// to continue without credential - this is the best approximation of Mac behavior
challenge.authenticationClient()->receivedRequestToContinueWithoutCredential(challenge);
-#else
- notImplemented();
-#endif
}
void WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge(DocumentLoader* loader, unsigned long identifier, const AuthenticationChallenge& challenge)
Modified: trunk/Source/WebKit/win/WebURLAuthenticationChallengeSenderCurl.cpp (152907 => 152908)
--- trunk/Source/WebKit/win/WebURLAuthenticationChallengeSenderCurl.cpp 2013-07-19 17:47:36 UTC (rev 152907)
+++ trunk/Source/WebKit/win/WebURLAuthenticationChallengeSenderCurl.cpp 2013-07-19 17:52:49 UTC (rev 152908)
@@ -28,7 +28,6 @@
#include <initguid.h>
#include "WebURLAuthenticationChallengeSender.h"
-#include "NotImplemented.h"
#include "WebKit.h"
#include "WebURLAuthenticationChallenge.h"
#include "WebURLCredential.h"
@@ -42,21 +41,37 @@
HRESULT STDMETHODCALLTYPE WebURLAuthenticationChallengeSender::cancelAuthenticationChallenge(
/* [in] */ IWebURLAuthenticationChallenge* challenge)
{
- notImplemented();
- return E_FAIL;
+ COMPtr<WebURLAuthenticationChallenge> webChallenge(Query, challenge);
+ if (!webChallenge)
+ return E_FAIL;
+
+ m_client->receivedCancellation(webChallenge->authenticationChallenge());
+ return S_OK;
}
HRESULT STDMETHODCALLTYPE WebURLAuthenticationChallengeSender::continueWithoutCredentialForAuthenticationChallenge(
/* [in] */ IWebURLAuthenticationChallenge* challenge)
{
- notImplemented();
- return E_FAIL;
+ COMPtr<WebURLAuthenticationChallenge> webChallenge(Query, challenge);
+ if (!webChallenge)
+ return E_FAIL;
+
+ m_client->receivedRequestToContinueWithoutCredential(webChallenge->authenticationChallenge());
+ return S_OK;
}
HRESULT STDMETHODCALLTYPE WebURLAuthenticationChallengeSender::useCredential(
/* [in] */ IWebURLCredential* credential,
/* [in] */ IWebURLAuthenticationChallenge* challenge)
{
- notImplemented();
- return E_FAIL;
+ COMPtr<WebURLAuthenticationChallenge> webChallenge(Query, challenge);
+ if (!webChallenge)
+ return E_FAIL;
+
+ COMPtr<WebURLCredential> webCredential;
+ if (!credential || FAILED(credential->QueryInterface(__uuidof(WebURLCredential), (void**)&webCredential)))
+ return E_FAIL;
+
+ m_client->receivedCredential(webChallenge->authenticationChallenge(), webCredential->credential());
+ return S_OK;
}