Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Side by Side Diff: chrome/browser/ui/android/chrome_http_auth_handler.cc

Issue 1466473003: Do not show untrustworthy strings in the basic auth dialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve memory leak. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_(NULL), authority_(authority), explanation_(explanation) {}
msw 2015/11/20 19:15:07 nit: nullptr
palmer 2015/11/20 19:33:48 Done.
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 72 }
73 } 73 }
74 74
75 void ChromeHttpAuthHandler::CancelAuth(JNIEnv* env, jobject) { 75 void ChromeHttpAuthHandler::CancelAuth(JNIEnv* env, jobject) {
76 if (observer_) 76 if (observer_)
77 observer_->CancelAuth(); 77 observer_->CancelAuth();
78 } 78 }
79 79
80 ScopedJavaLocalRef<jstring> ChromeHttpAuthHandler::GetMessageBody( 80 ScopedJavaLocalRef<jstring> ChromeHttpAuthHandler::GetMessageBody(
81 JNIEnv* env, jobject) { 81 JNIEnv* env, jobject) {
82 return ConvertUTF16ToJavaString(env, explanation_); 82 if (explanation_.length() == 0)
msw 2015/11/20 19:15:07 nit: if (explanation_.empty())
palmer 2015/11/20 19:33:48 Done.
83 return ConvertUTF16ToJavaString(env, authority_);
84 return ConvertUTF16ToJavaString(
85 env, authority_ + base::ASCIIToUTF16(" ") + explanation_);
83 } 86 }
84 87
85 // static 88 // static
86 bool ChromeHttpAuthHandler::RegisterChromeHttpAuthHandler(JNIEnv* env) { 89 bool ChromeHttpAuthHandler::RegisterChromeHttpAuthHandler(JNIEnv* env) {
87 return RegisterNativesImpl(env); 90 return RegisterNativesImpl(env);
88 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698