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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 content::NotificationService::current()->Notify( | 163 content::NotificationService::current()->Notify( |
163 chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED, | 164 chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED, |
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) { |
Jered
2014/06/19 21:09:46
This check makes me worry that there is a case whe
sidharthms
2014/06/20 00:31:44
Done.
| |
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 return; | |
182 | |
183 if (state == OMNIBOX_FOCUS_NONE) { | |
184 prerenderer->Cancel(); | |
185 return; | |
186 } | |
187 | |
188 if (!IsSearchResultsPage()) { | |
189 prerenderer->Init( | |
190 web_contents_->GetController().GetSessionStorageNamespaceMap(), | |
191 web_contents_->GetContainerBounds().size()); | |
192 } | |
193 } | |
175 } | 194 } |
176 | 195 |
177 void SearchTabHelper::NavigationEntryUpdated() { | 196 void SearchTabHelper::NavigationEntryUpdated() { |
178 if (!is_search_enabled_) | 197 if (!is_search_enabled_) |
179 return; | 198 return; |
180 | 199 |
181 UpdateMode(false, false); | 200 UpdateMode(false, false); |
182 } | 201 } |
183 | 202 |
184 void SearchTabHelper::InstantSupportChanged(bool instant_support) { | 203 void SearchTabHelper::InstantSupportChanged(bool instant_support) { |
(...skipping 22 matching lines...) Expand all Loading... | |
207 const InstantSuggestion& suggestion) { | 226 const InstantSuggestion& suggestion) { |
208 ipc_router_.SetSuggestionToPrefetch(suggestion); | 227 ipc_router_.SetSuggestionToPrefetch(suggestion); |
209 } | 228 } |
210 | 229 |
211 void SearchTabHelper::Submit(const base::string16& text) { | 230 void SearchTabHelper::Submit(const base::string16& text) { |
212 ipc_router_.Submit(text); | 231 ipc_router_.Submit(text); |
213 } | 232 } |
214 | 233 |
215 void SearchTabHelper::OnTabActivated() { | 234 void SearchTabHelper::OnTabActivated() { |
216 ipc_router_.OnTabActivated(); | 235 ipc_router_.OnTabActivated(); |
236 | |
237 OmniboxView* omnibox_view = GetOmniboxView(); | |
238 if (chrome::ShouldPrerenderInstantUrlOnOmniboxFocus() && omnibox_view && | |
239 omnibox_view->model()->has_focus()) { | |
240 InstantSearchPrerenderer* prerenderer = | |
241 InstantSearchPrerenderer::GetForProfile(profile()); | |
242 if (prerenderer && !IsSearchResultsPage()) { | |
243 prerenderer->Init( | |
244 web_contents_->GetController().GetSessionStorageNamespaceMap(), | |
245 web_contents_->GetContainerBounds().size()); | |
246 } | |
247 } | |
217 } | 248 } |
218 | 249 |
219 void SearchTabHelper::OnTabDeactivated() { | 250 void SearchTabHelper::OnTabDeactivated() { |
220 ipc_router_.OnTabDeactivated(); | 251 ipc_router_.OnTabDeactivated(); |
221 } | 252 } |
222 | 253 |
223 void SearchTabHelper::ToggleVoiceSearch() { | 254 void SearchTabHelper::ToggleVoiceSearch() { |
224 ipc_router_.ToggleVoiceSearch(); | 255 ipc_router_.ToggleVoiceSearch(); |
225 } | 256 } |
226 | 257 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 | 618 |
588 bool SearchTabHelper::IsInputInProgress() const { | 619 bool SearchTabHelper::IsInputInProgress() const { |
589 OmniboxView* omnibox = GetOmniboxView(); | 620 OmniboxView* omnibox = GetOmniboxView(); |
590 return !model_.mode().is_ntp() && omnibox && | 621 return !model_.mode().is_ntp() && omnibox && |
591 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; | 622 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; |
592 } | 623 } |
593 | 624 |
594 OmniboxView* SearchTabHelper::GetOmniboxView() const { | 625 OmniboxView* SearchTabHelper::GetOmniboxView() const { |
595 return delegate_ ? delegate_->GetOmniboxView() : NULL; | 626 return delegate_ ? delegate_->GetOmniboxView() : NULL; |
596 } | 627 } |
OLD | NEW |