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 { | |
michaeln
2014/05/01 02:52:07
naming nit: RunningServiceWorkerInfo? I can easily
horo
2014/05/01 04:52:32
Done.
| |
19 public: | |
20 ServiceWorkerInfo(int worker_process_id, | |
21 int worker_devtools_agent_route_id, | |
22 const GURL& scope, | |
23 const GURL& url) | |
24 : worker_process_id(worker_process_id), | |
25 worker_devtools_agent_route_id(worker_devtools_agent_route_id), | |
26 scope(scope), | |
27 url(url) {} | |
28 int worker_process_id; | |
29 int worker_devtools_agent_route_id; | |
30 GURL scope; | |
31 GURL url; | |
32 }; | |
33 | |
18 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/ index.html#url-scope: | 34 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/ index.html#url-scope: |
19 // roughly, must be of the form "<origin>/<path>/*". | 35 // roughly, must be of the form "<origin>/<path>/*". |
20 typedef GURL Scope; | 36 typedef GURL Scope; |
21 | 37 |
22 typedef base::Callback<void(bool success)> ResultCallback; | 38 typedef base::Callback<void(bool success)> ResultCallback; |
23 | 39 |
40 typedef base::Callback<void(const std::vector< | |
41 ServiceWorkerInfo>& registrations)> GetRunningServiceWorkerInfoCallback; | |
42 | |
24 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: | 43 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: |
25 // pattern}) from a renderer, except that |pattern| is an absolute URL instead | 44 // pattern}) from a renderer, except that |pattern| is an absolute URL instead |
26 // of relative to some current origin. |callback| is passed true when the JS | 45 // of relative to some current origin. |callback| is passed true when the JS |
27 // promise is fulfilled or false when the JS promise is rejected. | 46 // promise is fulfilled or false when the JS promise is rejected. |
28 // | 47 // |
29 // The registration can fail if: | 48 // The registration can fail if: |
30 // * |script_url| is on a different origin from |pattern| | 49 // * |script_url| is on a different origin from |pattern| |
31 // * Fetching |script_url| fails. | 50 // * Fetching |script_url| fails. |
32 // * |script_url| fails to parse or its top-level execution fails. | 51 // * |script_url| fails to parse or its top-level execution fails. |
33 // TODO: The error message for this needs to be available to developers. | 52 // TODO: The error message for this needs to be available to developers. |
34 // * Something unexpected goes wrong, like a renderer crash or a full disk. | 53 // * Something unexpected goes wrong, like a renderer crash or a full disk. |
35 virtual void RegisterServiceWorker(const Scope& pattern, | 54 virtual void RegisterServiceWorker(const Scope& pattern, |
36 const GURL& script_url, | 55 const GURL& script_url, |
37 const ResultCallback& callback) = 0; | 56 const ResultCallback& callback) = 0; |
38 | 57 |
39 // Equivalent to calling navigator.serviceWorker.unregister(pattern) from a | 58 // Equivalent to calling navigator.serviceWorker.unregister(pattern) from a |
40 // renderer in |source_process_id|, except that |pattern| is an absolute URL | 59 // renderer in |source_process_id|, except that |pattern| is an absolute URL |
41 // instead of relative to some current origin. |callback| is passed true | 60 // instead of relative to some current origin. |callback| is passed true |
42 // when the JS promise is fulfilled or false when the JS promise is rejected. | 61 // when the JS promise is fulfilled or false when the JS promise is rejected. |
43 // | 62 // |
44 // Unregistration can fail if: | 63 // Unregistration can fail if: |
45 // * No Service Worker was registered for |pattern|. | 64 // * No Service Worker was registered for |pattern|. |
46 // * Something unexpected goes wrong, like a renderer crash. | 65 // * Something unexpected goes wrong, like a renderer crash. |
47 virtual void UnregisterServiceWorker(const Scope& pattern, | 66 virtual void UnregisterServiceWorker(const Scope& pattern, |
48 int source_process_id, | 67 int source_process_id, |
49 const ResultCallback& callback) = 0; | 68 const ResultCallback& callback) = 0; |
50 | 69 |
51 // TODO(jyasskin): Provide a way to SendMessage to a Scope. | 70 // TODO(jyasskin): Provide a way to SendMessage to a Scope. |
52 | 71 |
72 virtual void AddStatusChangeCallback( | |
73 const base::Callback<void(void)>& callback) = 0; | |
74 | |
75 virtual void RemoveStatusChangeCallback( | |
76 const base::Callback<void(void)>& callback) = 0; | |
michaeln
2014/05/01 02:52:07
Identifying what to remove by callback ref seems o
horo
2014/05/01 04:52:32
Changed to use StatusChangeObserver.
| |
77 | |
78 virtual void GetRunningServiceWorkerInfo( | |
79 const GetRunningServiceWorkerInfoCallback& callback) = 0; | |
80 | |
53 protected: | 81 protected: |
54 ServiceWorkerContext() {} | 82 ServiceWorkerContext() {} |
55 virtual ~ServiceWorkerContext() {} | 83 virtual ~ServiceWorkerContext() {} |
56 }; | 84 }; |
57 | 85 |
58 } // namespace content | 86 } // namespace content |
59 | 87 |
60 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ | 88 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
OLD | NEW |