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: extensions/browser/api/usb/usb_api.cc

Issue 1034333002: Check USB device path access when prompting users to select a device. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move MockPermissionBrokerClient into its own header. Created 5 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/usb/usb_api.h" 5 #include "extensions/browser/api/usb/usb_api.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 case device::USB_TRANSFER_OVERFLOW: 235 case device::USB_TRANSFER_OVERFLOW:
236 return kErrorOverflow; 236 return kErrorOverflow;
237 case device::USB_TRANSFER_LENGTH_SHORT: 237 case device::USB_TRANSFER_LENGTH_SHORT:
238 return kErrorTransferLength; 238 return kErrorTransferLength;
239 default: 239 default:
240 NOTREACHED(); 240 NOTREACHED();
241 return ""; 241 return "";
242 } 242 }
243 } 243 }
244 244
245 #if defined(OS_CHROMEOS)
246 void RequestUsbDevicesAccessHelper( 245 void RequestUsbDevicesAccessHelper(
247 ScopedDeviceVector devices, 246 ScopedDeviceVector devices,
248 std::vector<scoped_refptr<UsbDevice> >::iterator i, 247 std::vector<scoped_refptr<UsbDevice> >::iterator i,
249 int interface_id, 248 int interface_id,
250 const base::Callback<void(ScopedDeviceVector result)>& callback, 249 const base::Callback<void(ScopedDeviceVector result)>& callback,
251 bool success) { 250 bool success) {
252 if (success) { 251 if (success) {
253 ++i; 252 ++i;
254 } else { 253 } else {
255 i = devices->erase(i); 254 i = devices->erase(i);
(...skipping 19 matching lines...) Expand all
275 return; 274 return;
276 } 275 }
277 std::vector<scoped_refptr<UsbDevice> >::iterator i = devices->begin(); 276 std::vector<scoped_refptr<UsbDevice> >::iterator i = devices->begin();
278 (*i)->RequestUsbAccess(interface_id, 277 (*i)->RequestUsbAccess(interface_id,
279 base::Bind(RequestUsbDevicesAccessHelper, 278 base::Bind(RequestUsbDevicesAccessHelper,
280 base::Passed(devices.Pass()), 279 base::Passed(devices.Pass()),
281 i, 280 i,
282 interface_id, 281 interface_id,
283 callback)); 282 callback));
284 } 283 }
285 #endif // OS_CHROMEOS
286 284
287 base::DictionaryValue* CreateTransferInfo(UsbTransferStatus status, 285 base::DictionaryValue* CreateTransferInfo(UsbTransferStatus status,
288 scoped_refptr<net::IOBuffer> data, 286 scoped_refptr<net::IOBuffer> data,
289 size_t length) { 287 size_t length) {
290 base::DictionaryValue* result = new base::DictionaryValue(); 288 base::DictionaryValue* result = new base::DictionaryValue();
291 result->SetInteger(kResultCodeKey, status); 289 result->SetInteger(kResultCodeKey, status);
292 result->Set(kDataKey, 290 result->Set(kDataKey,
293 base::BinaryValue::CreateWithCopiedBuffer(data->data(), length)); 291 base::BinaryValue::CreateWithCopiedBuffer(data->data(), length));
294 return result; 292 return result;
295 } 293 }
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 service->GetDevices(devices.get()); 591 service->GetDevices(devices.get());
594 592
595 for (DeviceVector::iterator it = devices->begin(); it != devices->end();) { 593 for (DeviceVector::iterator it = devices->begin(); it != devices->end();) {
596 if ((*it)->vendor_id() != vendor_id || (*it)->product_id() != product_id) { 594 if ((*it)->vendor_id() != vendor_id || (*it)->product_id() != product_id) {
597 it = devices->erase(it); 595 it = devices->erase(it);
598 } else { 596 } else {
599 ++it; 597 ++it;
600 } 598 }
601 } 599 }
602 600
603 #if defined(OS_CHROMEOS)
604 RequestUsbDevicesAccess( 601 RequestUsbDevicesAccess(
605 devices.Pass(), 602 devices.Pass(),
606 interface_id, 603 interface_id,
607 base::Bind(&UsbFindDevicesFunction::OpenDevices, this)); 604 base::Bind(&UsbFindDevicesFunction::OpenDevices, this));
608 #else
609 OpenDevices(devices.Pass());
610 #endif // OS_CHROMEOS
611 } 605 }
612 606
613 void UsbFindDevicesFunction::OpenDevices(ScopedDeviceVector devices) { 607 void UsbFindDevicesFunction::OpenDevices(ScopedDeviceVector devices) {
614 base::ListValue* result = new base::ListValue(); 608 base::ListValue* result = new base::ListValue();
615 609
616 for (size_t i = 0; i < devices->size(); ++i) { 610 for (size_t i = 0; i < devices->size(); ++i) {
617 scoped_refptr<UsbDeviceHandle> device_handle = devices->at(i)->Open(); 611 scoped_refptr<UsbDeviceHandle> device_handle = devices->at(i)->Open();
618 if (device_handle.get()) 612 if (device_handle.get())
619 device_handles_.push_back(device_handle); 613 device_handles_.push_back(device_handle);
620 } 614 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 return; 779 return;
786 } 780 }
787 781
788 if (!HasDevicePermission(device_)) { 782 if (!HasDevicePermission(device_)) {
789 // This function must act as if there is no such device. Otherwise it can be 783 // This function must act as if there is no such device. Otherwise it can be
790 // used to fingerprint unauthorized devices. 784 // used to fingerprint unauthorized devices.
791 CompleteWithError(kErrorNoDevice); 785 CompleteWithError(kErrorNoDevice);
792 return; 786 return;
793 } 787 }
794 788
795 #if defined(OS_CHROMEOS)
796 device_->RequestUsbAccess( 789 device_->RequestUsbAccess(
797 -1, /* any interface, unused by the permission broker */ 790 -1, /* any interface, unused by the permission broker */
798 base::Bind(&UsbOpenDeviceFunction::OnRequestAccessComplete, this)); 791 base::Bind(&UsbOpenDeviceFunction::OnRequestAccessComplete, this));
799 #else
800 OnRequestAccessComplete(true);
801 #endif // OS_CHROMEOS
802 } 792 }
803 793
804 void UsbOpenDeviceFunction::OnRequestAccessComplete(bool success) { 794 void UsbOpenDeviceFunction::OnRequestAccessComplete(bool success) {
805 if (!success) { 795 if (!success) {
806 SetError(kErrorPermissionDenied); 796 SetError(kErrorPermissionDenied);
807 AsyncWorkCompleted(); 797 AsyncWorkCompleted();
808 return; 798 return;
809 } 799 }
810 800
811 scoped_refptr<UsbDeviceHandle> handle = device_->Open(); 801 scoped_refptr<UsbDeviceHandle> handle = device_->Open();
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 SetResult(new base::FundamentalValue(false)); 1265 SetResult(new base::FundamentalValue(false));
1276 CompleteWithError(kErrorResetDevice); 1266 CompleteWithError(kErrorResetDevice);
1277 return; 1267 return;
1278 } 1268 }
1279 1269
1280 SetResult(new base::FundamentalValue(true)); 1270 SetResult(new base::FundamentalValue(true));
1281 AsyncWorkCompleted(); 1271 AsyncWorkCompleted();
1282 } 1272 }
1283 1273
1284 } // namespace extensions 1274 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/device_permissions_prompt.cc ('k') | extensions/browser/api/usb/usb_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698