Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(913)

Unified Diff: chrome/browser/instant/instant_controller.cc

Issue 11876045: [Search] Store and recall search terms using NavigationEntry to improve search term extraction (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: addressed comments Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..6084061d1fdf59eb081a6c3a70caa6a37a114f7f 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 char* 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(std::string(kSearchTermsKey), UTF8ToUTF16(query));
}
+
+ chrome::search::SearchTabHelper::FromWebContents(preview)->
+ NavigationEntryUpdated();
}
// If the preview page has navigated since the last Update(), we need to add

Powered by Google App Engine
This is Rietveld 408576698