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 blink { |
| 16 enum class WebServiceWorkerUpdateViaCache; |
| 17 } // namespace blink |
| 18 |
15 namespace content { | 19 namespace content { |
16 | 20 |
17 class ServiceWorkerContextObserver; | 21 class ServiceWorkerContextObserver; |
18 | 22 |
19 enum class ServiceWorkerCapability { | 23 enum class ServiceWorkerCapability { |
20 NO_SERVICE_WORKER, | 24 NO_SERVICE_WORKER, |
21 SERVICE_WORKER_NO_FETCH_HANDLER, | 25 SERVICE_WORKER_NO_FETCH_HANDLER, |
22 SERVICE_WORKER_WITH_FETCH_HANDLER, | 26 SERVICE_WORKER_WITH_FETCH_HANDLER, |
23 }; | 27 }; |
24 | 28 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 static bool IsExcludedHeaderNameForFetchEvent(const std::string& header_name); | 72 static bool IsExcludedHeaderNameForFetchEvent(const std::string& header_name); |
69 | 73 |
70 // Returns true if |url| is within the service worker |scope|. | 74 // Returns true if |url| is within the service worker |scope|. |
71 CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url); | 75 CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url); |
72 | 76 |
73 // Observer methods are always dispatched on the UI thread. | 77 // Observer methods are always dispatched on the UI thread. |
74 virtual void AddObserver(ServiceWorkerContextObserver* observer) = 0; | 78 virtual void AddObserver(ServiceWorkerContextObserver* observer) = 0; |
75 virtual void RemoveObserver(ServiceWorkerContextObserver* observer) = 0; | 79 virtual void RemoveObserver(ServiceWorkerContextObserver* observer) = 0; |
76 | 80 |
77 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: | 81 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: |
78 // pattern}) from a renderer, except that |pattern| is an absolute URL instead | 82 // pattern, updateViaCache: update_via_cache}) from a renderer, except that |
79 // of relative to some current origin. |callback| is passed true when the JS | 83 // |pattern| is an absolute URL instead of relative to some current origin. |
80 // promise is fulfilled or false when the JS promise is rejected. | 84 // |callback| is passed true when the JS promise is fulfilled or false when |
| 85 // the JS promise is rejected. |
81 // | 86 // |
82 // The registration can fail if: | 87 // The registration can fail if: |
83 // * |script_url| is on a different origin from |pattern| | 88 // * |script_url| is on a different origin from |pattern| |
84 // * Fetching |script_url| fails. | 89 // * Fetching |script_url| fails. |
85 // * |script_url| fails to parse or its top-level execution fails. | 90 // * |script_url| fails to parse or its top-level execution fails. |
86 // TODO: The error message for this needs to be available to developers. | 91 // TODO: The error message for this needs to be available to developers. |
87 // * Something unexpected goes wrong, like a renderer crash or a full disk. | 92 // * Something unexpected goes wrong, like a renderer crash or a full disk. |
88 // | 93 // |
89 // This function can be called from any thread, but the callback will always | 94 // This function can be called from any thread, but the callback will always |
90 // be called on the UI thread. | 95 // be called on the UI thread. |
91 virtual void RegisterServiceWorker(const Scope& pattern, | 96 virtual void RegisterServiceWorker( |
92 const GURL& script_url, | 97 const Scope& pattern, |
93 const ResultCallback& callback) = 0; | 98 const GURL& script_url, |
| 99 blink::WebServiceWorkerUpdateViaCache update_via_cache, |
| 100 const ResultCallback& callback) = 0; |
94 | 101 |
95 // Mechanism for embedder to increment/decrement ref count of a service | 102 // Mechanism for embedder to increment/decrement ref count of a service |
96 // worker. | 103 // worker. |
97 // Embedders can call StartingExternalRequest() while it is performing some | 104 // Embedders can call StartingExternalRequest() while it is performing some |
98 // work with the worker. The worker is considered to be working until embedder | 105 // work with the worker. The worker is considered to be working until embedder |
99 // calls FinishedExternalRequest(). This ensures that content/ does not | 106 // calls FinishedExternalRequest(). This ensures that content/ does not |
100 // shut the worker down while embedder is expecting the worker to be kept | 107 // shut the worker down while embedder is expecting the worker to be kept |
101 // alive. | 108 // alive. |
102 // | 109 // |
103 // Must be called from the IO thread. Returns whether or not changing the ref | 110 // Must be called from the IO thread. Returns whether or not changing the ref |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 const StartServiceWorkerForNavigationHintCallback& callback) = 0; | 181 const StartServiceWorkerForNavigationHintCallback& callback) = 0; |
175 | 182 |
176 protected: | 183 protected: |
177 ServiceWorkerContext() {} | 184 ServiceWorkerContext() {} |
178 virtual ~ServiceWorkerContext() {} | 185 virtual ~ServiceWorkerContext() {} |
179 }; | 186 }; |
180 | 187 |
181 } // namespace content | 188 } // namespace content |
182 | 189 |
183 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ | 190 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
OLD | NEW |