diff options
author | Iain Merrick <husky@google.com> | 2010-08-23 17:35:30 +0100 |
---|---|---|
committer | Iain Merrick <husky@google.com> | 2010-09-20 12:14:03 +0100 |
commit | d4ff0cc91b5eb975d563f355f9f4c7358e0e2c06 (patch) | |
tree | 69dda182d1890032def251c6888fcfb97d4d5135 /WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp | |
parent | f8230805249e7f0956d00204d2e610208efe5ad9 (diff) | |
download | external_webkit-d4ff0cc91b5eb975d563f355f9f4c7358e0e2c06.zip external_webkit-d4ff0cc91b5eb975d563f355f9f4c7358e0e2c06.tar.gz external_webkit-d4ff0cc91b5eb975d563f355f9f4c7358e0e2c06.tar.bz2 |
HTTP auth for Chromium HTTP stack (C++ side)
On receiving an auth request:
- WebRequest (on the IO thread) sends a message to WebUrlLoaderClient
- WebUrlLoaderClient (webkit thread) calls WebCoreFrameBridge.
- WebCoreFrameBridge makes a JNI call to BrowserFrame.java.
Each JNI call has a WebUrlLoaderClient pointer, cast to an int.
We use this to recover the context when we're called back, and
dispatch a message back to WebRequest.
Corresponding Java change: https://android-git.corp.google.com/g/63762
Change-Id: Ieb72f2eaa996a55916c987859f47f6dacf92e06c
Diffstat (limited to 'WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp')
-rw-r--r-- | WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp index 6e1aa76..626b7f4 100644 --- a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp +++ b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp @@ -92,7 +92,8 @@ bool WebUrlLoaderClient::isActive() const } WebUrlLoaderClient::WebUrlLoaderClient(WebFrame* webFrame, WebCore::ResourceHandle* resourceHandle, const WebCore::ResourceRequest& resourceRequest) - : m_resourceHandle(resourceHandle) + : m_webFrame(webFrame) + , m_resourceHandle(resourceHandle) , m_cancelling(false) , m_sync(false) , m_finished(false) @@ -189,6 +190,26 @@ void WebUrlLoaderClient::cancel() thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(m_request, &WebRequest::cancel)); } +void WebUrlLoaderClient::setAuth(const std::string& username, const std::string& password) +{ + base::Thread* thread = ioThread(); + if (!thread) { + return; + } + std::wstring wUsername = base::SysUTF8ToWide(username); + std::wstring wPassword = base::SysUTF8ToWide(password); + thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(m_request, &WebRequest::setAuth, wUsername, wPassword)); +} + +void WebUrlLoaderClient::cancelAuth() +{ + base::Thread* thread = ioThread(); + if (!thread) { + return; + } + thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(m_request, &WebRequest::cancelAuth)); +} + void WebUrlLoaderClient::finish() { m_finished = true; @@ -200,7 +221,8 @@ void WebUrlLoaderClient::finish() } // This is called from the IO thread, and dispatches the callback to the main thread. -void WebUrlLoaderClient::maybeCallOnMainThread(CallbackFunction* function, void* context) { +void WebUrlLoaderClient::maybeCallOnMainThread(CallbackFunction* function, void* context) +{ if (m_sync) { AutoLock autoLock(*syncLock()); if (m_queue.empty()) { @@ -311,4 +333,26 @@ void WebUrlLoaderClient::didFinishLoading(void* data) loader->finish(); } +// static - on main thread +void WebUrlLoaderClient::authRequired(void* data) +{ + OwnPtr<LoaderData> loaderData(static_cast<LoaderData*>(data)); + WebUrlLoaderClient* loader = loaderData->loader; + + if (!loader->isActive()) { + return; + } + + std::string host = base::SysWideToUTF8(loaderData->authChallengeInfo->host_and_port); + std::string realm = base::SysWideToUTF8(loaderData->authChallengeInfo->realm); + + // TODO: Not clear whose responsibility it is to cache credentials. There's nothing + // in AuthChallengeInfo that seems suitable, so for safety we'll tell the UI *not* + // to use cached credentials. We may need to track this ourselves (pass "true" on + // the first call, then "false" for a second call if the credentials are rejected). + bool useCachedCredentials = false; + + loader->m_webFrame->didReceiveAuthenticationChallenge(loader, host, realm, useCachedCredentials); +} + } // namespace android |