| 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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 // Represents the per-StoragePartition ServiceWorker data. Must be used from | 14 // Represents the per-StoragePartition ServiceWorker data. Must be used from |
| 15 // the UI thread. | 15 // the UI thread. |
| 16 class ServiceWorkerContext { | 16 class ServiceWorkerContext { |
| 17 public: | 17 public: |
| 18 class ServiceWorkerInfo { |
| 19 public: |
| 20 ServiceWorkerInfo(int worker_process_id, |
| 21 int embedded_worker_id, |
| 22 const GURL& scope, |
| 23 const GURL& url, |
| 24 int worker_devtools_agent_route_id) |
| 25 : worker_process_id(worker_process_id), |
| 26 embedded_worker_id(embedded_worker_id), |
| 27 scope(scope), |
| 28 url(url), |
| 29 worker_devtools_agent_route_id(worker_devtools_agent_route_id) {} |
| 30 int worker_process_id; |
| 31 int embedded_worker_id; |
| 32 GURL scope; |
| 33 GURL url; |
| 34 int worker_devtools_agent_route_id; |
| 35 }; |
| 36 |
| 18 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: | 37 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: |
| 19 // roughly, must be of the form "<origin>/<path>/*". | 38 // roughly, must be of the form "<origin>/<path>/*". |
| 20 typedef GURL Scope; | 39 typedef GURL Scope; |
| 21 | 40 |
| 22 typedef base::Callback<void(bool success)> ResultCallback; | 41 typedef base::Callback<void(bool success)> ResultCallback; |
| 23 | 42 |
| 43 typedef base::Callback<void(const std::vector< |
| 44 ServiceWorkerInfo>& registrations)> GetRunningServiceWorkerInfoCallback; |
| 45 |
| 46 |
| 24 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: | 47 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: |
| 25 // pattern}) from a renderer in |source_process_id|, except that |pattern| is | 48 // pattern}) from a renderer in |source_process_id|, except that |pattern| is |
| 26 // an absolute URL instead of relative to some current origin. |callback| is | 49 // an absolute URL instead of relative to some current origin. |callback| is |
| 27 // passed true when the JS promise is fulfilled or false when the JS | 50 // passed true when the JS promise is fulfilled or false when the JS |
| 28 // promise is rejected. | 51 // promise is rejected. |
| 29 // | 52 // |
| 30 // The registration can fail if: | 53 // The registration can fail if: |
| 31 // * |script_url| is on a different origin from |pattern| | 54 // * |script_url| is on a different origin from |pattern| |
| 32 // * Fetching |script_url| fails. | 55 // * Fetching |script_url| fails. |
| 33 // * |script_url| fails to parse or its top-level execution fails. | 56 // * |script_url| fails to parse or its top-level execution fails. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 45 // | 68 // |
| 46 // Unregistration can fail if: | 69 // Unregistration can fail if: |
| 47 // * No Service Worker was registered for |pattern|. | 70 // * No Service Worker was registered for |pattern|. |
| 48 // * Something unexpected goes wrong, like a renderer crash. | 71 // * Something unexpected goes wrong, like a renderer crash. |
| 49 virtual void UnregisterServiceWorker(const Scope& pattern, | 72 virtual void UnregisterServiceWorker(const Scope& pattern, |
| 50 int source_process_id, | 73 int source_process_id, |
| 51 const ResultCallback& callback) = 0; | 74 const ResultCallback& callback) = 0; |
| 52 | 75 |
| 53 // TODO(jyasskin): Provide a way to SendMessage to a Scope. | 76 // TODO(jyasskin): Provide a way to SendMessage to a Scope. |
| 54 | 77 |
| 78 virtual void AddStatusChangeCallback( |
| 79 const base::Callback<void(void)>& callback) = 0; |
| 80 |
| 81 virtual void RemoveStatusChangeCallback( |
| 82 const base::Callback<void(void)>& callback) = 0; |
| 83 |
| 84 virtual void GetRunningServiceWorkerInfo( |
| 85 const GetRunningServiceWorkerInfoCallback& callback) = 0; |
| 86 |
| 55 protected: | 87 protected: |
| 56 ServiceWorkerContext() {} | 88 ServiceWorkerContext() {} |
| 57 virtual ~ServiceWorkerContext() {} | 89 virtual ~ServiceWorkerContext() {} |
| 58 }; | 90 }; |
| 59 | 91 |
| 60 } // namespace content | 92 } // namespace content |
| 61 | 93 |
| 62 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ | 94 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
| OLD | NEW |