| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 } // namespace | 82 } // namespace |
| 83 | 83 |
| 84 namespace extensions { | 84 namespace extensions { |
| 85 | 85 |
| 86 HidGetDevicesFunction::HidGetDevicesFunction() {} | 86 HidGetDevicesFunction::HidGetDevicesFunction() {} |
| 87 | 87 |
| 88 HidGetDevicesFunction::~HidGetDevicesFunction() {} | 88 HidGetDevicesFunction::~HidGetDevicesFunction() {} |
| 89 | 89 |
| 90 ExtensionFunction::ResponseAction HidGetDevicesFunction::Run() { | 90 ExtensionFunction::ResponseAction HidGetDevicesFunction::Run() { |
| 91 scoped_ptr<api::hid::GetDevices::Params> parameters = | 91 std::unique_ptr<api::hid::GetDevices::Params> parameters = |
| 92 hid::GetDevices::Params::Create(*args_); | 92 hid::GetDevices::Params::Create(*args_); |
| 93 EXTENSION_FUNCTION_VALIDATE(parameters); | 93 EXTENSION_FUNCTION_VALIDATE(parameters); |
| 94 | 94 |
| 95 HidDeviceManager* device_manager = HidDeviceManager::Get(browser_context()); | 95 HidDeviceManager* device_manager = HidDeviceManager::Get(browser_context()); |
| 96 CHECK(device_manager); | 96 CHECK(device_manager); |
| 97 | 97 |
| 98 std::vector<HidDeviceFilter> filters; | 98 std::vector<HidDeviceFilter> filters; |
| 99 if (parameters->options.filters) { | 99 if (parameters->options.filters) { |
| 100 filters.resize(parameters->options.filters->size()); | 100 filters.resize(parameters->options.filters->size()); |
| 101 for (size_t i = 0; i < parameters->options.filters->size(); ++i) { | 101 for (size_t i = 0; i < parameters->options.filters->size(); ++i) { |
| 102 ConvertHidDeviceFilter(parameters->options.filters->at(i), &filters[i]); | 102 ConvertHidDeviceFilter(parameters->options.filters->at(i), &filters[i]); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 if (parameters->options.vendor_id) { | 105 if (parameters->options.vendor_id) { |
| 106 HidDeviceFilter legacy_filter; | 106 HidDeviceFilter legacy_filter; |
| 107 legacy_filter.SetVendorId(*parameters->options.vendor_id); | 107 legacy_filter.SetVendorId(*parameters->options.vendor_id); |
| 108 if (parameters->options.product_id) { | 108 if (parameters->options.product_id) { |
| 109 legacy_filter.SetProductId(*parameters->options.product_id); | 109 legacy_filter.SetProductId(*parameters->options.product_id); |
| 110 } | 110 } |
| 111 filters.push_back(legacy_filter); | 111 filters.push_back(legacy_filter); |
| 112 } | 112 } |
| 113 | 113 |
| 114 device_manager->GetApiDevices( | 114 device_manager->GetApiDevices( |
| 115 extension(), filters, | 115 extension(), filters, |
| 116 base::Bind(&HidGetDevicesFunction::OnEnumerationComplete, this)); | 116 base::Bind(&HidGetDevicesFunction::OnEnumerationComplete, this)); |
| 117 return RespondLater(); | 117 return RespondLater(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void HidGetDevicesFunction::OnEnumerationComplete( | 120 void HidGetDevicesFunction::OnEnumerationComplete( |
| 121 scoped_ptr<base::ListValue> devices) { | 121 std::unique_ptr<base::ListValue> devices) { |
| 122 Respond(OneArgument(devices.release())); | 122 Respond(OneArgument(devices.release())); |
| 123 } | 123 } |
| 124 | 124 |
| 125 HidGetUserSelectedDevicesFunction::HidGetUserSelectedDevicesFunction() { | 125 HidGetUserSelectedDevicesFunction::HidGetUserSelectedDevicesFunction() { |
| 126 } | 126 } |
| 127 | 127 |
| 128 HidGetUserSelectedDevicesFunction::~HidGetUserSelectedDevicesFunction() { | 128 HidGetUserSelectedDevicesFunction::~HidGetUserSelectedDevicesFunction() { |
| 129 } | 129 } |
| 130 | 130 |
| 131 ExtensionFunction::ResponseAction HidGetUserSelectedDevicesFunction::Run() { | 131 ExtensionFunction::ResponseAction HidGetUserSelectedDevicesFunction::Run() { |
| 132 scoped_ptr<api::hid::GetUserSelectedDevices::Params> parameters = | 132 std::unique_ptr<api::hid::GetUserSelectedDevices::Params> parameters = |
| 133 hid::GetUserSelectedDevices::Params::Create(*args_); | 133 hid::GetUserSelectedDevices::Params::Create(*args_); |
| 134 EXTENSION_FUNCTION_VALIDATE(parameters); | 134 EXTENSION_FUNCTION_VALIDATE(parameters); |
| 135 | 135 |
| 136 content::WebContents* web_contents = GetSenderWebContents(); | 136 content::WebContents* web_contents = GetSenderWebContents(); |
| 137 if (!web_contents || !user_gesture()) { | 137 if (!web_contents || !user_gesture()) { |
| 138 return RespondNow(OneArgument(new base::ListValue())); | 138 return RespondNow(OneArgument(new base::ListValue())); |
| 139 } | 139 } |
| 140 | 140 |
| 141 bool multiple = false; | 141 bool multiple = false; |
| 142 std::vector<HidDeviceFilter> filters; | 142 std::vector<HidDeviceFilter> filters; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 166 CHECK(device_manager); | 166 CHECK(device_manager); |
| 167 Respond(OneArgument(device_manager->GetApiDevicesFromList(devices))); | 167 Respond(OneArgument(device_manager->GetApiDevicesFromList(devices))); |
| 168 } | 168 } |
| 169 | 169 |
| 170 HidConnectFunction::HidConnectFunction() : connection_manager_(nullptr) { | 170 HidConnectFunction::HidConnectFunction() : connection_manager_(nullptr) { |
| 171 } | 171 } |
| 172 | 172 |
| 173 HidConnectFunction::~HidConnectFunction() {} | 173 HidConnectFunction::~HidConnectFunction() {} |
| 174 | 174 |
| 175 ExtensionFunction::ResponseAction HidConnectFunction::Run() { | 175 ExtensionFunction::ResponseAction HidConnectFunction::Run() { |
| 176 scoped_ptr<api::hid::Connect::Params> parameters = | 176 std::unique_ptr<api::hid::Connect::Params> parameters = |
| 177 hid::Connect::Params::Create(*args_); | 177 hid::Connect::Params::Create(*args_); |
| 178 EXTENSION_FUNCTION_VALIDATE(parameters); | 178 EXTENSION_FUNCTION_VALIDATE(parameters); |
| 179 | 179 |
| 180 HidDeviceManager* device_manager = HidDeviceManager::Get(browser_context()); | 180 HidDeviceManager* device_manager = HidDeviceManager::Get(browser_context()); |
| 181 CHECK(device_manager); | 181 CHECK(device_manager); |
| 182 | 182 |
| 183 connection_manager_ = | 183 connection_manager_ = |
| 184 ApiResourceManager<HidConnectionResource>::Get(browser_context()); | 184 ApiResourceManager<HidConnectionResource>::Get(browser_context()); |
| 185 CHECK(connection_manager_); | 185 CHECK(connection_manager_); |
| 186 | 186 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 214 int connection_id = connection_manager_->Add( | 214 int connection_id = connection_manager_->Add( |
| 215 new HidConnectionResource(extension_id(), connection)); | 215 new HidConnectionResource(extension_id(), connection)); |
| 216 Respond(OneArgument(PopulateHidConnection(connection_id, connection))); | 216 Respond(OneArgument(PopulateHidConnection(connection_id, connection))); |
| 217 } | 217 } |
| 218 | 218 |
| 219 HidDisconnectFunction::HidDisconnectFunction() {} | 219 HidDisconnectFunction::HidDisconnectFunction() {} |
| 220 | 220 |
| 221 HidDisconnectFunction::~HidDisconnectFunction() {} | 221 HidDisconnectFunction::~HidDisconnectFunction() {} |
| 222 | 222 |
| 223 ExtensionFunction::ResponseAction HidDisconnectFunction::Run() { | 223 ExtensionFunction::ResponseAction HidDisconnectFunction::Run() { |
| 224 scoped_ptr<api::hid::Disconnect::Params> parameters = | 224 std::unique_ptr<api::hid::Disconnect::Params> parameters = |
| 225 hid::Disconnect::Params::Create(*args_); | 225 hid::Disconnect::Params::Create(*args_); |
| 226 EXTENSION_FUNCTION_VALIDATE(parameters); | 226 EXTENSION_FUNCTION_VALIDATE(parameters); |
| 227 | 227 |
| 228 ApiResourceManager<HidConnectionResource>* connection_manager = | 228 ApiResourceManager<HidConnectionResource>* connection_manager = |
| 229 ApiResourceManager<HidConnectionResource>::Get(browser_context()); | 229 ApiResourceManager<HidConnectionResource>::Get(browser_context()); |
| 230 CHECK(connection_manager); | 230 CHECK(connection_manager); |
| 231 | 231 |
| 232 int connection_id = parameters->connection_id; | 232 int connection_id = parameters->connection_id; |
| 233 HidConnectionResource* resource = | 233 HidConnectionResource* resource = |
| 234 connection_manager->Get(extension_id(), connection_id); | 234 connection_manager->Get(extension_id(), connection_id); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 377 |
| 378 void HidSendFeatureReportFunction::OnFinished(bool success) { | 378 void HidSendFeatureReportFunction::OnFinished(bool success) { |
| 379 if (success) { | 379 if (success) { |
| 380 Respond(NoArguments()); | 380 Respond(NoArguments()); |
| 381 } else { | 381 } else { |
| 382 Respond(Error(kErrorTransfer)); | 382 Respond(Error(kErrorTransfer)); |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 } // namespace extensions | 386 } // namespace extensions |
| OLD | NEW |