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.
5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_
6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_
10 #include "base/basictypes.h"
11 #include "base/id_map.h"
12 #include "base/strings/string16.h"
13 #include "content/child/webmessageportchannel_impl.h"
14 #include "content/common/service_worker/service_worker_types.h"
15 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsInfo.h"
16 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h"
19 class WebServiceWorkerContextProxy;
28 class EmbeddedWorkerContextClient;
30 // TODO(kinuko): This should implement WebServiceWorkerContextClient
31 // rather than having EmbeddedWorkerContextClient implement it.
32 // See the header comment in embedded_worker_context_client.h for the
33 // potential EW/SW layering concerns.
34 class ServiceWorkerScriptContext {
36 ServiceWorkerScriptContext(
37 EmbeddedWorkerContextClient* embedded_context,
38 blink::WebServiceWorkerContextProxy* proxy);
39 ~ServiceWorkerScriptContext();
41 void OnMessageReceived(const IPC::Message& message);
43 void DidHandleActivateEvent(int request_id,
44 blink::WebServiceWorkerEventResult);
45 void DidHandleInstallEvent(int request_id,
46 blink::WebServiceWorkerEventResult result);
47 void DidHandleFetchEvent(int request_id,
48 ServiceWorkerFetchEventResult result,
49 const ServiceWorkerResponse& response);
50 void DidHandleSyncEvent(int request_id);
51 void GetClientDocuments(
52 blink::WebServiceWorkerClientsCallbacks* callbacks);
53 void PostMessageToDocument(int client_id,
54 const base::string16& message,
55 const std::vector<int>& message_port_ids);
58 typedef IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer>
61 // Send a message to the browser.
62 void Send(IPC::Message* message);
64 void OnActivateEvent(int request_id);
65 void OnInstallEvent(int request_id, int active_version_id);
66 void OnFetchEvent(int request_id, const ServiceWorkerFetchRequest& request);
67 void OnSyncEvent(int request_id);
68 void OnPostMessage(const base::string16& message,
69 const std::vector<int>& sent_message_port_ids,
70 const std::vector<int>& new_routing_ids);
71 void OnDidGetClientDocuments(
72 int request_id, const std::vector<int>& client_ids);
74 // Get routing_id for sending message to the ServiceWorkerVersion
75 // in the browser process.
76 int GetRoutingID() const;
78 // Not owned; embedded_context_ owns this.
79 EmbeddedWorkerContextClient* embedded_context_;
81 // Not owned; this object is destroyed when proxy_ becomes invalid.
82 blink::WebServiceWorkerContextProxy* proxy_;
84 // Used for incoming messages from the browser for which an outgoing response
85 // back to the browser is expected, the id must be sent back with the
87 int current_request_id_;
89 // Pending callbacks for GetClientDocuments().
90 ClientsCallbacksMap pending_clients_callbacks_;
92 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptContext);
95 } // namespace content
97 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_