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

Side by Side 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: Indentation 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/instant/instant_controller.h" 5 #include "chrome/browser/instant/instant_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 bool IsFullHeight(const InstantModel& model) { 158 bool IsFullHeight(const InstantModel& model) {
159 return model.height() == 100 && model.height_units() == INSTANT_SIZE_PERCENT; 159 return model.height() == 100 && model.height_units() == INSTANT_SIZE_PERCENT;
160 } 160 }
161 161
162 } // namespace 162 } // namespace
163 163
164 // static 164 // static
165 const char* InstantController::kLocalOmniboxPopupURL = 165 const char* InstantController::kLocalOmniboxPopupURL =
166 "chrome://local-omnibox-popup/local-omnibox-popup.html"; 166 "chrome://local-omnibox-popup/local-omnibox-popup.html";
167 167
168 // static
169 const std::string InstantController::kSearchTermsKey = "search_terms";
170
168 InstantController::InstantController(chrome::BrowserInstantController* browser, 171 InstantController::InstantController(chrome::BrowserInstantController* browser,
169 bool extended_enabled, 172 bool extended_enabled,
170 bool use_local_preview_only) 173 bool use_local_preview_only)
171 : browser_(browser), 174 : browser_(browser),
172 extended_enabled_(extended_enabled), 175 extended_enabled_(extended_enabled),
173 instant_enabled_(false), 176 instant_enabled_(false),
174 use_local_preview_only_(use_local_preview_only), 177 use_local_preview_only_(use_local_preview_only),
175 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 178 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
176 last_omnibox_text_has_inline_autocompletion_(false), 179 last_omnibox_text_has_inline_autocompletion_(false),
177 last_verbatim_(false), 180 last_verbatim_(false),
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 content::WebContents* InstantController::GetPreviewContents() const { 474 content::WebContents* InstantController::GetPreviewContents() const {
472 return loader_ ? loader_->contents() : NULL; 475 return loader_ ? loader_->contents() : NULL;
473 } 476 }
474 477
475 bool InstantController::IsPreviewingSearchResults() const { 478 bool InstantController::IsPreviewingSearchResults() const {
476 return model_.mode().is_search_suggestions() && IsFullHeight(model_) && 479 return model_.mode().is_search_suggestions() && IsFullHeight(model_) &&
477 (last_match_was_search_ || 480 (last_match_was_search_ ||
478 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER); 481 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER);
479 } 482 }
480 483
484 bool InstantController::IsInstantExtendedSearch() const {
485 return extended_enabled_ && instant_enabled_ && last_match_was_search_;
486 }
487
481 bool InstantController::CommitIfPossible(InstantCommitType type) { 488 bool InstantController::CommitIfPossible(InstantCommitType type) {
482 if (!extended_enabled_ && !instant_enabled_) 489 if (!extended_enabled_ && !instant_enabled_)
483 return false; 490 return false;
484 491
485 DVLOG(1) << "CommitIfPossible: type=" << type << " last_omnibox_text_='" 492 DVLOG(1) << "CommitIfPossible: type=" << type << " last_omnibox_text_='"
486 << last_omnibox_text_ << "' last_match_was_search_=" 493 << last_omnibox_text_ << "' last_match_was_search_="
487 << last_match_was_search_ << " instant_tab_=" << instant_tab_; 494 << last_match_was_search_ << " instant_tab_=" << instant_tab_;
488 495
489 // If we are on an already committed search results page, send a submit event 496 // If we are on an already committed search results page, send a submit event
490 // to the page, but otherwise, nothing else to do. 497 // to the page, but otherwise, nothing else to do.
(...skipping 23 matching lines...) Expand all
514 521
515 if (type == INSTANT_COMMIT_FOCUS_LOST) 522 if (type == INSTANT_COMMIT_FOCUS_LOST)
516 loader_->Cancel(last_omnibox_text_); 523 loader_->Cancel(last_omnibox_text_);
517 else if (type != INSTANT_COMMIT_NAVIGATED && 524 else if (type != INSTANT_COMMIT_NAVIGATED &&
518 type != INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION) 525 type != INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION)
519 loader_->Submit(last_omnibox_text_); 526 loader_->Submit(last_omnibox_text_);
520 527
521 content::WebContents* preview = loader_->ReleaseContents(); 528 content::WebContents* preview = loader_->ReleaseContents();
522 529
523 if (extended_enabled_) { 530 if (extended_enabled_) {
524 // Consider what's happening:
525 // 1. The user has typed a query in the omnibox and committed it (either
526 // by pressing Enter or clicking on the preview).
527 // 2. We commit the preview to the tab strip, and tell the page.
528 // 3. The page will update the URL hash fragment with the query terms.
529 // After steps 1 and 3, the omnibox will show the query terms. However, if
530 // the URL we are committing at step 2 doesn't already have query terms, it
531 // will flash for a brief moment as a plain URL. So, avoid that flicker by
532 // pretending that the plain URL is actually the typed query terms.
533 // TODO(samarth,beaudoin): Instead of this hack, we should add a new field
534 // to NavigationEntry to keep track of what the correct query, if any, is.
535 content::NavigationEntry* entry = 531 content::NavigationEntry* entry =
536 preview->GetController().GetVisibleEntry(); 532 preview->GetController().GetVisibleEntry();
537 std::string url = entry->GetVirtualURL().spec(); 533 // Adjust the search terms shown in the omnibox for this query. Hitting
538 if (!google_util::IsInstantExtendedAPIGoogleSearchUrl(url) && 534 // ENTER searches for what the user typed, so use last_omnibox_text_.
539 google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, 535 // Clicking on the overlay commits what is currently showing, so add in the
540 google_util::ALLOW_NON_STANDARD_PORTS)) { 536 // gray text in that case.
541 // Hitting ENTER searches for what the user typed, so use 537 std::string query(UTF16ToUTF8(last_omnibox_text_));
542 // last_omnibox_text_. Clicking on the overlay commits what is currently 538 if (type != INSTANT_COMMIT_PRESSED_ENTER)
543 // showing, so add in the gray text in that case. 539 query += UTF16ToUTF8(last_suggestion_.text);
544 std::string query(UTF16ToUTF8(last_omnibox_text_)); 540
545 if (type != INSTANT_COMMIT_PRESSED_ENTER) 541 if (type == INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION ||
546 query += UTF16ToUTF8(last_suggestion_.text); 542 type == INSTANT_COMMIT_FOCUS_LOST) {
543 // We update the virtual URL's hash fragment to the current omnibox text
544 // to avoid the flash of a URL that may not contain any search terms. The
545 // virtual URL will get reparsed once it is updated by the page to contain
546 // the valid search terms.
547 entry->SetVirtualURL(GURL( 547 entry->SetVirtualURL(GURL(
548 url + "#q=" + 548 entry->GetVirtualURL().spec() + "#q=" +
549 net::EscapeQueryParamValue(query, true))); 549 net::EscapeQueryParamValue(query, true)));
550 chrome::search::SearchTabHelper::FromWebContents(preview)-> 550 } else {
551 NavigationEntryUpdated(); 551 // The search terms contained in |query| are valid and should be
552 // persisted, with no need to be reparsed.
553 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
552 } 554 }
555
556 chrome::search::SearchTabHelper::FromWebContents(preview)->
557 NavigationEntryUpdated();
553 } 558 }
554 559
555 // If the preview page has navigated since the last Update(), we need to add 560 // If the preview page has navigated since the last Update(), we need to add
556 // the navigation to history ourselves. Else, the page will navigate after 561 // the navigation to history ourselves. Else, the page will navigate after
557 // commit, and it will be added to history in the usual manner. 562 // commit, and it will be added to history in the usual manner.
558 const history::HistoryAddPageArgs& last_navigation = 563 const history::HistoryAddPageArgs& last_navigation =
559 loader_->last_navigation(); 564 loader_->last_navigation();
560 if (!last_navigation.url.is_empty()) { 565 if (!last_navigation.url.is_empty()) {
561 content::NavigationEntry* entry = preview->GetController().GetActiveEntry(); 566 content::NavigationEntry* entry = preview->GetController().GetActiveEntry();
562 567
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 std::map<std::string, int>::const_iterator iter = 1230 std::map<std::string, int>::const_iterator iter =
1226 blacklisted_urls_.find(*instant_url); 1231 blacklisted_urls_.find(*instant_url);
1227 if (iter != blacklisted_urls_.end() && 1232 if (iter != blacklisted_urls_.end() &&
1228 iter->second > kMaxInstantSupportFailures) { 1233 iter->second > kMaxInstantSupportFailures) {
1229 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST); 1234 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST);
1230 return false; 1235 return false;
1231 } 1236 }
1232 1237
1233 return true; 1238 return true;
1234 } 1239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698