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 <stddef.h> | 7 #include <stddef.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 if (exclude_file_scheme && pattern.scheme() == url::kFileScheme) | 44 if (exclude_file_scheme && pattern.scheme() == url::kFileScheme) |
45 continue; | 45 continue; |
46 | 46 |
47 std::string host = pattern.host(); | 47 std::string host = pattern.host(); |
48 | 48 |
49 // Add the subdomain wildcard back to the host, if necessary. | 49 // Add the subdomain wildcard back to the host, if necessary. |
50 if (pattern.match_subdomains()) | 50 if (pattern.match_subdomains()) |
51 host = "*." + host; | 51 host = "*." + host; |
52 | 52 |
53 // If the host has an RCD, split it off so we can detect duplicates. | 53 // If the host has an RCD, split it off so we can detect duplicates. |
| 54 |
| 55 // TODO(bug 657199) this is wrong! This function internally canonicalizes |
| 56 // the host and returns the length in the canonicalized string. |
| 57 // Canonicalization can change the length of the host components, so these |
| 58 // lengths will not necessarily match our string. |
54 std::string rcd; | 59 std::string rcd; |
55 size_t reg_len = net::registry_controlled_domains::GetRegistryLength( | 60 size_t reg_len = |
56 host, | 61 net::registry_controlled_domains::BuggyGetHostRegistryLength( |
57 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | 62 host, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
58 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | 63 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
59 if (reg_len && reg_len != std::string::npos) { | 64 if (reg_len && reg_len != std::string::npos) { |
60 if (include_rcd) // else leave rcd empty | 65 if (include_rcd) // else leave rcd empty |
61 rcd = host.substr(host.size() - reg_len); | 66 rcd = host.substr(host.size() - reg_len); |
62 host = host.substr(0, host.size() - reg_len); | 67 host = host.substr(0, host.size() - reg_len); |
63 } | 68 } |
64 | 69 |
65 // Check if we've already seen this host. | 70 // Check if we've already seen this host. |
66 HostVector::iterator it = hosts_best_rcd.begin(); | 71 HostVector::iterator it = hosts_best_rcd.begin(); |
67 for (; it != hosts_best_rcd.end(); ++it) { | 72 for (; it != hosts_best_rcd.end(); ++it) { |
68 if (it->first == host) | 73 if (it->first == host) |
69 break; | 74 break; |
70 } | 75 } |
71 // If this host was found, replace the RCD if this one is better. | 76 // If this host was found, replace the RCD if this one is better. |
72 if (it != hosts_best_rcd.end()) { | 77 if (it != hosts_best_rcd.end()) { |
73 if (include_rcd && RcdBetterThan(rcd, it->second)) | 78 if (include_rcd && RcdBetterThan(rcd, it->second)) |
74 it->second = rcd; | 79 it->second = rcd; |
75 } else { // Previously unseen host, append it. | 80 } else { // Previously unseen host, append it. |
76 hosts_best_rcd.push_back(std::make_pair(host, rcd)); | 81 hosts_best_rcd.push_back(std::make_pair(host, rcd)); |
77 } | 82 } |
78 } | 83 } |
79 | 84 |
80 // Build up the result by concatenating hosts and RCDs. | 85 // Build up the result by concatenating hosts and RCDs. |
81 std::set<std::string> distinct_hosts; | 86 std::set<std::string> distinct_hosts; |
82 for (const auto& host_rcd : hosts_best_rcd) | 87 for (const auto& host_rcd : hosts_best_rcd) |
83 distinct_hosts.insert(host_rcd.first + host_rcd.second); | 88 distinct_hosts.insert(host_rcd.first + host_rcd.second); |
84 return distinct_hosts; | 89 return distinct_hosts; |
85 } | 90 } |
86 | 91 |
87 } // namespace permission_message_util | 92 } // namespace permission_message_util |
OLD | NEW |