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

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

Issue 2898313003: Ensure the NTP ServiceWorker has the proper site URL (Closed)
Patch Set: Rebase + addressed comments Created 3 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/search/search_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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
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
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/search/search_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698