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