Index: chrome/browser/instant/instant_controller.cc |
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc |
index acb9583c85849f88a7e1d93d5ca684c5db1ac6b2..6e36b987a8322e8c5c102cd64bf0f1f6cee00b05 100644 |
--- a/chrome/browser/instant/instant_controller.cc |
+++ b/chrome/browser/instant/instant_controller.cc |
@@ -180,7 +180,8 @@ InstantController::InstantController(chrome::BrowserInstantController* browser, |
omnibox_focus_state_(OMNIBOX_FOCUS_NONE), |
start_margin_(0), |
end_margin_(0), |
- allow_preview_to_show_search_suggestions_(false) { |
+ allow_preview_to_show_search_suggestions_(false), |
+ instant_set_transient_entry_(false) { |
} |
InstantController::~InstantController() { |
@@ -348,6 +349,7 @@ bool InstantController::Update(const AutocompleteMatch& match, |
last_suggestion_ = InstantSuggestion(); |
last_omnibox_text_ = full_text; |
+ SetTransientHistoryEntry(); |
if (!extended_enabled_) { |
// In non-extended mode, the query is verbatim if there's any selection |
@@ -809,6 +811,8 @@ void InstantController::SetSuggestions( |
} |
} |
+ SetTransientHistoryEntry(); |
+ |
// Extended mode pages will call ShowLoader() when they are ready. |
if (!extended_enabled_) |
ShowLoader(INSTANT_SHOWN_QUERY_SUGGESTIONS, 100, INSTANT_SIZE_PERCENT); |
@@ -1088,6 +1092,8 @@ void InstantController::HideInternal() { |
loader_->Update(string16(), 0, 0, true); |
} |
+ ResetTransientHistoryEntry(); |
+ |
// Clear the first interaction timestamp for later use. |
first_interaction_time_ = base::Time(); |
} |
@@ -1145,6 +1151,51 @@ void InstantController::ShowLoader(InstantShownReason reason, |
// overlay (because we're not full height). |
if (reason == INSTANT_SHOWN_CLICKED_QUERY_SUGGESTION) |
CommitIfPossible(INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION); |
+ else if (extended_enabled_ && IsFullHeight(model_)) |
+ SetTransientHistoryEntry(); |
+} |
+ |
+void InstantController::SetTransientHistoryEntry() { |
+ content::WebContents* active_tab = browser_->GetActiveWebContents(); |
+ // Save any transient entry already associated with the active tab. |
+ content::NavigationEntry* old_transient_entry = |
+ active_tab->GetController().GetTransientEntry(); |
+ if (old_transient_entry && !instant_set_transient_entry_) |
+ transient_entry_.reset( |
+ content::NavigationEntry::Create(*old_transient_entry)); |
+ // The loader's base navigation entry should describe the search provider |
+ // without reference to a specific query. The alternative, updating the query |
+ // in the tab title as the user types, would be distracting. |
+ const content::NavigationEntry* base_entry = loader_->base_navigation_entry(); |
+ DCHECK(base_entry != NULL); |
+ content::NavigationEntry* new_transient_entry = |
+ content::NavigationEntry::Create(*base_entry); |
+ // The URL should update so that if the user presses reload, we reload the |
+ // page for the current query. |
+ const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( |
+ Profile::FromBrowserContext(active_tab->GetBrowserContext()))-> |
+ GetDefaultSearchProvider(); |
+ const TemplateURLRef& url_ref = template_url->url_ref(); |
+ DCHECK(url_ref.IsValid()); |
+ TemplateURLRef::SearchTermsArgs search_terms(last_omnibox_text_ + |
+ last_suggestion_.text); |
+ std::string url = url_ref.ReplaceSearchTerms(search_terms); |
+ new_transient_entry->SetURL(GURL(url)); |
+ new_transient_entry->SetVirtualURL(GURL(url)); |
+ active_tab->GetController().AddTransientEntry(new_transient_entry); |
+ instant_set_transient_entry_ = true; |
sreeram
2013/01/22 05:28:34
Wow. This is really hacky. Why do we need this? Ca
Jered
2013/01/23 21:52:07
Navigating after 3 seconds is a very Google-specif
|
+} |
+ |
+void InstantController::ResetTransientHistoryEntry() { |
+ content::NavigationEntry* old_transient_entry = transient_entry_.release(); |
+ if (old_transient_entry) { |
+ DVLOG(1) << "ResetTransientHistoryEntry: restoring old transient entry"; |
+ content::WebContents* active_tab = browser_->GetActiveWebContents(); |
+ active_tab->GetController().AddTransientEntry(old_transient_entry); |
+ chrome::search::SearchTabHelper::FromWebContents(active_tab)-> |
+ NavigationEntryUpdated(); |
+ } |
+ instant_set_transient_entry_ = false; |
} |
void InstantController::SendPopupBoundsToPage() { |