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

Unified Diff: chrome/common/search/search_urls.cc

Issue 2898313003: Ensure the NTP ServiceWorker has the proper site URL (Closed)
Patch Set: Rebase + addressed comments Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/search/search_urls.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/search/search_urls.cc
diff --git a/chrome/common/search/search_urls.cc b/chrome/common/search/search_urls.cc
index eb32d38346ab83fb00e6c09d5e2997dc21783cfc..574a7d992e35905202bd2025fa0f441a8eef48ff 100644
--- a/chrome/common/search/search_urls.cc
+++ b/chrome/common/search/search_urls.cc
@@ -10,6 +10,9 @@
namespace search {
namespace {
+
+const char kServiceWorkerFileName[] = "newtab-serviceworker.js";
+
bool MatchesOrigin(const GURL& my_url, const GURL& other_url) {
return my_url.host_piece() == other_url.host_piece() &&
my_url.port() == other_url.port() &&
@@ -17,6 +20,7 @@ bool MatchesOrigin(const GURL& my_url, const GURL& other_url) {
(my_url.SchemeIs(url::kHttpsScheme) &&
other_url.SchemeIs(url::kHttpScheme)));
}
+
} // namespace
bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) {
@@ -24,4 +28,26 @@ bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) {
my_url.path_piece() == other_url.path_piece();
}
+bool IsMatchingServiceWorker(const GURL& my_url, const GURL& document_url) {
+ // The origin should match.
+ if (!MatchesOrigin(my_url, document_url))
+ return false;
+
+ // The url filename should be the new tab page ServiceWorker.
+ std::string my_filename = my_url.ExtractFileName();
+ if (my_filename != kServiceWorkerFileName)
+ return false;
+
+ // The paths up to the filenames should be the same.
+ std::string my_path_without_filename = my_url.path();
+ my_path_without_filename = my_path_without_filename.substr(
+ 0, my_path_without_filename.length() - my_filename.length());
+ std::string document_filename = document_url.ExtractFileName();
+ std::string document_path_without_filename = document_url.path();
+ document_path_without_filename = document_path_without_filename.substr(
+ 0, document_path_without_filename.length() - document_filename.length());
+
+ return my_path_without_filename == document_path_without_filename;
+}
+
} // namespace search
« no previous file with comments | « chrome/common/search/search_urls.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698