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

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

Issue 2815003005: Integrate WebUSB with Feature Policy (Closed)
Patch Set: Fixed usb-allowed-by-feature-policy.https.sub.html Created 3 years, 7 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/usb_chooser_controller.h" 5 #include "chrome/browser/usb/usb_chooser_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/usb/web_usb_permission_provider.h" 22 #include "chrome/browser/usb/web_usb_permission_provider.h"
23 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
24 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
25 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "device/base/device_client.h" 27 #include "device/base/device_client.h"
28 #include "device/usb/mojo/type_converters.h" 28 #include "device/usb/mojo/type_converters.h"
29 #include "device/usb/usb_device.h" 29 #include "device/usb/usb_device.h"
30 #include "device/usb/usb_device_filter.h" 30 #include "device/usb/usb_device_filter.h"
31 #include "device/usb/usb_ids.h" 31 #include "device/usb/usb_ids.h"
32 #include "device/usb/webusb_descriptors.h"
33 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
34 #include "url/gurl.h" 33 #include "url/gurl.h"
35 34
36 using content::RenderFrameHost; 35 using content::RenderFrameHost;
37 using content::WebContents; 36 using content::WebContents;
38 using device::UsbDevice; 37 using device::UsbDevice;
39 using device::UsbDeviceFilter; 38 using device::UsbDeviceFilter;
40 39
41 namespace { 40 namespace {
42 41
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 usb_service_observer_.Add(usb_service); 89 usb_service_observer_.Add(usb_service);
91 usb_service->GetDevices(base::Bind(&UsbChooserController::GotUsbDeviceList, 90 usb_service->GetDevices(base::Bind(&UsbChooserController::GotUsbDeviceList,
92 weak_factory_.GetWeakPtr())); 91 weak_factory_.GetWeakPtr()));
93 } 92 }
94 93
95 WebContents* web_contents = 94 WebContents* web_contents =
96 WebContents::FromRenderFrameHost(render_frame_host); 95 WebContents::FromRenderFrameHost(render_frame_host);
97 RenderFrameHost* main_frame = web_contents->GetMainFrame(); 96 RenderFrameHost* main_frame = web_contents->GetMainFrame();
98 requesting_origin_ = render_frame_host->GetLastCommittedURL().GetOrigin(); 97 requesting_origin_ = render_frame_host->GetLastCommittedURL().GetOrigin();
99 embedding_origin_ = main_frame->GetLastCommittedURL().GetOrigin(); 98 embedding_origin_ = main_frame->GetLastCommittedURL().GetOrigin();
100 is_embedded_frame_ = render_frame_host != main_frame;
101 Profile* profile = 99 Profile* profile =
102 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 100 Profile::FromBrowserContext(web_contents->GetBrowserContext());
103 chooser_context_ = 101 chooser_context_ =
104 UsbChooserContextFactory::GetForProfile(profile)->AsWeakPtr(); 102 UsbChooserContextFactory::GetForProfile(profile)->AsWeakPtr();
105 } 103 }
106 104
107 UsbChooserController::~UsbChooserController() { 105 UsbChooserController::~UsbChooserController() {
108 if (!callback_.is_null()) 106 if (!callback_.is_null())
109 callback_.Run(nullptr); 107 callback_.Run(nullptr);
110 } 108 }
(...skipping 22 matching lines...) Expand all
133 devices_[index].first->serial_number()); 131 devices_[index].first->serial_number());
134 } 132 }
135 133
136 bool UsbChooserController::IsPaired(size_t index) const { 134 bool UsbChooserController::IsPaired(size_t index) const {
137 scoped_refptr<UsbDevice> device = devices_[index].first; 135 scoped_refptr<UsbDevice> device = devices_[index].first;
138 136
139 if (!chooser_context_) 137 if (!chooser_context_)
140 return false; 138 return false;
141 139
142 return WebUSBPermissionProvider::HasDevicePermission( 140 return WebUSBPermissionProvider::HasDevicePermission(
143 chooser_context_.get(), requesting_origin_, embedding_origin_, 141 chooser_context_.get(), requesting_origin_, embedding_origin_, device);
144 is_embedded_frame_, device);
145 } 142 }
146 143
147 void UsbChooserController::RefreshOptions() {} 144 void UsbChooserController::RefreshOptions() {}
148 145
149 base::string16 UsbChooserController::GetStatus() const { 146 base::string16 UsbChooserController::GetStatus() const {
150 return base::string16(); 147 return base::string16();
151 } 148 }
152 149
153 void UsbChooserController::Select(const std::vector<size_t>& indices) { 150 void UsbChooserController::Select(const std::vector<size_t>& indices) {
154 DCHECK_EQ(1u, indices.size()); 151 DCHECK_EQ(1u, indices.size());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 222 }
226 223
227 bool UsbChooserController::DisplayDevice( 224 bool UsbChooserController::DisplayDevice(
228 scoped_refptr<UsbDevice> device) const { 225 scoped_refptr<UsbDevice> device) const {
229 if (!UsbDeviceFilter::MatchesAny(*device, filters_)) 226 if (!UsbDeviceFilter::MatchesAny(*device, filters_))
230 return false; 227 return false;
231 228
232 if (UsbBlocklist::Get().IsExcluded(device)) 229 if (UsbBlocklist::Get().IsExcluded(device))
233 return false; 230 return false;
234 231
235 // Embedded frames must have their origin in the list provided by the device.
236 if (is_embedded_frame_) {
237 return device::FindInWebUsbAllowedOrigins(device->webusb_allowed_origins(),
238 requesting_origin_, base::nullopt,
239 base::nullopt);
240 }
241
242 return true; 232 return true;
243 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698