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

Side by Side Diff: extensions/common/api/sockets/sockets_manifest_permission.cc

Issue 1223153003: Move JoinString to the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: windows Created 5 years, 5 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
« no previous file with comments | « extensions/browser/updater/manifest_fetch_data.cc ('k') | extensions/common/csp_validator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/sockets/sockets_manifest_permission.h" 5 #include "extensions/common/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/stl_util.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 if (!domains.empty()) { 124 if (!domains.empty()) {
125 // TODO(sashab): This is not correct for all languages - add proper 125 // TODO(sashab): This is not correct for all languages - add proper
126 // internationalization of this string for all plural states. 126 // internationalization of this string for all plural states.
127 if (messages) { 127 if (messages) {
128 int id = (domains.size() == 1) 128 int id = (domains.size() == 1)
129 ? IDS_EXTENSION_PROMPT_WARNING_SOCKET_HOSTS_IN_DOMAIN 129 ? IDS_EXTENSION_PROMPT_WARNING_SOCKET_HOSTS_IN_DOMAIN
130 : IDS_EXTENSION_PROMPT_WARNING_SOCKET_HOSTS_IN_DOMAINS; 130 : IDS_EXTENSION_PROMPT_WARNING_SOCKET_HOSTS_IN_DOMAINS;
131 messages->push_back(PermissionMessage( 131 messages->push_back(PermissionMessage(
132 PermissionMessage::kSocketDomainHosts, 132 PermissionMessage::kSocketDomainHosts,
133 l10n_util::GetStringFUTF16( 133 l10n_util::GetStringFUTF16(
134 id, JoinString(std::vector<base::string16>(domains.begin(), 134 id, base::JoinString(std::vector<base::string16>(domains.begin(),
135 domains.end()), 135 domains.end()),
136 ' ')))); 136 base::ASCIIToUTF16(" ")))));
137 } 137 }
138 if (ids) { 138 if (ids) {
139 for (const auto& domain : domains) 139 for (const auto& domain : domains)
140 ids->insert(APIPermission::kSocketDomainHosts, domain); 140 ids->insert(APIPermission::kSocketDomainHosts, domain);
141 } 141 }
142 } 142 }
143 } 143 }
144 144
145 // Helper function for adding specific host socket permissions. Determines what 145 // Helper function for adding specific host socket permissions. Determines what
146 // messages are needed from |sockets|, and adds permissions to |ids| and/or 146 // messages are needed from |sockets|, and adds permissions to |ids| and/or
147 // |messages|, ignoring them if they are NULL. 147 // |messages|, ignoring them if they are NULL.
148 void AddSpecificHostMessage(const SocketPermissionEntrySet& sockets, 148 void AddSpecificHostMessage(const SocketPermissionEntrySet& sockets,
149 PermissionIDSet* ids, 149 PermissionIDSet* ids,
150 PermissionMessages* messages) { 150 PermissionMessages* messages) {
151 std::set<base::string16> hostnames; 151 std::set<base::string16> hostnames;
152 for (const auto& socket : sockets) { 152 for (const auto& socket : sockets) {
153 if (socket.GetHostType() == SocketPermissionEntry::SPECIFIC_HOSTS) 153 if (socket.GetHostType() == SocketPermissionEntry::SPECIFIC_HOSTS)
154 hostnames.insert(base::UTF8ToUTF16(socket.pattern().host)); 154 hostnames.insert(base::UTF8ToUTF16(socket.pattern().host));
155 } 155 }
156 if (!hostnames.empty()) { 156 if (!hostnames.empty()) {
157 // TODO(sashab): This is not correct for all languages - add proper 157 // TODO(sashab): This is not correct for all languages - add proper
158 // internationalization of this string for all plural states. 158 // internationalization of this string for all plural states.
159 if (messages) { 159 if (messages) {
160 int id = (hostnames.size() == 1) 160 int id = (hostnames.size() == 1)
161 ? IDS_EXTENSION_PROMPT_WARNING_SOCKET_SPECIFIC_HOST 161 ? IDS_EXTENSION_PROMPT_WARNING_SOCKET_SPECIFIC_HOST
162 : IDS_EXTENSION_PROMPT_WARNING_SOCKET_SPECIFIC_HOSTS; 162 : IDS_EXTENSION_PROMPT_WARNING_SOCKET_SPECIFIC_HOSTS;
163 messages->push_back(PermissionMessage( 163 messages->push_back(PermissionMessage(
164 PermissionMessage::kSocketSpecificHosts, 164 PermissionMessage::kSocketSpecificHosts,
165 l10n_util::GetStringFUTF16( 165 l10n_util::GetStringFUTF16(
166 id, JoinString(std::vector<base::string16>(hostnames.begin(), 166 id, base::JoinString(std::vector<base::string16>(
167 hostnames.end()), 167 hostnames.begin(), hostnames.end()),
168 ' ')))); 168 base::ASCIIToUTF16(" ")))));
169 } 169 }
170 if (ids) { 170 if (ids) {
171 for (const auto& hostname : hostnames) 171 for (const auto& hostname : hostnames)
172 ids->insert(APIPermission::kSocketSpecificHosts, hostname); 172 ids->insert(APIPermission::kSocketSpecificHosts, hostname);
173 } 173 }
174 } 174 }
175 } 175 }
176 176
177 // Helper function for adding the network list socket permission. Determines if 177 // Helper function for adding the network list socket permission. Determines if
178 // the message is needed from |sockets|, and adds the permission to |ids| and/or 178 // the message is needed from |sockets|, and adds the permission to |ids| and/or
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 PermissionIDSet* ids, 374 PermissionIDSet* ids,
375 PermissionMessages* messages) { 375 PermissionMessages* messages) {
376 if (!AddAnyHostMessage(sockets, ids, messages)) { 376 if (!AddAnyHostMessage(sockets, ids, messages)) {
377 AddSpecificHostMessage(sockets, ids, messages); 377 AddSpecificHostMessage(sockets, ids, messages);
378 AddSubdomainHostMessage(sockets, ids, messages); 378 AddSubdomainHostMessage(sockets, ids, messages);
379 } 379 }
380 AddNetworkListMessage(sockets, ids, messages); 380 AddNetworkListMessage(sockets, ids, messages);
381 } 381 }
382 382
383 } // namespace extensions 383 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/updater/manifest_fetch_data.cc ('k') | extensions/common/csp_validator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698