Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(827)

Side by Side Diff: extensions/browser/api/usb/usb_event_router.cc

Issue 2418353002: Allow interfaceClass USB device permissions (Closed)
Patch Set: . Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/api/usb/usb_api.cc ('k') | extensions/common/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "extensions/browser/api/usb/usb_event_router.h" 5 #include "extensions/browser/api/usb/usb_event_router.h"
6 6
7 #include <memory>
7 #include <utility> 8 #include <utility>
8 9
9 #include "device/base/device_client.h" 10 #include "device/base/device_client.h"
10 #include "device/usb/usb_device.h" 11 #include "device/usb/usb_device.h"
11 #include "extensions/browser/api/device_permissions_manager.h" 12 #include "extensions/browser/api/device_permissions_manager.h"
12 #include "extensions/browser/api/usb/usb_guid_map.h" 13 #include "extensions/browser/api/usb/usb_guid_map.h"
13 #include "extensions/browser/event_router_factory.h" 14 #include "extensions/browser/event_router_factory.h"
14 #include "extensions/common/api/usb.h" 15 #include "extensions/common/api/usb.h"
15 #include "extensions/common/permissions/permissions_data.h" 16 #include "extensions/common/permissions/permissions_data.h"
16 #include "extensions/common/permissions/usb_device_permission.h" 17 #include "extensions/common/permissions/usb_device_permission.h"
17 18
18 namespace usb = extensions::api::usb; 19 namespace usb = extensions::api::usb;
19 20
20 using content::BrowserThread; 21 using content::BrowserThread;
21 using device::UsbDevice; 22 using device::UsbDevice;
22 using device::UsbService; 23 using device::UsbService;
23 24
24 namespace extensions { 25 namespace extensions {
25 26
26 namespace { 27 namespace {
27 28
28 // Returns true iff the given extension has permission to receive events 29 // Returns true iff the given extension has permission to receive events
29 // regarding this device. 30 // regarding this device.
30 bool WillDispatchDeviceEvent(scoped_refptr<UsbDevice> device, 31 bool WillDispatchDeviceEvent(scoped_refptr<UsbDevice> device,
31 content::BrowserContext* browser_context, 32 content::BrowserContext* browser_context,
32 const Extension* extension, 33 const Extension* extension,
33 Event* event, 34 Event* event,
34 const base::DictionaryValue* listener_filter) { 35 const base::DictionaryValue* listener_filter) {
35 // Check install-time and optional permissions. 36 // Check install-time and optional permissions.
36 UsbDevicePermission::CheckParam param( 37 std::unique_ptr<UsbDevicePermission::CheckParam> param =
37 device->vendor_id(), device->product_id(), 38 UsbDevicePermission::CheckParam::ForUsbDevice(extension, device.get());
38 UsbDevicePermissionData::UNSPECIFIED_INTERFACE);
39 if (extension->permissions_data()->CheckAPIPermissionWithParam( 39 if (extension->permissions_data()->CheckAPIPermissionWithParam(
40 APIPermission::kUsbDevice, &param)) { 40 APIPermission::kUsbDevice, param.get())) {
41 return true; 41 return true;
42 } 42 }
43 43
44 // Check permissions granted through chrome.usb.getUserSelectedDevices. 44 // Check permissions granted through chrome.usb.getUserSelectedDevices.
45 DevicePermissions* device_permissions = 45 DevicePermissions* device_permissions =
46 DevicePermissionsManager::Get(browser_context) 46 DevicePermissionsManager::Get(browser_context)
47 ->GetForExtension(extension->id()); 47 ->GetForExtension(extension->id());
48 if (device_permissions->FindUsbDeviceEntry(device).get()) { 48 if (device_permissions->FindUsbDeviceEntry(device).get()) {
49 return true; 49 return true;
50 } 50 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 template <> 126 template <>
127 void BrowserContextKeyedAPIFactory< 127 void BrowserContextKeyedAPIFactory<
128 UsbEventRouter>::DeclareFactoryDependencies() { 128 UsbEventRouter>::DeclareFactoryDependencies() {
129 DependsOn(DevicePermissionsManagerFactory::GetInstance()); 129 DependsOn(DevicePermissionsManagerFactory::GetInstance());
130 DependsOn(EventRouterFactory::GetInstance()); 130 DependsOn(EventRouterFactory::GetInstance());
131 DependsOn(UsbGuidMap::GetFactoryInstance()); 131 DependsOn(UsbGuidMap::GetFactoryInstance());
132 } 132 }
133 133
134 } // extensions 134 } // extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/usb/usb_api.cc ('k') | extensions/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698