Index: chrome/browser/usb/web_usb_permission_provider.cc |
diff --git a/chrome/browser/usb/web_usb_permission_provider.cc b/chrome/browser/usb/web_usb_permission_provider.cc |
index 33e54597394cd4ee4158aba99da40b99f296ce50..c01f8475b38df6362b44cae0b301efd08e67c636 100644 |
--- a/chrome/browser/usb/web_usb_permission_provider.cc |
+++ b/chrome/browser/usb/web_usb_permission_provider.cc |
@@ -6,11 +6,17 @@ |
#include "base/command_line.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/usb/usb_chooser_permission_context.h" |
+#include "chrome/browser/usb/usb_chooser_permission_context_factory.h" |
#include "chrome/common/chrome_switches.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/render_frame_host.h" |
+#include "content/public/browser/render_process_host.h" |
+#include "content/public/browser/web_contents.h" |
#include "device/core/device_client.h" |
+using content::RenderFrameHost; |
+using content::WebContents; |
using device::usb::WebUsbDescriptorSet; |
using device::usb::WebUsbConfigurationSubsetPtr; |
using device::usb::WebUsbFunctionSubsetPtr; |
@@ -62,7 +68,7 @@ bool EnableWebUsbOnAnyOrigin() { |
// static |
void WebUSBPermissionProvider::Create( |
- content::RenderFrameHost* render_frame_host, |
+ RenderFrameHost* render_frame_host, |
mojo::InterfaceRequest<PermissionProvider> request) { |
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
DCHECK(render_frame_host); |
@@ -74,7 +80,7 @@ void WebUSBPermissionProvider::Create( |
WebUSBPermissionProvider::~WebUSBPermissionProvider() {} |
WebUSBPermissionProvider::WebUSBPermissionProvider( |
- content::RenderFrameHost* render_frame_host, |
+ RenderFrameHost* render_frame_host, |
mojo::InterfaceRequest<PermissionProvider> request) |
: render_frame_host_(render_frame_host) { |
bindings_.set_connection_error_handler(base::Bind( |
@@ -86,14 +92,30 @@ void WebUSBPermissionProvider::HasDevicePermission( |
mojo::Array<device::usb::DeviceInfoPtr> requested_devices, |
const HasDevicePermissionCallback& callback) { |
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
- GURL origin = render_frame_host_->GetLastCommittedURL().GetOrigin(); |
- |
mojo::Array<mojo::String> allowed_guids(0); |
+ WebContents* web_contents = |
+ WebContents::FromRenderFrameHost(render_frame_host_); |
+ if (!web_contents) { |
+ callback.Run(allowed_guids.Pass()); |
+ return; |
+ } |
+ |
+ GURL embedding_origin = |
+ web_contents->GetMainFrame()->GetLastCommittedURL().GetOrigin(); |
+ GURL requesting_origin = |
+ render_frame_host_->GetLastCommittedURL().GetOrigin(); |
+ Profile* profile = Profile::FromBrowserContext( |
+ render_frame_host_->GetProcess()->GetBrowserContext()); |
+ UsbChooserPermissionContext* permission_context = |
+ UsbChooserPermissionContextFactory::GetForProfile(profile); |
+ |
for (size_t i = 0; i < requested_devices.size(); ++i) { |
const device::usb::DeviceInfoPtr& device = requested_devices[i]; |
- if (FindOriginInDescriptorSet(device->webusb_allowed_origins.get(), origin, |
- nullptr, nullptr) && |
- EnableWebUsbOnAnyOrigin()) |
+ if (FindOriginInDescriptorSet(device->webusb_allowed_origins.get(), |
+ requesting_origin, nullptr, nullptr) && |
+ (EnableWebUsbOnAnyOrigin() || |
+ permission_context->HasDevicePermission( |
+ requesting_origin, embedding_origin, device->guid))) |
allowed_guids.push_back(device->guid); |
} |
callback.Run(allowed_guids.Pass()); |