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 <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
13 #include "content/public/browser/service_worker_usage_info.h" | 13 #include "content/public/browser/service_worker_usage_info.h" |
14 #include "net/base/completion_callback.h" | |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
17 namespace net { | |
18 class URLRequest; | |
19 } | |
20 | |
16 namespace content { | 21 namespace content { |
17 | 22 |
18 // Represents the per-StoragePartition ServiceWorker data. | 23 // Represents the per-StoragePartition ServiceWorker data. |
19 class ServiceWorkerContext { | 24 class ServiceWorkerContext { |
20 public: | 25 public: |
21 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/ index.html#url-scope: | 26 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/ index.html#url-scope: |
22 // roughly, must be of the form "<origin>/<path>/*". | 27 // roughly, must be of the form "<origin>/<path>/*". |
23 typedef GURL Scope; | 28 typedef GURL Scope; |
24 | 29 |
25 typedef base::Callback<void(bool success)> ResultCallback; | 30 typedef base::Callback<void(bool success)> ResultCallback; |
26 | 31 |
27 typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>& | 32 typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>& |
28 usage_info)> GetUsageInfoCallback; | 33 usage_info)> GetUsageInfoCallback; |
29 | 34 |
30 // Registers the header name which should not be passed to the ServiceWorker. | 35 // Registers the header name which should not be passed to the ServiceWorker. |
31 // Must be called from the IO thread. | 36 // Must be called from the IO thread. |
32 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent( | 37 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent( |
33 const std::set<std::string>& header_names); | 38 const std::set<std::string>& header_names); |
34 | 39 |
35 // Returns true if the header name should not be passed to the ServiceWorker. | 40 // Returns true if the header name should not be passed to the ServiceWorker. |
36 // Must be called from the IO thread. | 41 // Must be called from the IO thread. |
37 static bool IsExcludedHeaderNameForFetchEvent(const std::string& header_name); | 42 static bool IsExcludedHeaderNameForFetchEvent(const std::string& header_name); |
38 | 43 |
44 // Retrieves the ServiceWorkerContext, if any, associated with |request|. | |
45 CONTENT_EXPORT static ServiceWorkerContext* GetServiceWorkerContext( | |
46 net::URLRequest* request); | |
47 | |
39 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: | 48 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: |
40 // pattern}) from a renderer, except that |pattern| is an absolute URL instead | 49 // pattern}) from a renderer, except that |pattern| is an absolute URL instead |
41 // of relative to some current origin. |callback| is passed true when the JS | 50 // of relative to some current origin. |callback| is passed true when the JS |
42 // promise is fulfilled or false when the JS promise is rejected. | 51 // promise is fulfilled or false when the JS promise is rejected. |
43 // | 52 // |
44 // The registration can fail if: | 53 // The registration can fail if: |
45 // * |script_url| is on a different origin from |pattern| | 54 // * |script_url| is on a different origin from |pattern| |
46 // * Fetching |script_url| fails. | 55 // * Fetching |script_url| fails. |
47 // * |script_url| fails to parse or its top-level execution fails. | 56 // * |script_url| fails to parse or its top-level execution fails. |
48 // TODO: The error message for this needs to be available to developers. | 57 // TODO: The error message for this needs to be available to developers. |
49 // * Something unexpected goes wrong, like a renderer crash or a full disk. | 58 // * Something unexpected goes wrong, like a renderer crash or a full disk. |
50 virtual void RegisterServiceWorker(const Scope& pattern, | 59 virtual void RegisterServiceWorker(const Scope& pattern, |
51 const GURL& script_url, | 60 const GURL& script_url, |
52 const ResultCallback& callback) = 0; | 61 const ResultCallback& callback) = 0; |
53 | 62 |
54 // Equivalent to calling navigator.serviceWorker.unregister(pattern) from a | 63 // Equivalent to calling navigator.serviceWorker.unregister(pattern) from a |
55 // renderer, except that |pattern| is an absolute URL instead of relative to | 64 // renderer, except that |pattern| is an absolute URL instead of relative to |
56 // some current origin. |callback| is passed true when the JS promise is | 65 // some current origin. |callback| is passed true when the JS promise is |
57 // fulfilled or false when the JS promise is rejected. | 66 // fulfilled or false when the JS promise is rejected. |
58 // | 67 // |
59 // Unregistration can fail if: | 68 // Unregistration can fail if: |
60 // * No Service Worker was registered for |pattern|. | 69 // * No Service Worker was registered for |pattern|. |
61 // * Something unexpected goes wrong, like a renderer crash. | 70 // * Something unexpected goes wrong, like a renderer crash. |
62 virtual void UnregisterServiceWorker(const Scope& pattern, | 71 virtual void UnregisterServiceWorker(const Scope& pattern, |
63 const ResultCallback& callback) = 0; | 72 const ResultCallback& callback) = 0; |
64 | 73 |
65 // TODO(jyasskin): Provide a way to SendMessage to a Scope. | 74 // TODO(jyasskin): Provide a way to SendMessage to a Scope. |
66 | 75 |
76 // Determines if a request for 'url' can be satisfied while offline. | |
falken
2014/12/16 08:16:50
nit: use |url| style instead of 'url'
| |
77 // This method always completes asynchronously. | |
78 virtual void CanHandleMainResourceOffline(const GURL& url, | |
79 const GURL& first_party, | |
80 const net::CompletionCallback& | |
81 callback) = 0; | |
82 | |
67 // Methods used in response to browsing data and quota manager requests. | 83 // Methods used in response to browsing data and quota manager requests. |
68 virtual void GetAllOriginsInfo(const GetUsageInfoCallback& callback) = 0; | 84 virtual void GetAllOriginsInfo(const GetUsageInfoCallback& callback) = 0; |
69 virtual void DeleteForOrigin(const GURL& origin_url) = 0; | 85 virtual void DeleteForOrigin(const GURL& origin_url) = 0; |
70 | 86 |
71 protected: | 87 protected: |
72 ServiceWorkerContext() {} | 88 ServiceWorkerContext() {} |
73 virtual ~ServiceWorkerContext() {} | 89 virtual ~ServiceWorkerContext() {} |
74 }; | 90 }; |
75 | 91 |
76 } // namespace content | 92 } // namespace content |
77 | 93 |
78 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ | 94 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
OLD | NEW |