OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/intranet_redirect_detector.h" | 5 #include "chrome/browser/intranet_redirect_detector.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 return; | 113 return; |
114 } | 114 } |
115 redirect_origin_ = GURL(); | 115 redirect_origin_ = GURL(); |
116 } else { | 116 } else { |
117 DCHECK(source->GetURL().is_valid()); | 117 DCHECK(source->GetURL().is_valid()); |
118 GURL origin(source->GetURL().GetOrigin()); | 118 GURL origin(source->GetURL().GetOrigin()); |
119 if (resulting_origins_.empty()) { | 119 if (resulting_origins_.empty()) { |
120 resulting_origins_.push_back(origin); | 120 resulting_origins_.push_back(origin); |
121 return; | 121 return; |
122 } | 122 } |
123 if (net::RegistryControlledDomainService::SameDomainOrHost( | 123 if (net::registry_controlled_domains::SameDomainOrHost( |
124 resulting_origins_.front(), origin)) { | 124 resulting_origins_.front(), |
| 125 origin, |
| 126 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)) { |
125 redirect_origin_ = origin; | 127 redirect_origin_ = origin; |
126 if (!fetchers_.empty()) { | 128 if (!fetchers_.empty()) { |
127 // Cancel remaining fetch, we don't need it. | 129 // Cancel remaining fetch, we don't need it. |
128 DCHECK(fetchers_.size() == 1); | 130 DCHECK(fetchers_.size() == 1); |
129 delete (*fetchers_.begin()); | 131 delete (*fetchers_.begin()); |
130 fetchers_.clear(); | 132 fetchers_.clear(); |
131 } | 133 } |
132 } | 134 } |
133 if (resulting_origins_.size() == 1) { | 135 if (resulting_origins_.size() == 1) { |
134 resulting_origins_.push_back(origin); | 136 resulting_origins_.push_back(origin); |
135 return; | 137 return; |
136 } | 138 } |
137 DCHECK(resulting_origins_.size() == 2); | 139 DCHECK(resulting_origins_.size() == 2); |
138 redirect_origin_ = net::RegistryControlledDomainService::SameDomainOrHost( | 140 const bool same_domain_or_host = |
139 resulting_origins_.back(), origin) ? origin : GURL(); | 141 net::registry_controlled_domains::SameDomainOrHost( |
| 142 resulting_origins_.back(), |
| 143 origin, |
| 144 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
| 145 redirect_origin_ = same_domain_or_host ? origin : GURL(); |
140 } | 146 } |
141 | 147 |
142 g_browser_process->local_state()->SetString( | 148 g_browser_process->local_state()->SetString( |
143 prefs::kLastKnownIntranetRedirectOrigin, redirect_origin_.is_valid() ? | 149 prefs::kLastKnownIntranetRedirectOrigin, redirect_origin_.is_valid() ? |
144 redirect_origin_.spec() : std::string()); | 150 redirect_origin_.spec() : std::string()); |
145 } | 151 } |
146 | 152 |
147 void IntranetRedirectDetector::OnIPAddressChanged() { | 153 void IntranetRedirectDetector::OnIPAddressChanged() { |
148 // If a request is already scheduled, do not scheduled yet another one. | 154 // If a request is already scheduled, do not scheduled yet another one. |
149 if (in_sleep_) | 155 if (in_sleep_) |
(...skipping 24 matching lines...) Expand all Loading... |
174 // the same thread. So just use the heuristic that any all-lowercase a-z | 180 // the same thread. So just use the heuristic that any all-lowercase a-z |
175 // hostname with the right number of characters is likely from the detector | 181 // hostname with the right number of characters is likely from the detector |
176 // (and thus should be blocked). | 182 // (and thus should be blocked). |
177 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && | 183 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && |
178 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == | 184 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == |
179 std::string::npos)) ? | 185 std::string::npos)) ? |
180 net::ERR_NAME_NOT_RESOLVED : | 186 net::ERR_NAME_NOT_RESOLVED : |
181 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, | 187 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, |
182 os_error); | 188 os_error); |
183 } | 189 } |
OLD | NEW |