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

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

Issue 2352393006: Show "Paired" for already paired WebUSB devices on the chooser (Closed)
Patch Set: make WebUSBPermissionProvider::HasDevicePermission a static function Created 4 years, 2 months 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/web_usb_permission_provider.h ('k') | no next file » | 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 <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"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 continue; 47 continue;
48 if (base::ContainsValue(function.origins, origin)) 48 if (base::ContainsValue(function.origins, origin))
49 return true; 49 return true;
50 } 50 }
51 } 51 }
52 return false; 52 return false;
53 } 53 }
54 54
55 } // namespace 55 } // namespace
56 56
57 WebUSBPermissionProvider::WebUSBPermissionProvider( 57 // static
58 content::RenderFrameHost* render_frame_host)
59 : render_frame_host_(render_frame_host), weak_factory_(this) {
60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
61 DCHECK(render_frame_host_);
62 }
63
64 WebUSBPermissionProvider::~WebUSBPermissionProvider() {}
65
66 base::WeakPtr<device::usb::PermissionProvider>
67 WebUSBPermissionProvider::GetWeakPtr() {
68 return weak_factory_.GetWeakPtr();
69 }
70
71 bool WebUSBPermissionProvider::HasDevicePermission( 58 bool WebUSBPermissionProvider::HasDevicePermission(
72 scoped_refptr<const device::UsbDevice> device) const { 59 content::RenderFrameHost* render_frame_host,
60 scoped_refptr<const device::UsbDevice> device) {
73 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 61 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
74 WebContents* web_contents = 62 WebContents* web_contents =
75 WebContents::FromRenderFrameHost(render_frame_host_); 63 WebContents::FromRenderFrameHost(render_frame_host);
76 GURL embedding_origin = 64 GURL embedding_origin =
77 web_contents->GetMainFrame()->GetLastCommittedURL().GetOrigin(); 65 web_contents->GetMainFrame()->GetLastCommittedURL().GetOrigin();
78 GURL requesting_origin = 66 GURL requesting_origin = render_frame_host->GetLastCommittedURL().GetOrigin();
79 render_frame_host_->GetLastCommittedURL().GetOrigin();
80 Profile* profile = 67 Profile* profile =
81 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 68 Profile::FromBrowserContext(web_contents->GetBrowserContext());
82 UsbChooserContext* chooser_context = 69 UsbChooserContext* chooser_context =
83 UsbChooserContextFactory::GetForProfile(profile); 70 UsbChooserContextFactory::GetForProfile(profile);
84 71
85 if (!chooser_context->HasDevicePermission(requesting_origin, embedding_origin, 72 if (!chooser_context->HasDevicePermission(requesting_origin, embedding_origin,
86 device)) { 73 device)) {
87 return false; 74 return false;
88 } 75 }
89 76
90 // On Android it is not possible to read the WebUSB descriptors until Chrome 77 // On Android it is not possible to read the WebUSB descriptors until Chrome
91 // has been granted permission to open it. Instead we grant provisional access 78 // has been granted permission to open it. Instead we grant provisional access
92 // to the device and perform the allowed origins check when the client tries 79 // to the device and perform the allowed origins check when the client tries
93 // to open it. 80 // to open it.
94 if (!device->permission_granted()) 81 if (!device->permission_granted())
95 return true; 82 return true;
96 83
97 return FindOriginInDescriptorSet(device->webusb_allowed_origins(), 84 return FindOriginInDescriptorSet(device->webusb_allowed_origins(),
98 requesting_origin, nullptr, nullptr); 85 requesting_origin, nullptr, nullptr);
99 } 86 }
100 87
88 WebUSBPermissionProvider::WebUSBPermissionProvider(
89 content::RenderFrameHost* render_frame_host)
90 : render_frame_host_(render_frame_host), weak_factory_(this) {
91 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
92 DCHECK(render_frame_host_);
93 }
94
95 WebUSBPermissionProvider::~WebUSBPermissionProvider() {}
96
97 base::WeakPtr<device::usb::PermissionProvider>
98 WebUSBPermissionProvider::GetWeakPtr() {
99 return weak_factory_.GetWeakPtr();
100 }
101
102 bool WebUSBPermissionProvider::HasDevicePermission(
103 scoped_refptr<const device::UsbDevice> device) const {
104 return HasDevicePermission(render_frame_host_, device);
105 }
106
101 bool WebUSBPermissionProvider::HasConfigurationPermission( 107 bool WebUSBPermissionProvider::HasConfigurationPermission(
102 uint8_t requested_configuration_value, 108 uint8_t requested_configuration_value,
103 scoped_refptr<const device::UsbDevice> device) const { 109 scoped_refptr<const device::UsbDevice> device) const {
104 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 110 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
105 return FindOriginInDescriptorSet( 111 return FindOriginInDescriptorSet(
106 device->webusb_allowed_origins(), 112 device->webusb_allowed_origins(),
107 render_frame_host_->GetLastCommittedURL().GetOrigin(), 113 render_frame_host_->GetLastCommittedURL().GetOrigin(),
108 &requested_configuration_value, nullptr); 114 &requested_configuration_value, nullptr);
109 } 115 }
110 116
(...skipping 16 matching lines...) Expand all
127 tab_helper->IncrementConnectionCount(render_frame_host_); 133 tab_helper->IncrementConnectionCount(render_frame_host_);
128 } 134 }
129 135
130 void WebUSBPermissionProvider::DecrementConnectionCount() { 136 void WebUSBPermissionProvider::DecrementConnectionCount() {
131 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 137 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
132 WebContents* web_contents = 138 WebContents* web_contents =
133 WebContents::FromRenderFrameHost(render_frame_host_); 139 WebContents::FromRenderFrameHost(render_frame_host_);
134 UsbTabHelper* tab_helper = UsbTabHelper::FromWebContents(web_contents); 140 UsbTabHelper* tab_helper = UsbTabHelper::FromWebContents(web_contents);
135 tab_helper->DecrementConnectionCount(render_frame_host_); 141 tab_helper->DecrementConnectionCount(render_frame_host_);
136 } 142 }
OLDNEW
« no previous file with comments | « chrome/browser/usb/web_usb_permission_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698