Simplify ChildProcessLauncher
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_utils.h
blobc03f4f2dccdd99b0da60f00dac0ff4fbc191f7f3
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_
8 #include "base/macros.h"
9 #include "content/common/content_export.h"
10 #include "content/common/service_worker/service_worker_status_code.h"
11 #include "content/public/common/resource_type.h"
12 #include "url/gurl.h"
14 namespace content {
16 class ServiceWorkerUtils {
17 public:
18 static bool IsMainResourceType(ResourceType type) {
19 return IsResourceTypeFrame(type) || type == RESOURCE_TYPE_SHARED_WORKER;
22 // A helper for creating a do-nothing status callback.
23 static void NoOpStatusCallback(ServiceWorkerStatusCode status) {}
25 // Returns true if |scope| matches |url|.
26 CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url);
28 // Returns true if the script at |script_url| is allowed to control |scope|
29 // according to Service Worker's path restriction policy. If
30 // |service_worker_allowed| is not null, it points to the
31 // Service-Worker-Allowed header value.
32 CONTENT_EXPORT static bool IsPathRestrictionSatisfied(
33 const GURL& scope,
34 const GURL& script_url,
35 const std::string* service_worker_allowed_header_value,
36 std::string* error_message);
38 static bool ContainsDisallowedCharacter(const GURL& scope,
39 const GURL& script_url,
40 std::string* error_message);
43 class CONTENT_EXPORT LongestScopeMatcher {
44 public:
45 explicit LongestScopeMatcher(const GURL& url) : url_(url) {}
46 virtual ~LongestScopeMatcher() {}
48 // Returns true if |scope| matches |url_| longer than |match_|.
49 bool MatchLongest(const GURL& scope);
51 private:
52 const GURL url_;
53 GURL match_;
55 DISALLOW_COPY_AND_ASSIGN(LongestScopeMatcher);
58 } // namespace content
60 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_