Index: chrome/browser/instant/instant_controller.cc |
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc |
index c8acaa796e93ed6dda019121ff37e303f88e0ea8..8aa9f6121689bfe62afe60d1d8a094d627ffe99b 100644 |
--- a/chrome/browser/instant/instant_controller.cc |
+++ b/chrome/browser/instant/instant_controller.cc |
@@ -165,6 +165,9 @@ bool IsFullHeight(const InstantModel& model) { |
const char* InstantController::kLocalOmniboxPopupURL = |
"chrome://local-omnibox-popup/local-omnibox-popup.html"; |
+// static |
+const std::string InstantController::kSearchTermsKey = "search_terms"; |
+ |
InstantController::InstantController(chrome::BrowserInstantController* browser, |
bool extended_enabled, |
bool use_local_preview_only) |
@@ -478,6 +481,10 @@ bool InstantController::IsPreviewingSearchResults() const { |
last_suggestion_.behavior == INSTANT_COMPLETE_NEVER); |
} |
+bool InstantController::IsInstantExtendedSearch() const { |
+ return extended_enabled_ && instant_enabled_ && last_match_was_search_; |
+} |
+ |
bool InstantController::CommitIfPossible(InstantCommitType type) { |
if (!extended_enabled_ && !instant_enabled_) |
return false; |
@@ -521,35 +528,33 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { |
content::WebContents* preview = loader_->ReleaseContents(); |
if (extended_enabled_) { |
- // Consider what's happening: |
- // 1. The user has typed a query in the omnibox and committed it (either |
- // by pressing Enter or clicking on the preview). |
- // 2. We commit the preview to the tab strip, and tell the page. |
- // 3. The page will update the URL hash fragment with the query terms. |
- // After steps 1 and 3, the omnibox will show the query terms. However, if |
- // the URL we are committing at step 2 doesn't already have query terms, it |
- // will flash for a brief moment as a plain URL. So, avoid that flicker by |
- // pretending that the plain URL is actually the typed query terms. |
- // TODO(samarth,beaudoin): Instead of this hack, we should add a new field |
- // to NavigationEntry to keep track of what the correct query, if any, is. |
content::NavigationEntry* entry = |
preview->GetController().GetVisibleEntry(); |
- std::string url = entry->GetVirtualURL().spec(); |
- if (!google_util::IsInstantExtendedAPIGoogleSearchUrl(url) && |
- google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, |
- google_util::ALLOW_NON_STANDARD_PORTS)) { |
- // Hitting ENTER searches for what the user typed, so use |
- // last_omnibox_text_. Clicking on the overlay commits what is currently |
- // showing, so add in the gray text in that case. |
- std::string query(UTF16ToUTF8(last_omnibox_text_)); |
- if (type != INSTANT_COMMIT_PRESSED_ENTER) |
- query += UTF16ToUTF8(last_suggestion_.text); |
+ // Adjust the search terms shown in the omnibox for this query. Hitting |
+ // ENTER searches for what the user typed, so use last_omnibox_text_. |
+ // Clicking on the overlay commits what is currently showing, so add in the |
+ // gray text in that case. |
+ std::string query(UTF16ToUTF8(last_omnibox_text_)); |
+ if (type != INSTANT_COMMIT_PRESSED_ENTER) |
+ query += UTF16ToUTF8(last_suggestion_.text); |
+ |
+ if (type == INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION || |
+ type == INSTANT_COMMIT_FOCUS_LOST) { |
+ // We update the virtual URL's hash fragment to the current omnibox text |
+ // to avoid the flash of a URL that may not contain any search terms. The |
+ // virtual URL will get reparsed once it is updated by the page to contain |
+ // the valid search terms. |
entry->SetVirtualURL(GURL( |
- url + "#q=" + |
+ entry->GetVirtualURL().spec() + "#q=" + |
net::EscapeQueryParamValue(query, true))); |
- chrome::search::SearchTabHelper::FromWebContents(preview)-> |
- NavigationEntryUpdated(); |
+ } else { |
+ // The search terms contained in |query| are valid and should be |
+ // persisted, with no need to be reparsed. |
+ entry->SetExtraData(kSearchTermsKey, UTF8ToUTF16(query)); |
sky
2013/01/16 22:32:37
Is there a reason we do this here rather than in a
Mathieu
2013/01/17 15:59:29
We set the displayed search terms here because Ins
sky
2013/01/17 17:23:22
Make sense. We also persist search terms to the da
|
} |
+ |
+ chrome::search::SearchTabHelper::FromWebContents(preview)-> |
+ NavigationEntryUpdated(); |
} |
// If the preview page has navigated since the last Update(), we need to add |