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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 // will flash for a brief moment as a plain URL. So, avoid that flicker by | 496 // will flash for a brief moment as a plain URL. So, avoid that flicker by |
497 // pretending that the plain URL is actually the typed query terms. | 497 // pretending that the plain URL is actually the typed query terms. |
498 // TODO(samarth,beaudoin): Instead of this hack, we should add a new field | 498 // TODO(samarth,beaudoin): Instead of this hack, we should add a new field |
499 // to NavigationEntry to keep track of what the correct query, if any, is. | 499 // to NavigationEntry to keep track of what the correct query, if any, is. |
500 content::NavigationEntry* entry = | 500 content::NavigationEntry* entry = |
501 preview->GetController().GetVisibleEntry(); | 501 preview->GetController().GetVisibleEntry(); |
502 std::string url = entry->GetVirtualURL().spec(); | 502 std::string url = entry->GetVirtualURL().spec(); |
503 if (!google_util::IsInstantExtendedAPIGoogleSearchUrl(url) && | 503 if (!google_util::IsInstantExtendedAPIGoogleSearchUrl(url) && |
504 google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, | 504 google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, |
505 google_util::ALLOW_NON_STANDARD_PORTS)) { | 505 google_util::ALLOW_NON_STANDARD_PORTS)) { |
| 506 // Hitting ENTER searches for what the user typed, so use |
| 507 // last_omnibox_text_. Clicking on the overlay commits what is currently |
| 508 // showing, so add in the gray text in that case. |
| 509 std::string query(UTF16ToUTF8(last_omnibox_text_)); |
| 510 if (type != INSTANT_COMMIT_PRESSED_ENTER) |
| 511 query += UTF16ToUTF8(last_suggestion_.text); |
506 entry->SetVirtualURL(GURL( | 512 entry->SetVirtualURL(GURL( |
507 url + "#q=" + | 513 url + "#q=" + |
508 net::EscapeQueryParamValue(UTF16ToUTF8(last_omnibox_text_), true))); | 514 net::EscapeQueryParamValue(query, true))); |
509 chrome::search::SearchTabHelper::FromWebContents(preview)-> | 515 chrome::search::SearchTabHelper::FromWebContents(preview)-> |
510 NavigationEntryUpdated(); | 516 NavigationEntryUpdated(); |
511 } | 517 } |
512 } | 518 } |
513 | 519 |
514 // If the preview page has navigated since the last Update(), we need to add | 520 // If the preview page has navigated since the last Update(), we need to add |
515 // the navigation to history ourselves. Else, the page will navigate after | 521 // the navigation to history ourselves. Else, the page will navigate after |
516 // commit, and it will be added to history in the usual manner. | 522 // commit, and it will be added to history in the usual manner. |
517 const history::HistoryAddPageArgs& last_navigation = | 523 const history::HistoryAddPageArgs& last_navigation = |
518 loader_->last_navigation(); | 524 loader_->last_navigation(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 | 683 |
678 if (loader_) | 684 if (loader_) |
679 loader_->SendThemeAreaHeight(height); | 685 loader_->SendThemeAreaHeight(height); |
680 } | 686 } |
681 | 687 |
682 void InstantController::SetSuggestions( | 688 void InstantController::SetSuggestions( |
683 const content::WebContents* contents, | 689 const content::WebContents* contents, |
684 const std::vector<InstantSuggestion>& suggestions) { | 690 const std::vector<InstantSuggestion>& suggestions) { |
685 DVLOG(1) << "SetSuggestions"; | 691 DVLOG(1) << "SetSuggestions"; |
686 | 692 |
687 // Ignore if we are not currently accepting search suggestions. | |
688 if (!search_mode_.is_search_suggestions() || last_omnibox_text_.empty()) | |
689 return; | |
690 | |
691 // Ignore if the message is from an unexpected source. | 693 // Ignore if the message is from an unexpected source. |
692 if (instant_tab_) { | 694 if (instant_tab_) { |
693 if (instant_tab_->contents() != contents) | 695 if (instant_tab_->contents() != contents) |
694 return; | 696 return; |
695 } else if (!loader_ || loader_->contents() != contents || | 697 } else if (!loader_ || loader_->contents() != contents || |
696 !allow_preview_to_show_search_suggestions_) { | 698 !allow_preview_to_show_search_suggestions_) { |
697 return; | 699 return; |
698 } | 700 } |
699 | 701 |
700 InstantSuggestion suggestion; | 702 InstantSuggestion suggestion; |
701 if (!suggestions.empty()) | 703 if (!suggestions.empty()) |
702 suggestion = suggestions[0]; | 704 suggestion = suggestions[0]; |
703 | 705 |
| 706 if (instant_tab_ && search_mode_.is_search_results() && |
| 707 suggestion.behavior == INSTANT_COMPLETE_REPLACE) { |
| 708 // This means a committed page in state search called setValue(). We should |
| 709 // update the omnibox to reflect what the search page says. |
| 710 browser_->SetInstantSuggestion(suggestion); |
| 711 // Don't update last_omnibox_text_ or last_suggestion_ since the user is not |
| 712 // currently editing text in the omnibox. |
| 713 return; |
| 714 } |
| 715 |
| 716 // Ignore if we are not currently accepting search suggestions. |
| 717 if (!search_mode_.is_search_suggestions() || last_omnibox_text_.empty()) |
| 718 return; |
| 719 |
704 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { | 720 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { |
705 // We don't get an Update() when changing the omnibox due to a REPLACE | 721 // We don't get an Update() when changing the omnibox due to a REPLACE |
706 // suggestion (so that we don't inadvertently cause the preview to change | 722 // suggestion (so that we don't inadvertently cause the preview to change |
707 // what it's showing, as the user arrows up/down through the page-provided | 723 // what it's showing, as the user arrows up/down through the page-provided |
708 // suggestions). So, update these state variables here. | 724 // suggestions). So, update these state variables here. |
709 last_omnibox_text_ = suggestion.text; | 725 last_omnibox_text_ = suggestion.text; |
710 last_suggestion_ = InstantSuggestion(); | 726 last_suggestion_ = InstantSuggestion(); |
711 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; | 727 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; |
712 DVLOG(1) << "SetReplaceSuggestion: text='" << suggestion.text << "'" | 728 DVLOG(1) << "SetReplaceSuggestion: text='" << suggestion.text << "'" |
713 << " type=" << suggestion.type; | 729 << " type=" << suggestion.type; |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 } | 1176 } |
1161 | 1177 |
1162 std::map<std::string, int>::const_iterator iter = | 1178 std::map<std::string, int>::const_iterator iter = |
1163 blacklisted_urls_.find(*instant_url); | 1179 blacklisted_urls_.find(*instant_url); |
1164 if (iter != blacklisted_urls_.end() && | 1180 if (iter != blacklisted_urls_.end() && |
1165 iter->second > kMaxInstantSupportFailures) | 1181 iter->second > kMaxInstantSupportFailures) |
1166 return false; | 1182 return false; |
1167 | 1183 |
1168 return true; | 1184 return true; |
1169 } | 1185 } |
OLD | NEW |