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 "device/usb/public/interfaces/chooser_service.mojom.h" |
| 18 #include "device/usb/usb_service.h" |
| 19 #include "mojo/public/cpp/bindings/array.h" |
| 20 |
| 21 namespace content { |
| 22 class RenderFrameHost; |
| 23 class WebContents; |
| 24 } |
| 25 |
| 26 namespace device { |
| 27 class UsbDevice; |
| 28 class UsbDeviceFilter; |
| 29 } |
| 30 |
| 31 // Represents a way to ask the user to select a USB device from a list of |
| 32 // options. |
| 33 class UsbChooserAndroid : public device::UsbService::Observer { |
| 34 public: |
| 35 UsbChooserAndroid( |
| 36 mojo::Array<device::usb::DeviceFilterPtr> device_filters, |
| 37 content::RenderFrameHost* render_frame_host, |
| 38 const device::usb::ChooserService::GetPermissionCallback& callback); |
| 39 ~UsbChooserAndroid() override; |
| 40 |
| 41 // device::UsbService::Observer: |
| 42 void OnDeviceAdded(scoped_refptr<device::UsbDevice> device) override; |
| 43 void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override; |
| 44 |
| 45 // Called when the user selects the USB device with |guid| from the chooser |
| 46 // dialog. |
| 47 void Select(const std::string& guid); |
| 48 // Called when the chooser dialog is closed. |
| 49 void Cancel(); |
| 50 |
| 51 void GotUsbDeviceList( |
| 52 const std::vector<scoped_refptr<device::UsbDevice>>& devices); |
| 53 |
| 54 // Report the dialog's result. |
| 55 void OnDialogFinished(JNIEnv* env, |
| 56 const base::android::JavaParamRef<jobject>& obj, |
| 57 jint event_type, |
| 58 const base::android::JavaParamRef<jstring>& device_id); |
| 59 |
| 60 void ShowUsbOverviewLink(JNIEnv* env, |
| 61 const base::android::JavaParamRef<jobject>& obj); |
| 62 |
| 63 static bool Register(JNIEnv* env); |
| 64 |
| 65 private: |
| 66 void UpdateChooserDialog() const; |
| 67 |
| 68 void OpenUrl(const std::string& url); |
| 69 |
| 70 content::RenderFrameHost* const render_frame_host_; |
| 71 content::WebContents* web_contents_; |
| 72 device::usb::ChooserService::GetPermissionCallback callback_; |
| 73 ScopedObserver<device::UsbService, device::UsbService::Observer> |
| 74 usb_service_observer_; |
| 75 std::vector<device::UsbDeviceFilter> filters_; |
| 76 |
| 77 // |devices_|, |device_guids_| and |device_names_| have the same size and |
| 78 // elements in the same index are synced to store information for the same |
| 79 // device. |
| 80 std::vector<scoped_refptr<device::UsbDevice>> devices_; |
| 81 std::vector<std::string> device_guids_; |
| 82 std::vector<base::string16> device_names_; |
| 83 |
| 84 base::android::ScopedJavaGlobalRef<jobject> java_dialog_; |
| 85 base::WeakPtrFactory<UsbChooserAndroid> weak_factory_; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(UsbChooserAndroid); |
| 88 }; |
| 89 |
| 90 #endif // CHROME_BROWSER_UI_ANDROID_USB_CHOOSER_ANDROID_H_ |
OLD | NEW |