| 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/ssl/chrome_security_state_model_client.h" | 10 #include "chrome/browser/ssl/security_state_tab_helper.h" |
| 11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 12 #include "components/security_state/core/security_state.h" |
| 12 #include "components/url_formatter/elide_url.h" | 13 #include "components/url_formatter/elide_url.h" |
| 13 #include "content/public/browser/android/content_view_core.h" | 14 #include "content/public/browser/android/content_view_core.h" |
| 14 #include "content/public/browser/render_frame_host.h" | 15 #include "content/public/browser/render_frame_host.h" |
| 15 #include "jni/BluetoothChooserDialog_jni.h" | 16 #include "jni/BluetoothChooserDialog_jni.h" |
| 16 #include "ui/android/window_android.h" | 17 #include "ui/android/window_android.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 #include "url/origin.h" | 19 #include "url/origin.h" |
| 19 | 20 |
| 20 using base::android::AttachCurrentThread; | 21 using base::android::AttachCurrentThread; |
| 21 using base::android::ConvertUTF8ToJavaString; | 22 using base::android::ConvertUTF8ToJavaString; |
| 22 using base::android::ConvertUTF16ToJavaString; | 23 using base::android::ConvertUTF16ToJavaString; |
| 23 using base::android::JavaParamRef; | 24 using base::android::JavaParamRef; |
| 24 using base::android::ScopedJavaLocalRef; | 25 using base::android::ScopedJavaLocalRef; |
| 25 | 26 |
| 26 BluetoothChooserAndroid::BluetoothChooserAndroid( | 27 BluetoothChooserAndroid::BluetoothChooserAndroid( |
| 27 content::RenderFrameHost* frame, | 28 content::RenderFrameHost* frame, |
| 28 const EventHandler& event_handler) | 29 const EventHandler& event_handler) |
| 29 : web_contents_(content::WebContents::FromRenderFrameHost(frame)), | 30 : web_contents_(content::WebContents::FromRenderFrameHost(frame)), |
| 30 event_handler_(event_handler) { | 31 event_handler_(event_handler) { |
| 31 const url::Origin origin = frame->GetLastCommittedOrigin(); | 32 const url::Origin origin = frame->GetLastCommittedOrigin(); |
| 32 DCHECK(!origin.unique()); | 33 DCHECK(!origin.unique()); |
| 33 | 34 |
| 34 base::android::ScopedJavaLocalRef<jobject> window_android = | 35 base::android::ScopedJavaLocalRef<jobject> window_android = |
| 35 content::ContentViewCore::FromWebContents(web_contents_) | 36 content::ContentViewCore::FromWebContents(web_contents_) |
| 36 ->GetWindowAndroid() | 37 ->GetWindowAndroid() |
| 37 ->GetJavaObject(); | 38 ->GetJavaObject(); |
| 38 | 39 |
| 39 ChromeSecurityStateModelClient* security_model_client = | 40 SecurityStateTabHelper* helper = |
| 40 ChromeSecurityStateModelClient::FromWebContents(web_contents_); | 41 SecurityStateTabHelper::FromWebContents(web_contents_); |
| 41 DCHECK(security_model_client); | 42 DCHECK(helper); |
| 42 | 43 |
| 43 // Create (and show) the BluetoothChooser dialog. | 44 // Create (and show) the BluetoothChooser dialog. |
| 44 JNIEnv* env = AttachCurrentThread(); | 45 JNIEnv* env = AttachCurrentThread(); |
| 45 base::android::ScopedJavaLocalRef<jstring> origin_string = | 46 base::android::ScopedJavaLocalRef<jstring> origin_string = |
| 46 base::android::ConvertUTF16ToJavaString( | 47 base::android::ConvertUTF16ToJavaString( |
| 47 env, url_formatter::FormatUrlForSecurityDisplay(origin.GetURL())); | 48 env, url_formatter::FormatUrlForSecurityDisplay(origin.GetURL())); |
| 48 security_state::SecurityStateModel::SecurityInfo security_info; | 49 security_state::SecurityInfo security_info; |
| 49 security_model_client->GetSecurityInfo(&security_info); | 50 helper->GetSecurityInfo(&security_info); |
| 50 java_dialog_.Reset(Java_BluetoothChooserDialog_create( | 51 java_dialog_.Reset(Java_BluetoothChooserDialog_create( |
| 51 env, window_android, origin_string, security_info.security_level, | 52 env, window_android, origin_string, security_info.security_level, |
| 52 reinterpret_cast<intptr_t>(this))); | 53 reinterpret_cast<intptr_t>(this))); |
| 53 } | 54 } |
| 54 | 55 |
| 55 BluetoothChooserAndroid::~BluetoothChooserAndroid() { | 56 BluetoothChooserAndroid::~BluetoothChooserAndroid() { |
| 56 if (!java_dialog_.is_null()) { | 57 if (!java_dialog_.is_null()) { |
| 57 Java_BluetoothChooserDialog_closeDialog(AttachCurrentThread(), | 58 Java_BluetoothChooserDialog_closeDialog(AttachCurrentThread(), |
| 58 java_dialog_); | 59 java_dialog_); |
| 59 } | 60 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // static | 171 // static |
| 171 bool BluetoothChooserAndroid::Register(JNIEnv* env) { | 172 bool BluetoothChooserAndroid::Register(JNIEnv* env) { |
| 172 return RegisterNativesImpl(env); | 173 return RegisterNativesImpl(env); |
| 173 } | 174 } |
| 174 | 175 |
| 175 void BluetoothChooserAndroid::OpenURL(const char* url) { | 176 void BluetoothChooserAndroid::OpenURL(const char* url) { |
| 176 web_contents_->OpenURL(content::OpenURLParams( | 177 web_contents_->OpenURL(content::OpenURLParams( |
| 177 GURL(url), content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, | 178 GURL(url), content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 178 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false /* is_renderer_initiated */)); | 179 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false /* is_renderer_initiated */)); |
| 179 } | 180 } |
| OLD | NEW |