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

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

Issue 2746313002: Remove RenderFrameHost pointer from ChooserController. (Closed)
Patch Set: Created 3 years, 9 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
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/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 continue; 43 continue;
44 if (base::ContainsValue(function.origins, origin)) 44 if (base::ContainsValue(function.origins, origin))
45 return true; 45 return true;
46 } 46 }
47 } 47 }
48 return false; 48 return false;
49 } 49 }
50 50
51 } // namespace 51 } // namespace
52 52
53 // static 53 WebUSBPermissionProvider::WebUSBPermissionProvider(
54 RenderFrameHost* render_frame_host)
55 : render_frame_host_(render_frame_host), weak_factory_(this) {
56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
57 DCHECK(render_frame_host_);
58 }
59
60 WebUSBPermissionProvider::~WebUSBPermissionProvider() {}
61
62 base::WeakPtr<device::usb::PermissionProvider>
63 WebUSBPermissionProvider::GetWeakPtr() {
64 return weak_factory_.GetWeakPtr();
65 }
66
54 bool WebUSBPermissionProvider::HasDevicePermission( 67 bool WebUSBPermissionProvider::HasDevicePermission(
55 RenderFrameHost* render_frame_host, 68 scoped_refptr<const device::UsbDevice> device) const {
56 scoped_refptr<const device::UsbDevice> device) {
57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 69 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
58 70
59 if (UsbBlocklist::Get().IsExcluded(device)) 71 if (UsbBlocklist::Get().IsExcluded(device))
60 return false; 72 return false;
61 73
62 WebContents* web_contents = 74 WebContents* web_contents =
63 WebContents::FromRenderFrameHost(render_frame_host); 75 WebContents::FromRenderFrameHost(render_frame_host_);
64 RenderFrameHost* main_frame = web_contents->GetMainFrame(); 76 RenderFrameHost* main_frame = web_contents->GetMainFrame();
65 GURL embedding_origin = main_frame->GetLastCommittedURL().GetOrigin(); 77 GURL embedding_origin = main_frame->GetLastCommittedURL().GetOrigin();
66 GURL requesting_origin = render_frame_host->GetLastCommittedURL().GetOrigin(); 78 GURL requesting_origin =
79 render_frame_host_->GetLastCommittedURL().GetOrigin();
67 Profile* profile = 80 Profile* profile =
68 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 81 Profile::FromBrowserContext(web_contents->GetBrowserContext());
69 UsbChooserContext* chooser_context = 82 UsbChooserContext* chooser_context =
70 UsbChooserContextFactory::GetForProfile(profile); 83 UsbChooserContextFactory::GetForProfile(profile);
71 84
72 if (!chooser_context->HasDevicePermission(requesting_origin, embedding_origin, 85 if (!chooser_context->HasDevicePermission(requesting_origin, embedding_origin,
73 device)) { 86 device)) {
74 return false; 87 return false;
75 } 88 }
76 89
77 // On Android it is not possible to read the WebUSB descriptors until Chrome 90 // On Android it is not possible to read the WebUSB descriptors until Chrome
78 // has been granted permission to open it. Instead we grant provisional access 91 // has been granted permission to open it. Instead we grant provisional access
79 // to the device and perform the allowed origins check when the client tries 92 // to the device and perform the allowed origins check when the client tries
80 // to open it. 93 // to open it.
81 if (!device->permission_granted()) 94 if (!device->permission_granted())
82 return true; 95 return true;
83 96
84 // Embedded frames must have their origin in the list provided by the device. 97 // Embedded frames must have their origin in the list provided by the device.
85 if (render_frame_host != main_frame) { 98 if (render_frame_host_ != main_frame) {
86 return FindOriginInDescriptorSet(device->webusb_allowed_origins(), 99 return FindOriginInDescriptorSet(device->webusb_allowed_origins(),
87 requesting_origin, nullptr, nullptr); 100 requesting_origin, nullptr, nullptr);
88 } 101 }
89 102
90 return true; 103 return true;
91 } 104 }
92 105
93 WebUSBPermissionProvider::WebUSBPermissionProvider(
94 RenderFrameHost* render_frame_host)
95 : render_frame_host_(render_frame_host), weak_factory_(this) {
96 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
97 DCHECK(render_frame_host_);
98 }
99
100 WebUSBPermissionProvider::~WebUSBPermissionProvider() {}
101
102 base::WeakPtr<device::usb::PermissionProvider>
103 WebUSBPermissionProvider::GetWeakPtr() {
104 return weak_factory_.GetWeakPtr();
105 }
106
107 bool WebUSBPermissionProvider::HasDevicePermission(
108 scoped_refptr<const device::UsbDevice> device) const {
109 return HasDevicePermission(render_frame_host_, device);
110 }
111
112 bool WebUSBPermissionProvider::HasConfigurationPermission( 106 bool WebUSBPermissionProvider::HasConfigurationPermission(
113 uint8_t requested_configuration_value, 107 uint8_t requested_configuration_value,
114 scoped_refptr<const device::UsbDevice> device) const { 108 scoped_refptr<const device::UsbDevice> device) const {
115 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
116 110
117 // Embedded frames may only access configurations if their origin in the list 111 // Embedded frames may only access configurations if their origin in the list
118 // provided by the device. 112 // provided by the device.
119 RenderFrameHost* main_frame = 113 RenderFrameHost* main_frame =
120 WebContents::FromRenderFrameHost(render_frame_host_)->GetMainFrame(); 114 WebContents::FromRenderFrameHost(render_frame_host_)->GetMainFrame();
121 if (render_frame_host_ != main_frame) { 115 if (render_frame_host_ != main_frame) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 tab_helper->IncrementConnectionCount(render_frame_host_); 150 tab_helper->IncrementConnectionCount(render_frame_host_);
157 } 151 }
158 152
159 void WebUSBPermissionProvider::DecrementConnectionCount() { 153 void WebUSBPermissionProvider::DecrementConnectionCount() {
160 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 154 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
161 WebContents* web_contents = 155 WebContents* web_contents =
162 WebContents::FromRenderFrameHost(render_frame_host_); 156 WebContents::FromRenderFrameHost(render_frame_host_);
163 UsbTabHelper* tab_helper = UsbTabHelper::FromWebContents(web_contents); 157 UsbTabHelper* tab_helper = UsbTabHelper::FromWebContents(web_contents);
164 tab_helper->DecrementConnectionCount(render_frame_host_); 158 tab_helper->DecrementConnectionCount(render_frame_host_);
165 } 159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698