| 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 redirect_origin_ = net::registry_controlled_domains::SameDomainOrHost( |
| 139 resulting_origins_.back(), origin) ? origin : GURL(); | 141 resulting_origins_.back(), |
| 142 origin, |
| 143 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES) ? |
| 144 origin : GURL(); |
| 140 } | 145 } |
| 141 | 146 |
| 142 g_browser_process->local_state()->SetString( | 147 g_browser_process->local_state()->SetString( |
| 143 prefs::kLastKnownIntranetRedirectOrigin, redirect_origin_.is_valid() ? | 148 prefs::kLastKnownIntranetRedirectOrigin, redirect_origin_.is_valid() ? |
| 144 redirect_origin_.spec() : std::string()); | 149 redirect_origin_.spec() : std::string()); |
| 145 } | 150 } |
| 146 | 151 |
| 147 void IntranetRedirectDetector::OnIPAddressChanged() { | 152 void IntranetRedirectDetector::OnIPAddressChanged() { |
| 148 // If a request is already scheduled, do not scheduled yet another one. | 153 // If a request is already scheduled, do not scheduled yet another one. |
| 149 if (in_sleep_) | 154 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 | 179 // 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 | 180 // hostname with the right number of characters is likely from the detector |
| 176 // (and thus should be blocked). | 181 // (and thus should be blocked). |
| 177 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && | 182 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && |
| 178 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == | 183 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == |
| 179 std::string::npos)) ? | 184 std::string::npos)) ? |
| 180 net::ERR_NAME_NOT_RESOLVED : | 185 net::ERR_NAME_NOT_RESOLVED : |
| 181 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, | 186 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, |
| 182 os_error); | 187 os_error); |
| 183 } | 188 } |
| OLD | NEW |