Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / extensions / common / permissions / socket_permission.cc
blobe5fac9d5626de0aaa211fee75918be09ef862029
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
3 // found in the LICENSE file.
5 #include "extensions/common/permissions/socket_permission.h"
7 #include <algorithm>
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "extensions/common/api/sockets/sockets_manifest_permission.h"
13 #include "extensions/common/permissions/permissions_info.h"
14 #include "extensions/common/permissions/set_disjunction_permission.h"
15 #include "grit/extensions_strings.h"
16 #include "ui/base/l10n/l10n_util.h"
18 namespace extensions {
20 namespace {
22 // Extracts the SocketPermissionEntry fields from a set of SocketPermissionData,
23 // and places them in their own set. Useful for converting the
24 // std::set<SocketPermissionEntry> field from SocketPermission into a parameter
25 // that can be passed to SocketsManifestPermission::AddSocketHostPermissions().
26 SocketPermissionEntrySet ExtractSocketEntries(
27 const std::set<SocketPermissionData>& data_set) {
28 SocketPermissionEntrySet entries;
29 for (const auto& data : data_set)
30 entries.insert(data.entry());
31 return entries;
34 } // namespace
36 SocketPermission::SocketPermission(const APIPermissionInfo* info)
37 : SetDisjunctionPermission<SocketPermissionData, SocketPermission>(info) {}
39 SocketPermission::~SocketPermission() {}
41 PermissionIDSet SocketPermission::GetPermissions() const {
42 PermissionIDSet ids;
43 SocketPermissionEntrySet entries = ExtractSocketEntries(data_set_);
44 SocketsManifestPermission::AddSocketHostPermissions(entries, &ids, NULL);
45 return ids;
48 PermissionMessages SocketPermission::GetMessages() const {
49 DCHECK(HasMessages());
50 PermissionMessages messages;
51 SocketPermissionEntrySet entries = ExtractSocketEntries(data_set_);
52 SocketsManifestPermission::AddSocketHostPermissions(entries, NULL, &messages);
53 return messages;
56 } // namespace extensions