Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / android_webview / native / aw_http_auth_handler.cc
blob0c4fd92776eebff100ca188811e3c7482bd3a992
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.
5 #include "android_webview/native/aw_http_auth_handler.h"
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"
16 using base::android::ConvertJavaStringToUTF16;
18 namespace android_webview {
20 AwHttpAuthHandler::AwHttpAuthHandler(AwLoginDelegate* login_delegate,
21 net::AuthChallengeInfo* auth_info,
22 bool first_auth_attempt)
23 : login_delegate_(login_delegate),
24 host_(auth_info->challenger.host()),
25 realm_(auth_info->realm) {
26 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
27 JNIEnv* env = base::android::AttachCurrentThread();
28 http_auth_handler_.Reset(
29 Java_AwHttpAuthHandler_create(
30 env, reinterpret_cast<intptr_t>(this), first_auth_attempt));
33 AwHttpAuthHandler:: ~AwHttpAuthHandler() {
34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
35 Java_AwHttpAuthHandler_handlerDestroyed(base::android::AttachCurrentThread(),
36 http_auth_handler_.obj());
39 void AwHttpAuthHandler::Proceed(JNIEnv* env,
40 jobject obj,
41 jstring user,
42 jstring password) {
43 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
44 if (login_delegate_.get()) {
45 login_delegate_->Proceed(ConvertJavaStringToUTF16(env, user),
46 ConvertJavaStringToUTF16(env, password));
47 login_delegate_ = NULL;
51 void AwHttpAuthHandler::Cancel(JNIEnv* env, jobject obj) {
52 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
53 if (login_delegate_.get()) {
54 login_delegate_->Cancel();
55 login_delegate_ = NULL;
59 bool AwHttpAuthHandler::HandleOnUIThread(content::WebContents* web_contents) {
60 DCHECK(web_contents);
61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
62 AwContents* aw_contents = AwContents::FromWebContents(web_contents);
64 return aw_contents->OnReceivedHttpAuthRequest(http_auth_handler_, host_,
65 realm_);
68 // static
69 AwHttpAuthHandlerBase* AwHttpAuthHandlerBase::Create(
70 AwLoginDelegate* login_delegate,
71 net::AuthChallengeInfo* auth_info,
72 bool first_auth_attempt) {
73 return new AwHttpAuthHandler(login_delegate, auth_info, first_auth_attempt);
76 bool RegisterAwHttpAuthHandler(JNIEnv* env) {
77 return RegisterNativesImpl(env);
80 } // namespace android_webview