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 "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 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 !last_omnibox_text_.empty(); | 1137 !last_omnibox_text_.empty(); |
1138 if (!can_use_instant_tab && !can_use_overlay) | 1138 if (!can_use_instant_tab && !can_use_overlay) |
1139 return; | 1139 return; |
1140 | 1140 |
1141 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { | 1141 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { |
1142 // We don't get an Update() when changing the omnibox due to a REPLACE | 1142 // We don't get an Update() when changing the omnibox due to a REPLACE |
1143 // suggestion (so that we don't inadvertently cause the overlay to change | 1143 // suggestion (so that we don't inadvertently cause the overlay to change |
1144 // what it's showing, as the user arrows up/down through the page-provided | 1144 // what it's showing, as the user arrows up/down through the page-provided |
1145 // suggestions). So, update these state variables here. | 1145 // suggestions). So, update these state variables here. |
1146 last_omnibox_text_ = suggestion.text; | 1146 last_omnibox_text_ = suggestion.text; |
| 1147 last_user_text_.clear(); |
1147 last_suggestion_ = InstantSuggestion(); | 1148 last_suggestion_ = InstantSuggestion(); |
1148 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; | 1149 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; |
1149 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 1150 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
1150 "ReplaceSuggestion text='%s' type=%d", | 1151 "ReplaceSuggestion text='%s' type=%d", |
1151 UTF16ToUTF8(suggestion.text).c_str(), suggestion.type)); | 1152 UTF16ToUTF8(suggestion.text).c_str(), suggestion.type)); |
1152 browser_->SetInstantSuggestion(suggestion); | 1153 browser_->SetInstantSuggestion(suggestion); |
1153 } else { | 1154 } else { |
1154 if (FixSuggestion(&suggestion)) { | 1155 if (FixSuggestion(&suggestion)) { |
1155 last_suggestion_ = suggestion; | 1156 last_suggestion_ = suggestion; |
1156 if (suggestion.type == INSTANT_SUGGESTION_SEARCH && | 1157 if (suggestion.type == INSTANT_SUGGESTION_SEARCH && |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 ntp_->SendMostVisitedItems(items); | 1550 ntp_->SendMostVisitedItems(items); |
1550 if (instant_tab_) | 1551 if (instant_tab_) |
1551 instant_tab_->SendMostVisitedItems(items); | 1552 instant_tab_->SendMostVisitedItems(items); |
1552 content::NotificationService::current()->Notify( | 1553 content::NotificationService::current()->Notify( |
1553 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, | 1554 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
1554 content::Source<InstantController>(this), | 1555 content::Source<InstantController>(this), |
1555 content::NotificationService::NoDetails()); | 1556 content::NotificationService::NoDetails()); |
1556 } | 1557 } |
1557 | 1558 |
1558 bool InstantController::FixSuggestion(InstantSuggestion* suggestion) const { | 1559 bool InstantController::FixSuggestion(InstantSuggestion* suggestion) const { |
| 1560 // We only accept suggestions if the user has typed text. If the user is |
| 1561 // arrowing up/down (|last_user_text_| is empty), we reject suggestions. |
| 1562 if (last_user_text_.empty()) |
| 1563 return false; |
| 1564 |
1559 // If the page is trying to set inline autocompletion in verbatim mode, | 1565 // If the page is trying to set inline autocompletion in verbatim mode, |
1560 // instead try suggesting the exact omnibox text. This makes the omnibox | 1566 // instead try suggesting the exact omnibox text. This makes the omnibox |
1561 // interpret user text as an URL if possible while preventing unwanted | 1567 // interpret user text as an URL if possible while preventing unwanted |
1562 // autocompletion during backspacing. | 1568 // autocompletion during backspacing. |
1563 if (suggestion->behavior == INSTANT_COMPLETE_NOW && last_verbatim_) | 1569 if (suggestion->behavior == INSTANT_COMPLETE_NOW && last_verbatim_) |
1564 suggestion->text = last_omnibox_text_; | 1570 suggestion->text = last_omnibox_text_; |
1565 | 1571 |
1566 // Suggestion text should be a full URL for URL suggestions, or the | 1572 // Suggestion text should be a full URL for URL suggestions, or the |
1567 // completion of a query for query suggestions. | 1573 // completion of a query for query suggestions. |
1568 if (suggestion->type == INSTANT_SUGGESTION_URL) { | 1574 if (suggestion->type == INSTANT_SUGGESTION_URL) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 return false; | 1629 return false; |
1624 | 1630 |
1625 // If this is not window startup, switch. | 1631 // If this is not window startup, switch. |
1626 // TODO(shishir): This is not completely reliable. Find a better way to detect | 1632 // TODO(shishir): This is not completely reliable. Find a better way to detect |
1627 // startup time. | 1633 // startup time. |
1628 if (browser_->GetActiveWebContents()) | 1634 if (browser_->GetActiveWebContents()) |
1629 return true; | 1635 return true; |
1630 | 1636 |
1631 return chrome::IsAggressiveLocalNTPFallbackEnabled(); | 1637 return chrome::IsAggressiveLocalNTPFallbackEnabled(); |
1632 } | 1638 } |
1633 | |
OLD | NEW |