Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / android / chrome_http_auth_handler.cc
blob01aae4cdae8436e14da4a38b317638121609f564
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 "chrome/browser/ui/android/chrome_http_auth_handler.h"
7 #include <jni.h>
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/logging.h"
13 #include "base/strings/string16.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "jni/ChromeHttpAuthHandler_jni.h"
16 #include "ui/base/l10n/l10n_util.h"
18 using base::android::AttachCurrentThread;
19 using base::android::CheckException;
20 using base::android::ConvertJavaStringToUTF16;
21 using base::android::ConvertUTF16ToJavaString;
22 using base::android::ScopedJavaLocalRef;
24 ChromeHttpAuthHandler::ChromeHttpAuthHandler(const base::string16& explanation)
25 : observer_(NULL),
26 explanation_(explanation) {
29 ChromeHttpAuthHandler::~ChromeHttpAuthHandler() {}
31 void ChromeHttpAuthHandler::Init() {
32 DCHECK(java_chrome_http_auth_handler_.is_null());
33 JNIEnv* env = AttachCurrentThread();
34 java_chrome_http_auth_handler_.Reset(
35 Java_ChromeHttpAuthHandler_create(env, reinterpret_cast<intptr_t>(this)));
38 void ChromeHttpAuthHandler::SetObserver(LoginHandler* observer) {
39 observer_ = observer;
42 void ChromeHttpAuthHandler::ShowDialog(jobject window_android) {
43 JNIEnv* env = AttachCurrentThread();
44 Java_ChromeHttpAuthHandler_showDialog(
45 env,
46 java_chrome_http_auth_handler_.obj(),
47 window_android);
50 void ChromeHttpAuthHandler::OnAutofillDataAvailable(
51 const base::string16& username,
52 const base::string16& password) {
53 DCHECK(java_chrome_http_auth_handler_.obj() != NULL);
54 JNIEnv* env = base::android::AttachCurrentThread();
55 ScopedJavaLocalRef<jstring> j_username =
56 ConvertUTF16ToJavaString(env, username);
57 ScopedJavaLocalRef<jstring> j_password =
58 ConvertUTF16ToJavaString(env, password);
59 Java_ChromeHttpAuthHandler_onAutofillDataAvailable(
60 env, java_chrome_http_auth_handler_.obj(),
61 j_username.obj(), j_password.obj());
64 void ChromeHttpAuthHandler::SetAuth(JNIEnv* env,
65 jobject,
66 jstring username,
67 jstring password) {
68 if (observer_) {
69 base::string16 username16 = ConvertJavaStringToUTF16(env, username);
70 base::string16 password16 = ConvertJavaStringToUTF16(env, password);
71 observer_->SetAuth(username16, password16);
75 void ChromeHttpAuthHandler::CancelAuth(JNIEnv* env, jobject) {
76 if (observer_)
77 observer_->CancelAuth();
80 ScopedJavaLocalRef<jstring> ChromeHttpAuthHandler::GetMessageTitle(
81 JNIEnv* env, jobject) {
82 return ConvertUTF16ToJavaString(env,
83 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_TITLE));
86 ScopedJavaLocalRef<jstring> ChromeHttpAuthHandler::GetMessageBody(
87 JNIEnv* env, jobject) {
88 return ConvertUTF16ToJavaString(env, explanation_);
91 ScopedJavaLocalRef<jstring> ChromeHttpAuthHandler::GetUsernameLabelText(
92 JNIEnv* env, jobject) {
93 return ConvertUTF16ToJavaString(env,
94 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_USERNAME_FIELD));
97 ScopedJavaLocalRef<jstring> ChromeHttpAuthHandler::GetPasswordLabelText(
98 JNIEnv* env, jobject) {
99 return ConvertUTF16ToJavaString(env,
100 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_PASSWORD_FIELD));
103 ScopedJavaLocalRef<jstring> ChromeHttpAuthHandler::GetOkButtonText(
104 JNIEnv* env, jobject) {
105 return ConvertUTF16ToJavaString(env,
106 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL));
109 ScopedJavaLocalRef<jstring> ChromeHttpAuthHandler::GetCancelButtonText(
110 JNIEnv* env, jobject) {
111 return ConvertUTF16ToJavaString(env, l10n_util::GetStringUTF16(IDS_CANCEL));
114 // static
115 bool ChromeHttpAuthHandler::RegisterChromeHttpAuthHandler(JNIEnv* env) {
116 return RegisterNativesImpl(env);