Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / content / public / browser / service_worker_context.h
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_
6 #define CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_
7
8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "content/public/browser/service_worker_usage_info.h"
11 #include "url/gurl.h"
12
13 namespace content {
14
15 // Represents the per-StoragePartition ServiceWorker data.  Must be used from
16 // the IO thread.
17 class ServiceWorkerContext {
18  public:
19   // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/index.html#url-scope:
20   // roughly, must be of the form "<origin>/<path>/*".
21   typedef GURL Scope;
22
23   typedef base::Callback<void(bool success)> ResultCallback;
24
25   typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>&
26                                   usage_info)> GetUsageInfoCallback;
27
28   // Equivalent to calling navigator.serviceWorker.register(script_url, {scope:
29   // pattern}) from a renderer, except that |pattern| is an absolute URL instead
30   // of relative to some current origin.  |callback| is passed true when the JS
31   // promise is fulfilled or false when the JS promise is rejected.
32   //
33   // The registration can fail if:
34   //  * |script_url| is on a different origin from |pattern|
35   //  * Fetching |script_url| fails.
36   //  * |script_url| fails to parse or its top-level execution fails.
37   //    TODO: The error message for this needs to be available to developers.
38   //  * Something unexpected goes wrong, like a renderer crash or a full disk.
39   virtual void RegisterServiceWorker(const Scope& pattern,
40                                      const GURL& script_url,
41                                      const ResultCallback& callback) = 0;
42
43   // Equivalent to calling navigator.serviceWorker.unregister(pattern) from a
44   // renderer, except that |pattern| is an absolute URL instead of relative to
45   // some current origin.  |callback| is passed true when the JS promise is
46   // fulfilled or false when the JS promise is rejected.
47   //
48   // Unregistration can fail if:
49   //  * No Service Worker was registered for |pattern|.
50   //  * Something unexpected goes wrong, like a renderer crash.
51   virtual void UnregisterServiceWorker(const Scope& pattern,
52                                        const ResultCallback& callback) = 0;
53
54   // TODO(jyasskin): Provide a way to SendMessage to a Scope.
55
56   // Synchronously releases all of the RenderProcessHosts that have Service
57   // Workers running inside them, and prevents any new Service Worker instances
58   // from starting up.
59   virtual void Terminate() = 0;
60
61   // Methods used in response to browsing data and quota manager requests.
62   virtual void GetAllOriginsInfo(const GetUsageInfoCallback& callback) = 0;
63   virtual void DeleteForOrigin(const GURL& origin_url) = 0;
64
65  protected:
66   ServiceWorkerContext() {}
67   virtual ~ServiceWorkerContext() {}
68 };
69
70 }  // namespace content
71
72 #endif  // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_