Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: extensions/common/api/bluetooth/bluetooth_manifest_permission.cc

Issue 1096393002: API stubs for the BLE advertisement API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 years, 7 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/common/api/bluetooth/bluetooth_manifest_permission.h" 5 #include "extensions/common/api/bluetooth/bluetooth_manifest_permission.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "device/bluetooth/bluetooth_uuid.h" 11 #include "device/bluetooth/bluetooth_uuid.h"
12 #include "extensions/common/api/bluetooth/bluetooth_manifest_data.h" 12 #include "extensions/common/api/bluetooth/bluetooth_manifest_data.h"
13 #include "extensions/common/api/extensions_manifest_types.h" 13 #include "extensions/common/api/extensions_manifest_types.h"
14 #include "extensions/common/error_utils.h" 14 #include "extensions/common/error_utils.h"
15 #include "extensions/common/features/behavior_feature.h"
16 #include "extensions/common/features/feature_provider.h"
15 #include "extensions/common/manifest_constants.h" 17 #include "extensions/common/manifest_constants.h"
16 #include "grit/extensions_strings.h" 18 #include "grit/extensions_strings.h"
17 #include "ipc/ipc_message.h" 19 #include "ipc/ipc_message.h"
18 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
19 21
20 namespace extensions { 22 namespace extensions {
21 23
22 namespace bluetooth_errors { 24 namespace bluetooth_errors {
23 const char kErrorInvalidUuid[] = "Invalid UUID '*'"; 25 const char kErrorInvalidUuid[] = "Invalid UUID '*'";
24 } 26 }
(...skipping 24 matching lines...) Expand all
49 if (!ParseUuid(permission, *it, error)) { 51 if (!ParseUuid(permission, *it, error)) {
50 return false; 52 return false;
51 } 53 }
52 } 54 }
53 return true; 55 return true;
54 } 56 }
55 57
56 } // namespace 58 } // namespace
57 59
58 BluetoothManifestPermission::BluetoothManifestPermission() 60 BluetoothManifestPermission::BluetoothManifestPermission()
59 : socket_(false), 61 : socket_(false), low_energy_(false), peripheral_(false) {
60 low_energy_(false) {} 62 }
61 63
62 BluetoothManifestPermission::~BluetoothManifestPermission() {} 64 BluetoothManifestPermission::~BluetoothManifestPermission() {}
63 65
64 // static 66 // static
65 scoped_ptr<BluetoothManifestPermission> BluetoothManifestPermission::FromValue( 67 scoped_ptr<BluetoothManifestPermission> BluetoothManifestPermission::FromValue(
66 const base::Value& value, 68 const base::Value& value,
67 base::string16* error) { 69 base::string16* error) {
68 scoped_ptr<core_api::extensions_manifest_types::Bluetooth> bluetooth = 70 scoped_ptr<core_api::extensions_manifest_types::Bluetooth> bluetooth =
69 core_api::extensions_manifest_types::Bluetooth::FromValue(value, error); 71 core_api::extensions_manifest_types::Bluetooth::FromValue(value, error);
70 if (!bluetooth) 72 if (!bluetooth)
71 return scoped_ptr<BluetoothManifestPermission>(); 73 return scoped_ptr<BluetoothManifestPermission>();
72 74
73 scoped_ptr<BluetoothManifestPermission> result( 75 scoped_ptr<BluetoothManifestPermission> result(
74 new BluetoothManifestPermission()); 76 new BluetoothManifestPermission());
75 if (bluetooth->uuids) { 77 if (bluetooth->uuids) {
76 if (!ParseUuidArray(result.get(), bluetooth->uuids, error)) { 78 if (!ParseUuidArray(result.get(), bluetooth->uuids, error)) {
77 return scoped_ptr<BluetoothManifestPermission>(); 79 return scoped_ptr<BluetoothManifestPermission>();
78 } 80 }
79 } 81 }
80 if (bluetooth->socket) { 82 if (bluetooth->socket) {
81 result->socket_ = *(bluetooth->socket); 83 result->socket_ = *(bluetooth->socket);
82 } 84 }
83 if (bluetooth->low_energy) { 85 if (bluetooth->low_energy) {
84 result->low_energy_ = *(bluetooth->low_energy); 86 result->low_energy_ = *(bluetooth->low_energy);
85 } 87 }
88 if (bluetooth->peripheral) {
89 result->peripheral_ = *(bluetooth->peripheral);
90 }
86 return result.Pass(); 91 return result.Pass();
87 } 92 }
88 93
89 bool BluetoothManifestPermission::CheckRequest( 94 bool BluetoothManifestPermission::CheckRequest(
90 const Extension* extension, 95 const Extension* extension,
91 const BluetoothPermissionRequest& request) const { 96 const BluetoothPermissionRequest& request) const {
92 97
93 device::BluetoothUUID param_uuid(request.uuid); 98 device::BluetoothUUID param_uuid(request.uuid);
94 for (BluetoothUuidSet::const_iterator it = uuids_.begin(); 99 for (BluetoothUuidSet::const_iterator it = uuids_.begin();
95 it != uuids_.end(); 100 it != uuids_.end();
96 ++it) { 101 ++it) {
97 device::BluetoothUUID uuid(*it); 102 device::BluetoothUUID uuid(*it);
98 if (param_uuid == uuid) 103 if (param_uuid == uuid)
99 return true; 104 return true;
100 } 105 }
101 return false; 106 return false;
102 } 107 }
103 108
104 bool BluetoothManifestPermission::CheckSocketPermitted( 109 bool BluetoothManifestPermission::CheckSocketPermitted(
105 const Extension* extension) const { 110 const Extension* extension) const {
106 return socket_; 111 return socket_;
107 } 112 }
108 113
109 bool BluetoothManifestPermission::CheckLowEnergyPermitted( 114 bool BluetoothManifestPermission::CheckLowEnergyPermitted(
110 const Extension* extension) const { 115 const Extension* extension) const {
111 return low_energy_; 116 return low_energy_;
112 } 117 }
113 118
119 bool BluetoothManifestPermission::CheckPeripheralPermitted(
120 const Extension* extension) const {
121 if (!FeatureProvider::GetBehaviorFeature(
122 BehaviorFeature::kBluetoothPeripheral)
123 ->IsAvailableToExtension(extension)
124 .is_available())
125 return false;
126 return peripheral_;
127 }
128
114 std::string BluetoothManifestPermission::name() const { 129 std::string BluetoothManifestPermission::name() const {
115 return manifest_keys::kBluetooth; 130 return manifest_keys::kBluetooth;
116 } 131 }
117 132
118 std::string BluetoothManifestPermission::id() const { return name(); } 133 std::string BluetoothManifestPermission::id() const { return name(); }
119 134
120 PermissionIDSet BluetoothManifestPermission::GetPermissions() const { 135 PermissionIDSet BluetoothManifestPermission::GetPermissions() const {
121 PermissionIDSet permissions; 136 PermissionIDSet permissions;
122 permissions.insert(APIPermission::kBluetooth); 137 permissions.insert(APIPermission::kBluetooth);
123 if (!uuids_.empty()) { 138 if (!uuids_.empty()) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 result->uuids_ = base::STLSetIntersection<BluetoothUuidSet>( 218 result->uuids_ = base::STLSetIntersection<BluetoothUuidSet>(
204 uuids_, other->uuids_); 219 uuids_, other->uuids_);
205 return result.release(); 220 return result.release();
206 } 221 }
207 222
208 void BluetoothManifestPermission::AddPermission(const std::string& uuid) { 223 void BluetoothManifestPermission::AddPermission(const std::string& uuid) {
209 uuids_.insert(uuid); 224 uuids_.insert(uuid);
210 } 225 }
211 226
212 } // namespace extensions 227 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/api/bluetooth/bluetooth_manifest_permission.h ('k') | extensions/common/api/bluetooth_low_energy.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698