Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "android_webview/native/aw_http_auth_handler.h" | 5 #include "android_webview/native/aw_http_auth_handler.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/aw_login_delegate.h" | 7 #include "android_webview/browser/aw_login_delegate.h" |
| 8 #include "android_webview/native/aw_contents.h" | 8 #include "android_webview/native/aw_contents.h" |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "jni/AwHttpAuthHandler_jni.h" | 11 #include "jni/AwHttpAuthHandler_jni.h" |
| 12 #include "net/base/auth.h" | 12 #include "net/base/auth.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 | 14 |
| 15 using base::android::ConvertJavaStringToUTF16; | 15 using base::android::ConvertJavaStringToUTF16; |
| 16 | 16 |
| 17 namespace android_webview { | 17 namespace android_webview { |
| 18 | 18 |
| 19 AwHttpAuthHandler::AwHttpAuthHandler( | 19 AwHttpAuthHandler::AwHttpAuthHandler(AwLoginDelegate* login_delegate, |
| 20 AwLoginDelegate* login_delegate, net::AuthChallengeInfo* auth_info) : | 20 net::AuthChallengeInfo* auth_info, |
| 21 login_delegate_(make_scoped_refptr(login_delegate)), | 21 bool first_auth_attempt) |
| 22 host_(auth_info->challenger.host()), | 22 : login_delegate_(make_scoped_refptr(login_delegate)), |
| 23 realm_(auth_info->realm) { | 23 host_(auth_info->challenger.host()), |
| 24 realm_(auth_info->realm) { | |
| 24 JNIEnv* env = base::android::AttachCurrentThread(); | 25 JNIEnv* env = base::android::AttachCurrentThread(); |
| 25 http_auth_handler_.Reset( | 26 http_auth_handler_.Reset( |
| 26 Java_AwHttpAuthHandler_create(env, reinterpret_cast<jint>(this))); | 27 Java_AwHttpAuthHandler_create( |
| 28 env, reinterpret_cast<jint>(this), first_auth_attempt)); | |
| 27 } | 29 } |
| 28 | 30 |
| 29 AwHttpAuthHandler:: ~AwHttpAuthHandler() { | 31 AwHttpAuthHandler:: ~AwHttpAuthHandler() { |
| 30 // TODO(joth): tell java counterpart, so it can null its native back-pointer. | 32 // TODO(joth): tell java counterpart, so it can null its native back-pointer. |
|
joth
2012/12/21 18:59:43
call Java_AwHttpAuthHandler_handerDestroyed();
| |
| 31 } | 33 } |
| 32 | 34 |
| 33 void AwHttpAuthHandler::Proceed(JNIEnv* env, | 35 void AwHttpAuthHandler::Proceed(JNIEnv* env, |
| 34 jobject obj, | 36 jobject obj, |
| 35 jstring user, | 37 jstring user, |
| 36 jstring password) { | 38 jstring password) { |
| 37 login_delegate_->Proceed(ConvertJavaStringToUTF16(env, user), | 39 login_delegate_->Proceed(ConvertJavaStringToUTF16(env, user), |
| 38 ConvertJavaStringToUTF16(env, password)); | 40 ConvertJavaStringToUTF16(env, password)); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void AwHttpAuthHandler::Cancel(JNIEnv* env, jobject obj) { | 43 void AwHttpAuthHandler::Cancel(JNIEnv* env, jobject obj) { |
| 42 login_delegate_->Cancel(); | 44 login_delegate_->Cancel(); |
| 43 } | 45 } |
| 44 | 46 |
| 45 void AwHttpAuthHandler::HandleOnUIThread(content::WebContents* web_contents) { | 47 void AwHttpAuthHandler::HandleOnUIThread(content::WebContents* web_contents) { |
| 46 DCHECK(web_contents); | 48 DCHECK(web_contents); |
| 47 AwContents* aw_contents = AwContents::FromWebContents(web_contents); | 49 AwContents* aw_contents = AwContents::FromWebContents(web_contents); |
| 48 | 50 |
| 49 aw_contents->onReceivedHttpAuthRequest( | 51 aw_contents->onReceivedHttpAuthRequest( |
| 50 http_auth_handler_, host_, realm_); | 52 http_auth_handler_, host_, realm_); |
| 51 } | 53 } |
| 52 | 54 |
| 53 // static | 55 // static |
| 54 AwHttpAuthHandlerBase* AwHttpAuthHandlerBase::Create( | 56 AwHttpAuthHandlerBase* AwHttpAuthHandlerBase::Create( |
| 55 AwLoginDelegate* login_delegate, net::AuthChallengeInfo* auth_info) { | 57 AwLoginDelegate* login_delegate, |
| 56 return new AwHttpAuthHandler(login_delegate, auth_info); | 58 net::AuthChallengeInfo* auth_info, |
| 59 bool first_auth_attempt) { | |
| 60 return new AwHttpAuthHandler(login_delegate, auth_info, first_auth_attempt); | |
| 57 } | 61 } |
| 58 | 62 |
| 59 bool RegisterAwHttpAuthHandler(JNIEnv* env) { | 63 bool RegisterAwHttpAuthHandler(JNIEnv* env) { |
| 60 return RegisterNativesImpl(env) >= 0; | 64 return RegisterNativesImpl(env) >= 0; |
| 61 } | 65 } |
| 62 | 66 |
| 63 } // namespace android_webview | 67 } // namespace android_webview |
| OLD | NEW |