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 "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_api.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <utility> | 10 #include <utility> |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 if (HasPermission( | 317 if (HasPermission( |
318 api_permissions, | 318 api_permissions, |
319 apibtle::DESCRIPTOR_PERMISSION_ENCRYPTEDAUTHENTICATEDWRITE)) { | 319 apibtle::DESCRIPTOR_PERMISSION_ENCRYPTEDAUTHENTICATEDWRITE)) { |
320 permissions |= device::BluetoothGattCharacteristic:: | 320 permissions |= device::BluetoothGattCharacteristic:: |
321 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; | 321 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; |
322 } | 322 } |
323 | 323 |
324 return permissions; | 324 return permissions; |
325 } | 325 } |
326 | 326 |
| 327 bool IsAutoLaunchedKioskApp(const ExtensionId& id) { |
| 328 #if defined(OS_CHROMEOS) |
| 329 chromeos::KioskAppManager::App app_info; |
| 330 return chromeos::KioskAppManager::Get()->GetApp(id, &app_info) && |
| 331 app_info.was_auto_launched_with_zero_delay; |
| 332 #else |
| 333 return false; |
| 334 #endif |
| 335 } |
| 336 |
| 337 bool IsPeripheralFlagEnabled() { |
| 338 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 339 switches::kEnableBLEAdvertising); |
| 340 } |
| 341 |
327 } // namespace | 342 } // namespace |
328 | 343 |
329 | 344 |
330 static base::LazyInstance<BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI> > | 345 static base::LazyInstance<BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI> > |
331 g_factory = LAZY_INSTANCE_INITIALIZER; | 346 g_factory = LAZY_INSTANCE_INITIALIZER; |
332 | 347 |
333 // static | 348 // static |
334 BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>* | 349 BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>* |
335 BluetoothLowEnergyAPI::GetFactoryInstance() { | 350 BluetoothLowEnergyAPI::GetFactoryInstance() { |
336 return g_factory.Pointer(); | 351 return g_factory.Pointer(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 448 |
434 template <typename Params> | 449 template <typename Params> |
435 ExtensionFunction::ResponseAction | 450 ExtensionFunction::ResponseAction |
436 BLEPeripheralExtensionFunction<Params>::Run() { | 451 BLEPeripheralExtensionFunction<Params>::Run() { |
437 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 452 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
438 | 453 |
439 // Check permissions in manifest. | 454 // Check permissions in manifest. |
440 if (!BluetoothManifestData::CheckPeripheralPermitted(extension())) | 455 if (!BluetoothManifestData::CheckPeripheralPermitted(extension())) |
441 return RespondNow(Error(kErrorPermissionDenied)); | 456 return RespondNow(Error(kErrorPermissionDenied)); |
442 | 457 |
| 458 if (!(IsAutoLaunchedKioskApp(extension()->id()) || |
| 459 IsPeripheralFlagEnabled())) { |
| 460 return RespondNow(Error(kErrorPermissionDenied)); |
| 461 } |
| 462 |
443 // Causes link error on Windows. API will never be on Windows, so #ifdefing. | 463 // Causes link error on Windows. API will never be on Windows, so #ifdefing. |
444 #if !defined(OS_WIN) | 464 #if !defined(OS_WIN) |
445 params_ = Params::Create(*args_); | 465 params_ = Params::Create(*args_); |
446 EXTENSION_FUNCTION_VALIDATE(params_.get() != NULL); | 466 EXTENSION_FUNCTION_VALIDATE(params_.get() != NULL); |
447 #endif | 467 #endif |
448 | 468 |
449 return BluetoothLowEnergyExtensionFunction::Run(); | 469 return BluetoothLowEnergyExtensionFunction::Run(); |
450 } | 470 } |
451 | 471 |
452 bool BluetoothLowEnergyConnectFunction::DoWork() { | 472 bool BluetoothLowEnergyConnectFunction::DoWork() { |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 bool BluetoothLowEnergyAdvertisementFunction::RunAsync() { | 1123 bool BluetoothLowEnergyAdvertisementFunction::RunAsync() { |
1104 Initialize(); | 1124 Initialize(); |
1105 return BluetoothLowEnergyExtensionFunctionDeprecated::RunAsync(); | 1125 return BluetoothLowEnergyExtensionFunctionDeprecated::RunAsync(); |
1106 } | 1126 } |
1107 | 1127 |
1108 void BluetoothLowEnergyAdvertisementFunction::Initialize() { | 1128 void BluetoothLowEnergyAdvertisementFunction::Initialize() { |
1109 advertisements_manager_ = | 1129 advertisements_manager_ = |
1110 ApiResourceManager<BluetoothApiAdvertisement>::Get(browser_context()); | 1130 ApiResourceManager<BluetoothApiAdvertisement>::Get(browser_context()); |
1111 } | 1131 } |
1112 | 1132 |
1113 static bool IsAutoLaunchedKioskApp(const ExtensionId& id) { | |
1114 #if defined(OS_CHROMEOS) | |
1115 chromeos::KioskAppManager::App app_info; | |
1116 return chromeos::KioskAppManager::Get()->GetApp(id, &app_info) && | |
1117 app_info.was_auto_launched_with_zero_delay; | |
1118 #else | |
1119 return false; | |
1120 #endif | |
1121 } | |
1122 | |
1123 static bool IsPeripheralFlagEnabled() { | |
1124 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1125 switches::kEnableBLEAdvertising); | |
1126 } | |
1127 | |
1128 // RegisterAdvertisement: | 1133 // RegisterAdvertisement: |
1129 | 1134 |
1130 bool BluetoothLowEnergyRegisterAdvertisementFunction::DoWork() { | 1135 bool BluetoothLowEnergyRegisterAdvertisementFunction::DoWork() { |
1131 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1136 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1132 | 1137 |
1133 // Check permissions in manifest. | 1138 // Check permissions in manifest. |
1134 if (!BluetoothManifestData::CheckPeripheralPermitted(extension())) { | 1139 if (!BluetoothManifestData::CheckPeripheralPermitted(extension())) { |
1135 error_ = kErrorPermissionDenied; | 1140 error_ = kErrorPermissionDenied; |
1136 SendResponse(false); | 1141 SendResponse(false); |
1137 return false; | 1142 return false; |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 params_->response.value->end()); | 1488 params_->response.value->end()); |
1484 } | 1489 } |
1485 event_router_->HandleRequestResponse( | 1490 event_router_->HandleRequestResponse( |
1486 extension(), params_->response.request_id, params_->response.is_error, | 1491 extension(), params_->response.request_id, params_->response.is_error, |
1487 uint8_vector); | 1492 uint8_vector); |
1488 Respond(NoArguments()); | 1493 Respond(NoArguments()); |
1489 } | 1494 } |
1490 | 1495 |
1491 } // namespace api | 1496 } // namespace api |
1492 } // namespace extensions | 1497 } // namespace extensions |
OLD | NEW |