| 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 StoragePartition; |
| 18 |
| 17 // Represents the per-StoragePartition ServiceWorker data. | 19 // Represents the per-StoragePartition ServiceWorker data. |
| 18 class ServiceWorkerContext { | 20 class ServiceWorkerContext { |
| 19 public: | 21 public: |
| 20 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: | 22 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: |
| 21 // roughly, must be of the form "<origin>/<path>/*". | 23 // roughly, must be of the form "<origin>/<path>/*". |
| 22 typedef GURL Scope; | 24 typedef GURL Scope; |
| 23 | 25 |
| 24 typedef base::Callback<void(bool success)> ResultCallback; | 26 typedef base::Callback<void(bool success)> ResultCallback; |
| 25 | 27 |
| 26 typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>& | 28 typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>& |
| 27 usage_info)> GetUsageInfoCallback; | 29 usage_info)> GetUsageInfoCallback; |
| 28 | 30 |
| 29 typedef base::Callback<void(bool has_service_worker)> | 31 typedef base::Callback<void(bool has_service_worker)> |
| 30 CheckHasServiceWorkerCallback; | 32 CheckHasServiceWorkerCallback; |
| 31 | 33 |
| 32 // Registers the header name which should not be passed to the ServiceWorker. | 34 // Registers the header name which should not be passed to the ServiceWorker. |
| 33 // Must be called from the IO thread. | 35 // Must be called from the IO thread. |
| 34 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent( | 36 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent( |
| 35 const std::set<std::string>& header_names); | 37 const std::set<std::string>& header_names); |
| 36 | 38 |
| 37 // Returns true if the header name should not be passed to the ServiceWorker. | 39 // Returns true if the header name should not be passed to the ServiceWorker. |
| 38 // Must be called from the IO thread. | 40 // Must be called from the IO thread. |
| 39 static bool IsExcludedHeaderNameForFetchEvent(const std::string& header_name); | 41 static bool IsExcludedHeaderNameForFetchEvent(const std::string& header_name); |
| 40 | 42 |
| 43 CONTENT_EXPORT static void IncrementEmbeddedWorkerRefCount( |
| 44 StoragePartition* storage_partition, |
| 45 int embedded_worker_id); |
| 46 CONTENT_EXPORT static void DecrementEmbeddedWorkerRefCount( |
| 47 StoragePartition* storage_partition, |
| 48 int embedded_worker_id); |
| 49 |
| 41 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: | 50 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: |
| 42 // pattern}) from a renderer, except that |pattern| is an absolute URL instead | 51 // pattern}) from a renderer, except that |pattern| is an absolute URL instead |
| 43 // of relative to some current origin. |callback| is passed true when the JS | 52 // of relative to some current origin. |callback| is passed true when the JS |
| 44 // promise is fulfilled or false when the JS promise is rejected. | 53 // promise is fulfilled or false when the JS promise is rejected. |
| 45 // | 54 // |
| 46 // The registration can fail if: | 55 // The registration can fail if: |
| 47 // * |script_url| is on a different origin from |pattern| | 56 // * |script_url| is on a different origin from |pattern| |
| 48 // * Fetching |script_url| fails. | 57 // * Fetching |script_url| fails. |
| 49 // * |script_url| fails to parse or its top-level execution fails. | 58 // * |script_url| fails to parse or its top-level execution fails. |
| 50 // TODO: The error message for this needs to be available to developers. | 59 // TODO: The error message for this needs to be available to developers. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 virtual void ClearAllServiceWorkersForTest(const base::Closure& callback) = 0; | 115 virtual void ClearAllServiceWorkersForTest(const base::Closure& callback) = 0; |
| 107 | 116 |
| 108 protected: | 117 protected: |
| 109 ServiceWorkerContext() {} | 118 ServiceWorkerContext() {} |
| 110 virtual ~ServiceWorkerContext() {} | 119 virtual ~ServiceWorkerContext() {} |
| 111 }; | 120 }; |
| 112 | 121 |
| 113 } // namespace content | 122 } // namespace content |
| 114 | 123 |
| 115 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ | 124 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
| OLD | NEW |