| 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/common/extensions/api/bluetooth/bluetooth_manifest_permission.h
" | 5 #include "chrome/common/extensions/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" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 ++it) { | 49 ++it) { |
| 50 if (!ParseUuid(permission, *it, error)) { | 50 if (!ParseUuid(permission, *it, error)) { |
| 51 return false; | 51 return false; |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 return true; | 54 return true; |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 BluetoothManifestPermission::BluetoothManifestPermission() {} | 59 BluetoothManifestPermission::BluetoothManifestPermission() |
| 60 : socket_(false), |
| 61 low_energy_(false) {} |
| 60 | 62 |
| 61 BluetoothManifestPermission::~BluetoothManifestPermission() {} | 63 BluetoothManifestPermission::~BluetoothManifestPermission() {} |
| 62 | 64 |
| 63 // static | 65 // static |
| 64 scoped_ptr<BluetoothManifestPermission> BluetoothManifestPermission::FromValue( | 66 scoped_ptr<BluetoothManifestPermission> BluetoothManifestPermission::FromValue( |
| 65 const base::Value& value, | 67 const base::Value& value, |
| 66 base::string16* error) { | 68 base::string16* error) { |
| 67 scoped_ptr<api::manifest_types::Bluetooth> bluetooth = | 69 scoped_ptr<api::manifest_types::Bluetooth> bluetooth = |
| 68 api::manifest_types::Bluetooth::FromValue(value, error); | 70 api::manifest_types::Bluetooth::FromValue(value, error); |
| 69 if (!bluetooth) | 71 if (!bluetooth) |
| 70 return scoped_ptr<BluetoothManifestPermission>(); | 72 return scoped_ptr<BluetoothManifestPermission>(); |
| 71 | 73 |
| 72 scoped_ptr<BluetoothManifestPermission> result( | 74 scoped_ptr<BluetoothManifestPermission> result( |
| 73 new BluetoothManifestPermission()); | 75 new BluetoothManifestPermission()); |
| 74 if (bluetooth->uuids) { | 76 if (bluetooth->uuids) { |
| 75 if (!ParseUuidArray(result.get(), bluetooth->uuids, error)) { | 77 if (!ParseUuidArray(result.get(), bluetooth->uuids, error)) { |
| 76 return scoped_ptr<BluetoothManifestPermission>(); | 78 return scoped_ptr<BluetoothManifestPermission>(); |
| 77 } | 79 } |
| 78 } | 80 } |
| 81 if (bluetooth->socket) { |
| 82 result->socket_ = *(bluetooth->socket); |
| 83 } |
| 84 if (bluetooth->low_energy) { |
| 85 result->low_energy_ = *(bluetooth->low_energy); |
| 86 } |
| 79 return result.Pass(); | 87 return result.Pass(); |
| 80 } | 88 } |
| 81 | 89 |
| 82 bool BluetoothManifestPermission::CheckRequest( | 90 bool BluetoothManifestPermission::CheckRequest( |
| 83 const Extension* extension, | 91 const Extension* extension, |
| 84 const BluetoothPermissionRequest& request) const { | 92 const BluetoothPermissionRequest& request) const { |
| 85 | 93 |
| 86 device::BluetoothUUID param_uuid(request.uuid); | 94 device::BluetoothUUID param_uuid(request.uuid); |
| 87 for (BluetoothUuidSet::const_iterator it = uuids_.begin(); | 95 for (BluetoothUuidSet::const_iterator it = uuids_.begin(); |
| 88 it != uuids_.end(); | 96 it != uuids_.end(); |
| 89 ++it) { | 97 ++it) { |
| 90 device::BluetoothUUID uuid(*it); | 98 device::BluetoothUUID uuid(*it); |
| 91 if (param_uuid == uuid) | 99 if (param_uuid == uuid) |
| 92 return true; | 100 return true; |
| 93 } | 101 } |
| 94 return false; | 102 return false; |
| 95 } | 103 } |
| 96 | 104 |
| 105 bool BluetoothManifestPermission::CheckSocketPermitted( |
| 106 const Extension* extension) const { |
| 107 return socket_; |
| 108 } |
| 109 |
| 110 bool BluetoothManifestPermission::CheckLowEnergyPermitted( |
| 111 const Extension* extension) const { |
| 112 return low_energy_; |
| 113 } |
| 114 |
| 97 std::string BluetoothManifestPermission::name() const { | 115 std::string BluetoothManifestPermission::name() const { |
| 98 return manifest_keys::kBluetooth; | 116 return manifest_keys::kBluetooth; |
| 99 } | 117 } |
| 100 | 118 |
| 101 std::string BluetoothManifestPermission::id() const { return name(); } | 119 std::string BluetoothManifestPermission::id() const { return name(); } |
| 102 | 120 |
| 103 bool BluetoothManifestPermission::HasMessages() const { return true; } | 121 bool BluetoothManifestPermission::HasMessages() const { return true; } |
| 104 | 122 |
| 105 PermissionMessages BluetoothManifestPermission::GetMessages() const { | 123 PermissionMessages BluetoothManifestPermission::GetMessages() const { |
| 106 DCHECK(HasMessages()); | 124 DCHECK(HasMessages()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 228 |
| 211 void BluetoothManifestPermission::Log(std::string* log) const { | 229 void BluetoothManifestPermission::Log(std::string* log) const { |
| 212 IPC::LogParam(uuids_, log); | 230 IPC::LogParam(uuids_, log); |
| 213 } | 231 } |
| 214 | 232 |
| 215 void BluetoothManifestPermission::AddPermission(const std::string& uuid) { | 233 void BluetoothManifestPermission::AddPermission(const std::string& uuid) { |
| 216 uuids_.insert(uuid); | 234 uuids_.insert(uuid); |
| 217 } | 235 } |
| 218 | 236 |
| 219 } // namespace extensions | 237 } // namespace extensions |
| OLD | NEW |