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

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

Issue 294593002: ServiceWorker: Support longest-prefix-match for registration scope (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
Index: content/browser/service_worker/service_worker_utils.h
diff --git a/content/browser/service_worker/service_worker_utils.h b/content/browser/service_worker/service_worker_utils.h
index 38669c4317648145870670961284df7a64f50aed..c0d7f6e4149b1ee7fa8c0d2b4484178aa086aa3b 100644
--- a/content/browser/service_worker/service_worker_utils.h
+++ b/content/browser/service_worker/service_worker_utils.h
@@ -13,6 +13,12 @@ namespace content {
class ServiceWorkerUtils {
public:
+ enum MatchResult {
+ SCOPE_NO_MATCH = 0,
+ SCOPE_EXACT_MATCH,
+ SCOPE_WILDCARD_MATCH,
+ };
+
static bool IsMainResourceType(ResourceType::Type type) {
return ResourceType::IsFrame(type) ||
ResourceType::IsSharedWorker(type);
@@ -29,8 +35,26 @@ class ServiceWorkerUtils {
// A helper for creating a do-nothing status callback.
static void NoOpStatusCallback(ServiceWorkerStatusCode status) {}
- // Returns true if |scope| matches |url|.
- CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url);
+ // Returns SCOPE_EXACT_MATCH if |scope| exactly matches |url|. Returns
dominicc (has gone to gerrit) 2014/05/22 05:03:31 I expect sometimes people call this with a URL and
+ // SCOPE_WILDCARD_MATCH if the scope matches the url with a wildcard.
+ // Otherwise, returns SCOPE_NO_MATCH.
+ CONTENT_EXPORT static MatchResult ScopeMatches(
+ const GURL& scope, const GURL& url);
+
+ // Compares given scopes' priorities in the longest-prefix-match way.
+ // - Returns a positive number if |scope1| has a higher priority.
+ // - Returns 0 if |scope1| and |scope2| are the same scope.
+ // - Returns a negative number if |scope2| has a higher priority.
+ //
+ // NOTE: Assumes that both scopes match a target document URL. You have to
+ // make sure it using ScopeMatches() in advance.
+ //
+ // Eg. if a document url is "/foo" and a pair of |scope1| and |scope2| is
+ // 1) ("/fo*", "/*"), returns a positive because |scope1| matches longer.
+ // 2) ("/fo*", "/fo*"), returns 0 because both scopes are same.
+ // 3) ("/foo*", "/foo"), returns a negative because |scope2| matches exactly.
+ CONTENT_EXPORT static int CompareScopePriorities(
+ const GURL& scope1, const GURL& scope2);
};
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698