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_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
6 #define CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ | 6 #define CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "content/public/browser/service_worker_usage_info.h" | 12 #include "content/public/browser/service_worker_usage_info.h" |
13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
| 17 class ServiceWorkerContextObserver; |
| 18 |
17 enum class ServiceWorkerCapability { | 19 enum class ServiceWorkerCapability { |
18 NO_SERVICE_WORKER, | 20 NO_SERVICE_WORKER, |
19 SERVICE_WORKER_NO_FETCH_HANDLER, | 21 SERVICE_WORKER_NO_FETCH_HANDLER, |
20 SERVICE_WORKER_WITH_FETCH_HANDLER, | 22 SERVICE_WORKER_WITH_FETCH_HANDLER, |
21 }; | 23 }; |
22 | 24 |
23 // Represents the per-StoragePartition ServiceWorker data. | 25 // Represents the per-StoragePartition ServiceWorker data. |
24 class ServiceWorkerContext { | 26 class ServiceWorkerContext { |
25 public: | 27 public: |
26 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: | 28 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: |
(...skipping 13 matching lines...) Expand all Loading... |
40 | 42 |
41 // Registers the header name which should not be passed to the ServiceWorker. | 43 // Registers the header name which should not be passed to the ServiceWorker. |
42 // Must be called from the IO thread. | 44 // Must be called from the IO thread. |
43 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent( | 45 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent( |
44 const std::set<std::string>& header_names); | 46 const std::set<std::string>& header_names); |
45 | 47 |
46 // Returns true if the header name should not be passed to the ServiceWorker. | 48 // Returns true if the header name should not be passed to the ServiceWorker. |
47 // Must be called from the IO thread. | 49 // Must be called from the IO thread. |
48 static bool IsExcludedHeaderNameForFetchEvent(const std::string& header_name); | 50 static bool IsExcludedHeaderNameForFetchEvent(const std::string& header_name); |
49 | 51 |
| 52 // Returns true if |url| is within the service worker |scope|. |
| 53 CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url); |
| 54 |
| 55 // Observer methods are always dispatched on the UI thread. |
| 56 virtual void AddObserver(ServiceWorkerContextObserver* observer) = 0; |
| 57 virtual void RemoveObserver(ServiceWorkerContextObserver* observer) = 0; |
| 58 |
50 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: | 59 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: |
51 // pattern}) from a renderer, except that |pattern| is an absolute URL instead | 60 // pattern}) from a renderer, except that |pattern| is an absolute URL instead |
52 // of relative to some current origin. |callback| is passed true when the JS | 61 // of relative to some current origin. |callback| is passed true when the JS |
53 // promise is fulfilled or false when the JS promise is rejected. | 62 // promise is fulfilled or false when the JS promise is rejected. |
54 // | 63 // |
55 // The registration can fail if: | 64 // The registration can fail if: |
56 // * |script_url| is on a different origin from |pattern| | 65 // * |script_url| is on a different origin from |pattern| |
57 // * Fetching |script_url| fails. | 66 // * Fetching |script_url| fails. |
58 // * |script_url| fails to parse or its top-level execution fails. | 67 // * |script_url| fails to parse or its top-level execution fails. |
59 // TODO: The error message for this needs to be available to developers. | 68 // TODO: The error message for this needs to be available to developers. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 virtual void ClearAllServiceWorkersForTest(const base::Closure& callback) = 0; | 149 virtual void ClearAllServiceWorkersForTest(const base::Closure& callback) = 0; |
141 | 150 |
142 protected: | 151 protected: |
143 ServiceWorkerContext() {} | 152 ServiceWorkerContext() {} |
144 virtual ~ServiceWorkerContext() {} | 153 virtual ~ServiceWorkerContext() {} |
145 }; | 154 }; |
146 | 155 |
147 } // namespace content | 156 } // namespace content |
148 | 157 |
149 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ | 158 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
OLD | NEW |