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 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 return false; | 847 return false; |
848 | 848 |
849 if (type == INSTANT_COMMIT_FOCUS_LOST) { | 849 if (type == INSTANT_COMMIT_FOCUS_LOST) { |
850 // Extended mode doesn't need or use the Cancel message. | 850 // Extended mode doesn't need or use the Cancel message. |
851 if (!extended_enabled()) | 851 if (!extended_enabled()) |
852 overlay_->Cancel(last_omnibox_text_); | 852 overlay_->Cancel(last_omnibox_text_); |
853 } else if (type != INSTANT_COMMIT_NAVIGATED) { | 853 } else if (type != INSTANT_COMMIT_NAVIGATED) { |
854 overlay_->Submit(last_omnibox_text_); | 854 overlay_->Submit(last_omnibox_text_); |
855 } | 855 } |
856 | 856 |
| 857 // Make sure the overlay WebContents is in a valid state (i.e., has a last |
| 858 // committed entry, no transient entry, and no existing pending entry). |
857 scoped_ptr<content::WebContents> overlay = overlay_->ReleaseContents(); | 859 scoped_ptr<content::WebContents> overlay = overlay_->ReleaseContents(); |
| 860 if (!overlay || !overlay->GetController().CanPruneAllButVisible()) |
| 861 return false; |
858 | 862 |
859 // If the overlay page has navigated since the last Update(), we need to add | 863 // If the overlay page has navigated since the last Update(), we need to add |
860 // the navigation to history ourselves. Else, the page will navigate after | 864 // the navigation to history ourselves. Else, the page will navigate after |
861 // commit, and it will be added to history in the usual manner. | 865 // commit, and it will be added to history in the usual manner. |
862 const history::HistoryAddPageArgs& last_navigation = | 866 const history::HistoryAddPageArgs& last_navigation = |
863 overlay_->last_navigation(); | 867 overlay_->last_navigation(); |
864 if (!last_navigation.url.is_empty()) { | 868 if (!last_navigation.url.is_empty()) { |
865 content::NavigationEntry* entry = overlay->GetController().GetActiveEntry(); | 869 content::NavigationEntry* entry = overlay->GetController().GetActiveEntry(); |
866 | 870 |
867 // The last navigation should be the same as the active entry if the overlay | 871 // The last navigation should be the same as the active entry if the overlay |
(...skipping 19 matching lines...) Expand all Loading... |
887 HistoryService* history = HistoryServiceFactory::GetForProfile( | 891 HistoryService* history = HistoryServiceFactory::GetForProfile( |
888 Profile::FromBrowserContext(overlay->GetBrowserContext()), | 892 Profile::FromBrowserContext(overlay->GetBrowserContext()), |
889 Profile::EXPLICIT_ACCESS); | 893 Profile::EXPLICIT_ACCESS); |
890 if (history) { | 894 if (history) { |
891 history->AddPage(url_for_history_, base::Time::Now(), NULL, 0, GURL(), | 895 history->AddPage(url_for_history_, base::Time::Now(), NULL, 0, GURL(), |
892 history::RedirectList(), last_transition_type_, | 896 history::RedirectList(), last_transition_type_, |
893 history::SOURCE_BROWSED, false); | 897 history::SOURCE_BROWSED, false); |
894 } | 898 } |
895 | 899 |
896 if (type == INSTANT_COMMIT_PRESSED_ALT_ENTER) { | 900 if (type == INSTANT_COMMIT_PRESSED_ALT_ENTER) { |
897 overlay->GetController().PruneAllButActive(); | 901 CHECK(overlay->GetController().PruneAllButVisible()); |
898 } else { | 902 } else { |
899 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 903 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
900 AddSessionStorageHistogram(extended_enabled(), active_tab, overlay.get()); | 904 AddSessionStorageHistogram(extended_enabled(), active_tab, overlay.get()); |
901 overlay->GetController().CopyStateFromAndPrune( | 905 CHECK(overlay->GetController().CopyStateFromAndPrune( |
902 &active_tab->GetController()); | 906 &active_tab->GetController())); |
903 } | 907 } |
904 | 908 |
905 if (extended_enabled()) { | 909 if (extended_enabled()) { |
906 // Adjust the search terms shown in the omnibox for this query. Hitting | 910 // Adjust the search terms shown in the omnibox for this query. Hitting |
907 // ENTER searches for what the user typed, so use last_omnibox_text_. | 911 // ENTER searches for what the user typed, so use last_omnibox_text_. |
908 // Clicking on the overlay commits what is currently showing, so add in the | 912 // Clicking on the overlay commits what is currently showing, so add in the |
909 // gray text in that case. | 913 // gray text in that case. |
910 if (type == INSTANT_COMMIT_FOCUS_LOST && | 914 if (type == INSTANT_COMMIT_FOCUS_LOST && |
911 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER) { | 915 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER) { |
912 // Update |last_omnibox_text_| so that the controller commits the proper | 916 // Update |last_omnibox_text_| so that the controller commits the proper |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1872 | 1876 |
1873 result->transition = match.transition; | 1877 result->transition = match.transition; |
1874 result->relevance = match.relevance; | 1878 result->relevance = match.relevance; |
1875 result->autocomplete_match_index = autocomplete_match_index; | 1879 result->autocomplete_match_index = autocomplete_match_index; |
1876 | 1880 |
1877 DVLOG(1) << " " << result->relevance << " " << result->type << " " | 1881 DVLOG(1) << " " << result->relevance << " " << result->type << " " |
1878 << result->provider << " " << result->destination_url << " '" | 1882 << result->provider << " " << result->destination_url << " '" |
1879 << result->description << "' '" << result->search_query << "' " | 1883 << result->description << "' '" << result->search_query << "' " |
1880 << result->transition << " " << result->autocomplete_match_index; | 1884 << result->transition << " " << result->autocomplete_match_index; |
1881 } | 1885 } |
OLD | NEW |