diff options
-rw-r--r-- | WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp | 5 | ||||
-rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.cpp | 52 | ||||
-rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.h | 4 |
3 files changed, 61 insertions, 0 deletions
diff --git a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp index 96dd04c..19f4f34 100644 --- a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp +++ b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp @@ -356,6 +356,11 @@ void WebUrlLoaderClient::didReceiveResponse(PassOwnPtr<WebResponse> webResponse) ssl_info.cert->GetChainDEREncodedBytes(&chain_bytes); m_webFrame->setCertificate(chain_bytes[0]); } + + // Look for X-Auto-Login on the main resource to log in the user. + std::string login; + if (m_response->getHeader("x-auto-login", &login)) + m_webFrame->autoLogin(login); } } diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index eff64e1..6683fb2 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -221,6 +221,7 @@ struct WebFrame::JavaBrowserFrame jmethodID mSetCertificate; jmethodID mShouldSaveFormData; jmethodID mSaveFormData; + jmethodID mAutoLogin; AutoJObject frame(JNIEnv* env) { return getRealObject(env, mObj); } @@ -294,6 +295,8 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page* mJavaFrame->mSetCertificate = env->GetMethodID(clazz, "setCertificate", "([B)V"); mJavaFrame->mShouldSaveFormData = env->GetMethodID(clazz, "shouldSaveFormData", "()Z"); mJavaFrame->mSaveFormData = env->GetMethodID(clazz, "saveFormData", "(Ljava/util/HashMap;)V"); + mJavaFrame->mAutoLogin = env->GetMethodID(clazz, "autoLogin", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); env->DeleteLocalRef(clazz); LOG_ASSERT(mJavaFrame->mStartLoadingResource, "Could not find method startLoadingResource"); @@ -326,6 +329,7 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page* LOG_ASSERT(mJavaFrame->mSetCertificate, "Could not find method setCertificate"); LOG_ASSERT(mJavaFrame->mShouldSaveFormData, "Could not find method shouldSaveFormData"); LOG_ASSERT(mJavaFrame->mSaveFormData, "Could not find method saveFormData"); + LOG_ASSERT(mJavaFrame->mAutoLogin, "Could not find method autoLogin"); mUserAgent = WTF::String(); mUserInitiatedAction = false; @@ -983,6 +987,54 @@ void WebFrame::setCertificate(const std::string& cert) } #endif +void WebFrame::autoLogin(const std::string& loginHeader) +{ +#ifdef ANDROID_INSTRUMENT + TimeCounterAuto counter(TimerCoutner::JavaCallbackTimeCounter); +#endif + WTF::String header(loginHeader.c_str(), loginHeader.length()); + WTF::Vector<WTF::String> split; + header.split('&', split); + if (!split.isEmpty()) { + WTF::String realm; + WTF::String account; + WTF::String args; + int len = split.size(); + while (len--) { + WTF::String& str = split[len]; + size_t equals = str.find('='); + if (equals == WTF::notFound) + continue; + + WTF::String* result = 0; + if (str.startsWith("realm", false)) + result = &realm; + else if (str.startsWith("account", false)) + result = &account; + else if (str.startsWith("args", false)) + result = &args; + + if (result) + // Decode url escape sequences before sending to the app. + *result = WebCore::decodeURLEscapeSequences(str.substring(equals + 1)); + } + + // realm and args are required parameters. + if (realm.isEmpty() || args.isEmpty()) + return; + + // Args is double-encoded as it contains urls. + args = WebCore::decodeURLEscapeSequences(args); + + JNIEnv* env = getJNIEnv(); + jstring jRealm = wtfStringToJstring(env, realm, true); + jstring jAccount = wtfStringToJstring(env, account); + jstring jArgs = wtfStringToJstring(env, args, true); + env->CallVoidMethod(mJavaFrame->frame(env).get(), + mJavaFrame->mAutoLogin, jRealm, jAccount, jArgs); + } +} + void WebFrame::maybeSavePassword(WebCore::Frame* frame, const WebCore::ResourceRequest& request) { if (request.httpMethod() != "POST") diff --git a/WebKit/android/jni/WebCoreFrameBridge.h b/WebKit/android/jni/WebCoreFrameBridge.h index af7be60..25232e4 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.h +++ b/WebKit/android/jni/WebCoreFrameBridge.h @@ -128,6 +128,10 @@ class WebFrame : public WebCoreRefObject { void setCertificate(const std::string& cert); + // Parse the x-auto-login header and propagate the parameters to the + // application. + void autoLogin(const std::string& loginHeader); + /** * When the user initiates a click, we set mUserInitiatedAction to true. * If a load happens due to this click, then we ask the application if it wants |