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

Unified Diff: content/browser/service_worker/service_worker_utils.cc

Issue 294593002: ServiceWorker: Support longest-prefix-match for registration scope (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_utils.cc
diff --git a/content/browser/service_worker/service_worker_utils.cc b/content/browser/service_worker/service_worker_utils.cc
index 165bcbec563e8226494083450aedad1f7a90c9c8..2c3d05b773fcecf90f95841c7e65eb83702fa705 100644
--- a/content/browser/service_worker/service_worker_utils.cc
+++ b/content/browser/service_worker/service_worker_utils.cc
@@ -4,9 +4,12 @@
#include "content/browser/service_worker/service_worker_utils.h"
+#include <string>
+
#include "base/command_line.h"
#include "base/logging.h"
#include "content/public/common/content_switches.h"
+#include "url/gurl.h"
namespace content {
@@ -30,4 +33,33 @@ bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) {
return scope_spec == url_spec;
}
+bool LongestScopeMatcher::MatchLongest(const GURL& scope) {
+ if (!ServiceWorkerUtils::ScopeMatches(scope, url_))
+ return false;
+ if (match_.is_empty()) {
+ match_ = scope;
+ return true;
+ }
+
+ const std::string match_spec = match_.spec();
+ const std::string scope_spec = scope.spec();
+ if (match_spec.size() < scope_spec.size()) {
+ match_ = scope;
+ return true;
+ }
+
+ // If |scope| has the same length with |match_|, they are compared as strings.
+ // For example:
+ // 1) for a document "/foo", "/foo" is prioritized over "/fo*".
+ // 2) for a document "/f(1)", "/f(1*" is prioritized over "/f(1)".
+ // TODO(nhiroki): This isn't in the spec.
+ // (https://github.com/slightlyoff/ServiceWorker/issues/287)
+ if (match_spec.size() == scope_spec.size() && match_spec < scope_spec) {
+ match_ = scope;
+ return true;
+ }
+
+ return false;
+}
+
} // namespace content
« no previous file with comments | « content/browser/service_worker/service_worker_utils.h ('k') | content/browser/service_worker/service_worker_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698