| 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..7ba81778c309491befcc639d906bdadb3eb50da0 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,28 @@ 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& other_url) {
|
| + // The origin should match.
|
| + if (!MatchesOrigin(my_url, other_url))
|
| + return false;
|
| +
|
| + // One of the urls filename should be the new tab page ServiceWorker.
|
| + std::string my_filename = my_url.ExtractFileName();
|
| + std::string other_filename = other_url.ExtractFileName();
|
| + if (my_filename != kServiceWorkerFileName &&
|
| + other_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 other_path_without_filename = other_url.path();
|
| + other_path_without_filename = other_path_without_filename.substr(
|
| + 0, other_path_without_filename.length() - other_filename.length());
|
| +
|
| + return my_path_without_filename == other_path_without_filename;
|
| +}
|
| +
|
| } // namespace search
|
|
|