OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/bluetooth_chooser_android.h" | 5 #include "chrome/browser/ui/android/bluetooth_chooser_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/browser/ssl/chrome_security_state_model_client.h" | 10 #include "chrome/browser/ssl/chrome_security_state_model_client.h" |
12 #include "chrome/common/pref_names.h" | |
13 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
14 #include "components/prefs/pref_service.h" | |
15 #include "components/url_formatter/elide_url.h" | 12 #include "components/url_formatter/elide_url.h" |
16 #include "content/public/browser/android/content_view_core.h" | 13 #include "content/public/browser/android/content_view_core.h" |
17 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
18 #include "jni/BluetoothChooserDialog_jni.h" | 15 #include "jni/BluetoothChooserDialog_jni.h" |
19 #include "ui/android/window_android.h" | 16 #include "ui/android/window_android.h" |
20 #include "url/gurl.h" | 17 #include "url/gurl.h" |
21 #include "url/origin.h" | 18 #include "url/origin.h" |
22 | 19 |
23 using base::android::AttachCurrentThread; | 20 using base::android::AttachCurrentThread; |
24 using base::android::ConvertUTF8ToJavaString; | 21 using base::android::ConvertUTF8ToJavaString; |
(...skipping 12 matching lines...) Expand all Loading... |
37 content::ContentViewCore::FromWebContents(web_contents_) | 34 content::ContentViewCore::FromWebContents(web_contents_) |
38 ->GetWindowAndroid() | 35 ->GetWindowAndroid() |
39 ->GetJavaObject(); | 36 ->GetJavaObject(); |
40 | 37 |
41 ChromeSecurityStateModelClient* security_model_client = | 38 ChromeSecurityStateModelClient* security_model_client = |
42 ChromeSecurityStateModelClient::FromWebContents(web_contents_); | 39 ChromeSecurityStateModelClient::FromWebContents(web_contents_); |
43 DCHECK(security_model_client); | 40 DCHECK(security_model_client); |
44 | 41 |
45 // Create (and show) the BluetoothChooser dialog. | 42 // Create (and show) the BluetoothChooser dialog. |
46 JNIEnv* env = AttachCurrentThread(); | 43 JNIEnv* env = AttachCurrentThread(); |
47 Profile* profile = | |
48 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
49 std::string languages = | |
50 profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | |
51 base::android::ScopedJavaLocalRef<jstring> origin_string = | 44 base::android::ScopedJavaLocalRef<jstring> origin_string = |
52 base::android::ConvertUTF16ToJavaString( | 45 base::android::ConvertUTF16ToJavaString( |
53 env, url_formatter::FormatUrlForSecurityDisplay( | 46 env, url_formatter::FormatUrlForSecurityDisplay( |
54 frame->GetLastCommittedURL(), languages)); | 47 frame->GetLastCommittedURL())); |
55 java_dialog_.Reset(Java_BluetoothChooserDialog_create( | 48 java_dialog_.Reset(Java_BluetoothChooserDialog_create( |
56 env, window_android.obj(), origin_string.obj(), | 49 env, window_android.obj(), origin_string.obj(), |
57 security_model_client->GetSecurityInfo().security_level, | 50 security_model_client->GetSecurityInfo().security_level, |
58 reinterpret_cast<intptr_t>(this))); | 51 reinterpret_cast<intptr_t>(this))); |
59 } | 52 } |
60 | 53 |
61 BluetoothChooserAndroid::~BluetoothChooserAndroid() { | 54 BluetoothChooserAndroid::~BluetoothChooserAndroid() { |
62 if (!java_dialog_.is_null()) { | 55 if (!java_dialog_.is_null()) { |
63 Java_BluetoothChooserDialog_closeDialog(AttachCurrentThread(), | 56 Java_BluetoothChooserDialog_closeDialog(AttachCurrentThread(), |
64 java_dialog_.obj()); | 57 java_dialog_.obj()); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // static | 166 // static |
174 bool BluetoothChooserAndroid::Register(JNIEnv* env) { | 167 bool BluetoothChooserAndroid::Register(JNIEnv* env) { |
175 return RegisterNativesImpl(env); | 168 return RegisterNativesImpl(env); |
176 } | 169 } |
177 | 170 |
178 void BluetoothChooserAndroid::OpenURL(const char* url) { | 171 void BluetoothChooserAndroid::OpenURL(const char* url) { |
179 web_contents_->OpenURL(content::OpenURLParams( | 172 web_contents_->OpenURL(content::OpenURLParams( |
180 GURL(url), content::Referrer(), NEW_FOREGROUND_TAB, | 173 GURL(url), content::Referrer(), NEW_FOREGROUND_TAB, |
181 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false /* is_renderer_initiated */)); | 174 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false /* is_renderer_initiated */)); |
182 } | 175 } |
OLD | NEW |