Chromium Code Reviews| Index: extensions/browser/api/device_permissions_prompt.h |
| diff --git a/extensions/browser/api/device_permissions_prompt.h b/extensions/browser/api/device_permissions_prompt.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..38245a765ae3caad52efc4aa24403b627851dc5a |
| --- /dev/null |
| +++ b/extensions/browser/api/device_permissions_prompt.h |
| @@ -0,0 +1,147 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef EXTENSIONS_BROWSER_DEVICE_PERMISSIONS_PROMPT_H_ |
| +#define EXTENSIONS_BROWSER_DEVICE_PERMISSIONS_PROMPT_H_ |
| + |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/logging.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/strings/string16.h" |
| + |
| +namespace content { |
| +class BrowserContext; |
| +class WebContents; |
| +} |
| + |
| +namespace device { |
| +class UsbDevice; |
| +class UsbDeviceFilter; |
| +} |
| + |
| +namespace extensions { |
| + |
| +class Extension; |
| + |
| +// Displays the UI for choosing devices (similar to choosing files). |
| +class DevicePermissionsPrompt { |
| + public: |
| + class Prompt : public base::RefCountedThreadSafe<Prompt> { |
| + public: |
| + struct DeviceInfo { |
| + DeviceInfo(scoped_refptr<device::UsbDevice> device, |
| + 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.
|
| + base::string16 serial_number, |
| + base::string16 tooltip); |
| + ~DeviceInfo(); |
| + |
| + scoped_refptr<device::UsbDevice> device; |
| + base::string16 name; |
| + base::string16 serial_number; |
| + base::string16 tooltip; |
| + }; |
| + |
| + class Observer { |
| + public: |
| + virtual void OnDevicesChanged() = 0; |
| + }; |
| + |
| + Prompt(); |
| + |
| + void SetObserver(Observer* observer); |
| + |
| + base::string16 GetHeading() const; |
| + base::string16 GetPromptMessage() const; |
| + size_t GetDeviceCount() const { return devices_.size(); } |
| + scoped_refptr<device::UsbDevice> GetDevice(size_t index) const; |
| + base::string16 GetDeviceName(size_t index) const { |
| + DCHECK_LT(index, devices_.size()); |
| + return devices_[index].name; |
| + } |
| + base::string16 GetDeviceSerialNumber(size_t index) const { |
| + DCHECK_LT(index, devices_.size()); |
| + return devices_[index].serial_number; |
| + } |
| + base::string16 GetDeviceTooltip(size_t index) const { |
| + DCHECK_LT(index, devices_.size()); |
| + return devices_[index].tooltip; |
| + } |
| + |
| + void GrantDevicePermission(size_t index) const; |
| + |
| + const extensions::Extension* extension() const { return extension_; } |
| + void set_extension(const extensions::Extension* extension) { |
| + extension_ = extension; |
| + } |
| + |
| + void set_browser_context(content::BrowserContext* context) { |
| + browser_context_ = context; |
| + } |
| + |
| + bool multiple() const { return multiple_; } |
| + void set_multiple(bool multiple) { multiple_ = multiple; } |
| + |
| + const std::vector<device::UsbDeviceFilter>& filters() const { |
| + return filters_; |
| + } |
| + void set_filters(const std::vector<device::UsbDeviceFilter>& filters); |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<Prompt>; |
| + |
| + virtual ~Prompt(); |
| + |
| + 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
|
| + void SetDevices(const std::vector<DeviceInfo>& devices); |
| + |
| + const extensions::Extension* extension_; |
| + content::BrowserContext* browser_context_; |
| + bool multiple_; |
| + std::vector<device::UsbDeviceFilter> filters_; |
| + std::vector<DeviceInfo> devices_; |
| + Observer* observer_; |
| + }; |
| + |
| + class Delegate { |
| + public: |
| + // Called with the list of selected USB devices. |
| + virtual void UsbDevicesChosen( |
| + const std::vector<scoped_refptr<device::UsbDevice>>& devices) = 0; |
| + |
| + protected: |
| + virtual ~Delegate() {} |
| + }; |
| + |
| + typedef base::Callback<void(content::WebContents*, |
| + DevicePermissionsPrompt::Delegate*, |
| + scoped_refptr<DevicePermissionsPrompt::Prompt>)> |
| + ShowDialogCallback; |
| + |
| + static ShowDialogCallback GetDefaultShowDialogCallback(); |
| + |
| + DevicePermissionsPrompt(content::WebContents* web_contents); |
| + virtual ~DevicePermissionsPrompt(); |
| + |
| + virtual void AskForUsbDevices(Delegate* delegate, |
| + const Extension* extension, |
| + content::BrowserContext* context, |
| + bool multiple, |
| + 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.
|
| + |
| + private: |
| + // Parent web contents of the device permissions UI dialog. |
| + content::WebContents* web_contents_; |
| + |
| + // The delegate called after the UI has been dismissed. |
| + Delegate* delegate_; |
| + |
| + // Parameters available to the UI implementation. |
| + scoped_refptr<Prompt> prompt_; |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // EXTENSIONS_BROWSER_API_DEVICE_PERMISSIONS_PROMPT_H_ |