summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/instant/instant_controller.cc30
-rw-r--r--chrome/browser/instant/instant_controller.h5
2 files changed, 33 insertions, 2 deletions
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index 869c029..11ddefc 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -182,7 +182,8 @@ bool InstantController::Update(const AutocompleteMatch& match,
// If the match's TemplateURL is valid, it's a search query; use it. If it's
// not valid, it's likely a URL; in EXTENDED mode, try using the default
// search engine's TemplateURL instead.
- if (GetInstantURL(match.GetTemplateURL(profile), &instant_url)) {
+ const GURL& tab_url = active_tab->web_contents()->GetURL();
+ if (GetInstantURL(match.GetTemplateURL(profile), tab_url, &instant_url)) {
ResetLoader(instant_url, active_tab);
} else if (mode_ != EXTENDED || !CreateDefaultLoader()) {
Hide();
@@ -595,8 +596,9 @@ bool InstantController::CreateDefaultLoader() {
const TemplateURL* template_url =
TemplateURLServiceFactory::GetForProfile(active_tab->profile())->
GetDefaultSearchProvider();
+ const GURL& tab_url = active_tab->web_contents()->GetURL();
std::string instant_url;
- if (!GetInstantURL(template_url, &instant_url))
+ if (!GetInstantURL(template_url, tab_url, &instant_url))
return false;
ResetLoader(instant_url, active_tab);
@@ -669,10 +671,12 @@ void InstantController::SendBoundsToPage() {
}
bool InstantController::GetInstantURL(const TemplateURL* template_url,
+ const GURL& tab_url,
std::string* instant_url) const {
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kInstantURL)) {
*instant_url = command_line->GetSwitchValueASCII(switches::kInstantURL);
+ MaybeSetRefFromURL(tab_url, instant_url);
return true;
}
@@ -717,9 +721,31 @@ bool InstantController::GetInstantURL(const TemplateURL* template_url,
iter->second > kMaxInstantSupportFailures)
return false;
+ MaybeSetRefFromURL(tab_url, instant_url);
return true;
}
+void InstantController::MaybeSetRefFromURL(const GURL& tab_url,
+ std::string* instant_url) const {
+ if (mode_ == EXTENDED) {
+ GURL url_obj(*instant_url);
+ if (!url_obj.is_valid())
+ return;
+
+ // Copy hash state so that search modes persist for query refinements.
+ if (tab_url.has_ref() &&
+ tab_url.host() == url_obj.host() &&
+ tab_url.path() == url_obj.path()) {
+ const std::string new_ref = tab_url.ref();
+ GURL::Replacements hash;
+ hash.SetRefStr(new_ref);
+ url_obj = url_obj.ReplaceComponents(hash);
+ DCHECK(url_obj.is_valid());
+ *instant_url = url_obj.spec();
+ }
+ }
+}
+
bool InstantController::IsOutOfDate() const {
return !last_active_tab_ ||
last_active_tab_ != delegate_->GetActiveTabContents();
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h
index d2510e4..27f4910 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -204,8 +204,13 @@ class InstantController : public InstantLoaderDelegate {
// Note: If the command-line switch kInstantURL is set, this method uses its
// value for |instant_url| and returns true without examining |template_url|.
bool GetInstantURL(const TemplateURL* template_url,
+ const GURL& tab_url,
std::string* instant_url) const;
+ // Copies hash state from |tab_url| to |instant_url| when |tab_url| is
+ // navigated to the default search engine.
+ void MaybeSetRefFromURL(const GURL& tab_url, std::string* instant_url) const;
+
// Returns true if the preview is no longer relevant, say because the last
// Update() was for a URL and not a search query, or the user switched tabs.
bool IsOutOfDate() const;