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 #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" |
12 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
13 #include "device/core/device_client.h" | 15 #include "device/core/device_client.h" |
14 | 16 |
15 using content::BrowserThread; | 17 using content::BrowserThread; |
16 using content::RenderFrameHost; | 18 using content::RenderFrameHost; |
17 using content::WebContents; | 19 using content::WebContents; |
18 using content::WebContentsObserver; | 20 using content::WebContentsObserver; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 render_frame_host_(render_frame_host) { | 87 render_frame_host_(render_frame_host) { |
86 bindings_.set_connection_error_handler(base::Bind( | 88 bindings_.set_connection_error_handler(base::Bind( |
87 &WebUSBPermissionProvider::OnConnectionError, base::Unretained(this))); | 89 &WebUSBPermissionProvider::OnConnectionError, base::Unretained(this))); |
88 bindings_.AddBinding(this, request.Pass()); | 90 bindings_.AddBinding(this, request.Pass()); |
89 } | 91 } |
90 | 92 |
91 void WebUSBPermissionProvider::HasDevicePermission( | 93 void WebUSBPermissionProvider::HasDevicePermission( |
92 mojo::Array<device::usb::DeviceInfoPtr> requested_devices, | 94 mojo::Array<device::usb::DeviceInfoPtr> requested_devices, |
93 const HasDevicePermissionCallback& callback) { | 95 const HasDevicePermissionCallback& callback) { |
94 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 96 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
95 GURL origin = render_frame_host_->GetLastCommittedURL().GetOrigin(); | 97 GURL embedding_origin = |
| 98 web_contents()->GetMainFrame()->GetLastCommittedURL().GetOrigin(); |
| 99 GURL requesting_origin = |
| 100 render_frame_host_->GetLastCommittedURL().GetOrigin(); |
| 101 Profile* profile = |
| 102 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 103 UsbChooserContext* chooser_context = |
| 104 UsbChooserContextFactory::GetForProfile(profile); |
96 | 105 |
97 mojo::Array<mojo::String> allowed_guids(0); | 106 mojo::Array<mojo::String> allowed_guids(0); |
98 for (size_t i = 0; i < requested_devices.size(); ++i) { | 107 for (size_t i = 0; i < requested_devices.size(); ++i) { |
99 const device::usb::DeviceInfoPtr& device = requested_devices[i]; | 108 const device::usb::DeviceInfoPtr& device = requested_devices[i]; |
100 if (FindOriginInDescriptorSet(device->webusb_allowed_origins.get(), origin, | 109 if (FindOriginInDescriptorSet(device->webusb_allowed_origins.get(), |
101 nullptr, nullptr) && | 110 requesting_origin, nullptr, nullptr) && |
102 EnableWebUsbOnAnyOrigin()) | 111 (EnableWebUsbOnAnyOrigin() || |
| 112 chooser_context->HasDevicePermission(requesting_origin, |
| 113 embedding_origin, device->guid))) |
103 allowed_guids.push_back(device->guid); | 114 allowed_guids.push_back(device->guid); |
104 } | 115 } |
105 callback.Run(allowed_guids.Pass()); | 116 callback.Run(allowed_guids.Pass()); |
106 } | 117 } |
107 | 118 |
108 void WebUSBPermissionProvider::HasConfigurationPermission( | 119 void WebUSBPermissionProvider::HasConfigurationPermission( |
109 uint8_t requested_configuration_value, | 120 uint8_t requested_configuration_value, |
110 device::usb::DeviceInfoPtr device, | 121 device::usb::DeviceInfoPtr device, |
111 const HasInterfacePermissionCallback& callback) { | 122 const HasInterfacePermissionCallback& callback) { |
112 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 123 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 23 matching lines...) Expand all Loading... |
136 void WebUSBPermissionProvider::RenderFrameDeleted( | 147 void WebUSBPermissionProvider::RenderFrameDeleted( |
137 RenderFrameHost* render_frame_host) { | 148 RenderFrameHost* render_frame_host) { |
138 if (render_frame_host == render_frame_host_) | 149 if (render_frame_host == render_frame_host_) |
139 delete this; | 150 delete this; |
140 } | 151 } |
141 | 152 |
142 void WebUSBPermissionProvider::OnConnectionError() { | 153 void WebUSBPermissionProvider::OnConnectionError() { |
143 if (bindings_.empty()) | 154 if (bindings_.empty()) |
144 delete this; | 155 delete this; |
145 } | 156 } |
OLD | NEW |