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 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: | 18 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: |
19 // roughly, must be of the form "<origin>/<path>/*". | 19 // roughly, must be of the form "<origin>/<path>/*". |
20 typedef GURL Scope; | 20 typedef GURL Scope; |
21 | 21 |
22 typedef base::Callback<void(bool success)> ResultCallback; | 22 typedef base::Callback<void(bool success)> ResultCallback; |
23 | 23 |
24 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: | 24 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: |
25 // pattern}) from a renderer in |source_process_id|, except that |pattern| is | 25 // pattern}) from a renderer, except that |pattern| is an absolute URL instead |
26 // an absolute URL instead of relative to some current origin. |callback| is | 26 // of relative to some current origin. |callback| is passed true when the JS |
27 // passed true when the JS promise is fulfilled or false when the JS | 27 // promise is fulfilled or false when the JS promise is rejected. |
28 // promise is rejected. | |
29 // | 28 // |
30 // The registration can fail if: | 29 // The registration can fail if: |
31 // * |script_url| is on a different origin from |pattern| | 30 // * |script_url| is on a different origin from |pattern| |
32 // * Fetching |script_url| fails. | 31 // * Fetching |script_url| fails. |
33 // * |script_url| fails to parse or its top-level execution fails. | 32 // * |script_url| fails to parse or its top-level execution fails. |
34 // TODO: The error message for this needs to be available to developers. | 33 // TODO: The error message for this needs to be available to developers. |
35 // * Something unexpected goes wrong, like a renderer crash or a full disk. | 34 // * Something unexpected goes wrong, like a renderer crash or a full disk. |
36 virtual void RegisterServiceWorker(const Scope& pattern, | 35 virtual void RegisterServiceWorker(const Scope& pattern, |
37 const GURL& script_url, | 36 const GURL& script_url, |
38 int source_process_id, | |
39 const ResultCallback& callback) = 0; | 37 const ResultCallback& callback) = 0; |
40 | 38 |
41 // Equivalent to calling navigator.serviceWorker.unregister(pattern) from a | 39 // Equivalent to calling navigator.serviceWorker.unregister(pattern) from a |
42 // renderer in |source_process_id|, except that |pattern| is an absolute URL | 40 // renderer in |source_process_id|, except that |pattern| is an absolute URL |
43 // instead of relative to some current origin. |callback| is passed true | 41 // instead of relative to some current origin. |callback| is passed true |
44 // when the JS promise is fulfilled or false when the JS promise is rejected. | 42 // when the JS promise is fulfilled or false when the JS promise is rejected. |
45 // | 43 // |
46 // Unregistration can fail if: | 44 // Unregistration can fail if: |
47 // * No Service Worker was registered for |pattern|. | 45 // * No Service Worker was registered for |pattern|. |
48 // * Something unexpected goes wrong, like a renderer crash. | 46 // * Something unexpected goes wrong, like a renderer crash. |
49 virtual void UnregisterServiceWorker(const Scope& pattern, | 47 virtual void UnregisterServiceWorker(const Scope& pattern, |
50 int source_process_id, | 48 int source_process_id, |
51 const ResultCallback& callback) = 0; | 49 const ResultCallback& callback) = 0; |
52 | 50 |
53 // TODO(jyasskin): Provide a way to SendMessage to a Scope. | 51 // TODO(jyasskin): Provide a way to SendMessage to a Scope. |
54 | 52 |
55 protected: | 53 protected: |
56 ServiceWorkerContext() {} | 54 ServiceWorkerContext() {} |
57 virtual ~ServiceWorkerContext() {} | 55 virtual ~ServiceWorkerContext() {} |
58 }; | 56 }; |
59 | 57 |
60 } // namespace content | 58 } // namespace content |
61 | 59 |
62 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ | 60 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
OLD | NEW |