| OLD | NEW |
| 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/hid/hid_api.h" | 5 #include "extensions/browser/api/hid/hid_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "device/core/device_client.h" | 11 #include "device/core/device_client.h" |
| 12 #include "device/hid/hid_connection.h" | 12 #include "device/hid/hid_connection.h" |
| 13 #include "device/hid/hid_device_filter.h" | 13 #include "device/hid/hid_device_filter.h" |
| 14 #include "device/hid/hid_device_info.h" | 14 #include "device/hid/hid_device_info.h" |
| 15 #include "device/hid/hid_service.h" | 15 #include "device/hid/hid_service.h" |
| 16 #include "extensions/browser/api/api_resource_manager.h" | 16 #include "extensions/browser/api/api_resource_manager.h" |
| 17 #include "extensions/browser/api/device_permissions_prompt.h" | 17 #include "extensions/browser/api/device_permissions_prompt.h" |
| 18 #include "extensions/browser/api/extensions_api_client.h" | 18 #include "extensions/browser/api/extensions_api_client.h" |
| 19 #include "extensions/common/api/hid.h" | 19 #include "extensions/common/api/hid.h" |
| 20 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
| 21 | 21 |
| 22 namespace hid = extensions::core_api::hid; | 22 namespace hid = extensions::api::hid; |
| 23 | 23 |
| 24 using device::HidConnection; | 24 using device::HidConnection; |
| 25 using device::HidDeviceFilter; | 25 using device::HidDeviceFilter; |
| 26 using device::HidDeviceInfo; | 26 using device::HidDeviceInfo; |
| 27 using device::HidService; | 27 using device::HidService; |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 const char kErrorPermissionDenied[] = "Permission to access device was denied."; | 31 const char kErrorPermissionDenied[] = "Permission to access device was denied."; |
| 32 const char kErrorInvalidDeviceId[] = "Invalid HID device ID."; | 32 const char kErrorInvalidDeviceId[] = "Invalid HID device ID."; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 namespace extensions { | 62 namespace extensions { |
| 63 | 63 |
| 64 HidGetDevicesFunction::HidGetDevicesFunction() {} | 64 HidGetDevicesFunction::HidGetDevicesFunction() {} |
| 65 | 65 |
| 66 HidGetDevicesFunction::~HidGetDevicesFunction() {} | 66 HidGetDevicesFunction::~HidGetDevicesFunction() {} |
| 67 | 67 |
| 68 ExtensionFunction::ResponseAction HidGetDevicesFunction::Run() { | 68 ExtensionFunction::ResponseAction HidGetDevicesFunction::Run() { |
| 69 scoped_ptr<core_api::hid::GetDevices::Params> parameters = | 69 scoped_ptr<api::hid::GetDevices::Params> parameters = |
| 70 hid::GetDevices::Params::Create(*args_); | 70 hid::GetDevices::Params::Create(*args_); |
| 71 EXTENSION_FUNCTION_VALIDATE(parameters); | 71 EXTENSION_FUNCTION_VALIDATE(parameters); |
| 72 | 72 |
| 73 HidDeviceManager* device_manager = HidDeviceManager::Get(browser_context()); | 73 HidDeviceManager* device_manager = HidDeviceManager::Get(browser_context()); |
| 74 CHECK(device_manager); | 74 CHECK(device_manager); |
| 75 | 75 |
| 76 std::vector<HidDeviceFilter> filters; | 76 std::vector<HidDeviceFilter> filters; |
| 77 if (parameters->options.filters) { | 77 if (parameters->options.filters) { |
| 78 filters.resize(parameters->options.filters->size()); | 78 filters.resize(parameters->options.filters->size()); |
| 79 for (size_t i = 0; i < parameters->options.filters->size(); ++i) { | 79 for (size_t i = 0; i < parameters->options.filters->size(); ++i) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 100 Respond(OneArgument(devices.release())); | 100 Respond(OneArgument(devices.release())); |
| 101 } | 101 } |
| 102 | 102 |
| 103 HidGetUserSelectedDevicesFunction::HidGetUserSelectedDevicesFunction() { | 103 HidGetUserSelectedDevicesFunction::HidGetUserSelectedDevicesFunction() { |
| 104 } | 104 } |
| 105 | 105 |
| 106 HidGetUserSelectedDevicesFunction::~HidGetUserSelectedDevicesFunction() { | 106 HidGetUserSelectedDevicesFunction::~HidGetUserSelectedDevicesFunction() { |
| 107 } | 107 } |
| 108 | 108 |
| 109 ExtensionFunction::ResponseAction HidGetUserSelectedDevicesFunction::Run() { | 109 ExtensionFunction::ResponseAction HidGetUserSelectedDevicesFunction::Run() { |
| 110 scoped_ptr<core_api::hid::GetUserSelectedDevices::Params> parameters = | 110 scoped_ptr<api::hid::GetUserSelectedDevices::Params> parameters = |
| 111 hid::GetUserSelectedDevices::Params::Create(*args_); | 111 hid::GetUserSelectedDevices::Params::Create(*args_); |
| 112 EXTENSION_FUNCTION_VALIDATE(parameters); | 112 EXTENSION_FUNCTION_VALIDATE(parameters); |
| 113 | 113 |
| 114 content::WebContents* web_contents = GetSenderWebContents(); | 114 content::WebContents* web_contents = GetSenderWebContents(); |
| 115 if (!web_contents || !user_gesture()) { | 115 if (!web_contents || !user_gesture()) { |
| 116 return RespondNow(OneArgument(new base::ListValue())); | 116 return RespondNow(OneArgument(new base::ListValue())); |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool multiple = false; | 119 bool multiple = false; |
| 120 std::vector<HidDeviceFilter> filters; | 120 std::vector<HidDeviceFilter> filters; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 144 CHECK(device_manager); | 144 CHECK(device_manager); |
| 145 Respond(OneArgument(device_manager->GetApiDevicesFromList(devices).Pass())); | 145 Respond(OneArgument(device_manager->GetApiDevicesFromList(devices).Pass())); |
| 146 } | 146 } |
| 147 | 147 |
| 148 HidConnectFunction::HidConnectFunction() : connection_manager_(nullptr) { | 148 HidConnectFunction::HidConnectFunction() : connection_manager_(nullptr) { |
| 149 } | 149 } |
| 150 | 150 |
| 151 HidConnectFunction::~HidConnectFunction() {} | 151 HidConnectFunction::~HidConnectFunction() {} |
| 152 | 152 |
| 153 ExtensionFunction::ResponseAction HidConnectFunction::Run() { | 153 ExtensionFunction::ResponseAction HidConnectFunction::Run() { |
| 154 scoped_ptr<core_api::hid::Connect::Params> parameters = | 154 scoped_ptr<api::hid::Connect::Params> parameters = |
| 155 hid::Connect::Params::Create(*args_); | 155 hid::Connect::Params::Create(*args_); |
| 156 EXTENSION_FUNCTION_VALIDATE(parameters); | 156 EXTENSION_FUNCTION_VALIDATE(parameters); |
| 157 | 157 |
| 158 HidDeviceManager* device_manager = HidDeviceManager::Get(browser_context()); | 158 HidDeviceManager* device_manager = HidDeviceManager::Get(browser_context()); |
| 159 CHECK(device_manager); | 159 CHECK(device_manager); |
| 160 | 160 |
| 161 connection_manager_ = | 161 connection_manager_ = |
| 162 ApiResourceManager<HidConnectionResource>::Get(browser_context()); | 162 ApiResourceManager<HidConnectionResource>::Get(browser_context()); |
| 163 CHECK(connection_manager_); | 163 CHECK(connection_manager_); |
| 164 | 164 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 192 int connection_id = connection_manager_->Add( | 192 int connection_id = connection_manager_->Add( |
| 193 new HidConnectionResource(extension_id(), connection)); | 193 new HidConnectionResource(extension_id(), connection)); |
| 194 Respond(OneArgument(PopulateHidConnection(connection_id, connection))); | 194 Respond(OneArgument(PopulateHidConnection(connection_id, connection))); |
| 195 } | 195 } |
| 196 | 196 |
| 197 HidDisconnectFunction::HidDisconnectFunction() {} | 197 HidDisconnectFunction::HidDisconnectFunction() {} |
| 198 | 198 |
| 199 HidDisconnectFunction::~HidDisconnectFunction() {} | 199 HidDisconnectFunction::~HidDisconnectFunction() {} |
| 200 | 200 |
| 201 ExtensionFunction::ResponseAction HidDisconnectFunction::Run() { | 201 ExtensionFunction::ResponseAction HidDisconnectFunction::Run() { |
| 202 scoped_ptr<core_api::hid::Disconnect::Params> parameters = | 202 scoped_ptr<api::hid::Disconnect::Params> parameters = |
| 203 hid::Disconnect::Params::Create(*args_); | 203 hid::Disconnect::Params::Create(*args_); |
| 204 EXTENSION_FUNCTION_VALIDATE(parameters); | 204 EXTENSION_FUNCTION_VALIDATE(parameters); |
| 205 | 205 |
| 206 ApiResourceManager<HidConnectionResource>* connection_manager = | 206 ApiResourceManager<HidConnectionResource>* connection_manager = |
| 207 ApiResourceManager<HidConnectionResource>::Get(browser_context()); | 207 ApiResourceManager<HidConnectionResource>::Get(browser_context()); |
| 208 CHECK(connection_manager); | 208 CHECK(connection_manager); |
| 209 | 209 |
| 210 int connection_id = parameters->connection_id; | 210 int connection_id = parameters->connection_id; |
| 211 HidConnectionResource* resource = | 211 HidConnectionResource* resource = |
| 212 connection_manager->Get(extension_id(), connection_id); | 212 connection_manager->Get(extension_id(), connection_id); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 355 |
| 356 void HidSendFeatureReportFunction::OnFinished(bool success) { | 356 void HidSendFeatureReportFunction::OnFinished(bool success) { |
| 357 if (success) { | 357 if (success) { |
| 358 Respond(NoArguments()); | 358 Respond(NoArguments()); |
| 359 } else { | 359 } else { |
| 360 Respond(Error(kErrorTransfer)); | 360 Respond(Error(kErrorTransfer)); |
| 361 } | 361 } |
| 362 } | 362 } |
| 363 | 363 |
| 364 } // namespace extensions | 364 } // namespace extensions |
| OLD | NEW |