diff options
-rw-r--r-- | chrome/browser/extensions/browser_context_keyed_service_factories.cc | 2 | ||||
-rw-r--r-- | chrome/chrome_browser_extensions.gypi | 6 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 4 | ||||
-rw-r--r-- | chrome/common/extensions/api/_api_features.json | 4 | ||||
-rw-r--r-- | chrome/common/extensions/api/_permission_features.json | 28 | ||||
-rw-r--r-- | chrome/common/extensions/api/api.gyp | 1 | ||||
-rw-r--r-- | extensions/DEPS | 3 | ||||
-rw-r--r-- | extensions/browser/api/usb/DEPS (renamed from chrome/browser/extensions/api/usb/DEPS) | 0 | ||||
-rw-r--r-- | extensions/browser/api/usb/OWNERS (renamed from chrome/browser/extensions/api/usb/OWNERS) | 0 | ||||
-rw-r--r-- | extensions/browser/api/usb/usb_api.cc (renamed from chrome/browser/extensions/api/usb/usb_api.cc) | 288 | ||||
-rw-r--r-- | extensions/browser/api/usb/usb_api.h (renamed from chrome/browser/extensions/api/usb/usb_api.h) | 61 | ||||
-rw-r--r-- | extensions/browser/api/usb/usb_apitest.cc (renamed from chrome/browser/extensions/api/usb/usb_apitest.cc) | 72 | ||||
-rw-r--r-- | extensions/browser/api/usb/usb_device_resource.cc (renamed from chrome/browser/extensions/api/usb/usb_device_resource.cc) | 9 | ||||
-rw-r--r-- | extensions/browser/api/usb/usb_device_resource.h (renamed from chrome/browser/extensions/api/usb/usb_device_resource.h) | 10 | ||||
-rw-r--r-- | extensions/browser/api/usb/usb_manual_apitest.cc (renamed from chrome/browser/extensions/api/usb/usb_manual_apitest.cc) | 5 | ||||
-rw-r--r-- | extensions/common/api/_api_features.json | 4 | ||||
-rw-r--r-- | extensions/common/api/_permission_features.json | 30 | ||||
-rw-r--r-- | extensions/common/api/api.gyp | 1 | ||||
-rw-r--r-- | extensions/common/api/usb.idl (renamed from chrome/common/extensions/api/usb.idl) | 2 | ||||
-rw-r--r-- | extensions/extensions.gyp | 8 |
20 files changed, 307 insertions, 231 deletions
diff --git a/chrome/browser/extensions/browser_context_keyed_service_factories.cc b/chrome/browser/extensions/browser_context_keyed_service_factories.cc index c9f3c43..d83454b 100644 --- a/chrome/browser/extensions/browser_context_keyed_service_factories.cc +++ b/chrome/browser/extensions/browser_context_keyed_service_factories.cc @@ -47,7 +47,6 @@ #include "chrome/browser/extensions/api/system_info/system_info_api.h" #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" -#include "chrome/browser/extensions/api/usb/usb_device_resource.h" #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" #include "chrome/browser/extensions/api/web_request/web_request_api.h" #include "chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.h" @@ -64,6 +63,7 @@ #include "chrome/browser/extensions/token_cache/token_cache_service_factory.h" #include "chrome/browser/speech/extension_api/tts_extension_api.h" #include "extensions/browser/api/api_resource_manager.h" +#include "extensions/browser/api/usb/usb_device_resource.h" #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_api_factory.h" diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index c740c77..108445f 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -49,7 +49,6 @@ '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', '../third_party/leveldatabase/leveldatabase.gyp:leveldatabase', - '../third_party/libusb/libusb.gyp:libusb', '../third_party/webrtc/modules/modules.gyp:desktop_capture', '../ui/accessibility/accessibility.gyp:ax_gen', '../ui/base/strings/ui_strings.gyp:ui_strings', @@ -581,10 +580,6 @@ 'browser/extensions/api/tabs/windows_util.h', 'browser/extensions/api/top_sites/top_sites_api.cc', 'browser/extensions/api/top_sites/top_sites_api.h', - 'browser/extensions/api/usb/usb_api.cc', - 'browser/extensions/api/usb/usb_api.h', - 'browser/extensions/api/usb/usb_device_resource.cc', - 'browser/extensions/api/usb/usb_device_resource.h', 'browser/extensions/api/web_navigation/frame_navigation_state.cc', 'browser/extensions/api/web_navigation/frame_navigation_state.h', 'browser/extensions/api/web_navigation/web_navigation_api.cc', @@ -1029,7 +1024,6 @@ ], 'dependencies!': [ '../device/bluetooth/bluetooth.gyp:device_bluetooth', - '../third_party/libusb/libusb.gyp:libusb' ], }], ['use_aura==1', { diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index cd3f4be..cb56659 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -818,6 +818,8 @@ '../apps/app_shim/test/app_shim_host_manager_test_api_mac.cc', '../apps/app_shim/test/app_shim_host_manager_test_api_mac.h', '../apps/load_and_launch_browsertest.cc', + '../extensions/browser/api/usb/usb_apitest.cc', + '../extensions/browser/api/usb/usb_manual_apitest.cc', # TODO(blundell): Bring up a components_browsertests target and move # this test to be in that target. crbug.com/283846 '../components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc', @@ -1091,8 +1093,6 @@ 'browser/extensions/api/terminal/terminal_private_apitest.cc', 'browser/extensions/api/test/apitest_apitest.cc', 'browser/extensions/api/top_sites/top_sites_apitest.cc', - 'browser/extensions/api/usb/usb_apitest.cc', - 'browser/extensions/api/usb/usb_manual_apitest.cc', 'browser/extensions/api/web_navigation/web_navigation_apitest.cc', 'browser/extensions/api/web_request/web_request_apitest.cc', 'browser/extensions/api/webrtc_audio_private/webrtc_audio_private_browsertest.cc', diff --git a/chrome/common/extensions/api/_api_features.json b/chrome/common/extensions/api/_api_features.json index f743964..a1df50b 100644 --- a/chrome/common/extensions/api/_api_features.json +++ b/chrome/common/extensions/api/_api_features.json @@ -732,10 +732,6 @@ "extension_types": ["extension"], "location": "component" }, - "usb": { - "dependencies": ["permission:usb"], - "contexts": ["blessed_extension"] - }, "virtualKeyboardPrivate": { "platforms": ["chromeos"], "dependencies": ["permission:virtualKeyboardPrivate"], diff --git a/chrome/common/extensions/api/_permission_features.json b/chrome/common/extensions/api/_permission_features.json index ea9889e..5052702 100644 --- a/chrome/common/extensions/api/_permission_features.json +++ b/chrome/common/extensions/api/_permission_features.json @@ -874,34 +874,6 @@ "extension", "legacy_packaged_app", "hosted_app", "platform_app" ] }, - "usb": [ - { - "channel": "stable", - "extension_types": ["platform_app"] - }, - { - "channel": "stable", - "extension_types": ["extension"], - "whitelist": [ - "496B6890097EB6E19809ADEADD095A8721FBB2E0", // FIDO U2F APIs - "E24F1786D842E91E74C27929B0B3715A4689A473" // CryptoToken - ] - } - ], - "usbDevices": [ - { - "channel": "stable", - "extension_types": ["platform_app"] - }, - { - "channel": "stable", - "extension_types": ["extension"], - "whitelist": [ - "496B6890097EB6E19809ADEADD095A8721FBB2E0", // FIDO U2F APIs - "E24F1786D842E91E74C27929B0B3715A4689A473" // CryptoToken - ] - } - ], "videoCapture": [ { "channel": "stable", diff --git a/chrome/common/extensions/api/api.gyp b/chrome/common/extensions/api/api.gyp index 6a20fa5..f701e84 100644 --- a/chrome/common/extensions/api/api.gyp +++ b/chrome/common/extensions/api/api.gyp @@ -119,7 +119,6 @@ 'tabs.json', 'terminal_private.json', 'types.json', - 'usb.idl', 'virtual_keyboard_private.json', 'web_navigation.json', 'web_request.json', diff --git a/extensions/DEPS b/extensions/DEPS index bb58d4f..11611da 100644 --- a/extensions/DEPS +++ b/extensions/DEPS @@ -26,9 +26,12 @@ specific_include_rules = { # Temporarily allowed testing includes. See above. # TODO(jamescook): Remove these. http://crbug.com/162530 + "+chrome/browser/extensions/api/permissions/permissions_api.h", "+chrome/browser/extensions/extension_api_unittest.h", + "+chrome/browser/extensions/extension_apitest.h", "+chrome/browser/extensions/extension_service_unittest.h", "+chrome/browser/extensions/test_extension_system.h", + "+chrome/browser/ui/browser.h", "+chrome/common/chrome_paths.h", "+chrome/common/extensions/features/feature_channel.h", "+chrome/common/extensions/manifest_tests/extension_manifest_test.h", diff --git a/chrome/browser/extensions/api/usb/DEPS b/extensions/browser/api/usb/DEPS index 70ac41d..70ac41d 100644 --- a/chrome/browser/extensions/api/usb/DEPS +++ b/extensions/browser/api/usb/DEPS diff --git a/chrome/browser/extensions/api/usb/OWNERS b/extensions/browser/api/usb/OWNERS index 38fa250..38fa250 100644 --- a/chrome/browser/extensions/api/usb/OWNERS +++ b/extensions/browser/api/usb/OWNERS diff --git a/chrome/browser/extensions/api/usb/usb_api.cc b/extensions/browser/api/usb/usb_api.cc index 94c0f8c..93ac6c1 100644 --- a/chrome/browser/extensions/api/usb/usb_api.cc +++ b/extensions/browser/api/usb/usb_api.cc @@ -1,23 +1,23 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/extensions/api/usb/usb_api.h" +#include "extensions/browser/api/usb/usb_api.h" #include <string> #include <vector> #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop_proxy.h" -#include "chrome/browser/extensions/api/usb/usb_device_resource.h" -#include "chrome/common/extensions/api/usb.h" #include "components/usb_service/usb_device_handle.h" #include "components/usb_service/usb_service.h" +#include "extensions/browser/api/usb/usb_device_resource.h" #include "extensions/browser/extension_system.h" +#include "extensions/common/api/usb.h" #include "extensions/common/permissions/permissions_data.h" #include "extensions/common/permissions/usb_device_permission.h" -namespace usb = extensions::api::usb; +namespace usb = extensions::core_api::usb; namespace BulkTransfer = usb::BulkTransfer; namespace ClaimInterface = usb::ClaimInterface; namespace CloseDevice = usb::CloseDevice; @@ -97,14 +97,13 @@ const char kErrorConvertTransferType[] = "Invalid endpoint type."; const char kErrorConvertUsageType[] = "Invalid usage type."; const char kErrorMalformedParameters[] = "Error parsing parameters."; const char kErrorNoDevice[] = "No such device."; -const char kErrorPermissionDenied[] = - "Permission to access device was denied"; +const char kErrorPermissionDenied[] = "Permission to access device was denied"; const char kErrorInvalidTransferLength[] = "Transfer length must be a positive number less than 104,857,600."; const char kErrorInvalidNumberOfPackets[] = "Number of packets must be a positive number less than 4,194,304."; -const char kErrorInvalidPacketLength[] = "Packet length must be a " - "positive number less than 65,536."; +const char kErrorInvalidPacketLength[] = + "Packet length must be a positive number less than 65,536."; const char kErrorResetDevice[] = "Error resetting the device. The device has been closed."; @@ -148,9 +147,8 @@ bool ConvertSynchronizationTypeToApi(const UsbSynchronizationType& input, } } -bool ConvertTransferTypeToApi( - const UsbTransferType& input, - usb::TransferType* output) { +bool ConvertTransferTypeToApi(const UsbTransferType& input, + usb::TransferType* output) { switch (input) { case usb_service::USB_TRANSFER_CONTROL: *output = usb::TRANSFER_TYPE_CONTROL; @@ -187,8 +185,7 @@ bool ConvertUsageTypeToApi(const UsbUsageType& input, usb::UsageType* output) { } } -bool ConvertDirection(const Direction& input, - UsbEndpointDirection* output) { +bool ConvertDirection(const Direction& input, UsbEndpointDirection* output) { switch (input) { case usb::DIRECTION_IN: *output = usb_service::USB_DIRECTION_INBOUND; @@ -244,7 +241,7 @@ bool ConvertRecipient(const Recipient& input, } } -template<class T> +template <class T> bool GetTransferSize(const T& input, size_t* output) { if (input.direction == usb::DIRECTION_IN) { const int* length = input.length.get(); @@ -262,18 +259,19 @@ bool GetTransferSize(const T& input, size_t* output) { return false; } -template<class T> +template <class T> scoped_refptr<net::IOBuffer> CreateBufferForTransfer( - const T& input, UsbEndpointDirection direction, size_t size) { - + const T& input, + UsbEndpointDirection direction, + size_t size) { if (size >= kMaxTransferLength) return NULL; // Allocate a |size|-bytes buffer, or a one-byte buffer if |size| is 0. This // is due to an impedance mismatch between IOBuffer and URBs. An IOBuffer // cannot represent a zero-length buffer, while an URB can. - scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(std::max( - static_cast<size_t>(1), size)); + scoped_refptr<net::IOBuffer> buffer = + new net::IOBuffer(std::max(static_cast<size_t>(1), size)); if (direction == usb_service::USB_DIRECTION_INBOUND) { return buffer; @@ -327,9 +325,12 @@ void RequestUsbDevicesAccessHelper( callback.Run(devices.Pass()); return; } - (*i)->RequestUsbAcess(interface_id, base::Bind(RequestUsbDevicesAccessHelper, - base::Passed(devices.Pass()), - i, interface_id, callback)); + (*i)->RequestUsbAcess(interface_id, + base::Bind(RequestUsbDevicesAccessHelper, + base::Passed(devices.Pass()), + i, + interface_id, + callback)); } void RequestUsbDevicesAccess( @@ -341,25 +342,27 @@ void RequestUsbDevicesAccess( return; } std::vector<scoped_refptr<UsbDevice> >::iterator i = devices->begin(); - (*i)->RequestUsbAcess( - interface_id, - base::Bind(RequestUsbDevicesAccessHelper, base::Passed(devices.Pass()), - i, interface_id, callback)); + (*i)->RequestUsbAcess(interface_id, + base::Bind(RequestUsbDevicesAccessHelper, + base::Passed(devices.Pass()), + i, + interface_id, + callback)); } #endif // OS_CHROMEOS -base::DictionaryValue* CreateTransferInfo( - UsbTransferStatus status, - scoped_refptr<net::IOBuffer> data, - size_t length) { +base::DictionaryValue* CreateTransferInfo(UsbTransferStatus status, + scoped_refptr<net::IOBuffer> data, + size_t length) { base::DictionaryValue* result = new base::DictionaryValue(); result->SetInteger(kResultCodeKey, status); - result->Set(kDataKey, base::BinaryValue::CreateWithCopiedBuffer(data->data(), - length)); + result->Set(kDataKey, + base::BinaryValue::CreateWithCopiedBuffer(data->data(), length)); return result; } -base::Value* PopulateConnectionHandle(int handle, int vendor_id, +base::Value* PopulateConnectionHandle(int handle, + int vendor_id, int product_id) { ConnectionHandle result; result.handle = handle; @@ -397,8 +400,7 @@ base::Value* PopulateInterfaceDescriptor( namespace extensions { -UsbAsyncApiFunction::UsbAsyncApiFunction() - : manager_(NULL) { +UsbAsyncApiFunction::UsbAsyncApiFunction() : manager_(NULL) { } UsbAsyncApiFunction::~UsbAsyncApiFunction() { @@ -414,8 +416,7 @@ bool UsbAsyncApiFunction::Respond() { return error_.empty(); } -scoped_refptr<UsbDevice> -UsbAsyncApiFunction::GetDeviceOrOrCompleteWithError( +scoped_refptr<UsbDevice> UsbAsyncApiFunction::GetDeviceOrOrCompleteWithError( const Device& input_device) { const uint16_t vendor_id = input_device.vendor_id; const uint16_t product_id = input_device.product_id; @@ -489,9 +490,11 @@ void UsbAsyncApiFunction::CompleteWithError(const std::string& error) { AsyncWorkCompleted(); } -UsbAsyncApiTransferFunction::UsbAsyncApiTransferFunction() {} +UsbAsyncApiTransferFunction::UsbAsyncApiTransferFunction() { +} -UsbAsyncApiTransferFunction::~UsbAsyncApiTransferFunction() {} +UsbAsyncApiTransferFunction::~UsbAsyncApiTransferFunction() { +} void UsbAsyncApiTransferFunction::OnCompleted(UsbTransferStatus status, scoped_refptr<net::IOBuffer> data, @@ -504,7 +507,8 @@ void UsbAsyncApiTransferFunction::OnCompleted(UsbTransferStatus status, } bool UsbAsyncApiTransferFunction::ConvertDirectionSafely( - const Direction& input, UsbEndpointDirection* output) { + const Direction& input, + UsbEndpointDirection* output) { const bool converted = ConvertDirection(input, output); if (!converted) SetError(kErrorConvertDirection); @@ -512,7 +516,8 @@ bool UsbAsyncApiTransferFunction::ConvertDirectionSafely( } bool UsbAsyncApiTransferFunction::ConvertRequestTypeSafely( - const RequestType& input, UsbDeviceHandle::TransferRequestType* output) { + const RequestType& input, + UsbDeviceHandle::TransferRequestType* output) { const bool converted = ConvertRequestType(input, output); if (!converted) SetError(kErrorConvertRequestType); @@ -520,16 +525,19 @@ bool UsbAsyncApiTransferFunction::ConvertRequestTypeSafely( } bool UsbAsyncApiTransferFunction::ConvertRecipientSafely( - const Recipient& input, UsbDeviceHandle::TransferRecipient* output) { + const Recipient& input, + UsbDeviceHandle::TransferRecipient* output) { const bool converted = ConvertRecipient(input, output); if (!converted) SetError(kErrorConvertRecipient); return converted; } -UsbFindDevicesFunction::UsbFindDevicesFunction() {} +UsbFindDevicesFunction::UsbFindDevicesFunction() { +} -UsbFindDevicesFunction::~UsbFindDevicesFunction() {} +UsbFindDevicesFunction::~UsbFindDevicesFunction() { +} bool UsbFindDevicesFunction::Prepare() { parameters_ = FindDevices::Params::Create(*args_); @@ -539,12 +547,11 @@ bool UsbFindDevicesFunction::Prepare() { void UsbFindDevicesFunction::AsyncWorkStart() { scoped_ptr<base::ListValue> result(new base::ListValue()); - const uint16_t vendor_id = parameters_->options.vendor_id; const uint16_t product_id = parameters_->options.product_id; - int interface_id = parameters_->options.interface_id.get() ? - *parameters_->options.interface_id.get() : - UsbDevicePermissionData::ANY_INTERFACE; + int interface_id = parameters_->options.interface_id.get() + ? *parameters_->options.interface_id.get() + : UsbDevicePermissionData::ANY_INTERFACE; UsbDevicePermission::CheckParam param(vendor_id, product_id, interface_id); if (!PermissionsData::CheckAPIPermissionWithParam( GetExtension(), APIPermission::kUsbDevice, ¶m)) { @@ -553,7 +560,7 @@ void UsbFindDevicesFunction::AsyncWorkStart() { return; } - UsbService *service = UsbService::GetInstance(); + UsbService* service = UsbService::GetInstance(); if (!service) { CompleteWithError(kErrorInitService); return; @@ -562,8 +569,7 @@ void UsbFindDevicesFunction::AsyncWorkStart() { ScopedDeviceVector devices(new DeviceVector()); service->GetDevices(devices.get()); - for (DeviceVector::iterator it = devices->begin(); - it != devices->end();) { + for (DeviceVector::iterator it = devices->begin(); it != devices->end();) { if ((*it)->vendor_id() != vendor_id || (*it)->product_id() != product_id) { it = devices->erase(it); } else { @@ -573,7 +579,8 @@ void UsbFindDevicesFunction::AsyncWorkStart() { #if defined(OS_CHROMEOS) RequestUsbDevicesAccess( - devices.Pass(), interface_id, + devices.Pass(), + interface_id, base::Bind(&UsbFindDevicesFunction::OpenDevices, this)); #else OpenDevices(devices.Pass()); @@ -584,8 +591,7 @@ void UsbFindDevicesFunction::OpenDevices(ScopedDeviceVector devices) { base::ListValue* result = new base::ListValue(); for (size_t i = 0; i < devices->size(); ++i) { - scoped_refptr<UsbDeviceHandle> device_handle = - devices->at(i)->Open(); + scoped_refptr<UsbDeviceHandle> device_handle = devices->at(i)->Open(); if (device_handle) device_handles_.push_back(device_handle); } @@ -596,8 +602,8 @@ void UsbFindDevicesFunction::OpenDevices(ScopedDeviceVector devices) { new UsbDeviceResource(extension_->id(), device_handle); result->Append(PopulateConnectionHandle(manager_->Add(resource), - parameters_->options.vendor_id, - parameters_->options.product_id)); + parameters_->options.vendor_id, + parameters_->options.product_id)); } SetResult(result); @@ -655,9 +661,11 @@ void UsbGetDevicesFunction::AsyncWorkStart() { AsyncWorkCompleted(); } -UsbRequestAccessFunction::UsbRequestAccessFunction() {} +UsbRequestAccessFunction::UsbRequestAccessFunction() { +} -UsbRequestAccessFunction::~UsbRequestAccessFunction() {} +UsbRequestAccessFunction::~UsbRequestAccessFunction() { +} bool UsbRequestAccessFunction::Prepare() { parameters_ = RequestAccess::Params::Create(*args_); @@ -669,11 +677,12 @@ void UsbRequestAccessFunction::AsyncWorkStart() { #if defined(OS_CHROMEOS) scoped_refptr<UsbDevice> device = GetDeviceOrOrCompleteWithError(parameters_->device); - if (!device) return; + if (!device) + return; - device->RequestUsbAcess(parameters_->interface_id, - base::Bind(&UsbRequestAccessFunction::OnCompleted, - this)); + device->RequestUsbAcess( + parameters_->interface_id, + base::Bind(&UsbRequestAccessFunction::OnCompleted, this)); #else SetResult(new base::FundamentalValue(false)); CompleteWithError(kErrorNotSupported); @@ -685,9 +694,11 @@ void UsbRequestAccessFunction::OnCompleted(bool success) { AsyncWorkCompleted(); } -UsbOpenDeviceFunction::UsbOpenDeviceFunction() {} +UsbOpenDeviceFunction::UsbOpenDeviceFunction() { +} -UsbOpenDeviceFunction::~UsbOpenDeviceFunction() {} +UsbOpenDeviceFunction::~UsbOpenDeviceFunction() { +} bool UsbOpenDeviceFunction::Prepare() { parameters_ = OpenDevice::Params::Create(*args_); @@ -698,7 +709,8 @@ bool UsbOpenDeviceFunction::Prepare() { void UsbOpenDeviceFunction::AsyncWorkStart() { scoped_refptr<UsbDevice> device = GetDeviceOrOrCompleteWithError(parameters_->device); - if (!device) return; + if (!device) + return; handle_ = device->Open(); if (!handle_) { @@ -714,9 +726,11 @@ void UsbOpenDeviceFunction::AsyncWorkStart() { AsyncWorkCompleted(); } -UsbListInterfacesFunction::UsbListInterfacesFunction() {} +UsbListInterfacesFunction::UsbListInterfacesFunction() { +} -UsbListInterfacesFunction::~UsbListInterfacesFunction() {} +UsbListInterfacesFunction::~UsbListInterfacesFunction() { +} bool UsbListInterfacesFunction::Prepare() { parameters_ = ListInterfaces::Params::Create(*args_); @@ -727,7 +741,8 @@ bool UsbListInterfacesFunction::Prepare() { void UsbListInterfacesFunction::AsyncWorkStart() { scoped_refptr<UsbDeviceHandle> device_handle = GetDeviceHandleOrCompleteWithError(parameters_->handle); - if (!device_handle) return; + if (!device_handle) + return; scoped_refptr<UsbConfigDescriptor> config = device_handle->device()->ListInterfaces(); @@ -741,18 +756,21 @@ void UsbListInterfacesFunction::AsyncWorkStart() { result_.reset(new base::ListValue()); for (size_t i = 0, num_interfaces = config->GetNumInterfaces(); - i < num_interfaces; ++i) { - scoped_refptr<const UsbInterfaceDescriptor> - usb_interface(config->GetInterface(i)); + i < num_interfaces; + ++i) { + scoped_refptr<const UsbInterfaceDescriptor> usb_interface( + config->GetInterface(i)); for (size_t j = 0, num_descriptors = usb_interface->GetNumAltSettings(); - j < num_descriptors; ++j) { - scoped_refptr<const UsbInterfaceAltSettingDescriptor> descriptor - = usb_interface->GetAltSetting(j); + j < num_descriptors; + ++j) { + scoped_refptr<const UsbInterfaceAltSettingDescriptor> descriptor = + usb_interface->GetAltSetting(j); std::vector<linked_ptr<EndpointDescriptor> > endpoints; for (size_t k = 0, num_endpoints = descriptor->GetNumEndpoints(); - k < num_endpoints; k++) { - scoped_refptr<const UsbEndpointDescriptor> endpoint - = descriptor->GetEndpoint(k); + k < num_endpoints; + k++) { + scoped_refptr<const UsbEndpointDescriptor> endpoint = + descriptor->GetEndpoint(k); linked_ptr<EndpointDescriptor> endpoint_desc(new EndpointDescriptor()); TransferType type; @@ -784,13 +802,13 @@ void UsbListInterfacesFunction::AsyncWorkStart() { endpoints.push_back(endpoint_desc); } - result_->Append(PopulateInterfaceDescriptor( - descriptor->GetInterfaceNumber(), - descriptor->GetAlternateSetting(), - descriptor->GetInterfaceClass(), - descriptor->GetInterfaceSubclass(), - descriptor->GetInterfaceProtocol(), - &endpoints)); + result_->Append( + PopulateInterfaceDescriptor(descriptor->GetInterfaceNumber(), + descriptor->GetAlternateSetting(), + descriptor->GetInterfaceClass(), + descriptor->GetInterfaceSubclass(), + descriptor->GetInterfaceProtocol(), + &endpoints)); } } @@ -834,9 +852,11 @@ bool UsbListInterfacesFunction::ConvertUsageTypeSafely( return converted; } -UsbCloseDeviceFunction::UsbCloseDeviceFunction() {} +UsbCloseDeviceFunction::UsbCloseDeviceFunction() { +} -UsbCloseDeviceFunction::~UsbCloseDeviceFunction() {} +UsbCloseDeviceFunction::~UsbCloseDeviceFunction() { +} bool UsbCloseDeviceFunction::Prepare() { parameters_ = CloseDevice::Params::Create(*args_); @@ -847,16 +867,19 @@ bool UsbCloseDeviceFunction::Prepare() { void UsbCloseDeviceFunction::AsyncWorkStart() { scoped_refptr<UsbDeviceHandle> device_handle = GetDeviceHandleOrCompleteWithError(parameters_->handle); - if (!device_handle) return; + if (!device_handle) + return; device_handle->Close(); RemoveUsbDeviceResource(parameters_->handle.handle); AsyncWorkCompleted(); } -UsbClaimInterfaceFunction::UsbClaimInterfaceFunction() {} +UsbClaimInterfaceFunction::UsbClaimInterfaceFunction() { +} -UsbClaimInterfaceFunction::~UsbClaimInterfaceFunction() {} +UsbClaimInterfaceFunction::~UsbClaimInterfaceFunction() { +} bool UsbClaimInterfaceFunction::Prepare() { parameters_ = ClaimInterface::Params::Create(*args_); @@ -867,7 +890,8 @@ bool UsbClaimInterfaceFunction::Prepare() { void UsbClaimInterfaceFunction::AsyncWorkStart() { scoped_refptr<UsbDeviceHandle> device_handle = GetDeviceHandleOrCompleteWithError(parameters_->handle); - if (!device_handle) return; + if (!device_handle) + return; bool success = device_handle->ClaimInterface(parameters_->interface_number); @@ -876,9 +900,11 @@ void UsbClaimInterfaceFunction::AsyncWorkStart() { AsyncWorkCompleted(); } -UsbReleaseInterfaceFunction::UsbReleaseInterfaceFunction() {} +UsbReleaseInterfaceFunction::UsbReleaseInterfaceFunction() { +} -UsbReleaseInterfaceFunction::~UsbReleaseInterfaceFunction() {} +UsbReleaseInterfaceFunction::~UsbReleaseInterfaceFunction() { +} bool UsbReleaseInterfaceFunction::Prepare() { parameters_ = ReleaseInterface::Params::Create(*args_); @@ -889,7 +915,8 @@ bool UsbReleaseInterfaceFunction::Prepare() { void UsbReleaseInterfaceFunction::AsyncWorkStart() { scoped_refptr<UsbDeviceHandle> device_handle = GetDeviceHandleOrCompleteWithError(parameters_->handle); - if (!device_handle) return; + if (!device_handle) + return; bool success = device_handle->ReleaseInterface(parameters_->interface_number); if (!success) @@ -898,10 +925,12 @@ void UsbReleaseInterfaceFunction::AsyncWorkStart() { } UsbSetInterfaceAlternateSettingFunction:: - UsbSetInterfaceAlternateSettingFunction() {} + UsbSetInterfaceAlternateSettingFunction() { +} UsbSetInterfaceAlternateSettingFunction:: - ~UsbSetInterfaceAlternateSettingFunction() {} + ~UsbSetInterfaceAlternateSettingFunction() { +} bool UsbSetInterfaceAlternateSettingFunction::Prepare() { parameters_ = SetInterfaceAlternateSetting::Params::Create(*args_); @@ -912,20 +941,22 @@ bool UsbSetInterfaceAlternateSettingFunction::Prepare() { void UsbSetInterfaceAlternateSettingFunction::AsyncWorkStart() { scoped_refptr<UsbDeviceHandle> device_handle = GetDeviceHandleOrCompleteWithError(parameters_->handle); - if (!device_handle) return; + if (!device_handle) + return; bool success = device_handle->SetInterfaceAlternateSetting( - parameters_->interface_number, - parameters_->alternate_setting); + parameters_->interface_number, parameters_->alternate_setting); if (!success) SetError(kErrorCannotSetInterfaceAlternateSetting); AsyncWorkCompleted(); } -UsbControlTransferFunction::UsbControlTransferFunction() {} +UsbControlTransferFunction::UsbControlTransferFunction() { +} -UsbControlTransferFunction::~UsbControlTransferFunction() {} +UsbControlTransferFunction::~UsbControlTransferFunction() { +} bool UsbControlTransferFunction::Prepare() { parameters_ = ControlTransfer::Params::Create(*args_); @@ -936,7 +967,8 @@ bool UsbControlTransferFunction::Prepare() { void UsbControlTransferFunction::AsyncWorkStart() { scoped_refptr<UsbDeviceHandle> device_handle = GetDeviceHandleOrCompleteWithError(parameters_->handle); - if (!device_handle) return; + if (!device_handle) + return; const ControlTransferInfo& transfer = parameters_->transfer_info; @@ -957,8 +989,8 @@ void UsbControlTransferFunction::AsyncWorkStart() { return; } - scoped_refptr<net::IOBuffer> buffer = CreateBufferForTransfer( - transfer, direction, size); + scoped_refptr<net::IOBuffer> buffer = + CreateBufferForTransfer(transfer, direction, size); if (!buffer.get()) { CompleteWithError(kErrorMalformedParameters); return; @@ -977,9 +1009,11 @@ void UsbControlTransferFunction::AsyncWorkStart() { base::Bind(&UsbControlTransferFunction::OnCompleted, this)); } -UsbBulkTransferFunction::UsbBulkTransferFunction() {} +UsbBulkTransferFunction::UsbBulkTransferFunction() { +} -UsbBulkTransferFunction::~UsbBulkTransferFunction() {} +UsbBulkTransferFunction::~UsbBulkTransferFunction() { +} bool UsbBulkTransferFunction::Prepare() { parameters_ = BulkTransfer::Params::Create(*args_); @@ -990,7 +1024,8 @@ bool UsbBulkTransferFunction::Prepare() { void UsbBulkTransferFunction::AsyncWorkStart() { scoped_refptr<UsbDeviceHandle> device_handle = GetDeviceHandleOrCompleteWithError(parameters_->handle); - if (!device_handle) return; + if (!device_handle) + return; const GenericTransferInfo& transfer = parameters_->transfer_info; @@ -1007,8 +1042,8 @@ void UsbBulkTransferFunction::AsyncWorkStart() { return; } - scoped_refptr<net::IOBuffer> buffer = CreateBufferForTransfer( - transfer, direction, size); + scoped_refptr<net::IOBuffer> buffer = + CreateBufferForTransfer(transfer, direction, size); if (!buffer.get()) { CompleteWithError(kErrorMalformedParameters); return; @@ -1023,9 +1058,11 @@ void UsbBulkTransferFunction::AsyncWorkStart() { base::Bind(&UsbBulkTransferFunction::OnCompleted, this)); } -UsbInterruptTransferFunction::UsbInterruptTransferFunction() {} +UsbInterruptTransferFunction::UsbInterruptTransferFunction() { +} -UsbInterruptTransferFunction::~UsbInterruptTransferFunction() {} +UsbInterruptTransferFunction::~UsbInterruptTransferFunction() { +} bool UsbInterruptTransferFunction::Prepare() { parameters_ = InterruptTransfer::Params::Create(*args_); @@ -1036,7 +1073,8 @@ bool UsbInterruptTransferFunction::Prepare() { void UsbInterruptTransferFunction::AsyncWorkStart() { scoped_refptr<UsbDeviceHandle> device_handle = GetDeviceHandleOrCompleteWithError(parameters_->handle); - if (!device_handle) return; + if (!device_handle) + return; const GenericTransferInfo& transfer = parameters_->transfer_info; @@ -1053,8 +1091,8 @@ void UsbInterruptTransferFunction::AsyncWorkStart() { return; } - scoped_refptr<net::IOBuffer> buffer = CreateBufferForTransfer( - transfer, direction, size); + scoped_refptr<net::IOBuffer> buffer = + CreateBufferForTransfer(transfer, direction, size); if (!buffer.get()) { CompleteWithError(kErrorMalformedParameters); return; @@ -1069,9 +1107,11 @@ void UsbInterruptTransferFunction::AsyncWorkStart() { base::Bind(&UsbInterruptTransferFunction::OnCompleted, this)); } -UsbIsochronousTransferFunction::UsbIsochronousTransferFunction() {} +UsbIsochronousTransferFunction::UsbIsochronousTransferFunction() { +} -UsbIsochronousTransferFunction::~UsbIsochronousTransferFunction() {} +UsbIsochronousTransferFunction::~UsbIsochronousTransferFunction() { +} bool UsbIsochronousTransferFunction::Prepare() { parameters_ = IsochronousTransfer::Params::Create(*args_); @@ -1082,7 +1122,8 @@ bool UsbIsochronousTransferFunction::Prepare() { void UsbIsochronousTransferFunction::AsyncWorkStart() { scoped_refptr<UsbDeviceHandle> device_handle = GetDeviceHandleOrCompleteWithError(parameters_->handle); - if (!device_handle) return; + if (!device_handle) + return; const IsochronousTransferInfo& transfer = parameters_->transfer_info; const GenericTransferInfo& generic_transfer = transfer.transfer_info; @@ -1115,8 +1156,8 @@ void UsbIsochronousTransferFunction::AsyncWorkStart() { return; } - scoped_refptr<net::IOBuffer> buffer = CreateBufferForTransfer( - generic_transfer, direction, size); + scoped_refptr<net::IOBuffer> buffer = + CreateBufferForTransfer(generic_transfer, direction, size); if (!buffer.get()) { CompleteWithError(kErrorMalformedParameters); return; @@ -1133,9 +1174,11 @@ void UsbIsochronousTransferFunction::AsyncWorkStart() { base::Bind(&UsbIsochronousTransferFunction::OnCompleted, this)); } -UsbResetDeviceFunction::UsbResetDeviceFunction() {} +UsbResetDeviceFunction::UsbResetDeviceFunction() { +} -UsbResetDeviceFunction::~UsbResetDeviceFunction() {} +UsbResetDeviceFunction::~UsbResetDeviceFunction() { +} bool UsbResetDeviceFunction::Prepare() { parameters_ = ResetDevice::Params::Create(*args_); @@ -1146,7 +1189,8 @@ bool UsbResetDeviceFunction::Prepare() { void UsbResetDeviceFunction::AsyncWorkStart() { scoped_refptr<UsbDeviceHandle> device_handle = GetDeviceHandleOrCompleteWithError(parameters_->handle); - if (!device_handle) return; + if (!device_handle) + return; bool success = device_handle->ResetDevice(); if (!success) { diff --git a/chrome/browser/extensions/api/usb/usb_api.h b/extensions/browser/api/usb/usb_api.h index a2f38ab..3dd0d2b 100644 --- a/chrome/browser/extensions/api/usb/usb_api.h +++ b/extensions/browser/api/usb/usb_api.h @@ -1,20 +1,20 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ -#define CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ +#ifndef EXTENSIONS_BROWSER_API_USB_USB_API_H_ +#define EXTENSIONS_BROWSER_API_USB_USB_API_H_ #include <string> #include <vector> #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "chrome/common/extensions/api/usb.h" #include "components/usb_service/usb_device.h" #include "components/usb_service/usb_device_handle.h" #include "extensions/browser/api/api_resource_manager.h" #include "extensions/browser/api/async_api_function.h" +#include "extensions/common/api/usb.h" #include "net/base/io_buffer.h" namespace extensions { @@ -32,11 +32,12 @@ class UsbAsyncApiFunction : public AsyncApiFunction { virtual bool Respond() OVERRIDE; scoped_refptr<usb_service::UsbDevice> GetDeviceOrOrCompleteWithError( - const extensions::api::usb::Device& input_device); + const extensions::core_api::usb::Device& input_device); scoped_refptr<usb_service::UsbDeviceHandle> GetDeviceHandleOrCompleteWithError( - const extensions::api::usb::ConnectionHandle& input_device_handle); + const extensions::core_api::usb::ConnectionHandle& + input_device_handle); void RemoveUsbDeviceResource(int api_resource_id); @@ -50,13 +51,13 @@ class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction { UsbAsyncApiTransferFunction(); virtual ~UsbAsyncApiTransferFunction(); - bool ConvertDirectionSafely(const extensions::api::usb::Direction& input, + bool ConvertDirectionSafely(const extensions::core_api::usb::Direction& input, usb_service::UsbEndpointDirection* output); bool ConvertRequestTypeSafely( - const extensions::api::usb::RequestType& input, + const extensions::core_api::usb::RequestType& input, usb_service::UsbDeviceHandle::TransferRequestType* output); bool ConvertRecipientSafely( - const extensions::api::usb::Recipient& input, + const extensions::core_api::usb::Recipient& input, usb_service::UsbDeviceHandle::TransferRecipient* output); void OnCompleted(usb_service::UsbTransferStatus status, @@ -81,7 +82,7 @@ class UsbFindDevicesFunction : public UsbAsyncApiFunction { scoped_ptr<std::vector<scoped_refptr<usb_service::UsbDevice> > > devices); std::vector<scoped_refptr<usb_service::UsbDeviceHandle> > device_handles_; - scoped_ptr<extensions::api::usb::FindDevices::Params> parameters_; + scoped_ptr<extensions::core_api::usb::FindDevices::Params> parameters_; }; class UsbGetDevicesFunction : public UsbAsyncApiFunction { @@ -100,7 +101,7 @@ class UsbGetDevicesFunction : public UsbAsyncApiFunction { void EnumerationCompletedFileThread( scoped_ptr<std::vector<scoped_refptr<usb_service::UsbDevice> > > devices); - scoped_ptr<extensions::api::usb::GetDevices::Params> parameters_; + scoped_ptr<extensions::core_api::usb::GetDevices::Params> parameters_; }; class UsbRequestAccessFunction : public UsbAsyncApiFunction { @@ -118,7 +119,7 @@ class UsbRequestAccessFunction : public UsbAsyncApiFunction { void OnCompleted(bool success); private: - scoped_ptr<extensions::api::usb::RequestAccess::Params> parameters_; + scoped_ptr<extensions::core_api::usb::RequestAccess::Params> parameters_; }; class UsbOpenDeviceFunction : public UsbAsyncApiFunction { @@ -135,7 +136,7 @@ class UsbOpenDeviceFunction : public UsbAsyncApiFunction { private: scoped_refptr<usb_service::UsbDeviceHandle> handle_; - scoped_ptr<extensions::api::usb::OpenDevice::Params> parameters_; + scoped_ptr<extensions::core_api::usb::OpenDevice::Params> parameters_; }; class UsbListInterfacesFunction : public UsbAsyncApiFunction { @@ -152,17 +153,18 @@ class UsbListInterfacesFunction : public UsbAsyncApiFunction { private: bool ConvertDirectionSafely(const usb_service::UsbEndpointDirection& input, - extensions::api::usb::Direction* output); + extensions::core_api::usb::Direction* output); bool ConvertSynchronizationTypeSafely( const usb_service::UsbSynchronizationType& input, - extensions::api::usb::SynchronizationType* output); - bool ConvertTransferTypeSafely(const usb_service::UsbTransferType& input, - extensions::api::usb::TransferType* output); + extensions::core_api::usb::SynchronizationType* output); + bool ConvertTransferTypeSafely( + const usb_service::UsbTransferType& input, + extensions::core_api::usb::TransferType* output); bool ConvertUsageTypeSafely(const usb_service::UsbUsageType& input, - extensions::api::usb::UsageType* output); + extensions::core_api::usb::UsageType* output); scoped_ptr<base::ListValue> result_; - scoped_ptr<extensions::api::usb::ListInterfaces::Params> parameters_; + scoped_ptr<extensions::core_api::usb::ListInterfaces::Params> parameters_; }; class UsbCloseDeviceFunction : public UsbAsyncApiFunction { @@ -178,7 +180,7 @@ class UsbCloseDeviceFunction : public UsbAsyncApiFunction { virtual void AsyncWorkStart() OVERRIDE; private: - scoped_ptr<extensions::api::usb::CloseDevice::Params> parameters_; + scoped_ptr<extensions::core_api::usb::CloseDevice::Params> parameters_; }; class UsbClaimInterfaceFunction : public UsbAsyncApiFunction { @@ -194,7 +196,7 @@ class UsbClaimInterfaceFunction : public UsbAsyncApiFunction { virtual void AsyncWorkStart() OVERRIDE; private: - scoped_ptr<extensions::api::usb::ClaimInterface::Params> parameters_; + scoped_ptr<extensions::core_api::usb::ClaimInterface::Params> parameters_; }; class UsbReleaseInterfaceFunction : public UsbAsyncApiFunction { @@ -210,7 +212,7 @@ class UsbReleaseInterfaceFunction : public UsbAsyncApiFunction { virtual void AsyncWorkStart() OVERRIDE; private: - scoped_ptr<extensions::api::usb::ReleaseInterface::Params> parameters_; + scoped_ptr<extensions::core_api::usb::ReleaseInterface::Params> parameters_; }; class UsbSetInterfaceAlternateSettingFunction : public UsbAsyncApiFunction { @@ -226,7 +228,7 @@ class UsbSetInterfaceAlternateSettingFunction : public UsbAsyncApiFunction { virtual bool Prepare() OVERRIDE; virtual void AsyncWorkStart() OVERRIDE; - scoped_ptr<extensions::api::usb::SetInterfaceAlternateSetting::Params> + scoped_ptr<extensions::core_api::usb::SetInterfaceAlternateSetting::Params> parameters_; }; @@ -243,7 +245,7 @@ class UsbControlTransferFunction : public UsbAsyncApiTransferFunction { virtual void AsyncWorkStart() OVERRIDE; private: - scoped_ptr<extensions::api::usb::ControlTransfer::Params> parameters_; + scoped_ptr<extensions::core_api::usb::ControlTransfer::Params> parameters_; }; class UsbBulkTransferFunction : public UsbAsyncApiTransferFunction { @@ -259,7 +261,7 @@ class UsbBulkTransferFunction : public UsbAsyncApiTransferFunction { virtual void AsyncWorkStart() OVERRIDE; private: - scoped_ptr<extensions::api::usb::BulkTransfer::Params> parameters_; + scoped_ptr<extensions::core_api::usb::BulkTransfer::Params> parameters_; }; class UsbInterruptTransferFunction : public UsbAsyncApiTransferFunction { @@ -275,7 +277,7 @@ class UsbInterruptTransferFunction : public UsbAsyncApiTransferFunction { virtual void AsyncWorkStart() OVERRIDE; private: - scoped_ptr<extensions::api::usb::InterruptTransfer::Params> parameters_; + scoped_ptr<extensions::core_api::usb::InterruptTransfer::Params> parameters_; }; class UsbIsochronousTransferFunction : public UsbAsyncApiTransferFunction { @@ -291,7 +293,8 @@ class UsbIsochronousTransferFunction : public UsbAsyncApiTransferFunction { virtual void AsyncWorkStart() OVERRIDE; private: - scoped_ptr<extensions::api::usb::IsochronousTransfer::Params> parameters_; + scoped_ptr<extensions::core_api::usb::IsochronousTransfer::Params> + parameters_; }; class UsbResetDeviceFunction : public UsbAsyncApiFunction { @@ -307,8 +310,8 @@ class UsbResetDeviceFunction : public UsbAsyncApiFunction { virtual void AsyncWorkStart() OVERRIDE; private: - scoped_ptr<extensions::api::usb::ResetDevice::Params> parameters_; + scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_; }; } // namespace extensions -#endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ +#endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_ diff --git a/chrome/browser/extensions/api/usb/usb_apitest.cc b/extensions/browser/api/usb/usb_apitest.cc index da67ff7..455c663 100644 --- a/chrome/browser/extensions/api/usb/usb_apitest.cc +++ b/extensions/browser/api/usb/usb_apitest.cc @@ -1,13 +1,13 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/extensions/api/usb/usb_api.h" #include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/ui/browser.h" #include "components/usb_service/usb_service.h" #include "content/public/browser/browser_thread.h" #include "content/public/test/test_utils.h" +#include "extensions/browser/api/usb/usb_api.h" #include "net/base/io_buffer.h" #include "testing/gmock/include/gmock/gmock.h" @@ -35,7 +35,7 @@ ACTION_TEMPLATE(InvokeUsbTransferCallback, // standards-noncompliant behaviour of their compiler. #if defined(OS_WIN) #pragma warning(push) -#pragma warning(disable:4373) +#pragma warning(disable : 4373) #endif class MockUsbDeviceHandle : public UsbDeviceHandle { @@ -44,24 +44,43 @@ class MockUsbDeviceHandle : public UsbDeviceHandle { MOCK_METHOD0(Close, void()); - MOCK_METHOD10(ControlTransfer, void(const UsbEndpointDirection direction, - const TransferRequestType request_type, const TransferRecipient recipient, - const uint8 request, const uint16 value, const uint16 index, - net::IOBuffer* buffer, const size_t length, const unsigned int timeout, - const UsbTransferCallback& callback)); - - MOCK_METHOD6(BulkTransfer, void(const UsbEndpointDirection direction, - const uint8 endpoint, net::IOBuffer* buffer, const size_t length, - const unsigned int timeout, const UsbTransferCallback& callback)); - - MOCK_METHOD6(InterruptTransfer, void(const UsbEndpointDirection direction, - const uint8 endpoint, net::IOBuffer* buffer, const size_t length, - const unsigned int timeout, const UsbTransferCallback& callback)); - - MOCK_METHOD8(IsochronousTransfer, void(const UsbEndpointDirection direction, - const uint8 endpoint, net::IOBuffer* buffer, const size_t length, - const unsigned int packets, const unsigned int packet_length, - const unsigned int timeout, const UsbTransferCallback& callback)); + MOCK_METHOD10(ControlTransfer, + void(const UsbEndpointDirection direction, + const TransferRequestType request_type, + const TransferRecipient recipient, + const uint8 request, + const uint16 value, + const uint16 index, + net::IOBuffer* buffer, + const size_t length, + const unsigned int timeout, + const UsbTransferCallback& callback)); + + MOCK_METHOD6(BulkTransfer, + void(const UsbEndpointDirection direction, + const uint8 endpoint, + net::IOBuffer* buffer, + const size_t length, + const unsigned int timeout, + const UsbTransferCallback& callback)); + + MOCK_METHOD6(InterruptTransfer, + void(const UsbEndpointDirection direction, + const uint8 endpoint, + net::IOBuffer* buffer, + const size_t length, + const unsigned int timeout, + const UsbTransferCallback& callback)); + + MOCK_METHOD8(IsochronousTransfer, + void(const UsbEndpointDirection direction, + const uint8 endpoint, + net::IOBuffer* buffer, + const size_t length, + const unsigned int packets, + const unsigned int packet_length, + const unsigned int timeout, + const UsbTransferCallback& callback)); MOCK_METHOD0(ResetDevice, bool()); @@ -82,8 +101,7 @@ class MockUsbConfigDescriptor : public UsbConfigDescriptor { class MockUsbDevice : public UsbDevice { public: explicit MockUsbDevice(MockUsbDeviceHandle* mock_handle) - : UsbDevice(), - mock_handle_(mock_handle) { + : UsbDevice(), mock_handle_(mock_handle) { mock_handle->set_device(this); } @@ -205,7 +223,13 @@ IN_PROC_BROWSER_TEST_F(UsbApiTest, TransferEvent) { ControlTransfer(usb_service::USB_DIRECTION_OUTBOUND, UsbDeviceHandle::STANDARD, UsbDeviceHandle::DEVICE, - 1, 2, 3, _, 1, _, _)) + 1, + 2, + 3, + _, + 1, + _, + _)) .WillOnce( InvokeUsbTransferCallback<9>(usb_service::USB_TRANSFER_COMPLETED)); EXPECT_CALL(*mock_device_handle_.get(), diff --git a/chrome/browser/extensions/api/usb/usb_device_resource.cc b/extensions/browser/api/usb/usb_device_resource.cc index 633635d..030de7b 100644 --- a/chrome/browser/extensions/api/usb/usb_device_resource.cc +++ b/extensions/browser/api/usb/usb_device_resource.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/extensions/api/usb/usb_device_resource.h" +#include "extensions/browser/api/usb/usb_device_resource.h" #include <string> #include <vector> @@ -10,10 +10,10 @@ #include "base/bind.h" #include "base/bind_helpers.h" #include "base/synchronization/lock.h" -#include "chrome/common/extensions/api/usb.h" #include "components/usb_service/usb_device_handle.h" #include "content/public/browser/browser_thread.h" #include "extensions/browser/api/api_resource.h" +#include "extensions/common/api/usb.h" using content::BrowserThread; using usb_service::UsbDeviceHandle; @@ -33,7 +33,8 @@ ApiResourceManager<UsbDeviceResource>::GetFactoryInstance() { UsbDeviceResource::UsbDeviceResource(const std::string& owner_extension_id, scoped_refptr<UsbDeviceHandle> device) - : ApiResource(owner_extension_id), device_(device) {} + : ApiResource(owner_extension_id), device_(device) { +} UsbDeviceResource::~UsbDeviceResource() { BrowserThread::PostTask(BrowserThread::FILE, diff --git a/chrome/browser/extensions/api/usb/usb_device_resource.h b/extensions/browser/api/usb/usb_device_resource.h index f07f2dc..cb6cbbe 100644 --- a/chrome/browser/extensions/api/usb/usb_device_resource.h +++ b/extensions/browser/api/usb/usb_device_resource.h @@ -1,9 +1,9 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_ -#define CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_ +#ifndef EXTENSIONS_BROWSER_API_USB_USB_DEVICE_RESOURCE_H_ +#define EXTENSIONS_BROWSER_API_USB_USB_DEVICE_RESOURCE_H_ #include <set> #include <string> @@ -12,11 +12,11 @@ #include "base/memory/linked_ptr.h" #include "base/memory/ref_counted.h" #include "base/synchronization/lock.h" -#include "chrome/common/extensions/api/usb.h" #include "components/usb_service/usb_device_handle.h" #include "content/public/browser/browser_thread.h" #include "extensions/browser/api/api_resource.h" #include "extensions/browser/api/api_resource_manager.h" +#include "extensions/common/api/usb.h" namespace net { class IOBuffer; @@ -47,4 +47,4 @@ class UsbDeviceResource : public ApiResource { } // namespace extensions -#endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_ +#endif // EXTENSIONS_BROWSER_API_USB_USB_DEVICE_RESOURCE_H_ diff --git a/chrome/browser/extensions/api/usb/usb_manual_apitest.cc b/extensions/browser/api/usb/usb_manual_apitest.cc index be08a8a34..d28be9d 100644 --- a/chrome/browser/extensions/api/usb/usb_manual_apitest.cc +++ b/extensions/browser/api/usb/usb_manual_apitest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,8 +7,7 @@ namespace { -class UsbManualApiTest : public ExtensionApiTest { -}; +class UsbManualApiTest : public ExtensionApiTest {}; } // namespace diff --git a/extensions/common/api/_api_features.json b/extensions/common/api/_api_features.json index cae93b1..4ea9b9e 100644 --- a/extensions/common/api/_api_features.json +++ b/extensions/common/api/_api_features.json @@ -39,5 +39,9 @@ "channel": "stable", "extension_types": "all", "contexts": ["blessed_extension", "unblessed_extension", "content_script"] + }, + "usb": { + "dependencies": ["permission:usb"], + "contexts": ["blessed_extension"] } } diff --git a/extensions/common/api/_permission_features.json b/extensions/common/api/_permission_features.json index a1e975b..3447aac 100644 --- a/extensions/common/api/_permission_features.json +++ b/extensions/common/api/_permission_features.json @@ -53,5 +53,33 @@ "channel": "stable", "extension_types": ["extension", "legacy_packaged_app", "platform_app"], "min_manifest_version": 2 - } + }, + "usb": [ + { + "channel": "stable", + "extension_types": ["platform_app"] + }, + { + "channel": "stable", + "extension_types": ["extension"], + "whitelist": [ + "496B6890097EB6E19809ADEADD095A8721FBB2E0", // FIDO U2F APIs + "E24F1786D842E91E74C27929B0B3715A4689A473" // CryptoToken + ] + } + ], + "usbDevices": [ + { + "channel": "stable", + "extension_types": ["platform_app"] + }, + { + "channel": "stable", + "extension_types": ["extension"], + "whitelist": [ + "496B6890097EB6E19809ADEADD095A8721FBB2E0", // FIDO U2F APIs + "E24F1786D842E91E74C27929B0B3715A4689A473" // CryptoToken + ] + } + ] } diff --git a/extensions/common/api/api.gyp b/extensions/common/api/api.gyp index 4e3c2b0..b124637 100644 --- a/extensions/common/api/api.gyp +++ b/extensions/common/api/api.gyp @@ -30,6 +30,7 @@ 'sockets_udp.idl', 'storage.json', 'test.json', + 'usb.idl', ], 'cc_dir': 'extensions/common/api', 'root_namespace': 'extensions::core_api', diff --git a/chrome/common/extensions/api/usb.idl b/extensions/common/api/usb.idl index 6b6b74c..278171e 100644 --- a/chrome/common/extensions/api/usb.idl +++ b/extensions/common/api/usb.idl @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index 4411dae6..faaa42bc 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -221,6 +221,7 @@ 'type': 'static_library', 'dependencies': [ '../components/components.gyp:keyed_service_content', + '../components/components.gyp:usb_service', '../content/content.gyp:content_browser', '../skia/skia.gyp:skia', '../third_party/leveldatabase/leveldatabase.gyp:leveldatabase', @@ -292,6 +293,10 @@ 'browser/api/storage/weak_unlimited_settings_storage.h', 'browser/api/test/test_api.cc', 'browser/api/test/test_api.h', + 'browser/api/usb/usb_api.cc', + 'browser/api/usb/usb_api.h', + 'browser/api/usb/usb_device_resource.cc', + 'browser/api/usb/usb_device_resource.h', 'browser/api_activity_monitor.h', 'browser/app_sorting.h', 'browser/blacklist_state.h', @@ -405,6 +410,9 @@ 'browser/browser_context_keyed_service_factories.cc', 'browser/browser_context_keyed_service_factories.h', ], + 'dependencies!': [ + '../components/components.gyp:usb_service', + ], }], ], # Disable c4267 warnings until we fix size_t to int truncations. |