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

Side by Side Diff: chrome/browser/ui/search/instant_controller.cc

Issue 13813006: Instant: Don't allow the page to set suggestions inappropriately. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/search/instant_extended_browsertest.cc » ('j') | 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/ui/search/instant_controller.h" 5 #include "chrome/browser/ui/search/instant_controller.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 !last_omnibox_text_.empty(); 1126 !last_omnibox_text_.empty();
1127 if (!can_use_instant_tab && !can_use_overlay) 1127 if (!can_use_instant_tab && !can_use_overlay)
1128 return; 1128 return;
1129 1129
1130 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { 1130 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) {
1131 // We don't get an Update() when changing the omnibox due to a REPLACE 1131 // We don't get an Update() when changing the omnibox due to a REPLACE
1132 // suggestion (so that we don't inadvertently cause the overlay to change 1132 // suggestion (so that we don't inadvertently cause the overlay to change
1133 // what it's showing, as the user arrows up/down through the page-provided 1133 // what it's showing, as the user arrows up/down through the page-provided
1134 // suggestions). So, update these state variables here. 1134 // suggestions). So, update these state variables here.
1135 last_omnibox_text_ = suggestion.text; 1135 last_omnibox_text_ = suggestion.text;
1136 last_user_text_.clear();
samarth 2013/04/09 16:11:34 IIRC, when you arrow back up into the omnibox, we
sreeram 2013/04/09 16:30:37 When you arrow back into the omnibox, you get a se
samarth 2013/04/09 20:32:15 Sorry if I'm missing something but I still don't s
sreeram 2013/04/09 20:58:24 FixSuggestions is only called for gray/blue sugges
samarth 2013/04/09 21:49:06 But what if we want to use last_user_text_ to vali
sreeram 2013/04/09 22:11:58 last_user_text_ is not needed for validating setVa
1136 last_suggestion_ = InstantSuggestion(); 1137 last_suggestion_ = InstantSuggestion();
1137 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; 1138 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH;
1138 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 1139 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
1139 "ReplaceSuggestion text='%s' type=%d", 1140 "ReplaceSuggestion text='%s' type=%d",
1140 UTF16ToUTF8(suggestion.text).c_str(), suggestion.type)); 1141 UTF16ToUTF8(suggestion.text).c_str(), suggestion.type));
1141 browser_->SetInstantSuggestion(suggestion); 1142 browser_->SetInstantSuggestion(suggestion);
1142 } else { 1143 } else {
1143 if (FixSuggestion(&suggestion)) { 1144 if (FixSuggestion(&suggestion)) {
1144 last_suggestion_ = suggestion; 1145 last_suggestion_ = suggestion;
1145 if (suggestion.type == INSTANT_SUGGESTION_SEARCH && 1146 if (suggestion.type == INSTANT_SUGGESTION_SEARCH &&
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 ntp_->SendMostVisitedItems(items); 1539 ntp_->SendMostVisitedItems(items);
1539 if (instant_tab_) 1540 if (instant_tab_)
1540 instant_tab_->SendMostVisitedItems(items); 1541 instant_tab_->SendMostVisitedItems(items);
1541 content::NotificationService::current()->Notify( 1542 content::NotificationService::current()->Notify(
1542 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, 1543 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS,
1543 content::Source<InstantController>(this), 1544 content::Source<InstantController>(this),
1544 content::NotificationService::NoDetails()); 1545 content::NotificationService::NoDetails());
1545 } 1546 }
1546 1547
1547 bool InstantController::FixSuggestion(InstantSuggestion* suggestion) const { 1548 bool InstantController::FixSuggestion(InstantSuggestion* suggestion) const {
1549 // If the page is attempting to set suggestions inappropriately, reject.
samarth 2013/04/09 16:11:34 Please be more specific--both here and in the chan
sreeram 2013/04/09 16:30:37 Done.
1550 if (last_user_text_.empty())
1551 return false;
1552
1548 // If the page is trying to set inline autocompletion in verbatim mode, 1553 // If the page is trying to set inline autocompletion in verbatim mode,
1549 // instead try suggesting the exact omnibox text. This makes the omnibox 1554 // instead try suggesting the exact omnibox text. This makes the omnibox
1550 // interpret user text as an URL if possible while preventing unwanted 1555 // interpret user text as an URL if possible while preventing unwanted
1551 // autocompletion during backspacing. 1556 // autocompletion during backspacing.
1552 if (suggestion->behavior == INSTANT_COMPLETE_NOW && last_verbatim_) 1557 if (suggestion->behavior == INSTANT_COMPLETE_NOW && last_verbatim_)
1553 suggestion->text = last_omnibox_text_; 1558 suggestion->text = last_omnibox_text_;
1554 1559
1555 // Suggestion text should be a full URL for URL suggestions, or the 1560 // Suggestion text should be a full URL for URL suggestions, or the
1556 // completion of a query for query suggestions. 1561 // completion of a query for query suggestions.
1557 if (suggestion->type == INSTANT_SUGGESTION_URL) { 1562 if (suggestion->type == INSTANT_SUGGESTION_URL) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 return false; 1617 return false;
1613 1618
1614 // If this is not window startup, switch. 1619 // If this is not window startup, switch.
1615 // TODO(shishir): This is not completely reliable. Find a better way to detect 1620 // TODO(shishir): This is not completely reliable. Find a better way to detect
1616 // startup time. 1621 // startup time.
1617 if (browser_->GetActiveWebContents()) 1622 if (browser_->GetActiveWebContents())
1618 return true; 1623 return true;
1619 1624
1620 return chrome::IsAggressiveLocalNTPFallbackEnabled(); 1625 return chrome::IsAggressiveLocalNTPFallbackEnabled();
1621 } 1626 }
1622
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/search/instant_extended_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698