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 "chrome/browser/ui/android/chrome_http_auth_handler.h" | 5 #include "chrome/browser/ui/android/chrome_http_auth_handler.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
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 "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
15 #include "jni/ChromeHttpAuthHandler_jni.h" | 16 #include "jni/ChromeHttpAuthHandler_jni.h" |
16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
17 | 18 |
18 using base::android::AttachCurrentThread; | 19 using base::android::AttachCurrentThread; |
19 using base::android::CheckException; | 20 using base::android::CheckException; |
20 using base::android::ConvertJavaStringToUTF16; | 21 using base::android::ConvertJavaStringToUTF16; |
21 using base::android::ConvertUTF16ToJavaString; | 22 using base::android::ConvertUTF16ToJavaString; |
22 using base::android::ScopedJavaLocalRef; | 23 using base::android::ScopedJavaLocalRef; |
23 | 24 |
24 ChromeHttpAuthHandler::ChromeHttpAuthHandler(const base::string16& explanation) | 25 ChromeHttpAuthHandler::ChromeHttpAuthHandler(const base::string16& authority, |
25 : observer_(NULL), | 26 const base::string16& explanation) |
26 explanation_(explanation) { | 27 : observer_(nullptr), authority_(authority), explanation_(explanation) {} |
27 } | |
28 | 28 |
29 ChromeHttpAuthHandler::~ChromeHttpAuthHandler() {} | 29 ChromeHttpAuthHandler::~ChromeHttpAuthHandler() {} |
30 | 30 |
31 void ChromeHttpAuthHandler::Init() { | 31 void ChromeHttpAuthHandler::Init() { |
32 DCHECK(java_chrome_http_auth_handler_.is_null()); | 32 DCHECK(java_chrome_http_auth_handler_.is_null()); |
33 JNIEnv* env = AttachCurrentThread(); | 33 JNIEnv* env = AttachCurrentThread(); |
34 java_chrome_http_auth_handler_.Reset( | 34 java_chrome_http_auth_handler_.Reset( |
35 Java_ChromeHttpAuthHandler_create(env, reinterpret_cast<intptr_t>(this))); | 35 Java_ChromeHttpAuthHandler_create(env, reinterpret_cast<intptr_t>(this))); |
36 } | 36 } |
37 | 37 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 void ChromeHttpAuthHandler::CancelAuth(JNIEnv* env, | 75 void ChromeHttpAuthHandler::CancelAuth(JNIEnv* env, |
76 const JavaParamRef<jobject>&) { | 76 const JavaParamRef<jobject>&) { |
77 if (observer_) | 77 if (observer_) |
78 observer_->CancelAuth(); | 78 observer_->CancelAuth(); |
79 } | 79 } |
80 | 80 |
81 ScopedJavaLocalRef<jstring> ChromeHttpAuthHandler::GetMessageBody( | 81 ScopedJavaLocalRef<jstring> ChromeHttpAuthHandler::GetMessageBody( |
82 JNIEnv* env, | 82 JNIEnv* env, |
83 const JavaParamRef<jobject>&) { | 83 const JavaParamRef<jobject>&) { |
84 return ConvertUTF16ToJavaString(env, explanation_); | 84 if (explanation_.empty()) |
| 85 return ConvertUTF16ToJavaString(env, authority_); |
| 86 return ConvertUTF16ToJavaString( |
| 87 env, authority_ + base::ASCIIToUTF16(" ") + explanation_); |
85 } | 88 } |
86 | 89 |
87 // static | 90 // static |
88 bool ChromeHttpAuthHandler::RegisterChromeHttpAuthHandler(JNIEnv* env) { | 91 bool ChromeHttpAuthHandler::RegisterChromeHttpAuthHandler(JNIEnv* env) { |
89 return RegisterNativesImpl(env); | 92 return RegisterNativesImpl(env); |
90 } | 93 } |
OLD | NEW |