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

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

Issue 15001020: InstantExtended: disallow setValue() without omnibox focus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo. Created 7 years, 6 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 | 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/ui/search/instant_controller.h" 5 #include "chrome/browser/ui/search/instant_controller.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 // TODO(samarth): allow InstantTabs to call SetSuggestions() from the NTP once 1327 // TODO(samarth): allow InstantTabs to call SetSuggestions() from the NTP once
1328 // that is better supported. 1328 // that is better supported.
1329 bool can_use_instant_tab = UseTabForSuggestions() && 1329 bool can_use_instant_tab = UseTabForSuggestions() &&
1330 search_mode_.is_search(); 1330 search_mode_.is_search();
1331 bool can_use_overlay = search_mode_.is_search_suggestions() && 1331 bool can_use_overlay = search_mode_.is_search_suggestions() &&
1332 !last_omnibox_text_.empty(); 1332 !last_omnibox_text_.empty();
1333 if (!can_use_instant_tab && !can_use_overlay) 1333 if (!can_use_instant_tab && !can_use_overlay)
1334 return; 1334 return;
1335 1335
1336 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { 1336 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) {
1337 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE) {
1338 // TODO(samarth,skanuj): setValue() needs to be handled differently when
1339 // the omnibox doesn't have focus. Instead of setting temporary text, we
1340 // should be setting search terms on the appropriate NavigationEntry.
1341 // (Among other things, this ensures that URL-shaped values will get the
1342 // additional security token.)
1343 //
1344 // Note that this also breaks clicking on a suggestion corresponding to
1345 // gray-text completion: we can't distinguish between the user
1346 // clicking on white space (where we don't accept the gray text) and the
1347 // user clicking on the suggestion (when we do accept the gray text).
1348 // This needs to be fixed before we can turn on Instant again.
1349 return;
1350 }
1351
1337 // We don't get an Update() when changing the omnibox due to a REPLACE 1352 // We don't get an Update() when changing the omnibox due to a REPLACE
1338 // suggestion (so that we don't inadvertently cause the overlay to change 1353 // suggestion (so that we don't inadvertently cause the overlay to change
1339 // what it's showing, as the user arrows up/down through the page-provided 1354 // what it's showing, as the user arrows up/down through the page-provided
1340 // suggestions). So, update these state variables here. 1355 // suggestions). So, update these state variables here.
1341 last_omnibox_text_ = suggestion.text; 1356 last_omnibox_text_ = suggestion.text;
1342 last_user_text_.clear(); 1357 last_user_text_.clear();
1343 last_suggestion_ = InstantSuggestion(); 1358 last_suggestion_ = InstantSuggestion();
1344 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; 1359 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH;
1345 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 1360 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
1346 "ReplaceSuggestion text='%s' type=%d", 1361 "ReplaceSuggestion text='%s' type=%d",
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 1427
1413 // Do not add a default case in the switch block for the following reasons: 1428 // Do not add a default case in the switch block for the following reasons:
1414 // (1) Explicitly handle the new states. If new states are added in the 1429 // (1) Explicitly handle the new states. If new states are added in the
1415 // OmniboxFocusState, the compiler will warn the developer to handle the new 1430 // OmniboxFocusState, the compiler will warn the developer to handle the new
1416 // states. 1431 // states.
1417 // (2) An attacker may control the renderer and sends the browser process a 1432 // (2) An attacker may control the renderer and sends the browser process a
1418 // malformed IPC. This function responds to the invalid |state| values by 1433 // malformed IPC. This function responds to the invalid |state| values by
1419 // doing nothing instead of crashing the browser process (intentional no-op). 1434 // doing nothing instead of crashing the browser process (intentional no-op).
1420 switch (state) { 1435 switch (state) {
1421 case OMNIBOX_FOCUS_VISIBLE: 1436 case OMNIBOX_FOCUS_VISIBLE:
1422 browser_->FocusOmnibox(true); 1437 // TODO(samarth): re-enable this once setValue() correctly handles
1438 // URL-shaped queries.
1439 // browser_->FocusOmnibox(true);
1423 break; 1440 break;
1424 case OMNIBOX_FOCUS_INVISIBLE: 1441 case OMNIBOX_FOCUS_INVISIBLE:
1425 browser_->FocusOmnibox(false); 1442 browser_->FocusOmnibox(false);
1426 break; 1443 break;
1427 case OMNIBOX_FOCUS_NONE: 1444 case OMNIBOX_FOCUS_NONE:
1428 if (omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE) 1445 if (omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE)
1429 contents->GetView()->Focus(); 1446 contents->GetView()->Focus();
1430 break; 1447 break;
1431 } 1448 }
1432 } 1449 }
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 result->transition = match.transition; 1898 result->transition = match.transition;
1882 result->relevance = match.relevance; 1899 result->relevance = match.relevance;
1883 result->autocomplete_match_index = autocomplete_match_index; 1900 result->autocomplete_match_index = autocomplete_match_index;
1884 1901
1885 DVLOG(1) << " " << result->relevance << " " 1902 DVLOG(1) << " " << result->relevance << " "
1886 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " " 1903 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " "
1887 << result->provider << " " << result->destination_url << " '" 1904 << result->provider << " " << result->destination_url << " '"
1888 << result->description << "' '" << result->search_query << "' " 1905 << result->description << "' '" << result->search_query << "' "
1889 << result->transition << " " << result->autocomplete_match_index; 1906 << result->transition << " " << result->autocomplete_match_index;
1890 } 1907 }
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