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_DIALOG_ANDROID_H_ |
| 6 #define CHROME_BROWSER_UI_ANDROID_USB_CHOOSER_DIALOG_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 UsbChooserDialogAndroid : public device::UsbService::Observer { |
| 34 public: |
| 35 UsbChooserDialogAndroid( |
| 36 mojo::Array<device::usb::DeviceFilterPtr> device_filters, |
| 37 content::RenderFrameHost* render_frame_host, |
| 38 const device::usb::ChooserService::GetPermissionCallback& callback); |
| 39 ~UsbChooserDialogAndroid() 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 // Report the dialog's result. |
| 46 void OnItemSelected(JNIEnv* env, |
| 47 const base::android::JavaParamRef<jobject>& obj, |
| 48 const base::android::JavaParamRef<jstring>& device_id); |
| 49 void OnDialogCancelled(JNIEnv* env, |
| 50 const base::android::JavaParamRef<jobject>& obj); |
| 51 |
| 52 void LoadUsbHelpPage(JNIEnv* env, |
| 53 const base::android::JavaParamRef<jobject>& obj); |
| 54 |
| 55 static bool Register(JNIEnv* env); |
| 56 |
| 57 private: |
| 58 void GotUsbDeviceList( |
| 59 const std::vector<scoped_refptr<device::UsbDevice>>& devices); |
| 60 |
| 61 // Called when the user selects the USB device with |guid| from the chooser |
| 62 // dialog. |
| 63 void Select(const std::string& guid); |
| 64 // Called when the chooser dialog is closed. |
| 65 void Cancel(); |
| 66 |
| 67 void AddDeviceToChooserDialog(scoped_refptr<device::UsbDevice> device) const; |
| 68 void RemoveDeviceFromChooserDialog( |
| 69 scoped_refptr<device::UsbDevice> device) const; |
| 70 |
| 71 void OpenUrl(const std::string& url); |
| 72 |
| 73 content::RenderFrameHost* const render_frame_host_; |
| 74 device::usb::ChooserService::GetPermissionCallback callback_; |
| 75 ScopedObserver<device::UsbService, device::UsbService::Observer> |
| 76 usb_service_observer_; |
| 77 std::vector<device::UsbDeviceFilter> filters_; |
| 78 |
| 79 std::vector<scoped_refptr<device::UsbDevice>> devices_; |
| 80 |
| 81 base::android::ScopedJavaGlobalRef<jobject> java_dialog_; |
| 82 base::WeakPtrFactory<UsbChooserDialogAndroid> weak_factory_; |
| 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(UsbChooserDialogAndroid); |
| 85 }; |
| 86 |
| 87 #endif // CHROME_BROWSER_UI_ANDROID_USB_CHOOSER_DIALOG_ANDROID_H_ |
OLD | NEW |