| 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/search_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/history/most_visited_tiles_experiment.h" | 14 #include "chrome/browser/history/most_visited_tiles_experiment.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/search/instant_service.h" | 16 #include "chrome/browser/search/instant_service.h" |
| 17 #include "chrome/browser/search/instant_service_factory.h" | 17 #include "chrome/browser/search/instant_service_factory.h" |
| 18 #include "chrome/browser/search/search.h" | 18 #include "chrome/browser/search/search.h" |
| 19 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
| 20 #include "chrome/browser/ui/app_list/app_list_util.h" | 20 #include "chrome/browser/ui/app_list/app_list_util.h" |
| 21 #include "chrome/browser/ui/browser_navigator.h" | 21 #include "chrome/browser/ui/browser_navigator.h" |
| 22 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "chrome/browser/ui/omnibox/location_bar.h" | 23 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 24 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 24 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
| 25 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 25 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| 26 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 26 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 27 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
| 27 #include "chrome/browser/ui/search/search_ipc_router_policy_impl.h" | 28 #include "chrome/browser/ui/search/search_ipc_router_policy_impl.h" |
| 28 #include "chrome/browser/ui/search/search_tab_helper_delegate.h" | 29 #include "chrome/browser/ui/search/search_tab_helper_delegate.h" |
| 29 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 30 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 30 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" | 31 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" |
| 31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 32 #include "components/signin/core/browser/signin_manager.h" | 33 #include "components/signin/core/browser/signin_manager.h" |
| 33 #include "content/public/browser/navigation_controller.h" | 34 #include "content/public/browser/navigation_controller.h" |
| 34 #include "content/public/browser/navigation_details.h" | 35 #include "content/public/browser/navigation_details.h" |
| 35 #include "content/public/browser/navigation_entry.h" | 36 #include "content/public/browser/navigation_entry.h" |
| 36 #include "content/public/browser/navigation_type.h" | 37 #include "content/public/browser/navigation_type.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 content::Source<SearchTabHelper>(this), | 165 content::Source<SearchTabHelper>(this), |
| 165 content::NotificationService::NoDetails()); | 166 content::NotificationService::NoDetails()); |
| 166 | 167 |
| 167 ipc_router_.OmniboxFocusChanged(state, reason); | 168 ipc_router_.OmniboxFocusChanged(state, reason); |
| 168 | 169 |
| 169 // Don't send oninputstart/oninputend updates in response to focus changes | 170 // Don't send oninputstart/oninputend updates in response to focus changes |
| 170 // if there's a navigation in progress. This prevents Chrome from sending | 171 // if there's a navigation in progress. This prevents Chrome from sending |
| 171 // a spurious oninputend when the user accepts a match in the omnibox. | 172 // a spurious oninputend when the user accepts a match in the omnibox. |
| 172 if (web_contents_->GetController().GetPendingEntry() == NULL) { | 173 if (web_contents_->GetController().GetPendingEntry() == NULL) { |
| 173 ipc_router_.SetInputInProgress(IsInputInProgress()); | 174 ipc_router_.SetInputInProgress(IsInputInProgress()); |
| 175 |
| 176 InstantSearchPrerenderer* prerenderer = |
| 177 InstantSearchPrerenderer::GetForProfile(profile()); |
| 178 if (!prerenderer || !chrome::ShouldPrerenderInstantUrlOnOmniboxFocus()) |
| 179 return; |
| 180 |
| 181 if (state == OMNIBOX_FOCUS_NONE) { |
| 182 prerenderer->Cancel(); |
| 183 return; |
| 184 } |
| 185 |
| 186 if (!IsSearchResultsPage()) { |
| 187 prerenderer->Init( |
| 188 web_contents_->GetController().GetSessionStorageNamespaceMap(), |
| 189 web_contents_->GetContainerBounds().size()); |
| 190 } |
| 174 } | 191 } |
| 175 } | 192 } |
| 176 | 193 |
| 177 void SearchTabHelper::NavigationEntryUpdated() { | 194 void SearchTabHelper::NavigationEntryUpdated() { |
| 178 if (!is_search_enabled_) | 195 if (!is_search_enabled_) |
| 179 return; | 196 return; |
| 180 | 197 |
| 181 UpdateMode(false, false); | 198 UpdateMode(false, false); |
| 182 } | 199 } |
| 183 | 200 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 207 const InstantSuggestion& suggestion) { | 224 const InstantSuggestion& suggestion) { |
| 208 ipc_router_.SetSuggestionToPrefetch(suggestion); | 225 ipc_router_.SetSuggestionToPrefetch(suggestion); |
| 209 } | 226 } |
| 210 | 227 |
| 211 void SearchTabHelper::Submit(const base::string16& text) { | 228 void SearchTabHelper::Submit(const base::string16& text) { |
| 212 ipc_router_.Submit(text); | 229 ipc_router_.Submit(text); |
| 213 } | 230 } |
| 214 | 231 |
| 215 void SearchTabHelper::OnTabActivated() { | 232 void SearchTabHelper::OnTabActivated() { |
| 216 ipc_router_.OnTabActivated(); | 233 ipc_router_.OnTabActivated(); |
| 234 |
| 235 OmniboxView* omnibox_view = GetOmniboxView(); |
| 236 if (chrome::ShouldPrerenderInstantUrlOnOmniboxFocus() && omnibox_view && |
| 237 omnibox_view->model()->has_focus()) { |
| 238 InstantSearchPrerenderer* prerenderer = |
| 239 InstantSearchPrerenderer::GetForProfile(profile()); |
| 240 if (prerenderer && !IsSearchResultsPage()) { |
| 241 prerenderer->Init( |
| 242 web_contents_->GetController().GetSessionStorageNamespaceMap(), |
| 243 web_contents_->GetContainerBounds().size()); |
| 244 } |
| 245 } |
| 217 } | 246 } |
| 218 | 247 |
| 219 void SearchTabHelper::OnTabDeactivated() { | 248 void SearchTabHelper::OnTabDeactivated() { |
| 220 ipc_router_.OnTabDeactivated(); | 249 ipc_router_.OnTabDeactivated(); |
| 221 } | 250 } |
| 222 | 251 |
| 223 void SearchTabHelper::ToggleVoiceSearch() { | 252 void SearchTabHelper::ToggleVoiceSearch() { |
| 224 ipc_router_.ToggleVoiceSearch(); | 253 ipc_router_.ToggleVoiceSearch(); |
| 225 } | 254 } |
| 226 | 255 |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 616 |
| 588 bool SearchTabHelper::IsInputInProgress() const { | 617 bool SearchTabHelper::IsInputInProgress() const { |
| 589 OmniboxView* omnibox = GetOmniboxView(); | 618 OmniboxView* omnibox = GetOmniboxView(); |
| 590 return !model_.mode().is_ntp() && omnibox && | 619 return !model_.mode().is_ntp() && omnibox && |
| 591 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; | 620 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; |
| 592 } | 621 } |
| 593 | 622 |
| 594 OmniboxView* SearchTabHelper::GetOmniboxView() const { | 623 OmniboxView* SearchTabHelper::GetOmniboxView() const { |
| 595 return delegate_ ? delegate_->GetOmniboxView() : NULL; | 624 return delegate_ ? delegate_->GetOmniboxView() : NULL; |
| 596 } | 625 } |
| OLD | NEW |