OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/android/bluetooth_chooser_android.h" | |
6 | |
7 #include "base/android/jni_android.h" | |
8 #include "base/android/jni_string.h" | |
9 #include "base/strings/utf_string_conversions.h" | |
10 #include "chrome/browser/ssl/connection_security.h" | |
11 #include "chrome/browser/ui/android/window_android_helper.h" | |
12 #include "content/public/browser/android/content_view_core.h" | |
13 #include "jni/BluetoothChooserDialog_jni.h" | |
14 | |
15 using base::android::AttachCurrentThread; | |
16 using base::android::ConvertUTF16ToJavaString; | |
17 using base::android::ScopedJavaLocalRef; | |
18 | |
19 BluetoothChooserAndroid::BluetoothChooserAndroid(const GURL& origin, | |
20 content::WebContents* web_contents, const EventHandler& event_handler) | |
21 : event_handler_(event_handler) { | |
22 base::android::ScopedJavaLocalRef<jobject> context = | |
23 content::ContentViewCore::FromWebContents(web_contents)->GetJavaObject(); | |
24 | |
25 // Create (and show) the BluetoothChooser dialog. | |
26 JNIEnv* env = AttachCurrentThread(); | |
27 ScopedJavaLocalRef<jstring> origin_string = ConvertUTF16ToJavaString( | |
28 env, base::UTF8ToUTF16(origin.spec())); | |
29 java_dialog_.Reset(Java_BluetoothChooserDialog_create( | |
30 env, context.obj(), origin_string.obj(), | |
31 connection_security::GetSecurityLevelForWebContents(web_contents), | |
32 reinterpret_cast<intptr_t>(this))); | |
33 } | |
34 | |
35 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?
| |
36 } | |
37 | |
38 void BluetoothChooserAndroid::SetAdapterPresence(AdapterPresence presence) { | |
39 if (presence != AdapterPresence::POWERED_ON) { | |
40 Java_BluetoothChooserDialog_notifyAdapterTurnedOff( | |
41 AttachCurrentThread(), java_dialog_.obj()); | |
42 } | |
43 } | |
44 | |
45 void BluetoothChooserAndroid::ShowDiscoveryState(DiscoveryState state) { | |
46 NOTIMPLEMENTED(); // Currently we don't show a 'still searching' state. | |
47 } | |
48 | |
49 void BluetoothChooserAndroid::AddDevice(const std::string& device_id, | |
50 const base::string16& device_name) { | |
51 JNIEnv* env = AttachCurrentThread(); | |
52 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.
| |
53 env, base::UTF8ToUTF16(device_id)); | |
54 ScopedJavaLocalRef<jstring> java_device_name = ConvertUTF16ToJavaString( | |
55 env, device_name); | |
56 Java_BluetoothChooserDialog_addDevice( | |
57 env, java_dialog_.obj(), java_device_id.obj(), java_device_name.obj()); | |
58 } | |
59 | |
60 void BluetoothChooserAndroid::RemoveDevice(const std::string& device_id) { | |
61 JNIEnv* env = AttachCurrentThread(); | |
62 ScopedJavaLocalRef<jstring> java_device_id = ConvertUTF16ToJavaString( | |
63 env, base::UTF8ToUTF16(device_id)); | |
64 Java_BluetoothChooserDialog_removeDevice( | |
65 env, java_dialog_.obj(), java_device_id.obj()); | |
66 } | |
67 | |
68 void BluetoothChooserAndroid::ReportDeviceSelected( | |
69 JNIEnv* env, jobject obj, jstring device_id) { | |
70 event_handler_.Run( | |
71 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
| |
72 } | |
73 | |
74 void BluetoothChooserAndroid::ReportRestartSearch(JNIEnv* env, jobject obj) { | |
75 event_handler_.Run(Event::RESTART, ""); | |
76 } | |
77 | |
78 // static | |
79 bool BluetoothChooserAndroid::Register(JNIEnv* env) { | |
80 return RegisterNativesImpl(env); | |
81 } | |
OLD | NEW |