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/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 "content/public/common/url_constants.h" | 9 #include "content/public/common/url_constants.h" |
10 #include "extensions/common/permissions/permission_message.h" | 10 #include "extensions/common/permissions/permission_message.h" |
11 #include "extensions/common/permissions/permission_set.h" | 11 #include "extensions/common/permissions/permission_set.h" |
12 #include "extensions/common/url_pattern_set.h" | 12 #include "extensions/common/url_pattern_set.h" |
13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 break; | 65 break; |
66 default: | 66 default: |
67 message_id = PermissionMessage::kHosts4OrMore; | 67 message_id = PermissionMessage::kHosts4OrMore; |
68 | 68 |
69 const int kRetainedFilesMessageIDs[6] = { | 69 const int kRetainedFilesMessageIDs[6] = { |
70 IDS_EXTENSION_PROMPT_WARNING_HOSTS_DEFAULT, | 70 IDS_EXTENSION_PROMPT_WARNING_HOSTS_DEFAULT, |
71 IDS_EXTENSION_PROMPT_WARNING_HOST_SINGULAR, | 71 IDS_EXTENSION_PROMPT_WARNING_HOST_SINGULAR, |
72 IDS_EXTENSION_PROMPT_WARNING_HOSTS_ZERO, | 72 IDS_EXTENSION_PROMPT_WARNING_HOSTS_ZERO, |
73 IDS_EXTENSION_PROMPT_WARNING_HOSTS_TWO, | 73 IDS_EXTENSION_PROMPT_WARNING_HOSTS_TWO, |
74 IDS_EXTENSION_PROMPT_WARNING_HOSTS_FEW, | 74 IDS_EXTENSION_PROMPT_WARNING_HOSTS_FEW, |
75 IDS_EXTENSION_PROMPT_WARNING_HOSTS_MANY, | 75 IDS_EXTENSION_PROMPT_WARNING_HOSTS_MANY, }; |
76 }; | |
77 std::vector<int> message_ids; | 76 std::vector<int> message_ids; |
78 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { | 77 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { |
79 message_ids.push_back(kRetainedFilesMessageIDs[i]); | 78 message_ids.push_back(kRetainedFilesMessageIDs[i]); |
80 } | 79 } |
81 message = l10n_util::GetPluralStringFUTF16(message_ids, host_list.size()); | 80 message = l10n_util::GetPluralStringFUTF16(message_ids, host_list.size()); |
82 | 81 |
83 for (size_t i = 0; i < host_list.size(); ++i) { | 82 for (size_t i = 0; i < host_list.size(); ++i) { |
84 if (i > 0) | 83 if (i > 0) |
85 details += base::ASCIIToUTF16("\n"); | 84 details += base::ASCIIToUTF16("\n"); |
86 details += l10n_util::GetStringFUTF16( | 85 details += l10n_util::GetStringFUTF16( |
87 IDS_EXTENSION_PROMPT_WARNING_HOST_LIST_ENTRY, | 86 IDS_EXTENSION_PROMPT_WARNING_HOST_LIST_ENTRY, |
88 base::UTF8ToUTF16(host_list[i])); | 87 base::UTF8ToUTF16(host_list[i])); |
89 } | 88 } |
90 } | 89 } |
91 | 90 |
92 return PermissionMessage(message_id, message, details); | 91 return PermissionMessage(message_id, message, details); |
93 } | 92 } |
94 | 93 |
95 std::set<std::string> GetDistinctHosts( | 94 std::set<std::string> GetDistinctHosts(const URLPatternSet& host_patterns, |
96 const URLPatternSet& host_patterns, | 95 bool include_rcd, |
97 bool include_rcd, | 96 bool exclude_file_scheme) { |
98 bool exclude_file_scheme) { | |
99 // Use a vector to preserve order (also faster than a map on small sets). | 97 // Use a vector to preserve order (also faster than a map on small sets). |
100 // Each item is a host split into two parts: host without RCDs and | 98 // Each item is a host split into two parts: host without RCDs and |
101 // current best RCD. | 99 // current best RCD. |
102 typedef std::vector<std::pair<std::string, std::string> > HostVector; | 100 typedef std::vector<std::pair<std::string, std::string> > HostVector; |
103 HostVector hosts_best_rcd; | 101 HostVector hosts_best_rcd; |
104 for (URLPatternSet::const_iterator i = host_patterns.begin(); | 102 for (URLPatternSet::const_iterator i = host_patterns.begin(); |
105 i != host_patterns.end(); ++i) { | 103 i != host_patterns.end(); |
| 104 ++i) { |
106 if (exclude_file_scheme && i->scheme() == content::kFileScheme) | 105 if (exclude_file_scheme && i->scheme() == content::kFileScheme) |
107 continue; | 106 continue; |
108 | 107 |
109 std::string host = i->host(); | 108 std::string host = i->host(); |
110 | 109 |
111 // Add the subdomain wildcard back to the host, if necessary. | 110 // Add the subdomain wildcard back to the host, if necessary. |
112 if (i->match_subdomains()) | 111 if (i->match_subdomains()) |
113 host = "*." + host; | 112 host = "*." + host; |
114 | 113 |
115 // If the host has an RCD, split it off so we can detect duplicates. | 114 // If the host has an RCD, split it off so we can detect duplicates. |
(...skipping 19 matching lines...) Expand all Loading... |
135 if (include_rcd && RcdBetterThan(rcd, it->second)) | 134 if (include_rcd && RcdBetterThan(rcd, it->second)) |
136 it->second = rcd; | 135 it->second = rcd; |
137 } else { // Previously unseen host, append it. | 136 } else { // Previously unseen host, append it. |
138 hosts_best_rcd.push_back(std::make_pair(host, rcd)); | 137 hosts_best_rcd.push_back(std::make_pair(host, rcd)); |
139 } | 138 } |
140 } | 139 } |
141 | 140 |
142 // Build up the final vector by concatenating hosts and RCDs. | 141 // Build up the final vector by concatenating hosts and RCDs. |
143 std::set<std::string> distinct_hosts; | 142 std::set<std::string> distinct_hosts; |
144 for (HostVector::iterator it = hosts_best_rcd.begin(); | 143 for (HostVector::iterator it = hosts_best_rcd.begin(); |
145 it != hosts_best_rcd.end(); ++it) | 144 it != hosts_best_rcd.end(); |
| 145 ++it) |
146 distinct_hosts.insert(it->first + it->second); | 146 distinct_hosts.insert(it->first + it->second); |
147 return distinct_hosts; | 147 return distinct_hosts; |
148 } | 148 } |
149 | 149 |
150 } // namespace permission_message_util | 150 } // namespace permission_message_util |
OLD | NEW |