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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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()); |
174 } | 175 } |
176 | |
177 if (chrome::ShouldPrerenderInstantUrlOnOmniboxFocus()) { | |
178 InstantSearchPrerenderer* prerenderer = | |
179 InstantSearchPrerenderer::GetForProfile(profile()); | |
180 if (prerenderer) { | |
181 if (state != OMNIBOX_FOCUS_NONE) { | |
kmadhusu
2014/06/18 16:23:50
nit: For better readability, can we split this if-
sidharthms
2014/06/19 20:36:52
Done.
| |
182 if (!IsSearchResultsPage()) | |
183 prerenderer->Init( | |
184 web_contents_->GetController().GetSessionStorageNamespaceMap(), | |
185 web_contents_->GetContainerBounds().size()); | |
186 } else { | |
187 prerenderer->Cancel(); | |
188 } | |
189 } | |
190 } | |
175 } | 191 } |
176 | 192 |
177 void SearchTabHelper::NavigationEntryUpdated() { | 193 void SearchTabHelper::NavigationEntryUpdated() { |
178 if (!is_search_enabled_) | 194 if (!is_search_enabled_) |
179 return; | 195 return; |
180 | 196 |
181 UpdateMode(false, false); | 197 UpdateMode(false, false); |
182 } | 198 } |
183 | 199 |
184 void SearchTabHelper::InstantSupportChanged(bool instant_support) { | 200 void SearchTabHelper::InstantSupportChanged(bool instant_support) { |
(...skipping 22 matching lines...) Expand all Loading... | |
207 const InstantSuggestion& suggestion) { | 223 const InstantSuggestion& suggestion) { |
208 ipc_router_.SetSuggestionToPrefetch(suggestion); | 224 ipc_router_.SetSuggestionToPrefetch(suggestion); |
209 } | 225 } |
210 | 226 |
211 void SearchTabHelper::Submit(const base::string16& text) { | 227 void SearchTabHelper::Submit(const base::string16& text) { |
212 ipc_router_.Submit(text); | 228 ipc_router_.Submit(text); |
213 } | 229 } |
214 | 230 |
215 void SearchTabHelper::OnTabActivated() { | 231 void SearchTabHelper::OnTabActivated() { |
216 ipc_router_.OnTabActivated(); | 232 ipc_router_.OnTabActivated(); |
233 | |
234 if (chrome::ShouldPrerenderInstantUrlOnOmniboxFocus() && | |
235 GetOmniboxView()->model()->has_focus()) { | |
236 InstantSearchPrerenderer* prerenderer = | |
237 InstantSearchPrerenderer::GetForProfile(profile()); | |
238 if (prerenderer && !IsSearchResultsPage()) { | |
239 prerenderer->Init( | |
240 web_contents_->GetController().GetSessionStorageNamespaceMap(), | |
241 web_contents_->GetContainerBounds().size()); | |
242 } | |
243 } | |
217 } | 244 } |
218 | 245 |
219 void SearchTabHelper::OnTabDeactivated() { | 246 void SearchTabHelper::OnTabDeactivated() { |
220 ipc_router_.OnTabDeactivated(); | 247 ipc_router_.OnTabDeactivated(); |
221 } | 248 } |
222 | 249 |
223 void SearchTabHelper::ToggleVoiceSearch() { | 250 void SearchTabHelper::ToggleVoiceSearch() { |
224 ipc_router_.ToggleVoiceSearch(); | 251 ipc_router_.ToggleVoiceSearch(); |
225 } | 252 } |
226 | 253 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 | 614 |
588 bool SearchTabHelper::IsInputInProgress() const { | 615 bool SearchTabHelper::IsInputInProgress() const { |
589 OmniboxView* omnibox = GetOmniboxView(); | 616 OmniboxView* omnibox = GetOmniboxView(); |
590 return !model_.mode().is_ntp() && omnibox && | 617 return !model_.mode().is_ntp() && omnibox && |
591 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; | 618 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; |
592 } | 619 } |
593 | 620 |
594 OmniboxView* SearchTabHelper::GetOmniboxView() const { | 621 OmniboxView* SearchTabHelper::GetOmniboxView() const { |
595 return delegate_ ? delegate_->GetOmniboxView() : NULL; | 622 return delegate_ ? delegate_->GetOmniboxView() : NULL; |
596 } | 623 } |
OLD | NEW |