OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_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" |
| 10 #include "url/gurl.h" |
9 | 11 |
10 namespace content { | 12 namespace content { |
11 | 13 |
12 // Represents the per-BrowserContext ServiceWorker data. | 14 // Represents the per-StoragePartition ServiceWorker data. Must be used from |
| 15 // the UI thread. |
13 class ServiceWorkerContext { | 16 class ServiceWorkerContext { |
14 public: | 17 public: |
15 // TODO(michaeln): This class is a place holder for content/public api | 18 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: |
16 // which will come later. Promote this class when we get there. | 19 // roughly, must be of the form "<origin>/<path>/*". |
| 20 typedef GURL Scope; |
| 21 |
| 22 typedef base::Callback<void(bool success)> ResultCallback; |
| 23 |
| 24 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: |
| 25 // 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 |
| 27 // passed true when the JS promise is fulfilled or false when the JS |
| 28 // promise is rejected. |
| 29 // |
| 30 // The registration can fail if: |
| 31 // * |script_url| is on a different origin from |pattern| |
| 32 // * Fetching |script_url| fails. |
| 33 // * |script_url| fails to parse or its top-level execution fails. |
| 34 // 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. |
| 36 virtual void RegisterServiceWorker(const Scope& pattern, |
| 37 const GURL& script_url, |
| 38 int source_process_id, |
| 39 const ResultCallback& callback) = 0; |
| 40 |
| 41 // Equivalent to calling navigator.serviceWorker.unregister(pattern) from a |
| 42 // renderer in |source_process_id|, except that |pattern| is an absolute URL |
| 43 // 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. |
| 45 // |
| 46 // Unregistration can fail if: |
| 47 // * No Service Worker was registered for |pattern|. |
| 48 // * Something unexpected goes wrong, like a renderer crash. |
| 49 virtual void UnregisterServiceWorker(const Scope& pattern, |
| 50 int source_process_id, |
| 51 const ResultCallback& callback) = 0; |
| 52 |
| 53 // TODO(jyasskin): Provide a way to SendMessage to a Scope. |
17 | 54 |
18 protected: | 55 protected: |
19 ServiceWorkerContext() {} | 56 ServiceWorkerContext() {} |
20 virtual ~ServiceWorkerContext() {} | 57 virtual ~ServiceWorkerContext() {} |
21 | |
22 private: | |
23 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContext); | |
24 }; | 58 }; |
25 | 59 |
26 } // namespace content | 60 } // namespace content |
27 | 61 |
28 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_ | 62 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
OLD | NEW |