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

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

Issue 145663004: Replace "bluetooth" permission with manifest property. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused function. Created 6 years, 10 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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.h "
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/stl_util.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h"
11 #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h"
12 #include "chrome/common/extensions/api/manifest_types.h"
13 #include "chrome/common/extensions/extension_messages.h"
14 #include "device/bluetooth/bluetooth_utils.h"
15 #include "extensions/common/error_utils.h"
16 #include "extensions/common/manifest_constants.h"
17 #include "grit/generated_resources.h"
18 #include "ipc/ipc_message.h"
19 #include "ui/base/l10n/l10n_util.h"
20
21 namespace extensions {
22
23 namespace bluetooth_errors {
24 const char kErrorInvalidProfileUuid[] = "Invalid UUID '*'";
25 }
26
27 namespace errors = bluetooth_errors;
28
29 namespace {
30
31 bool ParseUuid(BluetoothManifestPermission* permission,
32 const std::string& profile_uuid,
33 base::string16* error) {
34 std::string canonical_uuid =
35 device::bluetooth_utils::CanonicalUuid(profile_uuid);
36 if (canonical_uuid.empty()) {
37 *error = ErrorUtils::FormatErrorMessageUTF16(
38 errors::kErrorInvalidProfileUuid, profile_uuid);
39 return false;
40 }
41 permission->AddPermission(profile_uuid);
42 return true;
43 }
44
45 bool ParseUuidArray(BluetoothManifestPermission* permission,
46 const scoped_ptr<std::vector<std::string> >& profiles,
47 base::string16* error) {
48 for (std::vector<std::string>::const_iterator it = profiles->begin();
49 it != profiles->end();
50 ++it) {
51 if (!ParseUuid(permission, *it, error)) {
52 return false;
53 }
54 }
55 return true;
56 }
57
58 } // namespace
59
60 BluetoothManifestPermission::BluetoothManifestPermission() {}
61
62 BluetoothManifestPermission::~BluetoothManifestPermission() {}
63
64 // static
65 scoped_ptr<BluetoothManifestPermission> BluetoothManifestPermission::FromValue(
66 const base::Value& value,
67 base::string16* error) {
68 scoped_ptr<api::manifest_types::Bluetooth> bluetooth =
69 api::manifest_types::Bluetooth::FromValue(value, error);
70 if (!bluetooth)
71 return scoped_ptr<BluetoothManifestPermission>();
72
73 scoped_ptr<BluetoothManifestPermission> result(
74 new BluetoothManifestPermission());
75 if (bluetooth->profiles) {
76 if (!ParseUuidArray(result.get(), bluetooth->profiles, error)) {
77 return scoped_ptr<BluetoothManifestPermission>();
78 }
79 }
80 return result.Pass();
81 }
82
83 bool BluetoothManifestPermission::CheckRequest(
84 const Extension* extension,
85 const BluetoothPermissionRequest& request) const {
86
87 std::string canonical_param_uuid =
88 device::bluetooth_utils::CanonicalUuid(request.profile_uuid);
89 for (BluetoothProfileUuidSet::const_iterator it = profile_uuids_.begin();
90 it != profile_uuids_.end();
91 ++it) {
92 std::string canonical_uuid = device::bluetooth_utils::CanonicalUuid(*it);
93 if (canonical_uuid == canonical_param_uuid)
94 return true;
95 }
96 return false;
97 }
98
99 std::string BluetoothManifestPermission::name() const {
100 return manifest_keys::kBluetooth;
101 }
102
103 std::string BluetoothManifestPermission::id() const { return name(); }
104
105 bool BluetoothManifestPermission::HasMessages() const { return true; }
106
107 PermissionMessages BluetoothManifestPermission::GetMessages() const {
108 DCHECK(HasMessages());
109 PermissionMessages result;
110
111 result.push_back(PermissionMessage(
112 PermissionMessage::kBluetooth,
113 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH)));
114
115 if (!profile_uuids_.empty()) {
116 result.push_back(
117 PermissionMessage(PermissionMessage::kBluetoothDevices,
118 l10n_util::GetStringUTF16(
119 IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH_DEVICES)));
120 }
121
122 return result;
123 }
124
125 bool BluetoothManifestPermission::FromValue(const base::Value* value) {
126 if (!value)
127 return false;
128 base::string16 error;
129 scoped_ptr<BluetoothManifestPermission> manifest_permission(
130 BluetoothManifestPermission::FromValue(*value, &error));
131
132 if (!manifest_permission)
133 return false;
134
135 profile_uuids_ = manifest_permission->profile_uuids_;
136 return true;
137 }
138
139 scoped_ptr<base::Value> BluetoothManifestPermission::ToValue() const {
140 api::manifest_types::Bluetooth bluetooth;
141 bluetooth.profiles.reset(new std::vector<std::string>(profile_uuids_.begin(),
142 profile_uuids_.end()));
143 return bluetooth.ToValue().PassAs<base::Value>();
144 }
145
146 ManifestPermission* BluetoothManifestPermission::Clone() const {
147 scoped_ptr<BluetoothManifestPermission> result(
148 new BluetoothManifestPermission());
149 result->profile_uuids_ = profile_uuids_;
150 return result.release();
151 }
152
153 ManifestPermission* BluetoothManifestPermission::Diff(
154 const ManifestPermission* rhs) const {
155 const BluetoothManifestPermission* other =
156 static_cast<const BluetoothManifestPermission*>(rhs);
157
158 scoped_ptr<BluetoothManifestPermission> result(
159 new BluetoothManifestPermission());
160 result->profile_uuids_ = base::STLSetDifference<BluetoothProfileUuidSet>(
161 profile_uuids_, other->profile_uuids_);
162 return result.release();
163 }
164
165 ManifestPermission* BluetoothManifestPermission::Union(
166 const ManifestPermission* rhs) const {
167 const BluetoothManifestPermission* other =
168 static_cast<const BluetoothManifestPermission*>(rhs);
169
170 scoped_ptr<BluetoothManifestPermission> result(
171 new BluetoothManifestPermission());
172 result->profile_uuids_ = base::STLSetUnion<BluetoothProfileUuidSet>(
173 profile_uuids_, other->profile_uuids_);
174 return result.release();
175 }
176
177 ManifestPermission* BluetoothManifestPermission::Intersect(
178 const ManifestPermission* rhs) const {
179 const BluetoothManifestPermission* other =
180 static_cast<const BluetoothManifestPermission*>(rhs);
181
182 scoped_ptr<BluetoothManifestPermission> result(
183 new BluetoothManifestPermission());
184 result->profile_uuids_ = base::STLSetIntersection<BluetoothProfileUuidSet>(
185 profile_uuids_, other->profile_uuids_);
186 return result.release();
187 }
188
189 bool BluetoothManifestPermission::Contains(const ManifestPermission* rhs)
190 const {
191 const BluetoothManifestPermission* other =
192 static_cast<const BluetoothManifestPermission*>(rhs);
193
194 return base::STLIncludes(profile_uuids_, other->profile_uuids_);
195 }
196
197 bool BluetoothManifestPermission::Equal(const ManifestPermission* rhs) const {
198 const BluetoothManifestPermission* other =
199 static_cast<const BluetoothManifestPermission*>(rhs);
200
201 return (profile_uuids_ == other->profile_uuids_);
202 }
203
204 void BluetoothManifestPermission::Write(IPC::Message* m) const {
205 IPC::WriteParam(m, profile_uuids_);
206 }
207
208 bool BluetoothManifestPermission::Read(const IPC::Message* m,
209 PickleIterator* iter) {
210 return IPC::ReadParam(m, iter, &profile_uuids_);
211 }
212
213 void BluetoothManifestPermission::Log(std::string* log) const {
214 IPC::LogParam(profile_uuids_, log);
215 }
216
217 void BluetoothManifestPermission::AddPermission(
218 const std::string& profile_uuid) {
219 profile_uuids_.insert(profile_uuid);
220 }
221
222 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698