OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "android_webview/native/aw_http_auth_handler.h" | |
6 | |
7 #include "android_webview/browser/aw_login_delegate.h" | |
8 #include "android_webview/native/aw_contents.h" | |
9 #include "base/android/jni_android.h" | |
10 #include "base/android/jni_string.h" | |
11 #include "content/public/browser/browser_thread.h" | |
12 #include "jni/AwHttpAuthHandler_jni.h" | |
13 #include "net/base/auth.h" | |
14 #include "content/public/browser/web_contents.h" | |
15 | |
16 using base::android::ConvertJavaStringToUTF16; | |
17 using base::android::JavaParamRef; | |
18 using content::BrowserThread; | |
19 | |
20 namespace android_webview { | |
21 | |
22 AwHttpAuthHandler::AwHttpAuthHandler(AwLoginDelegate* login_delegate, | |
23 net::AuthChallengeInfo* auth_info, | |
24 bool first_auth_attempt) | |
25 : login_delegate_(login_delegate), | |
26 host_(auth_info->challenger.host()), | |
27 realm_(auth_info->realm) { | |
28 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
29 JNIEnv* env = base::android::AttachCurrentThread(); | |
30 http_auth_handler_.Reset( | |
31 Java_AwHttpAuthHandler_create( | |
32 env, reinterpret_cast<intptr_t>(this), first_auth_attempt)); | |
33 } | |
34 | |
35 AwHttpAuthHandler:: ~AwHttpAuthHandler() { | |
36 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
37 Java_AwHttpAuthHandler_handlerDestroyed(base::android::AttachCurrentThread(), | |
38 http_auth_handler_); | |
39 } | |
40 | |
41 void AwHttpAuthHandler::Proceed(JNIEnv* env, | |
42 const JavaParamRef<jobject>& obj, | |
43 const JavaParamRef<jstring>& user, | |
44 const JavaParamRef<jstring>& password) { | |
45 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
46 if (login_delegate_.get()) { | |
47 login_delegate_->Proceed(ConvertJavaStringToUTF16(env, user), | |
48 ConvertJavaStringToUTF16(env, password)); | |
49 login_delegate_ = NULL; | |
50 } | |
51 } | |
52 | |
53 void AwHttpAuthHandler::Cancel(JNIEnv* env, const JavaParamRef<jobject>& obj) { | |
54 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
55 if (login_delegate_.get()) { | |
56 login_delegate_->Cancel(); | |
57 login_delegate_ = NULL; | |
58 } | |
59 } | |
60 | |
61 bool AwHttpAuthHandler::HandleOnUIThread(content::WebContents* web_contents) { | |
62 DCHECK(web_contents); | |
63 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
64 AwContents* aw_contents = AwContents::FromWebContents(web_contents); | |
65 | |
66 return aw_contents->OnReceivedHttpAuthRequest(http_auth_handler_, host_, | |
67 realm_); | |
68 } | |
69 | |
70 // static | |
71 AwHttpAuthHandlerBase* AwHttpAuthHandlerBase::Create( | |
72 AwLoginDelegate* login_delegate, | |
73 net::AuthChallengeInfo* auth_info, | |
74 bool first_auth_attempt) { | |
75 return new AwHttpAuthHandler(login_delegate, auth_info, first_auth_attempt); | |
76 } | |
77 | |
78 bool RegisterAwHttpAuthHandler(JNIEnv* env) { | |
79 return RegisterNativesImpl(env); | |
80 } | |
81 | |
82 } // namespace android_webview | |
OLD | NEW |