| 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 class GURL; |
| 18 class UsbChooserContext; |
| 19 |
| 17 // This implementation of the permission provider interface enforces the rules | 20 // This implementation of the permission provider interface enforces the rules |
| 18 // of the WebUSB permission model. Devices are checked for WebUSB descriptors | 21 // 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 | 22 // granting access to the render frame's current origin as well as permission |
| 20 // granted by the user through a device chooser UI. | 23 // granted by the user through a device chooser UI. |
| 21 class WebUSBPermissionProvider : public device::usb::PermissionProvider { | 24 class WebUSBPermissionProvider : public device::usb::PermissionProvider { |
| 22 public: | 25 public: |
| 23 static bool HasDevicePermission( | 26 static bool HasDevicePermission( |
| 24 content::RenderFrameHost* render_frame_host, | 27 UsbChooserContext* chooser_context, |
| 28 const GURL& requesting_origin, |
| 29 const GURL& embedding_origin, |
| 30 bool is_embedded_frame, |
| 25 scoped_refptr<const device::UsbDevice> device); | 31 scoped_refptr<const device::UsbDevice> device); |
| 26 | 32 |
| 27 explicit WebUSBPermissionProvider( | 33 explicit WebUSBPermissionProvider( |
| 28 content::RenderFrameHost* render_frame_host); | 34 content::RenderFrameHost* render_frame_host); |
| 29 ~WebUSBPermissionProvider() override; | 35 ~WebUSBPermissionProvider() override; |
| 30 | 36 |
| 31 base::WeakPtr<PermissionProvider> GetWeakPtr(); | 37 base::WeakPtr<PermissionProvider> GetWeakPtr(); |
| 32 | 38 |
| 33 // device::usb::PermissionProvider implementation. | 39 // device::usb::PermissionProvider implementation. |
| 34 bool HasDevicePermission( | 40 bool HasDevicePermission( |
| 35 scoped_refptr<const device::UsbDevice> device) const override; | 41 scoped_refptr<const device::UsbDevice> device) const override; |
| 36 bool HasConfigurationPermission( | 42 bool HasConfigurationPermission( |
| 37 uint8_t requested_configuration, | 43 uint8_t requested_configuration, |
| 38 scoped_refptr<const device::UsbDevice> device) const override; | 44 scoped_refptr<const device::UsbDevice> device) const override; |
| 39 bool HasFunctionPermission( | 45 bool HasFunctionPermission( |
| 40 uint8_t requested_function, | 46 uint8_t requested_function, |
| 41 uint8_t configuration_value, | 47 uint8_t configuration_value, |
| 42 scoped_refptr<const device::UsbDevice> device) const override; | 48 scoped_refptr<const device::UsbDevice> device) const override; |
| 43 void IncrementConnectionCount() override; | 49 void IncrementConnectionCount() override; |
| 44 void DecrementConnectionCount() override; | 50 void DecrementConnectionCount() override; |
| 45 | 51 |
| 46 private: | 52 private: |
| 47 content::RenderFrameHost* const render_frame_host_; | 53 content::RenderFrameHost* const render_frame_host_; |
| 48 base::WeakPtrFactory<PermissionProvider> weak_factory_; | 54 base::WeakPtrFactory<PermissionProvider> weak_factory_; |
| 49 }; | 55 }; |
| 50 | 56 |
| 51 #endif // CHROME_BROWSER_USB_WEB_USB_PERMISSION_PROVIDER_H_ | 57 #endif // CHROME_BROWSER_USB_WEB_USB_PERMISSION_PROVIDER_H_ |
| OLD | NEW |