| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/usb/usb_blocklist.h" |
| 13 #include "chrome/browser/usb/usb_chooser_context.h" | 14 #include "chrome/browser/usb/usb_chooser_context.h" |
| 14 #include "chrome/browser/usb/usb_chooser_context_factory.h" | 15 #include "chrome/browser/usb/usb_chooser_context_factory.h" |
| 15 #include "chrome/browser/usb/usb_tab_helper.h" | 16 #include "chrome/browser/usb/usb_tab_helper.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "device/usb/usb_device.h" | 21 #include "device/usb/usb_device.h" |
| 21 #include "device/usb/webusb_descriptors.h" | 22 #include "device/usb/webusb_descriptors.h" |
| 22 | 23 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 52 return false; | 53 return false; |
| 53 } | 54 } |
| 54 | 55 |
| 55 } // namespace | 56 } // namespace |
| 56 | 57 |
| 57 // static | 58 // static |
| 58 bool WebUSBPermissionProvider::HasDevicePermission( | 59 bool WebUSBPermissionProvider::HasDevicePermission( |
| 59 content::RenderFrameHost* render_frame_host, | 60 content::RenderFrameHost* render_frame_host, |
| 60 scoped_refptr<const device::UsbDevice> device) { | 61 scoped_refptr<const device::UsbDevice> device) { |
| 61 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 62 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 63 |
| 64 if (UsbBlocklist::Get().IsExcluded(device)) |
| 65 return false; |
| 66 |
| 62 WebContents* web_contents = | 67 WebContents* web_contents = |
| 63 WebContents::FromRenderFrameHost(render_frame_host); | 68 WebContents::FromRenderFrameHost(render_frame_host); |
| 64 GURL embedding_origin = | 69 GURL embedding_origin = |
| 65 web_contents->GetMainFrame()->GetLastCommittedURL().GetOrigin(); | 70 web_contents->GetMainFrame()->GetLastCommittedURL().GetOrigin(); |
| 66 GURL requesting_origin = render_frame_host->GetLastCommittedURL().GetOrigin(); | 71 GURL requesting_origin = render_frame_host->GetLastCommittedURL().GetOrigin(); |
| 67 Profile* profile = | 72 Profile* profile = |
| 68 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 73 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 69 UsbChooserContext* chooser_context = | 74 UsbChooserContext* chooser_context = |
| 70 UsbChooserContextFactory::GetForProfile(profile); | 75 UsbChooserContextFactory::GetForProfile(profile); |
| 71 | 76 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 tab_helper->IncrementConnectionCount(render_frame_host_); | 138 tab_helper->IncrementConnectionCount(render_frame_host_); |
| 134 } | 139 } |
| 135 | 140 |
| 136 void WebUSBPermissionProvider::DecrementConnectionCount() { | 141 void WebUSBPermissionProvider::DecrementConnectionCount() { |
| 137 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 142 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 138 WebContents* web_contents = | 143 WebContents* web_contents = |
| 139 WebContents::FromRenderFrameHost(render_frame_host_); | 144 WebContents::FromRenderFrameHost(render_frame_host_); |
| 140 UsbTabHelper* tab_helper = UsbTabHelper::FromWebContents(web_contents); | 145 UsbTabHelper* tab_helper = UsbTabHelper::FromWebContents(web_contents); |
| 141 tab_helper->DecrementConnectionCount(render_frame_host_); | 146 tab_helper->DecrementConnectionCount(render_frame_host_); |
| 142 } | 147 } |
| OLD | NEW |