Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ |
| 7 | 7 |
| 8 #include "content/common/content_export.h" | 8 #include "content/common/content_export.h" |
| 9 #include "content/common/service_worker/service_worker_status_code.h" | 9 #include "content/common/service_worker/service_worker_status_code.h" |
| 10 #include "webkit/common/resource_type.h" | 10 #include "webkit/common/resource_type.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 class ServiceWorkerUtils { | 14 class ServiceWorkerUtils { |
| 15 public: | 15 public: |
| 16 enum MatchResult { | |
| 17 SCOPE_NO_MATCH = 0, | |
| 18 SCOPE_EXACT_MATCH, | |
| 19 SCOPE_WILDCARD_MATCH, | |
| 20 }; | |
| 21 | |
| 16 static bool IsMainResourceType(ResourceType::Type type) { | 22 static bool IsMainResourceType(ResourceType::Type type) { |
| 17 return ResourceType::IsFrame(type) || | 23 return ResourceType::IsFrame(type) || |
| 18 ResourceType::IsSharedWorker(type); | 24 ResourceType::IsSharedWorker(type); |
| 19 } | 25 } |
| 20 | 26 |
| 21 static bool IsServiceWorkerResourceType(ResourceType::Type type) { | 27 static bool IsServiceWorkerResourceType(ResourceType::Type type) { |
| 22 return ResourceType::IsServiceWorker(type); | 28 return ResourceType::IsServiceWorker(type); |
| 23 } | 29 } |
| 24 | 30 |
| 25 // Returns true if the feature is enabled (or not disabled) by command-line | 31 // Returns true if the feature is enabled (or not disabled) by command-line |
| 26 // flag. | 32 // flag. |
| 27 static bool IsFeatureEnabled(); | 33 static bool IsFeatureEnabled(); |
| 28 | 34 |
| 29 // A helper for creating a do-nothing status callback. | 35 // A helper for creating a do-nothing status callback. |
| 30 static void NoOpStatusCallback(ServiceWorkerStatusCode status) {} | 36 static void NoOpStatusCallback(ServiceWorkerStatusCode status) {} |
| 31 | 37 |
| 32 // Returns true if |scope| matches |url|. | 38 // 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
| |
| 33 CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url); | 39 // SCOPE_WILDCARD_MATCH if the scope matches the url with a wildcard. |
| 40 // Otherwise, returns SCOPE_NO_MATCH. | |
| 41 CONTENT_EXPORT static MatchResult ScopeMatches( | |
| 42 const GURL& scope, const GURL& url); | |
| 43 | |
| 44 // Compares given scopes' priorities in the longest-prefix-match way. | |
| 45 // - Returns a positive number if |scope1| has a higher priority. | |
| 46 // - Returns 0 if |scope1| and |scope2| are the same scope. | |
| 47 // - Returns a negative number if |scope2| has a higher priority. | |
| 48 // | |
| 49 // NOTE: Assumes that both scopes match a target document URL. You have to | |
| 50 // make sure it using ScopeMatches() in advance. | |
| 51 // | |
| 52 // Eg. if a document url is "/foo" and a pair of |scope1| and |scope2| is | |
| 53 // 1) ("/fo*", "/*"), returns a positive because |scope1| matches longer. | |
| 54 // 2) ("/fo*", "/fo*"), returns 0 because both scopes are same. | |
| 55 // 3) ("/foo*", "/foo"), returns a negative because |scope2| matches exactly. | |
| 56 CONTENT_EXPORT static int CompareScopePriorities( | |
| 57 const GURL& scope1, const GURL& scope2); | |
| 34 }; | 58 }; |
| 35 | 59 |
| 36 } // namespace content | 60 } // namespace content |
| 37 | 61 |
| 38 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ | 62 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ |
| OLD | NEW |