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 "content/public/common/url_constants.h" | |
10 #include "extensions/common/permissions/permission_message.h" | 9 #include "extensions/common/permissions/permission_message.h" |
11 #include "extensions/common/permissions/permission_set.h" | 10 #include "extensions/common/permissions/permission_set.h" |
12 #include "extensions/common/url_pattern_set.h" | 11 #include "extensions/common/url_pattern_set.h" |
13 #include "grit/extensions_strings.h" | 12 #include "grit/extensions_strings.h" |
14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 13 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
15 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "url/url_constants.h" |
16 | 16 |
17 using extensions::PermissionMessage; | 17 using extensions::PermissionMessage; |
18 using extensions::PermissionSet; | 18 using extensions::PermissionSet; |
19 using extensions::URLPatternSet; | 19 using extensions::URLPatternSet; |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // Helper for GetDistinctHosts(): com > net > org > everything else. | 23 // Helper for GetDistinctHosts(): com > net > org > everything else. |
24 bool RcdBetterThan(const std::string& a, const std::string& b) { | 24 bool RcdBetterThan(const std::string& a, const std::string& b) { |
25 if (a == b) | 25 if (a == b) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 bool include_rcd, | 95 bool include_rcd, |
96 bool exclude_file_scheme) { | 96 bool exclude_file_scheme) { |
97 // 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). |
98 // 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 |
99 // current best RCD. | 99 // current best RCD. |
100 typedef std::vector<std::pair<std::string, std::string> > HostVector; | 100 typedef std::vector<std::pair<std::string, std::string> > HostVector; |
101 HostVector hosts_best_rcd; | 101 HostVector hosts_best_rcd; |
102 for (URLPatternSet::const_iterator i = host_patterns.begin(); | 102 for (URLPatternSet::const_iterator i = host_patterns.begin(); |
103 i != host_patterns.end(); | 103 i != host_patterns.end(); |
104 ++i) { | 104 ++i) { |
105 if (exclude_file_scheme && i->scheme() == content::kFileScheme) | 105 if (exclude_file_scheme && i->scheme() == url::kFileScheme) |
106 continue; | 106 continue; |
107 | 107 |
108 std::string host = i->host(); | 108 std::string host = i->host(); |
109 | 109 |
110 // Add the subdomain wildcard back to the host, if necessary. | 110 // Add the subdomain wildcard back to the host, if necessary. |
111 if (i->match_subdomains()) | 111 if (i->match_subdomains()) |
112 host = "*." + host; | 112 host = "*." + host; |
113 | 113 |
114 // 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. |
115 std::string rcd; | 115 std::string rcd; |
(...skipping 25 matching lines...) Expand all Loading... |
141 // Build up the final vector by concatenating hosts and RCDs. | 141 // Build up the final vector by concatenating hosts and RCDs. |
142 std::set<std::string> distinct_hosts; | 142 std::set<std::string> distinct_hosts; |
143 for (HostVector::iterator it = hosts_best_rcd.begin(); | 143 for (HostVector::iterator it = hosts_best_rcd.begin(); |
144 it != hosts_best_rcd.end(); | 144 it != hosts_best_rcd.end(); |
145 ++it) | 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 |