| 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/search/search.h" | 5 #include "chrome/browser/search/search.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "content/public/browser/navigation_entry.h" | 35 #include "content/public/browser/navigation_entry.h" |
| 36 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
| 37 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 38 | 38 |
| 39 #if defined(ENABLE_SUPERVISED_USERS) | 39 #if defined(ENABLE_SUPERVISED_USERS) |
| 40 #include "chrome/browser/supervised_user/supervised_user_service.h" | 40 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 41 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 41 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 42 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" | 42 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 #if defined(OS_CHROMEOS) |
| 46 #include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h" |
| 47 #endif // defined(OS_CHROMEOS) |
| 48 |
| 45 namespace search { | 49 namespace search { |
| 46 | 50 |
| 47 namespace { | 51 namespace { |
| 48 | 52 |
| 49 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; | 53 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; |
| 50 const char kPrerenderInstantUrlOnOmniboxFocus[] = | 54 const char kPrerenderInstantUrlOnOmniboxFocus[] = |
| 51 "prerender_instant_url_on_omnibox_focus"; | 55 "prerender_instant_url_on_omnibox_focus"; |
| 52 | 56 |
| 53 // Controls whether to use the alternate Instant search base URL. This allows | 57 // Controls whether to use the alternate Instant search base URL. This allows |
| 54 // experimentation of Instant search. | 58 // experimentation of Instant search. |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 return NEW_TAB_URL_INCOGNITO; | 236 return NEW_TAB_URL_INCOGNITO; |
| 233 if (!new_tab_url.is_valid()) | 237 if (!new_tab_url.is_valid()) |
| 234 return NEW_TAB_URL_NOT_SET; | 238 return NEW_TAB_URL_NOT_SET; |
| 235 if (!new_tab_url.SchemeIsCryptographic()) | 239 if (!new_tab_url.SchemeIsCryptographic()) |
| 236 return NEW_TAB_URL_INSECURE; | 240 return NEW_TAB_URL_INSECURE; |
| 237 if (!IsURLAllowedForSupervisedUser(new_tab_url, profile)) | 241 if (!IsURLAllowedForSupervisedUser(new_tab_url, profile)) |
| 238 return NEW_TAB_URL_BLOCKED; | 242 return NEW_TAB_URL_BLOCKED; |
| 239 return NEW_TAB_URL_VALID; | 243 return NEW_TAB_URL_VALID; |
| 240 } | 244 } |
| 241 | 245 |
| 246 // On Chrome OS, if the session hasn't merged yet, we need to avoid loading the |
| 247 // remote NTP because that will trigger showing the merge session throttle |
| 248 // interstitial page, which can show for 5+ seconds. crbug.com/591530. |
| 249 bool ShouldShowLocalNewTab(const GURL& url, Profile* profile) { |
| 250 #if defined(OS_CHROMEOS) |
| 251 if (merge_session_throttling_utils::ShouldDelayRequestForProfile(profile) && |
| 252 merge_session_throttling_utils::ShouldDelayUrl(url)) { |
| 253 return true; |
| 254 } |
| 255 #endif // defined(OS_CHROMEOS) |
| 256 return false; |
| 257 } |
| 258 |
| 242 // Used to look up the URL to use for the New Tab page. Also tracks how we | 259 // Used to look up the URL to use for the New Tab page. Also tracks how we |
| 243 // arrived at that URL so it can be logged with UMA. | 260 // arrived at that URL so it can be logged with UMA. |
| 244 struct NewTabURLDetails { | 261 struct NewTabURLDetails { |
| 245 NewTabURLDetails(const GURL& url, NewTabURLState state) | 262 NewTabURLDetails(const GURL& url, NewTabURLState state) |
| 246 : url(url), state(state) {} | 263 : url(url), state(state) {} |
| 247 | 264 |
| 248 static NewTabURLDetails ForProfile(Profile* profile) { | 265 static NewTabURLDetails ForProfile(Profile* profile) { |
| 249 const GURL local_url(chrome::kChromeSearchLocalNtpUrl); | 266 const GURL local_url(chrome::kChromeSearchLocalNtpUrl); |
| 250 | 267 |
| 251 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 268 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 252 if (command_line->HasSwitch(switches::kForceLocalNtp)) | 269 if (command_line->HasSwitch(switches::kForceLocalNtp)) |
| 253 return NewTabURLDetails(local_url, NEW_TAB_URL_VALID); | 270 return NewTabURLDetails(local_url, NEW_TAB_URL_VALID); |
| 254 | 271 |
| 255 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 272 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); |
| 256 if (!profile || !template_url) | 273 if (!profile || !template_url) |
| 257 return NewTabURLDetails(local_url, NEW_TAB_URL_BAD); | 274 return NewTabURLDetails(local_url, NEW_TAB_URL_BAD); |
| 258 | 275 |
| 259 GURL search_provider_url = TemplateURLRefToGURL( | 276 GURL search_provider_url = TemplateURLRefToGURL( |
| 260 template_url->new_tab_url_ref(), UIThreadSearchTermsData(profile), | 277 template_url->new_tab_url_ref(), UIThreadSearchTermsData(profile), |
| 261 false, false); | 278 false, false); |
| 279 |
| 280 if (ShouldShowLocalNewTab(search_provider_url, profile)) |
| 281 return NewTabURLDetails(local_url, NEW_TAB_URL_VALID); |
| 282 |
| 262 NewTabURLState state = IsValidNewTabURL(profile, search_provider_url); | 283 NewTabURLState state = IsValidNewTabURL(profile, search_provider_url); |
| 263 switch (state) { | 284 switch (state) { |
| 264 case NEW_TAB_URL_VALID: | 285 case NEW_TAB_URL_VALID: |
| 265 // We can use the search provider's page. | 286 // We can use the search provider's page. |
| 266 return NewTabURLDetails(search_provider_url, state); | 287 return NewTabURLDetails(search_provider_url, state); |
| 267 case NEW_TAB_URL_INCOGNITO: | 288 case NEW_TAB_URL_INCOGNITO: |
| 268 // Incognito has its own New Tab. | 289 // Incognito has its own New Tab. |
| 269 return NewTabURLDetails(GURL(), state); | 290 return NewTabURLDetails(GURL(), state); |
| 270 default: | 291 default: |
| 271 // Use the local New Tab otherwise. | 292 // Use the local New Tab otherwise. |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 kUseAltInstantURL, false, flags); | 605 kUseAltInstantURL, false, flags); |
| 585 } | 606 } |
| 586 | 607 |
| 587 bool ShouldUseSearchPathForInstant() { | 608 bool ShouldUseSearchPathForInstant() { |
| 588 FieldTrialFlags flags; | 609 FieldTrialFlags flags; |
| 589 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 610 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 590 kUseSearchPathForInstant, false, flags); | 611 kUseSearchPathForInstant, false, flags); |
| 591 } | 612 } |
| 592 | 613 |
| 593 } // namespace search | 614 } // namespace search |
| OLD | NEW |