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_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_ | 5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_ |
6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_ | 6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/id_map.h" | 12 #include "base/id_map.h" |
| 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
14 #include "content/child/webmessageportchannel_impl.h" | 15 #include "content/child/webmessageportchannel_impl.h" |
15 #include "content/common/service_worker/service_worker_types.h" | 16 #include "content/common/service_worker/service_worker_types.h" |
| 17 #include "content/renderer/service_worker/service_worker_cache_storage_dispatche
r.h" |
16 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 18 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 19 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheStorage.h" |
17 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsInfo.h" | 20 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsInfo.h" |
18 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" | 21 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" |
19 | 22 |
20 namespace blink { | 23 namespace blink { |
21 class WebServiceWorkerContextProxy; | 24 class WebServiceWorkerContextProxy; |
| 25 class WebServiceWorkerCacheStorage; |
22 } | 26 } |
23 | 27 |
24 namespace IPC { | 28 namespace IPC { |
25 class Message; | 29 class Message; |
26 } | 30 } |
27 | 31 |
28 namespace content { | 32 namespace content { |
29 | 33 |
30 class EmbeddedWorkerContextClient; | 34 class EmbeddedWorkerContextClient; |
| 35 class ServiceWorkerCacheStorageDispatcher; |
31 | 36 |
32 // TODO(kinuko): This should implement WebServiceWorkerContextClient | 37 // TODO(kinuko): This should implement WebServiceWorkerContextClient |
33 // rather than having EmbeddedWorkerContextClient implement it. | 38 // rather than having EmbeddedWorkerContextClient implement it. |
34 // See the header comment in embedded_worker_context_client.h for the | 39 // See the header comment in embedded_worker_context_client.h for the |
35 // potential EW/SW layering concerns. | 40 // potential EW/SW layering concerns. |
36 class ServiceWorkerScriptContext { | 41 class ServiceWorkerScriptContext { |
37 public: | 42 public: |
38 ServiceWorkerScriptContext( | 43 ServiceWorkerScriptContext( |
39 EmbeddedWorkerContextClient* embedded_context, | 44 EmbeddedWorkerContextClient* embedded_context, |
40 blink::WebServiceWorkerContextProxy* proxy); | 45 blink::WebServiceWorkerContextProxy* proxy); |
41 ~ServiceWorkerScriptContext(); | 46 ~ServiceWorkerScriptContext(); |
42 | 47 |
43 void OnMessageReceived(const IPC::Message& message); | 48 void OnMessageReceived(const IPC::Message& message); |
44 | 49 |
45 void DidHandleActivateEvent(int request_id, | 50 void DidHandleActivateEvent(int request_id, |
46 blink::WebServiceWorkerEventResult); | 51 blink::WebServiceWorkerEventResult); |
47 void DidHandleInstallEvent(int request_id, | 52 void DidHandleInstallEvent(int request_id, |
48 blink::WebServiceWorkerEventResult result); | 53 blink::WebServiceWorkerEventResult result); |
49 void DidHandleFetchEvent(int request_id, | 54 void DidHandleFetchEvent(int request_id, |
50 ServiceWorkerFetchEventResult result, | 55 ServiceWorkerFetchEventResult result, |
51 const ServiceWorkerResponse& response); | 56 const ServiceWorkerResponse& response); |
52 void DidHandleSyncEvent(int request_id); | 57 void DidHandleSyncEvent(int request_id); |
53 void GetClientDocuments( | 58 void GetClientDocuments( |
54 blink::WebServiceWorkerClientsCallbacks* callbacks); | 59 blink::WebServiceWorkerClientsCallbacks* callbacks); |
55 void PostMessageToDocument( | 60 void PostMessageToDocument( |
56 int client_id, | 61 int client_id, |
57 const base::string16& message, | 62 const base::string16& message, |
58 scoped_ptr<blink::WebMessagePortChannelArray> channels); | 63 scoped_ptr<blink::WebMessagePortChannelArray> channels); |
59 | 64 |
| 65 // Send a message to the browser. Takes ownership of message. |
| 66 void Send(IPC::Message* message); |
| 67 |
| 68 // Get routing_id for sending message to the ServiceWorkerVersion |
| 69 // in the browser process. |
| 70 int GetRoutingID() const; |
| 71 |
| 72 blink::WebServiceWorkerCacheStorage* cache_storage() { |
| 73 return cache_storage_dispatcher_.get(); |
| 74 } |
| 75 |
60 private: | 76 private: |
61 typedef IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer> | 77 typedef IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer> |
62 ClientsCallbacksMap; | 78 ClientsCallbacksMap; |
63 | 79 |
64 // Send a message to the browser. | |
65 void Send(IPC::Message* message); | |
66 | 80 |
67 void OnActivateEvent(int request_id); | 81 void OnActivateEvent(int request_id); |
68 void OnInstallEvent(int request_id, int active_version_id); | 82 void OnInstallEvent(int request_id, int active_version_id); |
69 void OnFetchEvent(int request_id, const ServiceWorkerFetchRequest& request); | 83 void OnFetchEvent(int request_id, const ServiceWorkerFetchRequest& request); |
70 void OnSyncEvent(int request_id); | 84 void OnSyncEvent(int request_id); |
71 void OnPushEvent(int request_id, const std::string& data); | 85 void OnPushEvent(int request_id, const std::string& data); |
72 void OnPostMessage(const base::string16& message, | 86 void OnPostMessage(const base::string16& message, |
73 const std::vector<int>& sent_message_port_ids, | 87 const std::vector<int>& sent_message_port_ids, |
74 const std::vector<int>& new_routing_ids); | 88 const std::vector<int>& new_routing_ids); |
75 void OnDidGetClientDocuments( | 89 void OnDidGetClientDocuments( |
76 int request_id, const std::vector<int>& client_ids); | 90 int request_id, const std::vector<int>& client_ids); |
77 | 91 |
78 // Get routing_id for sending message to the ServiceWorkerVersion | 92 |
79 // in the browser process. | 93 scoped_ptr<ServiceWorkerCacheStorageDispatcher> cache_storage_dispatcher_; |
80 int GetRoutingID() const; | |
81 | 94 |
82 // Not owned; embedded_context_ owns this. | 95 // Not owned; embedded_context_ owns this. |
83 EmbeddedWorkerContextClient* embedded_context_; | 96 EmbeddedWorkerContextClient* embedded_context_; |
84 | 97 |
85 // Not owned; this object is destroyed when proxy_ becomes invalid. | 98 // Not owned; this object is destroyed when proxy_ becomes invalid. |
86 blink::WebServiceWorkerContextProxy* proxy_; | 99 blink::WebServiceWorkerContextProxy* proxy_; |
87 | 100 |
88 // Used for incoming messages from the browser for which an outgoing response | 101 // Used for incoming messages from the browser for which an outgoing response |
89 // back to the browser is expected, the id must be sent back with the | 102 // back to the browser is expected, the id must be sent back with the |
90 // response. | 103 // response. |
91 int current_request_id_; | 104 int current_request_id_; |
92 | 105 |
93 // Pending callbacks for GetClientDocuments(). | 106 // Pending callbacks for GetClientDocuments(). |
94 ClientsCallbacksMap pending_clients_callbacks_; | 107 ClientsCallbacksMap pending_clients_callbacks_; |
95 | 108 |
96 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptContext); | 109 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptContext); |
97 }; | 110 }; |
98 | 111 |
99 } // namespace content | 112 } // namespace content |
100 | 113 |
101 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_ | 114 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_ |
OLD | NEW |