OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/sockets/sockets_manifest_permission.h" | 5 #include "chrome/common/extensions/api/sockets/sockets_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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "chrome/common/extensions/api/manifest_types.h" | 11 #include "chrome/common/extensions/api/manifest_types.h" |
11 #include "chrome/common/extensions/api/sockets/sockets_manifest_data.h" | 12 #include "chrome/common/extensions/api/sockets/sockets_manifest_data.h" |
12 #include "chrome/common/extensions/extension_messages.h" | 13 #include "chrome/common/extensions/extension_messages.h" |
13 #include "extensions/common/error_utils.h" | 14 #include "extensions/common/error_utils.h" |
14 #include "extensions/common/manifest_constants.h" | 15 #include "extensions/common/manifest_constants.h" |
15 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
16 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 result->permissions_ = permissions_; | 226 result->permissions_ = permissions_; |
226 return result.release(); | 227 return result.release(); |
227 } | 228 } |
228 | 229 |
229 ManifestPermission* SocketsManifestPermission::Diff( | 230 ManifestPermission* SocketsManifestPermission::Diff( |
230 const ManifestPermission* rhs) const { | 231 const ManifestPermission* rhs) const { |
231 const SocketsManifestPermission* other = | 232 const SocketsManifestPermission* other = |
232 static_cast<const SocketsManifestPermission*>(rhs); | 233 static_cast<const SocketsManifestPermission*>(rhs); |
233 | 234 |
234 scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); | 235 scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); |
235 std::set_difference( | 236 result->permissions_ = base::STLSetDifference<SocketPermissionEntrySet>( |
236 permissions_.begin(), permissions_.end(), | 237 permissions_, other->permissions_); |
237 other->permissions_.begin(), other->permissions_.end(), | |
238 std::inserter<SocketPermissionEntrySet>( | |
239 result->permissions_, result->permissions_.begin())); | |
240 return result.release(); | 238 return result.release(); |
241 } | 239 } |
242 | 240 |
243 ManifestPermission* SocketsManifestPermission::Union( | 241 ManifestPermission* SocketsManifestPermission::Union( |
244 const ManifestPermission* rhs) const { | 242 const ManifestPermission* rhs) const { |
245 const SocketsManifestPermission* other = | 243 const SocketsManifestPermission* other = |
246 static_cast<const SocketsManifestPermission*>(rhs); | 244 static_cast<const SocketsManifestPermission*>(rhs); |
247 | 245 |
248 scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); | 246 scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); |
249 std::set_union( | 247 result->permissions_ = base::STLSetUnion<SocketPermissionEntrySet>( |
250 permissions_.begin(), permissions_.end(), | 248 permissions_, other->permissions_); |
251 other->permissions_.begin(), other->permissions_.end(), | |
252 std::inserter<SocketPermissionEntrySet>( | |
253 result->permissions_, result->permissions_.begin())); | |
254 return result.release(); | 249 return result.release(); |
255 } | 250 } |
256 | 251 |
257 ManifestPermission* SocketsManifestPermission::Intersect( | 252 ManifestPermission* SocketsManifestPermission::Intersect( |
258 const ManifestPermission* rhs) const { | 253 const ManifestPermission* rhs) const { |
259 const SocketsManifestPermission* other = | 254 const SocketsManifestPermission* other = |
260 static_cast<const SocketsManifestPermission*>(rhs); | 255 static_cast<const SocketsManifestPermission*>(rhs); |
261 | 256 |
262 scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); | 257 scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); |
263 std::set_intersection( | 258 result->permissions_ = base::STLSetIntersection<SocketPermissionEntrySet>( |
264 permissions_.begin(), permissions_.end(), | 259 permissions_, other->permissions_); |
265 other->permissions_.begin(), other->permissions_.end(), | |
266 std::inserter<SocketPermissionEntrySet>( | |
267 result->permissions_, result->permissions_.begin())); | |
268 return result.release(); | 260 return result.release(); |
269 } | 261 } |
270 | 262 |
271 bool SocketsManifestPermission::Contains(const ManifestPermission* rhs) const { | 263 bool SocketsManifestPermission::Contains(const ManifestPermission* rhs) const { |
272 const SocketsManifestPermission* other = | 264 const SocketsManifestPermission* other = |
273 static_cast<const SocketsManifestPermission*>(rhs); | 265 static_cast<const SocketsManifestPermission*>(rhs); |
274 | 266 |
275 return std::includes( | 267 return base::STLIncludes<SocketPermissionEntrySet>(permissions_, |
276 permissions_.begin(), permissions_.end(), | 268 other->permissions_); |
277 other->permissions_.begin(), other->permissions_.end()); | |
278 } | 269 } |
279 | 270 |
280 bool SocketsManifestPermission::Equal(const ManifestPermission* rhs) const { | 271 bool SocketsManifestPermission::Equal(const ManifestPermission* rhs) const { |
281 const SocketsManifestPermission* other = | 272 const SocketsManifestPermission* other = |
282 static_cast<const SocketsManifestPermission*>(rhs); | 273 static_cast<const SocketsManifestPermission*>(rhs); |
283 | 274 |
284 return (permissions_ == other->permissions_); | 275 return (permissions_ == other->permissions_); |
285 } | 276 } |
286 | 277 |
287 void SocketsManifestPermission::Write(IPC::Message* m) const { | 278 void SocketsManifestPermission::Write(IPC::Message* m) const { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 if (it->pattern().type == SocketPermissionRequest::NETWORK_STATE) { | 360 if (it->pattern().type == SocketPermissionRequest::NETWORK_STATE) { |
370 messages.push_back(PermissionMessage( | 361 messages.push_back(PermissionMessage( |
371 PermissionMessage::kNetworkState, | 362 PermissionMessage::kNetworkState, |
372 l10n_util::GetStringUTF16( | 363 l10n_util::GetStringUTF16( |
373 IDS_EXTENSION_PROMPT_WARNING_NETWORK_STATE))); | 364 IDS_EXTENSION_PROMPT_WARNING_NETWORK_STATE))); |
374 } | 365 } |
375 } | 366 } |
376 } | 367 } |
377 | 368 |
378 } // namespace extensions | 369 } // namespace extensions |
OLD | NEW |