| 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/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 // Returns true if |url| can be used as an Instant URL for |profile|. | 129 // Returns true if |url| can be used as an Instant URL for |profile|. |
| 130 bool IsInstantURL(const GURL& url, Profile* profile) { | 130 bool IsInstantURL(const GURL& url, Profile* profile) { |
| 131 if (!IsInstantExtendedAPIEnabled()) | 131 if (!IsInstantExtendedAPIEnabled()) |
| 132 return false; | 132 return false; |
| 133 | 133 |
| 134 if (!url.is_valid()) | 134 if (!url.is_valid()) |
| 135 return false; | 135 return false; |
| 136 | 136 |
| 137 const GURL new_tab_url(GetNewTabPageURL(profile)); | 137 const GURL new_tab_url(GetNewTabPageURL(profile)); |
| 138 if (new_tab_url.is_valid() && MatchesOriginAndPath(url, new_tab_url)) | 138 if (new_tab_url.is_valid() && (MatchesOriginAndPath(url, new_tab_url) || |
| 139 IsMatchingServiceWorker(url, new_tab_url))) { |
| 139 return true; | 140 return true; |
| 141 } |
| 140 | 142 |
| 141 const TemplateURL* template_url = | 143 const TemplateURL* template_url = |
| 142 GetDefaultSearchProviderTemplateURL(profile); | 144 GetDefaultSearchProviderTemplateURL(profile); |
| 143 if (!template_url) | 145 if (!template_url) |
| 144 return false; | 146 return false; |
| 145 | 147 |
| 146 if (!IsSuitableURLForInstant(url, template_url)) | 148 if (!IsSuitableURLForInstant(url, template_url)) |
| 147 return false; | 149 return false; |
| 148 | 150 |
| 149 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); | 151 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 std::string search_scheme(chrome::kChromeSearchScheme); | 415 std::string search_scheme(chrome::kChromeSearchScheme); |
| 414 replacements.SetScheme(search_scheme.data(), | 416 replacements.SetScheme(search_scheme.data(), |
| 415 url::Component(0, search_scheme.length())); | 417 url::Component(0, search_scheme.length())); |
| 416 replacements.ClearPort(); | 418 replacements.ClearPort(); |
| 417 | 419 |
| 418 // If this is the URL for a server-provided NTP, replace the host with | 420 // If this is the URL for a server-provided NTP, replace the host with |
| 419 // "remote-ntp". | 421 // "remote-ntp". |
| 420 std::string remote_ntp_host(chrome::kChromeSearchRemoteNtpHost); | 422 std::string remote_ntp_host(chrome::kChromeSearchRemoteNtpHost); |
| 421 NewTabURLDetails details = NewTabURLDetails::ForProfile(profile); | 423 NewTabURLDetails details = NewTabURLDetails::ForProfile(profile); |
| 422 if (details.state == NEW_TAB_URL_VALID && | 424 if (details.state == NEW_TAB_URL_VALID && |
| 423 MatchesOriginAndPath(url, details.url)) { | 425 (MatchesOriginAndPath(url, details.url) || |
| 426 IsMatchingServiceWorker(url, details.url))) { |
| 424 replacements.SetHost(remote_ntp_host.c_str(), | 427 replacements.SetHost(remote_ntp_host.c_str(), |
| 425 url::Component(0, remote_ntp_host.length())); | 428 url::Component(0, remote_ntp_host.length())); |
| 426 } | 429 } |
| 427 | 430 |
| 428 return url.ReplaceComponents(replacements); | 431 return url.ReplaceComponents(replacements); |
| 429 } | 432 } |
| 430 | 433 |
| 431 bool HandleNewTabURLRewrite(GURL* url, | 434 bool HandleNewTabURLRewrite(GURL* url, |
| 432 content::BrowserContext* browser_context) { | 435 content::BrowserContext* browser_context) { |
| 433 if (!IsInstantExtendedAPIEnabled()) | 436 if (!IsInstantExtendedAPIEnabled()) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 460 | 463 |
| 461 if (IsInstantNTPURL(*url, profile)) { | 464 if (IsInstantNTPURL(*url, profile)) { |
| 462 *url = GURL(chrome::kChromeUINewTabURL); | 465 *url = GURL(chrome::kChromeUINewTabURL); |
| 463 return true; | 466 return true; |
| 464 } | 467 } |
| 465 | 468 |
| 466 return false; | 469 return false; |
| 467 } | 470 } |
| 468 | 471 |
| 469 } // namespace search | 472 } // namespace search |
| OLD | NEW |