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

Side by Side Diff: chrome/browser/instant/instant_controller.cc

Issue 12035083: [Instant] Update InstantController state to ensure valid subsequent queries (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: tweak Created 7 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 content::NavigationEntry* entry = 552 content::NavigationEntry* entry =
553 preview->GetController().GetVisibleEntry(); 553 preview->GetController().GetVisibleEntry();
554 std::string url = entry->GetVirtualURL().spec(); 554 std::string url = entry->GetVirtualURL().spec();
555 if (!google_util::IsInstantExtendedAPIGoogleSearchUrl(url) && 555 if (!google_util::IsInstantExtendedAPIGoogleSearchUrl(url) &&
556 google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, 556 google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
557 google_util::ALLOW_NON_STANDARD_PORTS)) { 557 google_util::ALLOW_NON_STANDARD_PORTS)) {
558 // Hitting ENTER searches for what the user typed, so use 558 // Hitting ENTER searches for what the user typed, so use
559 // last_omnibox_text_. Clicking on the overlay commits what is currently 559 // last_omnibox_text_. Clicking on the overlay commits what is currently
560 // showing, so add in the gray text in that case. 560 // showing, so add in the gray text in that case.
561 std::string query(UTF16ToUTF8(last_omnibox_text_)); 561 std::string query(UTF16ToUTF8(last_omnibox_text_));
562 if (type != INSTANT_COMMIT_PRESSED_ENTER) 562 if (type != INSTANT_COMMIT_PRESSED_ENTER) {
563 query += UTF16ToUTF8(last_suggestion_.text); 563 query += UTF16ToUTF8(last_suggestion_.text);
564 // Update |last_omnibox_text_| so that the controller commits the proper
565 // query if the user focuses the omnibox and presses Enter.
566 last_omnibox_text_ += last_suggestion_.text;
567 }
564 entry->SetVirtualURL(GURL( 568 entry->SetVirtualURL(GURL(
565 url + "#q=" + 569 url + "#q=" +
566 net::EscapeQueryParamValue(query, true))); 570 net::EscapeQueryParamValue(query, true)));
567 chrome::search::SearchTabHelper::FromWebContents(preview)-> 571 chrome::search::SearchTabHelper::FromWebContents(preview)->
568 NavigationEntryUpdated(); 572 NavigationEntryUpdated();
569 } 573 }
570 } 574 }
571 575
572 // If the preview page has navigated since the last Update(), we need to add 576 // If the preview page has navigated since the last Update(), we need to add
573 // the navigation to history ourselves. Else, the page will navigate after 577 // the navigation to history ourselves. Else, the page will navigate after
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 !allow_preview_to_show_search_suggestions_) { 757 !allow_preview_to_show_search_suggestions_) {
754 return; 758 return;
755 } 759 }
756 760
757 InstantSuggestion suggestion; 761 InstantSuggestion suggestion;
758 if (!suggestions.empty()) 762 if (!suggestions.empty())
759 suggestion = suggestions[0]; 763 suggestion = suggestions[0];
760 764
761 if (instant_tab_ && search_mode_.is_search_results() && 765 if (instant_tab_ && search_mode_.is_search_results() &&
762 suggestion.behavior == INSTANT_COMPLETE_REPLACE) { 766 suggestion.behavior == INSTANT_COMPLETE_REPLACE) {
767 // Update |last_omnibox_text_| so that the controller commits the proper
768 // query if the user focuses the omnibox and presses Enter.
769 last_omnibox_text_ = suggestion.text;
770 last_suggestion_ = InstantSuggestion();
771 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH;
763 // This means a committed page in state search called setValue(). We should 772 // This means a committed page in state search called setValue(). We should
764 // update the omnibox to reflect what the search page says. 773 // update the omnibox to reflect what the search page says.
765 browser_->SetInstantSuggestion(suggestion); 774 browser_->SetInstantSuggestion(suggestion);
766 // Don't update last_omnibox_text_ or last_suggestion_ since the user is not
767 // currently editing text in the omnibox.
768 return; 775 return;
769 } 776 }
770 777
771 // Ignore if we are not currently accepting search suggestions. 778 // Ignore if we are not currently accepting search suggestions.
772 if (!search_mode_.is_search_suggestions() || last_omnibox_text_.empty()) 779 if (!search_mode_.is_search_suggestions() || last_omnibox_text_.empty())
773 return; 780 return;
774 781
775 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { 782 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) {
776 // We don't get an Update() when changing the omnibox due to a REPLACE 783 // We don't get an Update() when changing the omnibox due to a REPLACE
777 // suggestion (so that we don't inadvertently cause the preview to change 784 // suggestion (so that we don't inadvertently cause the preview to change
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 iter->second > kMaxInstantSupportFailures) { 1264 iter->second > kMaxInstantSupportFailures) {
1258 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST); 1265 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST);
1259 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 1266 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
1260 "GetInstantURL: Instant URL blacklisted: url=%s", 1267 "GetInstantURL: Instant URL blacklisted: url=%s",
1261 instant_url->c_str())); 1268 instant_url->c_str()));
1262 return false; 1269 return false;
1263 } 1270 }
1264 1271
1265 return true; 1272 return true;
1266 } 1273 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698