Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: chrome/browser/ui/search/search_tab_helper.cc

Issue 2152743002: Remove search::ShouldPrerenderInstantUrlOnOmniboxFocus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_prefetch_srp
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 9
10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
12 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
13 #include "base/strings/string16.h"
14 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
15 #include "build/build_config.h" 13 #include "build/build_config.h"
16 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/search/instant_service.h" 16 #include "chrome/browser/search/instant_service.h"
19 #include "chrome/browser/search/instant_service_factory.h" 17 #include "chrome/browser/search/instant_service_factory.h"
20 #include "chrome/browser/search/search.h" 18 #include "chrome/browser/search/search.h"
21 #include "chrome/browser/signin/signin_manager_factory.h" 19 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "chrome/browser/sync/profile_sync_service_factory.h" 20 #include "chrome/browser/sync/profile_sync_service_factory.h"
23 #include "chrome/browser/ui/browser_window.h" 21 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/location_bar/location_bar.h" 22 #include "chrome/browser/ui/location_bar/location_bar.h"
25 #include "chrome/browser/ui/omnibox/clipboard_utils.h" 23 #include "chrome/browser/ui/omnibox/clipboard_utils.h"
26 #include "chrome/browser/ui/search/instant_search_prerenderer.h"
27 #include "chrome/browser/ui/search/instant_tab.h" 24 #include "chrome/browser/ui/search/instant_tab.h"
28 #include "chrome/browser/ui/search/search_ipc_router_policy_impl.h" 25 #include "chrome/browser/ui/search/search_ipc_router_policy_impl.h"
29 #include "chrome/browser/ui/search/search_tab_helper_delegate.h" 26 #include "chrome/browser/ui/search/search_tab_helper_delegate.h"
30 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 27 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
31 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" 28 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h"
32 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
33 #include "chrome/grit/generated_resources.h" 30 #include "chrome/grit/generated_resources.h"
34 #include "components/browser_sync/browser/profile_sync_service.h" 31 #include "components/browser_sync/browser/profile_sync_service.h"
35 #include "components/google/core/browser/google_util.h" 32 #include "components/google/core/browser/google_util.h"
36 #include "components/omnibox/browser/omnibox_edit_model.h" 33 #include "components/omnibox/browser/omnibox_edit_model.h"
37 #include "components/omnibox/browser/omnibox_popup_model.h" 34 #include "components/omnibox/browser/omnibox_popup_model.h"
38 #include "components/omnibox/browser/omnibox_view.h" 35 #include "components/omnibox/browser/omnibox_view.h"
39 #include "components/search/search.h" 36 #include "components/search/search.h"
40 #include "components/signin/core/browser/signin_manager.h" 37 #include "components/signin/core/browser/signin_manager.h"
41 #include "components/strings/grit/components_strings.h" 38 #include "components/strings/grit/components_strings.h"
42 #include "content/public/browser/navigation_controller.h" 39 #include "content/public/browser/navigation_controller.h"
43 #include "content/public/browser/navigation_details.h" 40 #include "content/public/browser/navigation_details.h"
44 #include "content/public/browser/navigation_entry.h" 41 #include "content/public/browser/navigation_entry.h"
45 #include "content/public/browser/navigation_type.h"
46 #include "content/public/browser/notification_service.h" 42 #include "content/public/browser/notification_service.h"
47 #include "content/public/browser/notification_source.h" 43 #include "content/public/browser/notification_source.h"
48 #include "content/public/browser/render_frame_host.h" 44 #include "content/public/browser/render_frame_host.h"
49 #include "content/public/browser/render_process_host.h" 45 #include "content/public/browser/render_process_host.h"
50 #include "content/public/browser/user_metrics.h" 46 #include "content/public/browser/user_metrics.h"
51 #include "content/public/browser/web_contents.h" 47 #include "content/public/browser/web_contents.h"
52 #include "content/public/common/referrer.h" 48 #include "content/public/common/referrer.h"
53 #include "google_apis/gaia/gaia_auth_util.h" 49 #include "google_apis/gaia/gaia_auth_util.h"
54 #include "net/base/net_errors.h" 50 #include "net/base/net_errors.h"
55 #include "ui/base/l10n/l10n_util.h" 51 #include "ui/base/l10n/l10n_util.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // is not a guarantee that history is being synced, but it can be used to 127 // is not a guarantee that history is being synced, but it can be used to
132 // disable a feature that should not be shown to users who prefer not to sync 128 // disable a feature that should not be shown to users who prefer not to sync
133 // their history. 129 // their history.
134 bool IsHistorySyncEnabled(Profile* profile) { 130 bool IsHistorySyncEnabled(Profile* profile) {
135 ProfileSyncService* sync = 131 ProfileSyncService* sync =
136 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); 132 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
137 return sync && 133 return sync &&
138 sync->GetPreferredDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES); 134 sync->GetPreferredDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES);
139 } 135 }
140 136
141 bool OmniboxHasFocus(OmniboxView* omnibox) {
142 return omnibox && omnibox->model()->has_focus();
143 }
144
145 } // namespace 137 } // namespace
146 138
147 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) 139 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents)
148 : WebContentsObserver(web_contents), 140 : WebContentsObserver(web_contents),
149 is_search_enabled_(search::IsInstantExtendedAPIEnabled()), 141 is_search_enabled_(search::IsInstantExtendedAPIEnabled()),
150 web_contents_(web_contents), 142 web_contents_(web_contents),
151 ipc_router_( 143 ipc_router_(
152 web_contents, 144 web_contents,
153 this, 145 this,
154 base::WrapUnique(new SearchIPCRouterPolicyImpl(web_contents))), 146 base::WrapUnique(new SearchIPCRouterPolicyImpl(web_contents))),
155 instant_service_(NULL), 147 instant_service_(NULL),
156 delegate_(NULL), 148 delegate_(NULL) {
157 omnibox_has_focus_fn_(&OmniboxHasFocus) {
158 if (!is_search_enabled_) 149 if (!is_search_enabled_)
159 return; 150 return;
160 151
161 instant_service_ = 152 instant_service_ =
162 InstantServiceFactory::GetForProfile( 153 InstantServiceFactory::GetForProfile(
163 Profile::FromBrowserContext(web_contents_->GetBrowserContext())); 154 Profile::FromBrowserContext(web_contents_->GetBrowserContext()));
164 if (instant_service_) 155 if (instant_service_)
165 instant_service_->AddObserver(this); 156 instant_service_->AddObserver(this);
166 } 157 }
167 158
(...skipping 14 matching lines...) Expand all
182 content::NotificationService::current()->Notify( 173 content::NotificationService::current()->Notify(
183 chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED, 174 chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED,
184 content::Source<SearchTabHelper>(this), 175 content::Source<SearchTabHelper>(this),
185 content::NotificationService::NoDetails()); 176 content::NotificationService::NoDetails());
186 177
187 ipc_router_.OmniboxFocusChanged(state, reason); 178 ipc_router_.OmniboxFocusChanged(state, reason);
188 179
189 // Don't send oninputstart/oninputend updates in response to focus changes 180 // Don't send oninputstart/oninputend updates in response to focus changes
190 // if there's a navigation in progress. This prevents Chrome from sending 181 // if there's a navigation in progress. This prevents Chrome from sending
191 // a spurious oninputend when the user accepts a match in the omnibox. 182 // a spurious oninputend when the user accepts a match in the omnibox.
192 if (web_contents_->GetController().GetPendingEntry() == NULL) { 183 if (web_contents_->GetController().GetPendingEntry() == NULL)
193 ipc_router_.SetInputInProgress(IsInputInProgress()); 184 ipc_router_.SetInputInProgress(IsInputInProgress());
194
195 InstantSearchPrerenderer* prerenderer =
196 InstantSearchPrerenderer::GetForProfile(profile());
197 if (!prerenderer || !search::ShouldPrerenderInstantUrlOnOmniboxFocus())
198 return;
199
200 if (state == OMNIBOX_FOCUS_NONE) {
201 prerenderer->Cancel();
202 return;
203 }
204
205 if (!IsSearchResultsPage()) {
206 prerenderer->Init(
207 web_contents_->GetController().GetDefaultSessionStorageNamespace(),
208 web_contents_->GetContainerBounds().size());
209 }
210 }
211 } 185 }
212 186
213 void SearchTabHelper::NavigationEntryUpdated() { 187 void SearchTabHelper::NavigationEntryUpdated() {
214 if (!is_search_enabled_) 188 if (!is_search_enabled_)
215 return; 189 return;
216 190
217 UpdateMode(false); 191 UpdateMode(false);
218 } 192 }
219 193
220 bool SearchTabHelper::SupportsInstant() const { 194 bool SearchTabHelper::SupportsInstant() const {
(...skipping 13 matching lines...) Expand all
234 void SearchTabHelper::OnTabActivated() { 208 void SearchTabHelper::OnTabActivated() {
235 ipc_router_.OnTabActivated(); 209 ipc_router_.OnTabActivated();
236 210
237 if (search::IsInstantNTP(web_contents_)) { 211 if (search::IsInstantNTP(web_contents_)) {
238 // Force creation of NTPUserDataLogger, if we loaded an NTP. The 212 // Force creation of NTPUserDataLogger, if we loaded an NTP. The
239 // NTPUserDataLogger tries to detect whether the NTP is being created at 213 // NTPUserDataLogger tries to detect whether the NTP is being created at
240 // startup or from the user opening a new tab, and if we wait until later, 214 // startup or from the user opening a new tab, and if we wait until later,
241 // it won't correctly detect this case. 215 // it won't correctly detect this case.
242 NTPUserDataLogger::GetOrCreateFromWebContents(web_contents_); 216 NTPUserDataLogger::GetOrCreateFromWebContents(web_contents_);
243 } 217 }
244
245 OmniboxView* omnibox_view = GetOmniboxView();
246 if (search::ShouldPrerenderInstantUrlOnOmniboxFocus() &&
247 omnibox_has_focus_fn_(omnibox_view)) {
248 InstantSearchPrerenderer* prerenderer =
249 InstantSearchPrerenderer::GetForProfile(profile());
250 if (prerenderer && !IsSearchResultsPage()) {
251 prerenderer->Init(
252 web_contents_->GetController().GetDefaultSessionStorageNamespace(),
253 web_contents_->GetContainerBounds().size());
254 }
255 }
256 } 218 }
257 219
258 void SearchTabHelper::OnTabDeactivated() { 220 void SearchTabHelper::OnTabDeactivated() {
259 ipc_router_.OnTabDeactivated(); 221 ipc_router_.OnTabDeactivated();
260 } 222 }
261 223
262 bool SearchTabHelper::IsSearchResultsPage() { 224 bool SearchTabHelper::IsSearchResultsPage() {
263 return model_.mode().is_origin_search(); 225 return model_.mode().is_origin_search();
264 } 226 }
265 227
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 519
558 bool SearchTabHelper::IsInputInProgress() const { 520 bool SearchTabHelper::IsInputInProgress() const {
559 OmniboxView* omnibox = GetOmniboxView(); 521 OmniboxView* omnibox = GetOmniboxView();
560 return !model_.mode().is_ntp() && omnibox && 522 return !model_.mode().is_ntp() && omnibox &&
561 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; 523 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE;
562 } 524 }
563 525
564 OmniboxView* SearchTabHelper::GetOmniboxView() const { 526 OmniboxView* SearchTabHelper::GetOmniboxView() const {
565 return delegate_ ? delegate_->GetOmniboxView() : NULL; 527 return delegate_ ? delegate_->GetOmniboxView() : NULL;
566 } 528 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.h ('k') | chrome/browser/ui/search/search_tab_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698