Chromium Code Reviews| 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 "extensions/common/permissions/permission_message_util.h" | 5 #include "extensions/common/permissions/permission_message_util.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "extensions/common/permissions/permission_message.h" | 9 #include "extensions/common/permissions/permission_message.h" |
| 10 #include "extensions/common/permissions/permission_set.h" | 10 #include "extensions/common/permissions/permission_set.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 if (a == "org") | 31 if (a == "org") |
| 32 return b != "com" && b != "net"; | 32 return b != "com" && b != "net"; |
| 33 return false; | 33 return false; |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 namespace permission_message_util { | 38 namespace permission_message_util { |
| 39 | 39 |
| 40 PermissionMessage CreateFromHostList(const std::set<std::string>& hosts) { | 40 PermissionMessage CreateFromHostList(const std::set<std::string>& hosts) { |
| 41 std::vector<std::string> host_list(hosts.begin(), hosts.end()); | 41 std::vector<base::string16> host_list; |
| 42 DCHECK(host_list.size()); | |
| 43 PermissionMessage::ID message_id; | 42 PermissionMessage::ID message_id; |
| 44 base::string16 message; | 43 base::string16 message; |
| 45 base::string16 details; | 44 base::string16 details; |
|
not at google - send to devlin
2014/07/23 01:32:45
nits: declare these 3 (or 2) variables only when y
mhm
2014/07/23 02:38:45
Done.
| |
| 45 const uint32_t kMaxBeforeListOfHosts = 3; | |
|
not at google - send to devlin
2014/07/23 01:32:45
size_t?
mhm
2014/07/23 02:38:45
Done.
| |
| 46 typedef std::pair<PermissionMessage::ID, int> MsgPair; | |
| 47 int host_msg_id = hosts.size() <= kMaxBeforeListOfHosts | |
| 48 ? IDS_EXTENSION_PROMPT_WARNING_HOST_AND_SUBDOMAIN | |
| 49 : IDS_EXTENSION_PROMPT_WARNING_HOST_AND_SUBDOMAIN_LIST; | |
| 50 const MsgPair kMessagesList[kMaxBeforeListOfHosts + 1] = { | |
|
not at google - send to devlin
2014/07/23 01:32:45
do you even need to specify a size here? I would h
mhm
2014/07/23 02:38:45
Done.
| |
| 51 std::make_pair(PermissionMessage::kHosts1, | |
| 52 IDS_EXTENSION_PROMPT_WARNING_1_HOST), | |
| 53 std::make_pair(PermissionMessage::kHosts2, | |
| 54 IDS_EXTENSION_PROMPT_WARNING_2_HOSTS), | |
| 55 std::make_pair(PermissionMessage::kHosts3, | |
| 56 IDS_EXTENSION_PROMPT_WARNING_3_HOSTS), | |
| 57 std::make_pair(PermissionMessage::kHosts4OrMore, | |
| 58 IDS_EXTENSION_PROMPT_WARNING_HOSTS_4_OR_MORE_HOSTS)}; | |
| 46 | 59 |
| 47 switch (host_list.size()) { | 60 for (std::set<std::string>::const_iterator it = hosts.begin(); |
| 48 case 1: | 61 it != hosts.end(); |
| 49 message_id = PermissionMessage::kHosts1; | 62 ++it) { |
| 50 message = l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_1_HOST, | 63 std::string host = *it; |
| 51 base::UTF8ToUTF16(host_list[0])); | 64 host_list.push_back( |
| 52 break; | 65 host[0] == '*' && host[1] == '.' |
| 53 case 2: | 66 ? l10n_util::GetStringFUTF16(host_msg_id, |
| 54 message_id = PermissionMessage::kHosts2; | 67 base::UTF8ToUTF16(host.erase(0, 2))) |
| 55 message = l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_2_HOSTS, | 68 : base::UTF8ToUTF16(host)); |
| 56 base::UTF8ToUTF16(host_list[0]), | 69 } |
| 57 base::UTF8ToUTF16(host_list[1])); | 70 DCHECK(host_list.size()); |
| 58 break; | |
| 59 case 3: | |
| 60 message_id = PermissionMessage::kHosts3; | |
| 61 message = l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_3_HOSTS, | |
| 62 base::UTF8ToUTF16(host_list[0]), | |
| 63 base::UTF8ToUTF16(host_list[1]), | |
| 64 base::UTF8ToUTF16(host_list[2])); | |
| 65 break; | |
| 66 default: | |
| 67 message_id = PermissionMessage::kHosts4OrMore; | |
| 68 | 71 |
| 69 const int kRetainedFilesMessageIDs[6] = { | 72 if (host_list.size() <= kMaxBeforeListOfHosts) { |
|
not at google - send to devlin
2014/07/23 01:32:45
this could be a bit simpler if you used a MsgPair
mhm
2014/07/23 02:38:45
Done.
| |
| 70 IDS_EXTENSION_PROMPT_WARNING_HOSTS_DEFAULT, | 73 message_id = kMessagesList[host_list.size() - 1].first; |
| 71 IDS_EXTENSION_PROMPT_WARNING_HOST_SINGULAR, | 74 message = l10n_util::GetStringFUTF16( |
| 72 IDS_EXTENSION_PROMPT_WARNING_HOSTS_ZERO, | 75 kMessagesList[host_list.size() - 1].second, host_list, NULL); |
| 73 IDS_EXTENSION_PROMPT_WARNING_HOSTS_TWO, | 76 } else { |
| 74 IDS_EXTENSION_PROMPT_WARNING_HOSTS_FEW, | 77 message_id = kMessagesList[kMaxBeforeListOfHosts].first; |
| 75 IDS_EXTENSION_PROMPT_WARNING_HOSTS_MANY, }; | 78 message = |
| 76 std::vector<int> message_ids; | 79 l10n_util::GetStringUTF16(kMessagesList[kMaxBeforeListOfHosts].second); |
| 77 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { | 80 for (size_t i = 0; i < host_list.size(); ++i) { |
| 78 message_ids.push_back(kRetainedFilesMessageIDs[i]); | 81 if (i > 0) |
| 79 } | 82 details += base::ASCIIToUTF16("\n"); |
| 80 message = l10n_util::GetPluralStringFUTF16(message_ids, host_list.size()); | 83 details += l10n_util::GetStringFUTF16( |
| 81 | 84 IDS_EXTENSION_PROMPT_WARNING_HOST_LIST_ENTRY, host_list[i]); |
| 82 for (size_t i = 0; i < host_list.size(); ++i) { | 85 } |
| 83 if (i > 0) | |
| 84 details += base::ASCIIToUTF16("\n"); | |
| 85 details += l10n_util::GetStringFUTF16( | |
| 86 IDS_EXTENSION_PROMPT_WARNING_HOST_LIST_ENTRY, | |
| 87 base::UTF8ToUTF16(host_list[i])); | |
| 88 } | |
| 89 } | 86 } |
| 90 | 87 |
| 91 return PermissionMessage(message_id, message, details); | 88 return PermissionMessage(message_id, message, details); |
| 92 } | 89 } |
| 93 | 90 |
| 94 std::set<std::string> GetDistinctHosts(const URLPatternSet& host_patterns, | 91 std::set<std::string> GetDistinctHosts(const URLPatternSet& host_patterns, |
| 95 bool include_rcd, | 92 bool include_rcd, |
| 96 bool exclude_file_scheme) { | 93 bool exclude_file_scheme) { |
| 97 // Use a vector to preserve order (also faster than a map on small sets). | 94 // Use a vector to preserve order (also faster than a map on small sets). |
| 98 // Each item is a host split into two parts: host without RCDs and | 95 // Each item is a host split into two parts: host without RCDs and |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 // Build up the final vector by concatenating hosts and RCDs. | 138 // Build up the final vector by concatenating hosts and RCDs. |
| 142 std::set<std::string> distinct_hosts; | 139 std::set<std::string> distinct_hosts; |
| 143 for (HostVector::iterator it = hosts_best_rcd.begin(); | 140 for (HostVector::iterator it = hosts_best_rcd.begin(); |
| 144 it != hosts_best_rcd.end(); | 141 it != hosts_best_rcd.end(); |
| 145 ++it) | 142 ++it) |
| 146 distinct_hosts.insert(it->first + it->second); | 143 distinct_hosts.insert(it->first + it->second); |
| 147 return distinct_hosts; | 144 return distinct_hosts; |
| 148 } | 145 } |
| 149 | 146 |
| 150 } // namespace permission_message_util | 147 } // namespace permission_message_util |
| OLD | NEW |