Chromium Code Reviews| 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..7be1c5fcdeb321553d6a0518d2397fc65c9d8017 |
| --- /dev/null |
| +++ b/chrome/browser/ui/android/bluetooth_chooser_android.cc |
| @@ -0,0 +1,81 @@ |
| +// 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" |
| + |
| +using base::android::AttachCurrentThread; |
| +using base::android::ConvertUTF16ToJavaString; |
| +using base::android::ScopedJavaLocalRef; |
| + |
| +BluetoothChooserAndroid::BluetoothChooserAndroid(const GURL& origin, |
| + content::WebContents* web_contents, const EventHandler& event_handler) |
| + : event_handler_(event_handler) { |
| + base::android::ScopedJavaLocalRef<jobject> context = |
| + content::ContentViewCore::FromWebContents(web_contents)->GetJavaObject(); |
| + |
| + // Create (and show) the BluetoothChooser dialog. |
| + JNIEnv* env = AttachCurrentThread(); |
| + ScopedJavaLocalRef<jstring> origin_string = ConvertUTF16ToJavaString( |
| + env, base::UTF8ToUTF16(origin.spec())); |
| + java_dialog_.Reset(Java_BluetoothChooserDialog_create( |
| + env, context.obj(), origin_string.obj(), |
| + connection_security::GetSecurityLevelForWebContents(web_contents), |
| + reinterpret_cast<intptr_t>(this))); |
| +} |
| + |
| +BluetoothChooserAndroid::~BluetoothChooserAndroid() { |
|
Jeffrey Yasskin
2015/08/28 18:16:33
I think this destructor needs to call into Java to
Finnur
2015/08/31 15:25:22
Done. Look ok?
|
| +} |
| + |
| +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) { |
| + JNIEnv* env = AttachCurrentThread(); |
| + ScopedJavaLocalRef<jstring> java_device_id = ConvertUTF16ToJavaString( |
|
Jeffrey Yasskin
2015/08/28 18:16:33
Use ConvertUTF8ToJavaString() for this one.
Finnur
2015/08/31 15:25:22
Done.
|
| + env, base::UTF8ToUTF16(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)); |
|
Jeffrey Yasskin
2015/08/28 18:16:33
It looks like we're missing a way to report that t
Finnur
2015/08/31 15:25:22
And a way to report that the help link was pressed
|
| +} |
| + |
| +void BluetoothChooserAndroid::ReportRestartSearch(JNIEnv* env, jobject obj) { |
| + event_handler_.Run(Event::RESTART, ""); |
| +} |
| + |
| +// static |
| +bool BluetoothChooserAndroid::Register(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |