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

Side by Side Diff: extensions/common/permissions/permission_message_util.cc

Issue 2446273004: Reduce buggy usage of the registry controlled domain service. (Closed)
Patch Set: Review comment Created 4 years, 1 month 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
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/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
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
54 std::string rcd; 55 std::string rcd;
55 size_t reg_len = net::registry_controlled_domains::GetRegistryLength( 56 size_t reg_len =
56 host, 57 net::registry_controlled_domains::PermissiveGetHostRegistryLength(
57 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, 58 host, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
58 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); 59 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
59 if (reg_len && reg_len != std::string::npos) { 60 if (reg_len && reg_len != std::string::npos) {
60 if (include_rcd) // else leave rcd empty 61 if (include_rcd) // else leave rcd empty
61 rcd = host.substr(host.size() - reg_len); 62 rcd = host.substr(host.size() - reg_len);
62 host = host.substr(0, host.size() - reg_len); 63 host = host.substr(0, host.size() - reg_len);
63 } 64 }
64 65
65 // Check if we've already seen this host. 66 // Check if we've already seen this host.
66 HostVector::iterator it = hosts_best_rcd.begin(); 67 HostVector::iterator it = hosts_best_rcd.begin();
67 for (; it != hosts_best_rcd.end(); ++it) { 68 for (; it != hosts_best_rcd.end(); ++it) {
68 if (it->first == host) 69 if (it->first == host)
69 break; 70 break;
70 } 71 }
71 // If this host was found, replace the RCD if this one is better. 72 // If this host was found, replace the RCD if this one is better.
72 if (it != hosts_best_rcd.end()) { 73 if (it != hosts_best_rcd.end()) {
73 if (include_rcd && RcdBetterThan(rcd, it->second)) 74 if (include_rcd && RcdBetterThan(rcd, it->second))
74 it->second = rcd; 75 it->second = rcd;
75 } else { // Previously unseen host, append it. 76 } else { // Previously unseen host, append it.
76 hosts_best_rcd.push_back(std::make_pair(host, rcd)); 77 hosts_best_rcd.push_back(std::make_pair(host, rcd));
77 } 78 }
78 } 79 }
79 80
80 // Build up the result by concatenating hosts and RCDs. 81 // Build up the result by concatenating hosts and RCDs.
81 std::set<std::string> distinct_hosts; 82 std::set<std::string> distinct_hosts;
82 for (const auto& host_rcd : hosts_best_rcd) 83 for (const auto& host_rcd : hosts_best_rcd)
83 distinct_hosts.insert(host_rcd.first + host_rcd.second); 84 distinct_hosts.insert(host_rcd.first + host_rcd.second);
84 return distinct_hosts; 85 return distinct_hosts;
85 } 86 }
86 87
87 } // namespace permission_message_util 88 } // namespace permission_message_util
OLDNEW
« no previous file with comments | « extensions/common/manifest_handlers/externally_connectable.cc ('k') | extensions/common/url_pattern.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698