OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 #ifndef CHROME_BROWSER_UI_ANDROID_USB_CHOOSER_ANDROID_H_ | |
6 #define CHROME_BROWSER_UI_ANDROID_USB_CHOOSER_ANDROID_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/android/scoped_java_ref.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "base/scoped_observer.h" | |
16 #include "base/strings/string16.h" | |
17 #include "content/public/browser/web_contents_observer.h" | |
18 #include "device/usb/public/interfaces/chooser_service.mojom.h" | |
19 #include "device/usb/usb_service.h" | |
20 #include "mojo/public/cpp/bindings/array.h" | |
21 | |
22 namespace content { | |
23 class RenderFrameHost; | |
24 class WebContents; | |
25 } | |
26 | |
27 namespace device { | |
28 class UsbDevice; | |
29 class UsbDeviceFilter; | |
30 } | |
31 | |
32 // Represents a way to ask the user to select a USB device from a list of | |
33 // options. | |
34 class UsbChooserAndroid : public device::UsbService::Observer, | |
35 public content::WebContentsObserver { | |
Reilly Grant (use Gerrit)
2016/03/04 20:53:39
I've been told that WebContentsObservers are expen
juncai
2016/03/05 00:18:25
Done.
| |
36 public: | |
37 UsbChooserAndroid( | |
38 mojo::Array<device::usb::DeviceFilterPtr> device_filters, | |
39 content::RenderFrameHost* render_frame_host, | |
40 const device::usb::ChooserService::GetPermissionCallback& callback); | |
41 ~UsbChooserAndroid() override; | |
42 | |
43 // device::UsbService::Observer: | |
44 void OnDeviceAdded(scoped_refptr<device::UsbDevice> device) override; | |
45 void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override; | |
46 | |
47 // content::WebContentsObserver: | |
48 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | |
49 | |
50 void Select(const std::string& guid); | |
51 void Cancel(); | |
52 | |
53 void GotUsbDeviceList( | |
54 const std::vector<scoped_refptr<device::UsbDevice>>& devices); | |
55 | |
56 // Report the dialog's result. | |
57 void OnDialogFinished(JNIEnv* env, | |
58 const base::android::JavaParamRef<jobject>& obj, | |
59 jint event_type, | |
60 const base::android::JavaParamRef<jstring>& device_id); | |
61 | |
62 void ShowUsbOverviewLink(JNIEnv* env, | |
63 const base::android::JavaParamRef<jobject>& obj); | |
64 | |
65 static bool Register(JNIEnv* env); | |
66 | |
67 private: | |
68 void UpdateChooserDialog() const; | |
69 | |
70 void OpenUrl(const std::string& url); | |
71 | |
72 content::RenderFrameHost* const render_frame_host_; | |
73 content::WebContents* web_contents_; | |
74 device::usb::ChooserService::GetPermissionCallback callback_; | |
75 ScopedObserver<device::UsbService, device::UsbService::Observer> | |
76 usb_service_observer_; | |
77 std::vector<device::UsbDeviceFilter> filters_; | |
78 std::vector<scoped_refptr<device::UsbDevice>> devices_; | |
79 std::vector<std::string> device_guids_; | |
80 std::vector<base::string16> device_names_; | |
81 base::android::ScopedJavaGlobalRef<jobject> java_dialog_; | |
82 base::WeakPtrFactory<UsbChooserAndroid> weak_factory_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(UsbChooserAndroid); | |
85 }; | |
86 | |
87 #endif // CHROME_BROWSER_UI_ANDROID_USB_CHOOSER_ANDROID_H_ | |
OLD | NEW |