Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 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 EXTENSIONS_BROWSER_DEVICE_PERMISSIONS_PROMPT_H_ | |
| 6 #define EXTENSIONS_BROWSER_DEVICE_PERMISSIONS_PROMPT_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/strings/string16.h" | |
| 14 | |
| 15 namespace content { | |
| 16 class BrowserContext; | |
| 17 class WebContents; | |
| 18 } | |
| 19 | |
| 20 namespace device { | |
| 21 class UsbDevice; | |
| 22 class UsbDeviceFilter; | |
| 23 } | |
| 24 | |
| 25 namespace extensions { | |
| 26 | |
| 27 class Extension; | |
| 28 | |
| 29 // Displays the UI for choosing devices (similar to choosing files). | |
| 30 class DevicePermissionsPrompt { | |
| 31 public: | |
| 32 class Prompt : public base::RefCountedThreadSafe<Prompt> { | |
| 33 public: | |
| 34 struct DeviceInfo { | |
| 35 DeviceInfo(scoped_refptr<device::UsbDevice> device, | |
| 36 base::string16 name, | |
|
Finnur
2014/10/15 10:01:26
nit: const base::string16& ?
Reilly Grant (use Gerrit)
2014/10/15 19:15:33
Done.
| |
| 37 base::string16 serial_number, | |
| 38 base::string16 tooltip); | |
| 39 ~DeviceInfo(); | |
| 40 | |
| 41 scoped_refptr<device::UsbDevice> device; | |
| 42 base::string16 name; | |
| 43 base::string16 serial_number; | |
| 44 base::string16 tooltip; | |
| 45 }; | |
| 46 | |
| 47 class Observer { | |
| 48 public: | |
| 49 virtual void OnDevicesChanged() = 0; | |
| 50 }; | |
| 51 | |
| 52 Prompt(); | |
| 53 | |
| 54 void SetObserver(Observer* observer); | |
| 55 | |
| 56 base::string16 GetHeading() const; | |
| 57 base::string16 GetPromptMessage() const; | |
| 58 size_t GetDeviceCount() const { return devices_.size(); } | |
| 59 scoped_refptr<device::UsbDevice> GetDevice(size_t index) const; | |
| 60 base::string16 GetDeviceName(size_t index) const { | |
| 61 DCHECK_LT(index, devices_.size()); | |
| 62 return devices_[index].name; | |
| 63 } | |
| 64 base::string16 GetDeviceSerialNumber(size_t index) const { | |
| 65 DCHECK_LT(index, devices_.size()); | |
| 66 return devices_[index].serial_number; | |
| 67 } | |
| 68 base::string16 GetDeviceTooltip(size_t index) const { | |
| 69 DCHECK_LT(index, devices_.size()); | |
| 70 return devices_[index].tooltip; | |
| 71 } | |
| 72 | |
| 73 void GrantDevicePermission(size_t index) const; | |
| 74 | |
| 75 const extensions::Extension* extension() const { return extension_; } | |
| 76 void set_extension(const extensions::Extension* extension) { | |
| 77 extension_ = extension; | |
| 78 } | |
| 79 | |
| 80 void set_browser_context(content::BrowserContext* context) { | |
| 81 browser_context_ = context; | |
| 82 } | |
| 83 | |
| 84 bool multiple() const { return multiple_; } | |
| 85 void set_multiple(bool multiple) { multiple_ = multiple; } | |
| 86 | |
| 87 const std::vector<device::UsbDeviceFilter>& filters() const { | |
| 88 return filters_; | |
| 89 } | |
| 90 void set_filters(const std::vector<device::UsbDeviceFilter>& filters); | |
| 91 | |
| 92 private: | |
| 93 friend class base::RefCountedThreadSafe<Prompt>; | |
| 94 | |
| 95 virtual ~Prompt(); | |
| 96 | |
| 97 void DoDeviceQuery(); | |
|
Finnur
2014/10/15 10:01:26
You are not a big fan of comments, I've noticed...
Reilly Grant (use Gerrit)
2014/10/15 19:15:33
My previous employer's coding standard went a bit
| |
| 98 void SetDevices(const std::vector<DeviceInfo>& devices); | |
| 99 | |
| 100 const extensions::Extension* extension_; | |
| 101 content::BrowserContext* browser_context_; | |
| 102 bool multiple_; | |
| 103 std::vector<device::UsbDeviceFilter> filters_; | |
| 104 std::vector<DeviceInfo> devices_; | |
| 105 Observer* observer_; | |
| 106 }; | |
| 107 | |
| 108 class Delegate { | |
| 109 public: | |
| 110 // Called with the list of selected USB devices. | |
| 111 virtual void UsbDevicesChosen( | |
| 112 const std::vector<scoped_refptr<device::UsbDevice>>& devices) = 0; | |
| 113 | |
| 114 protected: | |
| 115 virtual ~Delegate() {} | |
| 116 }; | |
| 117 | |
| 118 typedef base::Callback<void(content::WebContents*, | |
| 119 DevicePermissionsPrompt::Delegate*, | |
| 120 scoped_refptr<DevicePermissionsPrompt::Prompt>)> | |
| 121 ShowDialogCallback; | |
| 122 | |
| 123 static ShowDialogCallback GetDefaultShowDialogCallback(); | |
| 124 | |
| 125 DevicePermissionsPrompt(content::WebContents* web_contents); | |
| 126 virtual ~DevicePermissionsPrompt(); | |
| 127 | |
| 128 virtual void AskForUsbDevices(Delegate* delegate, | |
| 129 const Extension* extension, | |
| 130 content::BrowserContext* context, | |
| 131 bool multiple, | |
| 132 std::vector<device::UsbDeviceFilter> filters); | |
|
Finnur
2014/10/15 10:01:26
Can this be const std::vector<device::UsbDeviceFil
Reilly Grant (use Gerrit)
2014/10/15 19:15:33
Done.
| |
| 133 | |
| 134 private: | |
| 135 // Parent web contents of the device permissions UI dialog. | |
| 136 content::WebContents* web_contents_; | |
| 137 | |
| 138 // The delegate called after the UI has been dismissed. | |
| 139 Delegate* delegate_; | |
| 140 | |
| 141 // Parameters available to the UI implementation. | |
| 142 scoped_refptr<Prompt> prompt_; | |
| 143 }; | |
| 144 | |
| 145 } // namespace extensions | |
| 146 | |
| 147 #endif // EXTENSIONS_BROWSER_API_DEVICE_PERMISSIONS_PROMPT_H_ | |
| OLD | NEW |