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 #include "ui/android/window_android.h" | |
15 | |
16 using base::android::AttachCurrentThread; | |
17 using base::android::ConvertUTF8ToJavaString; | |
18 using base::android::ConvertUTF16ToJavaString; | |
19 using base::android::ScopedJavaLocalRef; | |
20 | |
21 BluetoothChooserAndroid::BluetoothChooserAndroid( | |
22 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.
| |
23 const GURL& origin) | |
24 : event_handler_(event_handler), | |
25 web_contents_(web_contents) { | |
26 base::android::ScopedJavaLocalRef<jobject> window_android = | |
27 content::ContentViewCore::FromWebContents( | |
28 web_contents)->GetWindowAndroid()->GetJavaObject(); | |
29 | |
30 // Create (and show) the BluetoothChooser dialog. | |
31 JNIEnv* env = AttachCurrentThread(); | |
32 ScopedJavaLocalRef<jstring> origin_string = ConvertUTF8ToJavaString( | |
33 env, origin.spec()); | |
34 java_dialog_.Reset(Java_BluetoothChooserDialog_create( | |
35 env, window_android.obj(), origin_string.obj(), | |
36 connection_security::GetSecurityLevelForWebContents(web_contents), | |
37 reinterpret_cast<intptr_t>(this))); | |
38 } | |
39 | |
40 BluetoothChooserAndroid::~BluetoothChooserAndroid() { | |
41 Java_BluetoothChooserDialog_closeDialog( | |
42 AttachCurrentThread(), java_dialog_.obj()); | |
43 } | |
44 | |
45 void BluetoothChooserAndroid::SetAdapterPresence(AdapterPresence presence) { | |
46 if (presence != AdapterPresence::POWERED_ON) { | |
47 Java_BluetoothChooserDialog_notifyAdapterTurnedOff( | |
48 AttachCurrentThread(), java_dialog_.obj()); | |
49 } | |
50 } | |
51 | |
52 void BluetoothChooserAndroid::ShowDiscoveryState(DiscoveryState state) { | |
53 NOTIMPLEMENTED(); // Currently we don't show a 'still searching' state. | |
54 } | |
55 | |
56 void BluetoothChooserAndroid::AddDevice(const std::string& device_id, | |
57 const base::string16& device_name) { | |
newt (away)
2015/09/01 21:51:23
fix param indentation
Finnur
2015/09/02 16:01:43
Done.
| |
58 JNIEnv* env = AttachCurrentThread(); | |
59 ScopedJavaLocalRef<jstring> java_device_id = ConvertUTF8ToJavaString( | |
60 env, device_id); | |
61 ScopedJavaLocalRef<jstring> java_device_name = ConvertUTF16ToJavaString( | |
62 env, device_name); | |
63 Java_BluetoothChooserDialog_addDevice( | |
64 env, java_dialog_.obj(), java_device_id.obj(), java_device_name.obj()); | |
65 } | |
66 | |
67 void BluetoothChooserAndroid::RemoveDevice(const std::string& device_id) { | |
68 JNIEnv* env = AttachCurrentThread(); | |
69 ScopedJavaLocalRef<jstring> java_device_id = ConvertUTF16ToJavaString( | |
70 env, base::UTF8ToUTF16(device_id)); | |
71 Java_BluetoothChooserDialog_removeDevice( | |
72 env, java_dialog_.obj(), java_device_id.obj()); | |
73 } | |
74 | |
75 void BluetoothChooserAndroid::ReportDeviceSelected( | |
76 JNIEnv* env, jobject obj, jstring device_id) { | |
77 event_handler_.Run( | |
78 Event::SELECTED, base::android::ConvertJavaStringToUTF8(env, device_id)); | |
79 } | |
80 | |
81 void BluetoothChooserAndroid::ReportRestartSearch(JNIEnv* env, jobject obj) { | |
82 event_handler_.Run(Event::RESCAN, ""); | |
83 } | |
84 | |
85 void BluetoothChooserAndroid::ShowBluetoothOverviewLink( | |
86 JNIEnv* env, jobject obj) { | |
87 ShowOverviewLink(web_contents_); | |
88 } | |
89 | |
90 void BluetoothChooserAndroid::ShowBluetoothPairingLink( | |
91 JNIEnv* env, jobject obj) { | |
92 ShowPairingLink(web_contents_); | |
93 } | |
94 | |
95 void BluetoothChooserAndroid::ShowBluetoothAdapterOffLink( | |
96 JNIEnv* env, jobject obj) { | |
97 ShowAdapterOffLink(web_contents_); | |
98 } | |
99 | |
100 // static | |
101 bool BluetoothChooserAndroid::Register(JNIEnv* env) { | |
102 return RegisterNativesImpl(env); | |
103 } | |
OLD | NEW |