| 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 | |
| 27 explicit WebUSBPermissionProvider( | 23 explicit WebUSBPermissionProvider( |
| 28 content::RenderFrameHost* render_frame_host); | 24 content::RenderFrameHost* render_frame_host); |
| 29 ~WebUSBPermissionProvider() override; | 25 ~WebUSBPermissionProvider() override; |
| 30 | 26 |
| 31 base::WeakPtr<PermissionProvider> GetWeakPtr(); | 27 base::WeakPtr<PermissionProvider> GetWeakPtr(); |
| 32 | 28 |
| 33 // device::usb::PermissionProvider implementation. | 29 // device::usb::PermissionProvider implementation. |
| 34 bool HasDevicePermission( | 30 bool HasDevicePermission( |
| 35 scoped_refptr<const device::UsbDevice> device) const override; | 31 scoped_refptr<const device::UsbDevice> device) const override; |
| 36 bool HasConfigurationPermission( | 32 bool HasConfigurationPermission( |
| 37 uint8_t requested_configuration, | 33 uint8_t requested_configuration, |
| 38 scoped_refptr<const device::UsbDevice> device) const override; | 34 scoped_refptr<const device::UsbDevice> device) const override; |
| 39 bool HasFunctionPermission( | 35 bool HasFunctionPermission( |
| 40 uint8_t requested_function, | 36 uint8_t requested_function, |
| 41 uint8_t configuration_value, | 37 uint8_t configuration_value, |
| 42 scoped_refptr<const device::UsbDevice> device) const override; | 38 scoped_refptr<const device::UsbDevice> device) const override; |
| 43 void IncrementConnectionCount() override; | 39 void IncrementConnectionCount() override; |
| 44 void DecrementConnectionCount() override; | 40 void DecrementConnectionCount() override; |
| 45 | 41 |
| 46 private: | 42 private: |
| 47 content::RenderFrameHost* const render_frame_host_; | 43 content::RenderFrameHost* const render_frame_host_; |
| 48 base::WeakPtrFactory<PermissionProvider> weak_factory_; | 44 base::WeakPtrFactory<PermissionProvider> weak_factory_; |
| 49 }; | 45 }; |
| 50 | 46 |
| 51 #endif // CHROME_BROWSER_USB_WEB_USB_PERMISSION_PROVIDER_H_ | 47 #endif // CHROME_BROWSER_USB_WEB_USB_PERMISSION_PROVIDER_H_ |
| OLD | NEW |