diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-08 19:12:47 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-08 19:12:47 +0000 |
commit | c4ff495718e7b190229e863e3387c4e5f99475a9 (patch) | |
tree | 3d2aef85fe5590905f80e71687154c664b9c42c0 /chrome/browser/alternate_nav_url_fetcher.cc | |
parent | 8348cb325bebf4d3516bd94949f5a4eb7c4056a9 (diff) | |
download | chromium_src-c4ff495718e7b190229e863e3387c4e5f99475a9.zip chromium_src-c4ff495718e7b190229e863e3387c4e5f99475a9.tar.gz chromium_src-c4ff495718e7b190229e863e3387c4e5f99475a9.tar.bz2 |
Add autodetection of "intranet" redirection, for ISPs etc. that send typos and nonexistent addresses to custom pages, and plumb it to the code that puts up infobars when users type in a search that appears to be an intranet address, so we don't show these for erroneous cases.
BUG=31556
TEST=none
Review URL: http://codereview.chromium.org/525079
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35807 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/alternate_nav_url_fetcher.cc')
-rw-r--r-- | chrome/browser/alternate_nav_url_fetcher.cc | 76 |
1 files changed, 44 insertions, 32 deletions
diff --git a/chrome/browser/alternate_nav_url_fetcher.cc b/chrome/browser/alternate_nav_url_fetcher.cc index 7523f66..ee8c7b6 100644 --- a/chrome/browser/alternate_nav_url_fetcher.cc +++ b/chrome/browser/alternate_nav_url_fetcher.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "chrome/browser/intranet_redirect_detector.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" @@ -82,37 +83,7 @@ void AlternateNavURLFetcher::OnURLFetchComplete(const URLFetcher* source, const ResponseCookies& cookies, const std::string& data) { DCHECK(fetcher_.get() == source); - if (status.is_success() && - // HTTP 2xx, 401, and 407 all indicate that the target address exists. - (((response_code / 100) == 2) || - (response_code == 401) || (response_code == 407))) { - state_ = SUCCEEDED; - - // The following TLD+1s are used as destinations by ISPs/DNS providers/etc. - // who return provider-controlled pages to arbitrary user navigation - // attempts. Because this can result in infobars on large fractions of user - // searches, we don't show automatic infobars for these. Note that users - // can still choose to explicitly navigate to or search for pages in these - // domains, and can still get infobars for cases that wind up on other - // domains (e.g. legit intranet sites), we're just trying to avoid - // erroneously harassing the user with our own UI prompts. - const char* kBlacklistedSites[] = { - // NOTE: Use complete URLs, because GURL() doesn't do fixup! - "http://comcast.com/", - "http://opendns.com/", - "http://verizon.net/", - }; - for (size_t i = 0; i < arraysize(kBlacklistedSites); ++i) { - if (net::RegistryControlledDomainService::SameDomainOrHost( - url, GURL(kBlacklistedSites[i]))) { - state_ = FAILED; - break; - } - } - } else { - state_ = FAILED; - } - + SetStatusFromURLFetch(url, status, response_code); ShowInfobarIfPossible(); } @@ -150,6 +121,47 @@ void AlternateNavURLFetcher::InfoBarClosed() { delete this; } +void AlternateNavURLFetcher::SetStatusFromURLFetch( + const GURL& url, + const URLRequestStatus& status, + int response_code) { + if (!status.is_success() || + // HTTP 2xx, 401, and 407 all indicate that the target address exists. + (((response_code / 100) != 2) && + (response_code != 401) && (response_code != 407)) || + // Fail if we're redirected to a common location. This is the "automatic + // heuristic" version of the explicit blacklist below; see comments there. + net::RegistryControlledDomainService::SameDomainOrHost(url, + IntranetRedirectDetector::RedirectOrigin())) { + state_ = FAILED; + return; + } + + // The following TLD+1s are used as destinations by ISPs/DNS providers/etc. + // who return provider-controlled pages to arbitrary user navigation attempts. + // Because this can result in infobars on large fractions of user searches, we + // don't show automatic infobars for these. Note that users can still choose + // to explicitly navigate to or search for pages in these domains, and can + // still get infobars for cases that wind up on other domains (e.g. legit + // intranet sites), we're just trying to avoid erroneously harassing the user + // with our own UI prompts. + const char* kBlacklistedSites[] = { + // NOTE: Use complete URLs, because GURL() doesn't do fixup! + "http://comcast.com/", + "http://opendns.com/", + "http://verizon.net/", + }; + for (size_t i = 0; i < arraysize(kBlacklistedSites); ++i) { + if (net::RegistryControlledDomainService::SameDomainOrHost(url, + GURL(kBlacklistedSites[i]))) { + state_ = FAILED; + return; + } + } + + state_ = SUCCEEDED; +} + void AlternateNavURLFetcher::ShowInfobarIfPossible() { if (!navigated_to_entry_ || state_ != SUCCEEDED) { if (state_ == FAILED) |