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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 return url.is_valid() && | 428 return url.is_valid() && |
429 profile && | 429 profile && |
430 IsInstantExtendedAPIEnabled() && | 430 IsInstantExtendedAPIEnabled() && |
431 (url.SchemeIs(chrome::kChromeSearchScheme) || | 431 (url.SchemeIs(chrome::kChromeSearchScheme) || |
432 IsInstantURL(url, profile)); | 432 IsInstantURL(url, profile)); |
433 } | 433 } |
434 | 434 |
435 bool ShouldUseProcessPerSiteForInstantURL(const GURL& url, Profile* profile) { | 435 bool ShouldUseProcessPerSiteForInstantURL(const GURL& url, Profile* profile) { |
436 return ShouldAssignURLToInstantRenderer(url, profile) && | 436 return ShouldAssignURLToInstantRenderer(url, profile) && |
437 (url.host() == chrome::kChromeSearchLocalNtpHost || | 437 (url.host() == chrome::kChromeSearchLocalNtpHost || |
438 url.host() == chrome::kChromeSearchOnlineNtpHost); | 438 url.host() == chrome::kChromeSearchRemoteNtpHost); |
439 } | 439 } |
440 | 440 |
441 bool IsNTPURL(const GURL& url, Profile* profile) { | 441 bool IsNTPURL(const GURL& url, Profile* profile) { |
442 if (!url.is_valid()) | 442 if (!url.is_valid()) |
443 return false; | 443 return false; |
444 | 444 |
445 if (!IsInstantExtendedAPIEnabled()) | 445 if (!IsInstantExtendedAPIEnabled()) |
446 return url == GURL(chrome::kChromeUINewTabURL); | 446 return url == GURL(chrome::kChromeUINewTabURL); |
447 | 447 |
448 return profile && | 448 return profile && |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 return url; | 619 return url; |
620 | 620 |
621 GURL effective_url(url); | 621 GURL effective_url(url); |
622 | 622 |
623 // Replace the scheme with "chrome-search:". | 623 // Replace the scheme with "chrome-search:". |
624 url_canon::Replacements<char> replacements; | 624 url_canon::Replacements<char> replacements; |
625 std::string search_scheme(chrome::kChromeSearchScheme); | 625 std::string search_scheme(chrome::kChromeSearchScheme); |
626 replacements.SetScheme(search_scheme.data(), | 626 replacements.SetScheme(search_scheme.data(), |
627 url_parse::Component(0, search_scheme.length())); | 627 url_parse::Component(0, search_scheme.length())); |
628 | 628 |
629 // If the URL corresponds to an online NTP, replace the host with | 629 // If this is the URL for a server-provided NTP, replace the host with |
630 // "online-ntp". | 630 // "remote-ntp". |
631 std::string online_ntp_host(chrome::kChromeSearchOnlineNtpHost); | 631 std::string remote_ntp_host(chrome::kChromeSearchRemoteNtpHost); |
kmadhusu
2014/02/04 01:20:09
nit: You can move this declaration to line 635.
samarth
2014/02/04 02:14:53
Sadly that doesn't work. Because of the stupid wa
| |
632 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 632 NewTabURLDetails details = NewTabURLDetails::ForProfile(profile); |
633 if (template_url) { | 633 if (details.state == NEW_TAB_URL_VALID && |
634 const GURL instant_url = TemplateURLRefToGURL( | 634 search::MatchesOriginAndPath(url, details.url)) { |
635 template_url->instant_url_ref(), kDisableStartMargin, false, false); | 635 replacements.SetHost(remote_ntp_host.c_str(), |
636 if (instant_url.is_valid() && | 636 url_parse::Component(0, remote_ntp_host.length())); |
637 search::MatchesOriginAndPath(url, instant_url)) { | |
638 replacements.SetHost(online_ntp_host.c_str(), | |
639 url_parse::Component(0, online_ntp_host.length())); | |
640 } | |
641 } | 637 } |
642 | 638 |
643 effective_url = effective_url.ReplaceComponents(replacements); | 639 effective_url = effective_url.ReplaceComponents(replacements); |
644 return effective_url; | 640 return effective_url; |
645 } | 641 } |
646 | 642 |
647 bool HandleNewTabURLRewrite(GURL* url, | 643 bool HandleNewTabURLRewrite(GURL* url, |
648 content::BrowserContext* browser_context) { | 644 content::BrowserContext* browser_context) { |
649 if (!IsInstantExtendedAPIEnabled()) | 645 if (!IsInstantExtendedAPIEnabled()) |
650 return false; | 646 return false; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 | 772 |
777 // Given a FieldTrialFlags object, returns the boolean value of the provided | 773 // Given a FieldTrialFlags object, returns the boolean value of the provided |
778 // flag. | 774 // flag. |
779 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 775 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
780 bool default_value, | 776 bool default_value, |
781 const FieldTrialFlags& flags) { | 777 const FieldTrialFlags& flags) { |
782 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 778 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
783 } | 779 } |
784 | 780 |
785 } // namespace chrome | 781 } // namespace chrome |
OLD | NEW |