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

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: 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
« 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/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 // last_omnibox_text_. Clicking on the overlay commits what is currently 542 // last_omnibox_text_. Clicking on the overlay commits what is currently
543 // showing, so add in the gray text in that case. 543 // showing, so add in the gray text in that case.
544 std::string query(UTF16ToUTF8(last_omnibox_text_)); 544 std::string query(UTF16ToUTF8(last_omnibox_text_));
545 if (type != INSTANT_COMMIT_PRESSED_ENTER) 545 if (type != INSTANT_COMMIT_PRESSED_ENTER)
546 query += UTF16ToUTF8(last_suggestion_.text); 546 query += UTF16ToUTF8(last_suggestion_.text);
547 entry->SetVirtualURL(GURL( 547 entry->SetVirtualURL(GURL(
548 url + "#q=" + 548 url + "#q=" +
549 net::EscapeQueryParamValue(query, true))); 549 net::EscapeQueryParamValue(query, true)));
550 chrome::search::SearchTabHelper::FromWebContents(preview)-> 550 chrome::search::SearchTabHelper::FromWebContents(preview)->
551 NavigationEntryUpdated(); 551 NavigationEntryUpdated();
552 // Update |last_omnibox_text_| so that the controller commits the proper
553 // query if the user focuses the omnibox and presses Enter.
554 last_omnibox_text_ = ASCIIToUTF16(query);
sreeram 2013/01/24 22:54:32 You only need to do this if we hit the "if" condit
Mathieu 2013/01/28 18:50:32 Done.
552 } 555 }
553 } 556 }
554 557
555 // If the preview page has navigated since the last Update(), we need to add 558 // 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 559 // the navigation to history ourselves. Else, the page will navigate after
557 // commit, and it will be added to history in the usual manner. 560 // commit, and it will be added to history in the usual manner.
558 const history::HistoryAddPageArgs& last_navigation = 561 const history::HistoryAddPageArgs& last_navigation =
559 loader_->last_navigation(); 562 loader_->last_navigation();
560 if (!last_navigation.url.is_empty()) { 563 if (!last_navigation.url.is_empty()) {
561 content::NavigationEntry* entry = preview->GetController().GetActiveEntry(); 564 content::NavigationEntry* entry = preview->GetController().GetActiveEntry();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 739
737 InstantSuggestion suggestion; 740 InstantSuggestion suggestion;
738 if (!suggestions.empty()) 741 if (!suggestions.empty())
739 suggestion = suggestions[0]; 742 suggestion = suggestions[0];
740 743
741 if (instant_tab_ && search_mode_.is_search_results() && 744 if (instant_tab_ && search_mode_.is_search_results() &&
742 suggestion.behavior == INSTANT_COMPLETE_REPLACE) { 745 suggestion.behavior == INSTANT_COMPLETE_REPLACE) {
743 // This means a committed page in state search called setValue(). We should 746 // This means a committed page in state search called setValue(). We should
744 // update the omnibox to reflect what the search page says. 747 // update the omnibox to reflect what the search page says.
745 browser_->SetInstantSuggestion(suggestion); 748 browser_->SetInstantSuggestion(suggestion);
746 // Don't update last_omnibox_text_ or last_suggestion_ since the user is not 749 // Update |last_omnibox_text_| so that the controller commits the proper
747 // currently editing text in the omnibox. 750 // query if the user focuses the omnibox and presses Enter.
751 last_omnibox_text_ = suggestion.text;
sreeram 2013/01/24 22:54:32 Put this above the call to browser_->SetInstantSug
Mathieu 2013/01/28 18:50:32 Okay, copied the lines over there.
748 return; 752 return;
749 } 753 }
750 754
751 // Ignore if we are not currently accepting search suggestions. 755 // Ignore if we are not currently accepting search suggestions.
752 if (!search_mode_.is_search_suggestions() || last_omnibox_text_.empty()) 756 if (!search_mode_.is_search_suggestions() || last_omnibox_text_.empty())
753 return; 757 return;
754 758
755 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { 759 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) {
756 // We don't get an Update() when changing the omnibox due to a REPLACE 760 // We don't get an Update() when changing the omnibox due to a REPLACE
757 // suggestion (so that we don't inadvertently cause the preview to change 761 // suggestion (so that we don't inadvertently cause the preview to change
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 std::map<std::string, int>::const_iterator iter = 1234 std::map<std::string, int>::const_iterator iter =
1231 blacklisted_urls_.find(*instant_url); 1235 blacklisted_urls_.find(*instant_url);
1232 if (iter != blacklisted_urls_.end() && 1236 if (iter != blacklisted_urls_.end() &&
1233 iter->second > kMaxInstantSupportFailures) { 1237 iter->second > kMaxInstantSupportFailures) {
1234 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST); 1238 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST);
1235 return false; 1239 return false;
1236 } 1240 }
1237 1241
1238 return true; 1242 return true;
1239 } 1243 }
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