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 |