| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_USB_WEB_USB_PERMISSION_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_USB_WEB_USB_PERMISSION_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_USB_WEB_USB_PERMISSION_PROVIDER_H_ | 6 #define CHROME_BROWSER_USB_WEB_USB_PERMISSION_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "device/usb/mojo/permission_provider.h" | 11 #include "device/usb/mojo/permission_provider.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 class RenderFrameHost; | 14 class RenderFrameHost; |
| 15 } | 15 } |
| 16 | 16 |
| 17 // This implementation of the permission provider interface enforces the rules | 17 // This implementation of the permission provider interface enforces the rules |
| 18 // of the WebUSB permission model. Devices are checked for WebUSB descriptors | 18 // of the WebUSB permission model. Devices are checked for WebUSB descriptors |
| 19 // granting access to the render frame's current origin as well as permission | 19 // granting access to the render frame's current origin as well as permission |
| 20 // granted by the user through a device chooser UI. | 20 // granted by the user through a device chooser UI. |
| 21 class WebUSBPermissionProvider : public device::usb::PermissionProvider { | 21 class WebUSBPermissionProvider : public device::usb::PermissionProvider { |
| 22 public: | 22 public: |
| 23 static bool HasDevicePermission( |
| 24 content::RenderFrameHost* render_frame_host, |
| 25 scoped_refptr<const device::UsbDevice> device); |
| 26 |
| 23 explicit WebUSBPermissionProvider( | 27 explicit WebUSBPermissionProvider( |
| 24 content::RenderFrameHost* render_frame_host); | 28 content::RenderFrameHost* render_frame_host); |
| 25 ~WebUSBPermissionProvider() override; | 29 ~WebUSBPermissionProvider() override; |
| 26 | 30 |
| 27 base::WeakPtr<PermissionProvider> GetWeakPtr(); | 31 base::WeakPtr<PermissionProvider> GetWeakPtr(); |
| 28 | 32 |
| 29 // device::usb::PermissionProvider implementation. | 33 // device::usb::PermissionProvider implementation. |
| 30 bool HasDevicePermission( | 34 bool HasDevicePermission( |
| 31 scoped_refptr<const device::UsbDevice> device) const override; | 35 scoped_refptr<const device::UsbDevice> device) const override; |
| 32 bool HasConfigurationPermission( | 36 bool HasConfigurationPermission( |
| 33 uint8_t requested_configuration, | 37 uint8_t requested_configuration, |
| 34 scoped_refptr<const device::UsbDevice> device) const override; | 38 scoped_refptr<const device::UsbDevice> device) const override; |
| 35 bool HasFunctionPermission( | 39 bool HasFunctionPermission( |
| 36 uint8_t requested_function, | 40 uint8_t requested_function, |
| 37 uint8_t configuration_value, | 41 uint8_t configuration_value, |
| 38 scoped_refptr<const device::UsbDevice> device) const override; | 42 scoped_refptr<const device::UsbDevice> device) const override; |
| 39 void IncrementConnectionCount() override; | 43 void IncrementConnectionCount() override; |
| 40 void DecrementConnectionCount() override; | 44 void DecrementConnectionCount() override; |
| 41 | 45 |
| 42 private: | 46 private: |
| 43 content::RenderFrameHost* const render_frame_host_; | 47 content::RenderFrameHost* const render_frame_host_; |
| 44 base::WeakPtrFactory<PermissionProvider> weak_factory_; | 48 base::WeakPtrFactory<PermissionProvider> weak_factory_; |
| 45 }; | 49 }; |
| 46 | 50 |
| 47 #endif // CHROME_BROWSER_USB_WEB_USB_PERMISSION_PROVIDER_H_ | 51 #endif // CHROME_BROWSER_USB_WEB_USB_PERMISSION_PROVIDER_H_ |
| OLD | NEW |