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

Side by Side Diff: chrome/browser/usb/web_usb_permission_provider.cc

Issue 1382783002: Store USB device permissions in website settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address mlamouri@'s comments. Created 5 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 | « chrome/browser/usb/usb_chooser_context_unittest.cc ('k') | chrome/chrome_browser.gypi » ('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 "chrome/browser/usb/web_usb_permission_provider.h" 5 #include "chrome/browser/usb/web_usb_permission_provider.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/usb/usb_chooser_context.h"
10 #include "chrome/browser/usb/usb_chooser_context_factory.h"
9 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
10 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/render_frame_host.h" 13 #include "content/public/browser/render_frame_host.h"
14 #include "content/public/browser/web_contents.h"
12 #include "device/core/device_client.h" 15 #include "device/core/device_client.h"
13 16
17 using content::WebContents;
14 using device::usb::WebUsbDescriptorSet; 18 using device::usb::WebUsbDescriptorSet;
15 using device::usb::WebUsbConfigurationSubsetPtr; 19 using device::usb::WebUsbConfigurationSubsetPtr;
16 using device::usb::WebUsbFunctionSubsetPtr; 20 using device::usb::WebUsbFunctionSubsetPtr;
17 21
18 namespace { 22 namespace {
19 23
20 bool FindOriginInDescriptorSet(const WebUsbDescriptorSet* set, 24 bool FindOriginInDescriptorSet(const WebUsbDescriptorSet* set,
21 const GURL& origin, 25 const GURL& origin,
22 const uint8_t* configuration_value, 26 const uint8_t* configuration_value,
23 const uint8_t* interface_number) { 27 const uint8_t* interface_number) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
67 DCHECK(render_frame_host_); 71 DCHECK(render_frame_host_);
68 } 72 }
69 73
70 WebUSBPermissionProvider::~WebUSBPermissionProvider() {} 74 WebUSBPermissionProvider::~WebUSBPermissionProvider() {}
71 75
72 void WebUSBPermissionProvider::HasDevicePermission( 76 void WebUSBPermissionProvider::HasDevicePermission(
73 mojo::Array<device::usb::DeviceInfoPtr> requested_devices, 77 mojo::Array<device::usb::DeviceInfoPtr> requested_devices,
74 const HasDevicePermissionCallback& callback) { 78 const HasDevicePermissionCallback& callback) {
75 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 79 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
76 GURL origin = render_frame_host_->GetLastCommittedURL().GetOrigin(); 80 WebContents* web_contents =
81 WebContents::FromRenderFrameHost(render_frame_host_);
82 GURL embedding_origin =
83 web_contents->GetMainFrame()->GetLastCommittedURL().GetOrigin();
84 GURL requesting_origin =
85 render_frame_host_->GetLastCommittedURL().GetOrigin();
86 Profile* profile =
87 Profile::FromBrowserContext(web_contents->GetBrowserContext());
88 UsbChooserContext* chooser_context =
89 UsbChooserContextFactory::GetForProfile(profile);
77 90
78 mojo::Array<mojo::String> allowed_guids(0); 91 mojo::Array<mojo::String> allowed_guids(0);
79 for (size_t i = 0; i < requested_devices.size(); ++i) { 92 for (size_t i = 0; i < requested_devices.size(); ++i) {
80 const device::usb::DeviceInfoPtr& device = requested_devices[i]; 93 const device::usb::DeviceInfoPtr& device = requested_devices[i];
81 if (FindOriginInDescriptorSet(device->webusb_allowed_origins.get(), origin, 94 if (FindOriginInDescriptorSet(device->webusb_allowed_origins.get(),
82 nullptr, nullptr) && 95 requesting_origin, nullptr, nullptr) &&
83 EnableWebUsbOnAnyOrigin()) 96 (EnableWebUsbOnAnyOrigin() ||
97 chooser_context->HasDevicePermission(requesting_origin,
98 embedding_origin, device->guid)))
84 allowed_guids.push_back(device->guid); 99 allowed_guids.push_back(device->guid);
85 } 100 }
86 callback.Run(allowed_guids.Pass()); 101 callback.Run(allowed_guids.Pass());
87 } 102 }
88 103
89 void WebUSBPermissionProvider::HasConfigurationPermission( 104 void WebUSBPermissionProvider::HasConfigurationPermission(
90 uint8_t requested_configuration_value, 105 uint8_t requested_configuration_value,
91 device::usb::DeviceInfoPtr device, 106 device::usb::DeviceInfoPtr device,
92 const HasInterfacePermissionCallback& callback) { 107 const HasInterfacePermissionCallback& callback) {
93 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 13 matching lines...) Expand all
107 device->webusb_allowed_origins.get(), 122 device->webusb_allowed_origins.get(),
108 render_frame_host_->GetLastCommittedURL().GetOrigin(), 123 render_frame_host_->GetLastCommittedURL().GetOrigin(),
109 &configuration_value, &requested_interface)); 124 &configuration_value, &requested_interface));
110 } 125 }
111 126
112 void WebUSBPermissionProvider::Bind( 127 void WebUSBPermissionProvider::Bind(
113 mojo::InterfaceRequest<device::usb::PermissionProvider> request) { 128 mojo::InterfaceRequest<device::usb::PermissionProvider> request) {
114 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 129 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
115 bindings_.AddBinding(this, request.Pass()); 130 bindings_.AddBinding(this, request.Pass());
116 } 131 }
OLDNEW
« no previous file with comments | « chrome/browser/usb/usb_chooser_context_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698