| 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 { | 15 namespace blink { |
| 16 enum class WebNavigationHintType; | 16 enum class WebNavigationHintType; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 enum class ServiceWorkerCapability { |
| 22 NO_SERVICE_WORKER, |
| 23 SERVICE_WORKER_NO_FETCH_HANDLER, |
| 24 SERVICE_WORKER_WITH_FETCH_HANDLER, |
| 25 }; |
| 26 |
| 21 // Represents the per-StoragePartition ServiceWorker data. | 27 // Represents the per-StoragePartition ServiceWorker data. |
| 22 class ServiceWorkerContext { | 28 class ServiceWorkerContext { |
| 23 public: | 29 public: |
| 24 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: | 30 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: |
| 25 // roughly, must be of the form "<origin>/<path>/*". | 31 // roughly, must be of the form "<origin>/<path>/*". |
| 26 using Scope = GURL; | 32 using Scope = GURL; |
| 27 | 33 |
| 28 using ResultCallback = base::Callback<void(bool success)>; | 34 using ResultCallback = base::Callback<void(bool success)>; |
| 29 | 35 |
| 30 using GetUsageInfoCallback = base::Callback<void( | 36 using GetUsageInfoCallback = base::Callback<void( |
| 31 const std::vector<ServiceWorkerUsageInfo>& usage_info)>; | 37 const std::vector<ServiceWorkerUsageInfo>& usage_info)>; |
| 32 | 38 |
| 33 using CheckHasServiceWorkerCallback = | 39 using CheckHasServiceWorkerCallback = |
| 34 base::Callback<void(bool has_service_worker)>; | 40 base::Callback<void(ServiceWorkerCapability capability)>; |
| 35 | 41 |
| 36 using CountExternalRequestsCallback = | 42 using CountExternalRequestsCallback = |
| 37 base::Callback<void(size_t external_request_count)>; | 43 base::Callback<void(size_t external_request_count)>; |
| 38 | 44 |
| 39 // Registers the header name which should not be passed to the ServiceWorker. | 45 // Registers the header name which should not be passed to the ServiceWorker. |
| 40 // Must be called from the IO thread. | 46 // Must be called from the IO thread. |
| 41 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent( | 47 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent( |
| 42 const std::set<std::string>& header_names); | 48 const std::set<std::string>& header_names); |
| 43 | 49 |
| 44 // Returns true if the header name should not be passed to the ServiceWorker. | 50 // Returns true if the header name should not be passed to the ServiceWorker. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // Methods used in response to browsing data and quota manager requests. | 101 // Methods used in response to browsing data and quota manager requests. |
| 96 | 102 |
| 97 // Must be called from the IO thread. | 103 // Must be called from the IO thread. |
| 98 virtual void GetAllOriginsInfo(const GetUsageInfoCallback& callback) = 0; | 104 virtual void GetAllOriginsInfo(const GetUsageInfoCallback& callback) = 0; |
| 99 | 105 |
| 100 // This function can be called from any thread, but the callback will always | 106 // This function can be called from any thread, but the callback will always |
| 101 // be called on the IO thread. | 107 // be called on the IO thread. |
| 102 virtual void DeleteForOrigin(const GURL& origin_url, | 108 virtual void DeleteForOrigin(const GURL& origin_url, |
| 103 const ResultCallback& callback) = 0; | 109 const ResultCallback& callback) = 0; |
| 104 | 110 |
| 105 // Returns true if a Service Worker registration exists that matches |url|, | 111 // Returns ServiceWorkerCapability describing existence and properties of a |
| 106 // and if |other_url| falls inside the scope of the same registration. Note | 112 // Service Worker registration matching |url|. Found service worker |
| 107 // this still returns true even if there is a Service Worker registration | 113 // registration must also encompass the |other_url|, otherwise it will be |
| 108 // which has a longer match for |other_url|. | 114 // considered non existent by this method. Note that the longest matching |
| 115 // registration for |url| is described, which is not necessarily the longest |
| 116 // matching registration for |other_url|. In case the service worker is being |
| 117 // installed as of calling this method, it will wait for the installation to |
| 118 // finish before coming back with the result. |
| 109 // | 119 // |
| 110 // This function can be called from any thread, but the callback will always | 120 // This function can be called from any thread, but the callback will always |
| 111 // be called on the UI thread. | 121 // be called on the UI thread. |
| 112 virtual void CheckHasServiceWorker( | 122 virtual void CheckHasServiceWorker( |
| 113 const GURL& url, | 123 const GURL& url, |
| 114 const GURL& other_url, | 124 const GURL& other_url, |
| 115 const CheckHasServiceWorkerCallback& callback) = 0; | 125 const CheckHasServiceWorkerCallback& callback) = 0; |
| 116 | 126 |
| 117 // Returns the pending external request count for the worker with the | 127 // Returns the pending external request count for the worker with the |
| 118 // specified |origin| via |callback|. | 128 // specified |origin| via |callback|. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 146 const ResultCallback& callback) = 0; | 156 const ResultCallback& callback) = 0; |
| 147 | 157 |
| 148 protected: | 158 protected: |
| 149 ServiceWorkerContext() {} | 159 ServiceWorkerContext() {} |
| 150 virtual ~ServiceWorkerContext() {} | 160 virtual ~ServiceWorkerContext() {} |
| 151 }; | 161 }; |
| 152 | 162 |
| 153 } // namespace content | 163 } // namespace content |
| 154 | 164 |
| 155 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ | 165 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
| OLD | NEW |