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 #include "content/renderer/service_worker/service_worker_script_context.h"
7 #include "base/logging.h"
8 #include "content/common/service_worker/service_worker_messages.h"
9 #include "content/renderer/service_worker/embedded_worker_context_client.h"
10 #include "ipc/ipc_message.h"
11 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h"
15 ServiceWorkerScriptContext::ServiceWorkerScriptContext(
16 EmbeddedWorkerContextClient
* embedded_context
,
17 blink::WebServiceWorkerContextProxy
* proxy
)
18 : embedded_context_(embedded_context
),
20 current_request_id_(kInvalidRequestId
) {
23 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {}
25 void ServiceWorkerScriptContext::OnMessageReceived(
27 const IPC::Message
& message
) {
28 DCHECK_EQ(kInvalidRequestId
, current_request_id_
);
29 current_request_id_
= request_id
;
31 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext
, message
)
32 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent
, OnInstallEvent
)
33 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent
, OnFetchEvent
)
34 IPC_MESSAGE_UNHANDLED(handled
= false)
37 current_request_id_
= kInvalidRequestId
;
40 void ServiceWorkerScriptContext::DidHandleInstallEvent(int request_id
) {
41 Send(request_id
, ServiceWorkerHostMsg_InstallEventFinished());
44 void ServiceWorkerScriptContext::Send(int request_id
,
45 const IPC::Message
& message
) {
46 embedded_context_
->SendMessageToBrowser(request_id
, message
);
49 void ServiceWorkerScriptContext::OnInstallEvent(
50 int active_version_embedded_worker_id
) {
51 // TODO(kinuko): Uncomment this when blink side becomes ready.
52 // proxy_->dispatchInstallEvent(current_request_id_);
54 // TODO(kinuko): this should be called asynchronously from blink side
55 // when blink-side plumbing is done.
56 DidHandleInstallEvent(current_request_id_
);
59 void ServiceWorkerScriptContext::OnFetchEvent(
60 const ServiceWorkerFetchRequest
& request
) {
64 } // namespace content