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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 53320fb60966db5552bda9ce2e34e4e3e839142b..b8f38172e21e2e33b3b9411fba30f55a1687362e 100644
--- a/chrome/browser/usb/web_usb_permission_provider.cc
+++ b/chrome/browser/usb/web_usb_permission_provider.cc
@@ -6,11 +6,15 @@
#include "base/command_line.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/usb/usb_chooser_context.h"
+#include "chrome/browser/usb/usb_chooser_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/web_contents.h"
#include "device/core/device_client.h"
+using content::WebContents;
using device::usb::WebUsbDescriptorSet;
using device::usb::WebUsbConfigurationSubsetPtr;
using device::usb::WebUsbFunctionSubsetPtr;
@@ -73,14 +77,25 @@ 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();
+ WebContents* web_contents =
+ WebContents::FromRenderFrameHost(render_frame_host_);
+ GURL embedding_origin =
+ web_contents->GetMainFrame()->GetLastCommittedURL().GetOrigin();
+ GURL requesting_origin =
+ render_frame_host_->GetLastCommittedURL().GetOrigin();
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents->GetBrowserContext());
+ UsbChooserContext* chooser_context =
+ UsbChooserContextFactory::GetForProfile(profile);
mojo::Array<mojo::String> allowed_guids(0);
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() ||
+ chooser_context->HasDevicePermission(requesting_origin,
+ embedding_origin, device->guid)))
allowed_guids.push_back(device->guid);
}
callback.Run(allowed_guids.Pass());
« 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