| 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 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 return false; | 855 return false; |
| 856 | 856 |
| 857 if (type == INSTANT_COMMIT_FOCUS_LOST) { | 857 if (type == INSTANT_COMMIT_FOCUS_LOST) { |
| 858 // Extended mode doesn't need or use the Cancel message. | 858 // Extended mode doesn't need or use the Cancel message. |
| 859 if (!extended_enabled()) | 859 if (!extended_enabled()) |
| 860 overlay_->Cancel(last_omnibox_text_); | 860 overlay_->Cancel(last_omnibox_text_); |
| 861 } else if (type != INSTANT_COMMIT_NAVIGATED) { | 861 } else if (type != INSTANT_COMMIT_NAVIGATED) { |
| 862 overlay_->Submit(last_omnibox_text_); | 862 overlay_->Submit(last_omnibox_text_); |
| 863 } | 863 } |
| 864 | 864 |
| 865 // We expect the WebContents to be in a valid state (i.e., has a last |
| 866 // committed entry, no transient entry, and no existing pending entry). |
| 865 scoped_ptr<content::WebContents> overlay = overlay_->ReleaseContents(); | 867 scoped_ptr<content::WebContents> overlay = overlay_->ReleaseContents(); |
| 868 CHECK(overlay->GetController().CanPruneAllButVisible()); |
| 866 | 869 |
| 867 // If the overlay page has navigated since the last Update(), we need to add | 870 // If the overlay page has navigated since the last Update(), we need to add |
| 868 // the navigation to history ourselves. Else, the page will navigate after | 871 // the navigation to history ourselves. Else, the page will navigate after |
| 869 // commit, and it will be added to history in the usual manner. | 872 // commit, and it will be added to history in the usual manner. |
| 870 const history::HistoryAddPageArgs& last_navigation = | 873 const history::HistoryAddPageArgs& last_navigation = |
| 871 overlay_->last_navigation(); | 874 overlay_->last_navigation(); |
| 872 if (!last_navigation.url.is_empty()) { | 875 if (!last_navigation.url.is_empty()) { |
| 873 content::NavigationEntry* entry = overlay->GetController().GetActiveEntry(); | 876 content::NavigationEntry* entry = overlay->GetController().GetActiveEntry(); |
| 874 | 877 |
| 875 // The last navigation should be the same as the active entry if the overlay | 878 // The last navigation should be the same as the active entry if the overlay |
| (...skipping 19 matching lines...) Expand all Loading... |
| 895 HistoryService* history = HistoryServiceFactory::GetForProfile( | 898 HistoryService* history = HistoryServiceFactory::GetForProfile( |
| 896 Profile::FromBrowserContext(overlay->GetBrowserContext()), | 899 Profile::FromBrowserContext(overlay->GetBrowserContext()), |
| 897 Profile::EXPLICIT_ACCESS); | 900 Profile::EXPLICIT_ACCESS); |
| 898 if (history) { | 901 if (history) { |
| 899 history->AddPage(url_for_history_, base::Time::Now(), NULL, 0, GURL(), | 902 history->AddPage(url_for_history_, base::Time::Now(), NULL, 0, GURL(), |
| 900 history::RedirectList(), last_transition_type_, | 903 history::RedirectList(), last_transition_type_, |
| 901 history::SOURCE_BROWSED, false); | 904 history::SOURCE_BROWSED, false); |
| 902 } | 905 } |
| 903 | 906 |
| 904 if (type == INSTANT_COMMIT_PRESSED_ALT_ENTER) { | 907 if (type == INSTANT_COMMIT_PRESSED_ALT_ENTER) { |
| 905 overlay->GetController().PruneAllButActive(); | 908 overlay->GetController().PruneAllButVisible(); |
| 906 } else { | 909 } else { |
| 907 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 910 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
| 908 AddSessionStorageHistogram(extended_enabled(), active_tab, overlay.get()); | 911 AddSessionStorageHistogram(extended_enabled(), active_tab, overlay.get()); |
| 909 overlay->GetController().CopyStateFromAndPrune( | 912 overlay->GetController().CopyStateFromAndPrune( |
| 910 &active_tab->GetController()); | 913 &active_tab->GetController()); |
| 911 } | 914 } |
| 912 | 915 |
| 913 if (extended_enabled()) { | 916 if (extended_enabled()) { |
| 914 // Adjust the search terms shown in the omnibox for this query. Hitting | 917 // Adjust the search terms shown in the omnibox for this query. Hitting |
| 915 // ENTER searches for what the user typed, so use last_omnibox_text_. | 918 // ENTER searches for what the user typed, so use last_omnibox_text_. |
| (...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 result->transition = match.transition; | 1884 result->transition = match.transition; |
| 1882 result->relevance = match.relevance; | 1885 result->relevance = match.relevance; |
| 1883 result->autocomplete_match_index = autocomplete_match_index; | 1886 result->autocomplete_match_index = autocomplete_match_index; |
| 1884 | 1887 |
| 1885 DVLOG(1) << " " << result->relevance << " " | 1888 DVLOG(1) << " " << result->relevance << " " |
| 1886 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " " | 1889 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " " |
| 1887 << result->provider << " " << result->destination_url << " '" | 1890 << result->provider << " " << result->destination_url << " '" |
| 1888 << result->description << "' '" << result->search_query << "' " | 1891 << result->description << "' '" << result->search_query << "' " |
| 1889 << result->transition << " " << result->autocomplete_match_index; | 1892 << result->transition << " " << result->autocomplete_match_index; |
| 1890 } | 1893 } |
| OLD | NEW |