summaryrefslogtreecommitdiffstats
path: root/chrome/browser/google/google_url_tracker.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-10 00:55:16 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-10 00:55:16 +0000
commitf7e41ad98aa53249555f4992edeb76e2d62e0784 (patch)
tree80549a4fcb9dc56e9b6909348a2dd973268f8dc0 /chrome/browser/google/google_url_tracker.cc
parent49f7b7751dd53e71698a46fc80314688644e2590 (diff)
downloadchromium_src-f7e41ad98aa53249555f4992edeb76e2d62e0784.zip
chromium_src-f7e41ad98aa53249555f4992edeb76e2d62e0784.tar.gz
chromium_src-f7e41ad98aa53249555f4992edeb76e2d62e0784.tar.bz2
Support scheme-setting for GoogleURLTracker.
This switches the searchdomaincheck request from format=domain (".google.com") to format=url ("http://www.google.com/"). This in turn allows the server to direct us to use HTTPS searches by default, which should save a redirect on each search over the current situation when it's applicable. We hide this detail from the user; we continue to prompt about TLD changes, but we don't prompt about scheme changes. BUG=96636 TEST=Make sure the cookie store has cookies such that you get HTTPS search by default on Google. After this patch, doing a search should not involve a redirect through HTTP. Review URL: https://chromiumcodereview.appspot.com/10382091 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136205 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google/google_url_tracker.cc')
-rw-r--r--chrome/browser/google/google_url_tracker.cc99
1 files changed, 68 insertions, 31 deletions
diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc
index c751bd9..82a4283 100644
--- a/chrome/browser/google/google_url_tracker.cc
+++ b/chrome/browser/google/google_url_tracker.cc
@@ -45,6 +45,11 @@ GoogleURLTrackerInfoBarDelegate* CreateInfoBar(
google_url_tracker, new_google_url);
}
+string16 GetHost(const GURL& url) {
+ DCHECK(url.is_valid());
+ return net::StripWWW(UTF8ToUTF16(url.host()));
+}
+
} // namespace
// GoogleURLTrackerInfoBarDelegate --------------------------------------------
@@ -63,7 +68,7 @@ GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate(
}
bool GoogleURLTrackerInfoBarDelegate::Accept() {
- google_url_tracker_->AcceptGoogleURL(new_google_url_);
+ google_url_tracker_->AcceptGoogleURL(new_google_url_, true);
return false;
}
@@ -87,6 +92,11 @@ bool GoogleURLTrackerInfoBarDelegate::LinkClicked(
return false;
}
+void GoogleURLTrackerInfoBarDelegate::SetGoogleURL(const GURL& new_google_url) {
+ DCHECK_EQ(GetHost(new_google_url_), GetHost(new_google_url));
+ new_google_url_ = new_google_url;
+}
+
void GoogleURLTrackerInfoBarDelegate::Show() {
showing_ = true;
owner()->AddInfoBar(this); // May delete |this| on failure!
@@ -137,7 +147,7 @@ GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() {
string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringFUTF16(IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE,
- GetHost(true), GetHost(false));
+ GetHost(new_google_url_), GetHost(google_url_tracker_->google_url_));
}
string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel(
@@ -145,12 +155,8 @@ string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel(
bool new_host = (button == BUTTON_OK);
return l10n_util::GetStringFUTF16(new_host ?
IDS_GOOGLE_URL_TRACKER_INFOBAR_SWITCH :
- IDS_GOOGLE_URL_TRACKER_INFOBAR_DONT_SWITCH, GetHost(new_host));
-}
-
-string16 GoogleURLTrackerInfoBarDelegate::GetHost(bool new_host) const {
- return net::StripWWW(UTF8ToUTF16(
- (new_host ? new_google_url_ : google_url_tracker_->google_url_).host()));
+ IDS_GOOGLE_URL_TRACKER_INFOBAR_DONT_SWITCH,
+ GetHost(new_host ? new_google_url_ : google_url_tracker_->google_url_));
}
@@ -159,7 +165,7 @@ string16 GoogleURLTrackerInfoBarDelegate::GetHost(bool new_host) const {
const char GoogleURLTracker::kDefaultGoogleHomepage[] =
"http://www.google.com/";
const char GoogleURLTracker::kSearchDomainCheckURL[] =
- "https://www.google.com/searchdomaincheck?format=domain&type=chrome";
+ "https://www.google.com/searchdomaincheck?format=url&type=chrome";
GoogleURLTracker::GoogleURLTracker(Profile* profile, Mode mode)
: profile_(profile),
@@ -219,7 +225,8 @@ void GoogleURLTracker::GoogleURLSearchCommitted(Profile* profile) {
tracker->SearchCommitted();
}
-void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) {
+void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url,
+ bool redo_searches) {
google_url_ = new_google_url;
PrefService* prefs = profile_->GetPrefs();
prefs->SetString(prefs::kLastKnownGoogleURL, google_url_.spec());
@@ -229,7 +236,7 @@ void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) {
content::Source<Profile>(profile_),
content::Details<const GURL>(&new_google_url));
need_to_prompt_ = false;
- CloseAllInfoBars(true);
+ CloseAllInfoBars(redo_searches);
}
void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) {
@@ -301,43 +308,73 @@ void GoogleURLTracker::OnURLFetchComplete(const content::URLFetcher* source) {
return;
}
- // See if the response data was one we want to use, and if so, convert to the
- // appropriate Google base URL.
+ // See if the response data was valid. It should be
+ // "<scheme>://[www.]google.<TLD>/".
std::string url_str;
source->GetResponseAsString(&url_str);
TrimWhitespace(url_str, TRIM_ALL, &url_str);
-
- if (!StartsWithASCII(url_str, ".google.", false))
+ GURL url(url_str);
+ if (!url.is_valid() || (url.path().length() > 1) || url.has_query() ||
+ url.has_ref() ||
+ !google_util::IsGoogleDomainUrl(url.spec(),
+ google_util::DISALLOW_SUBDOMAIN))
return;
- fetched_google_url_ = GURL("http://www" + url_str);
+ std::swap(url, fetched_google_url_);
GURL last_prompted_url(
profile_->GetPrefs()->GetString(prefs::kLastPromptedGoogleURL));
if (last_prompted_url.is_empty()) {
// On the very first run of Chrome, when we've never looked up the URL at
// all, we should just silently switch over to whatever we get immediately.
- AcceptGoogleURL(fetched_google_url_);
+ AcceptGoogleURL(fetched_google_url_, true); // Second arg is irrelevant.
return;
}
- // If the URL hasn't changed, then whether |need_to_prompt_| is true or false,
- // nothing has changed, so just bail.
- if (fetched_google_url_ == last_prompted_url)
- return;
-
+ string16 fetched_host(GetHost(fetched_google_url_));
if (fetched_google_url_ == google_url_) {
- // The user came back to their original location after having temporarily
- // moved. Reset the prompted URL so we'll prompt again if they move again.
+ // Either the user has continually been on this URL, or we prompted for a
+ // different URL but have now changed back before they responded to any of
+ // the prompts. In this latter case we want to close any open infobars and
+ // stop prompting.
CancelGoogleURL(fetched_google_url_);
- return;
+ } else if (fetched_host == GetHost(google_url_)) {
+ // Similar to the above case, but this time the new URL differs from the
+ // existing one, probably due to switching between HTTP and HTTPS searching.
+ // Like before we want to close any open infobars and stop prompting; we
+ // also want to silently accept the change in scheme. We don't redo open
+ // searches so as to avoid suddenly changing a page the user might be
+ // interacting with; it's enough to simply get future searches right.
+ AcceptGoogleURL(fetched_google_url_, false);
+ } else if (fetched_host == GetHost(last_prompted_url)) {
+ // We've re-fetched a TLD the user previously turned down. Although the new
+ // URL might have a different scheme than the old, we want to preserve the
+ // user's decision. Note that it's possible that, like in the above two
+ // cases, we fetched yet another different URL in the meantime, which we
+ // have open infobars prompting about; in this case, as in those above, we
+ // want to go ahead and close the infobars and stop prompting, since we've
+ // switched back away from that URL.
+ CancelGoogleURL(fetched_google_url_);
+ } else {
+ // We've fetched a URL with a different TLD than the user is currently using
+ // or was previously prompted about. This means we need to prompt again.
+ need_to_prompt_ = true;
+
+ // As in all the above cases, there could be open infobars prompting about
+ // some URL. If these URLs have the same TLD, we can simply leave the
+ // existing infobars open and quietly point their "new Google URL"s at the
+ // new URL (for e.g. scheme changes). Otherwise we go ahead and close the
+ // existing infobars since their message is out-of-date.
+ if (!url.is_valid()) // Note: |url| is the previous |fetched_google_url_|.
+ return;
+ if (fetched_host != GetHost(url)) {
+ CloseAllInfoBars(false);
+ } else if (fetched_google_url_ != url) {
+ for (InfoBarMap::iterator i(infobar_map_.begin());
+ i != infobar_map_.end(); ++i)
+ i->second->SetGoogleURL(fetched_google_url_);
+ }
}
-
- need_to_prompt_ = true;
-
- // Any open infobars are pointing at the wrong Google URL. (This can happen
- // if an infobar has been sitting open and then our IP address changes.)
- CloseAllInfoBars(false);
}
void GoogleURLTracker::Observe(int type,