OLD | NEW |
---|---|
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 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 // TODO(samarth): allow InstantTabs to call SetSuggestions() from the NTP once | 1290 // TODO(samarth): allow InstantTabs to call SetSuggestions() from the NTP once |
1291 // that is better supported. | 1291 // that is better supported. |
1292 bool can_use_instant_tab = UseTabForSuggestions() && | 1292 bool can_use_instant_tab = UseTabForSuggestions() && |
1293 search_mode_.is_search(); | 1293 search_mode_.is_search(); |
1294 bool can_use_overlay = search_mode_.is_search_suggestions() && | 1294 bool can_use_overlay = search_mode_.is_search_suggestions() && |
1295 !last_omnibox_text_.empty(); | 1295 !last_omnibox_text_.empty(); |
1296 if (!can_use_instant_tab && !can_use_overlay) | 1296 if (!can_use_instant_tab && !can_use_overlay) |
1297 return; | 1297 return; |
1298 | 1298 |
1299 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { | 1299 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { |
1300 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && | |
1301 !(last_suggestion_.behavior == INSTANT_COMPLETE_NEVER && | |
1302 !last_omnibox_text_has_inline_autocompletion_ && | |
1303 suggestion.text == last_omnibox_text_ + last_suggestion_.text)) { | |
sreeram
2013/05/28 22:45:02
Does this work in the following case?
1. In Tab A,
samarth
2013/05/29 19:03:46
I took out this check since we don't need to deal
| |
1304 // TODO(samarth,skanuj): setValue() needs to be handled differently when | |
1305 // the omnibox doesn't have focus. Instead of setting temporary text, we | |
1306 // should be setting search terms on the appopriate NavigationEntry. | |
1307 // (Among other things, this ensures that URL-shaped values will get the | |
1308 // additional security token.) | |
1309 // | |
1310 // However, today, we need to allow setValue() to happen in one particular | |
1311 // case which is when a user clicks on the suggestion correponding to a | |
1312 // gray-text completion. Otherwise, we can't distinguish between the user | |
1313 // clicking on white space (where we don't accept the gray text) and the | |
1314 // user clicking on the suggestion (when we do accept the gray text). | |
1315 return; | |
1316 } | |
1317 | |
1300 // We don't get an Update() when changing the omnibox due to a REPLACE | 1318 // We don't get an Update() when changing the omnibox due to a REPLACE |
1301 // suggestion (so that we don't inadvertently cause the overlay to change | 1319 // suggestion (so that we don't inadvertently cause the overlay to change |
1302 // what it's showing, as the user arrows up/down through the page-provided | 1320 // what it's showing, as the user arrows up/down through the page-provided |
1303 // suggestions). So, update these state variables here. | 1321 // suggestions). So, update these state variables here. |
1304 last_omnibox_text_ = suggestion.text; | 1322 last_omnibox_text_ = suggestion.text; |
1305 last_user_text_.clear(); | 1323 last_user_text_.clear(); |
1306 last_suggestion_ = InstantSuggestion(); | 1324 last_suggestion_ = InstantSuggestion(); |
1307 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; | 1325 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; |
1308 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 1326 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
1309 "ReplaceSuggestion text='%s' type=%d", | 1327 "ReplaceSuggestion text='%s' type=%d", |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1375 | 1393 |
1376 // Do not add a default case in the switch block for the following reasons: | 1394 // Do not add a default case in the switch block for the following reasons: |
1377 // (1) Explicitly handle the new states. If new states are added in the | 1395 // (1) Explicitly handle the new states. If new states are added in the |
1378 // OmniboxFocusState, the compiler will warn the developer to handle the new | 1396 // OmniboxFocusState, the compiler will warn the developer to handle the new |
1379 // states. | 1397 // states. |
1380 // (2) An attacker may control the renderer and sends the browser process a | 1398 // (2) An attacker may control the renderer and sends the browser process a |
1381 // malformed IPC. This function responds to the invalid |state| values by | 1399 // malformed IPC. This function responds to the invalid |state| values by |
1382 // doing nothing instead of crashing the browser process (intentional no-op). | 1400 // doing nothing instead of crashing the browser process (intentional no-op). |
1383 switch (state) { | 1401 switch (state) { |
1384 case OMNIBOX_FOCUS_VISIBLE: | 1402 case OMNIBOX_FOCUS_VISIBLE: |
1385 browser_->FocusOmnibox(true); | 1403 // TODO(samarth): re-enable this once setValue() correctly handles |
1404 // URL-shaped queries. | |
1405 // browser_->FocusOmnibox(true); | |
1386 break; | 1406 break; |
1387 case OMNIBOX_FOCUS_INVISIBLE: | 1407 case OMNIBOX_FOCUS_INVISIBLE: |
1388 browser_->FocusOmnibox(false); | 1408 browser_->FocusOmnibox(false); |
1389 break; | 1409 break; |
1390 case OMNIBOX_FOCUS_NONE: | 1410 case OMNIBOX_FOCUS_NONE: |
1391 if (omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE) | 1411 if (omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE) |
1392 contents->GetView()->Focus(); | 1412 contents->GetView()->Focus(); |
1393 break; | 1413 break; |
1394 } | 1414 } |
1395 } | 1415 } |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1831 | 1851 |
1832 result->transition = match.transition; | 1852 result->transition = match.transition; |
1833 result->relevance = match.relevance; | 1853 result->relevance = match.relevance; |
1834 result->autocomplete_match_index = autocomplete_match_index; | 1854 result->autocomplete_match_index = autocomplete_match_index; |
1835 | 1855 |
1836 DVLOG(1) << " " << result->relevance << " " << result->type << " " | 1856 DVLOG(1) << " " << result->relevance << " " << result->type << " " |
1837 << result->provider << " " << result->destination_url << " '" | 1857 << result->provider << " " << result->destination_url << " '" |
1838 << result->description << "' '" << result->search_query << "' " | 1858 << result->description << "' '" << result->search_query << "' " |
1839 << result->transition << " " << result->autocomplete_match_index; | 1859 << result->transition << " " << result->autocomplete_match_index; |
1840 } | 1860 } |
OLD | NEW |