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/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 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 | 645 |
646 if (loader_) | 646 if (loader_) |
647 loader_->SendThemeAreaHeight(height); | 647 loader_->SendThemeAreaHeight(height); |
648 } | 648 } |
649 | 649 |
650 void InstantController::SetSuggestions( | 650 void InstantController::SetSuggestions( |
651 const content::WebContents* contents, | 651 const content::WebContents* contents, |
652 const std::vector<InstantSuggestion>& suggestions) { | 652 const std::vector<InstantSuggestion>& suggestions) { |
653 DVLOG(1) << "SetSuggestions"; | 653 DVLOG(1) << "SetSuggestions"; |
654 | 654 |
655 // Ignore if we are not currently accepting search suggestions. | |
656 if (!search_mode_.is_search_suggestions() || last_omnibox_text_.empty()) | |
657 return; | |
658 | |
659 // Ignore if the message is from an unexpected source. | 655 // Ignore if the message is from an unexpected source. |
660 if (instant_tab_) { | 656 if (instant_tab_) { |
661 if (instant_tab_->contents() != contents) | 657 if (instant_tab_->contents() != contents) |
662 return; | 658 return; |
663 } else if (!loader_ || loader_->contents() != contents || | 659 } else if (!loader_ || loader_->contents() != contents || |
664 !allow_preview_to_show_search_suggestions_) { | 660 !allow_preview_to_show_search_suggestions_) { |
665 return; | 661 return; |
666 } | 662 } |
667 | 663 |
668 InstantSuggestion suggestion; | 664 InstantSuggestion suggestion; |
669 if (!suggestions.empty()) | 665 if (!suggestions.empty()) |
670 suggestion = suggestions[0]; | 666 suggestion = suggestions[0]; |
671 | 667 |
668 if (instant_tab_ && instant_tab_->contents() == contents && | |
beaudoin
2012/12/14 15:36:20
Nit: the "instant_tab_->contents() == contents" pa
samarth
2012/12/14 17:48:59
Done.
| |
669 search_mode_.is_search_results()) { | |
670 // Treat any calls to SetSuggestions in committed search mode as a REPLACE. | |
beaudoin
2012/12/14 15:36:20
Not sure that the comment here describes the next
samarth
2012/12/14 17:48:59
Done.
| |
671 browser_->SetInstantSuggestion(suggestion); | |
672 return; | |
673 } | |
674 | |
675 // Ignore if we are not currently accepting search suggestions. | |
676 if (!search_mode_.is_search_suggestions() || last_omnibox_text_.empty()) | |
677 return; | |
678 | |
672 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { | 679 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { |
673 // We don't get an Update() when changing the omnibox due to a REPLACE | 680 // We don't get an Update() when changing the omnibox due to a REPLACE |
674 // suggestion (so that we don't inadvertently cause the preview to change | 681 // suggestion (so that we don't inadvertently cause the preview to change |
675 // what it's showing, as the user arrows up/down through the page-provided | 682 // what it's showing, as the user arrows up/down through the page-provided |
676 // suggestions). So, update these state variables here. | 683 // suggestions). So, update these state variables here. |
677 last_omnibox_text_ = suggestion.text; | 684 last_omnibox_text_ = suggestion.text; |
678 last_suggestion_ = InstantSuggestion(); | 685 last_suggestion_ = InstantSuggestion(); |
679 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; | 686 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; |
680 DVLOG(1) << "SetReplaceSuggestion: text='" << suggestion.text << "'" | 687 DVLOG(1) << "SetReplaceSuggestion: text='" << suggestion.text << "'" |
681 << " type=" << suggestion.type; | 688 << " type=" << suggestion.type; |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1088 } | 1095 } |
1089 | 1096 |
1090 std::map<std::string, int>::const_iterator iter = | 1097 std::map<std::string, int>::const_iterator iter = |
1091 blacklisted_urls_.find(*instant_url); | 1098 blacklisted_urls_.find(*instant_url); |
1092 if (iter != blacklisted_urls_.end() && | 1099 if (iter != blacklisted_urls_.end() && |
1093 iter->second > kMaxInstantSupportFailures) | 1100 iter->second > kMaxInstantSupportFailures) |
1094 return false; | 1101 return false; |
1095 | 1102 |
1096 return true; | 1103 return true; |
1097 } | 1104 } |
OLD | NEW |