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

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

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