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