Index: chrome/browser/ui/android/bluetooth_chooser_android.cc |
diff --git a/chrome/browser/ui/android/bluetooth_chooser_android.cc b/chrome/browser/ui/android/bluetooth_chooser_android.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ecc8acdc4fa790909740680f414a0c9427b42e9b |
--- /dev/null |
+++ b/chrome/browser/ui/android/bluetooth_chooser_android.cc |
@@ -0,0 +1,103 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/android/bluetooth_chooser_android.h" |
+ |
+#include "base/android/jni_android.h" |
+#include "base/android/jni_string.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/ssl/connection_security.h" |
+#include "chrome/browser/ui/android/window_android_helper.h" |
+#include "content/public/browser/android/content_view_core.h" |
+#include "jni/BluetoothChooserDialog_jni.h" |
+#include "ui/android/window_android.h" |
+ |
+using base::android::AttachCurrentThread; |
+using base::android::ConvertUTF8ToJavaString; |
+using base::android::ConvertUTF16ToJavaString; |
+using base::android::ScopedJavaLocalRef; |
+ |
+BluetoothChooserAndroid::BluetoothChooserAndroid( |
+ content::WebContents* web_contents, const EventHandler& event_handler, |
newt (away)
2015/09/01 21:51:23
params should each be on their own line, I believe
Finnur
2015/09/02 16:01:43
Done.
|
+ const GURL& origin) |
+ : event_handler_(event_handler), |
+ web_contents_(web_contents) { |
+ base::android::ScopedJavaLocalRef<jobject> window_android = |
+ content::ContentViewCore::FromWebContents( |
+ web_contents)->GetWindowAndroid()->GetJavaObject(); |
+ |
+ // Create (and show) the BluetoothChooser dialog. |
+ JNIEnv* env = AttachCurrentThread(); |
+ ScopedJavaLocalRef<jstring> origin_string = ConvertUTF8ToJavaString( |
+ env, origin.spec()); |
+ java_dialog_.Reset(Java_BluetoothChooserDialog_create( |
+ env, window_android.obj(), origin_string.obj(), |
+ connection_security::GetSecurityLevelForWebContents(web_contents), |
+ reinterpret_cast<intptr_t>(this))); |
+} |
+ |
+BluetoothChooserAndroid::~BluetoothChooserAndroid() { |
+ Java_BluetoothChooserDialog_closeDialog( |
+ AttachCurrentThread(), java_dialog_.obj()); |
+} |
+ |
+void BluetoothChooserAndroid::SetAdapterPresence(AdapterPresence presence) { |
+ if (presence != AdapterPresence::POWERED_ON) { |
+ Java_BluetoothChooserDialog_notifyAdapterTurnedOff( |
+ AttachCurrentThread(), java_dialog_.obj()); |
+ } |
+} |
+ |
+void BluetoothChooserAndroid::ShowDiscoveryState(DiscoveryState state) { |
+ NOTIMPLEMENTED(); // Currently we don't show a 'still searching' state. |
+} |
+ |
+void BluetoothChooserAndroid::AddDevice(const std::string& device_id, |
+ const base::string16& device_name) { |
newt (away)
2015/09/01 21:51:23
fix param indentation
Finnur
2015/09/02 16:01:43
Done.
|
+ JNIEnv* env = AttachCurrentThread(); |
+ ScopedJavaLocalRef<jstring> java_device_id = ConvertUTF8ToJavaString( |
+ env, device_id); |
+ ScopedJavaLocalRef<jstring> java_device_name = ConvertUTF16ToJavaString( |
+ env, device_name); |
+ Java_BluetoothChooserDialog_addDevice( |
+ env, java_dialog_.obj(), java_device_id.obj(), java_device_name.obj()); |
+} |
+ |
+void BluetoothChooserAndroid::RemoveDevice(const std::string& device_id) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ ScopedJavaLocalRef<jstring> java_device_id = ConvertUTF16ToJavaString( |
+ env, base::UTF8ToUTF16(device_id)); |
+ Java_BluetoothChooserDialog_removeDevice( |
+ env, java_dialog_.obj(), java_device_id.obj()); |
+} |
+ |
+void BluetoothChooserAndroid::ReportDeviceSelected( |
+ JNIEnv* env, jobject obj, jstring device_id) { |
+ event_handler_.Run( |
+ Event::SELECTED, base::android::ConvertJavaStringToUTF8(env, device_id)); |
+} |
+ |
+void BluetoothChooserAndroid::ReportRestartSearch(JNIEnv* env, jobject obj) { |
+ event_handler_.Run(Event::RESCAN, ""); |
+} |
+ |
+void BluetoothChooserAndroid::ShowBluetoothOverviewLink( |
+ JNIEnv* env, jobject obj) { |
+ ShowOverviewLink(web_contents_); |
+} |
+ |
+void BluetoothChooserAndroid::ShowBluetoothPairingLink( |
+ JNIEnv* env, jobject obj) { |
+ ShowPairingLink(web_contents_); |
+} |
+ |
+void BluetoothChooserAndroid::ShowBluetoothAdapterOffLink( |
+ JNIEnv* env, jobject obj) { |
+ ShowAdapterOffLink(web_contents_); |
+} |
+ |
+// static |
+bool BluetoothChooserAndroid::Register(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |