- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / message_port_message_filter.cc
1 // Copyright 2013 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 #include "content/browser/message_port_message_filter.h"
6
7 #include "content/browser/message_port_service.h"
8 #include "content/common/message_port_messages.h"
9
10 namespace content {
11
12 MessagePortMessageFilter::MessagePortMessageFilter(
13     const NextRoutingIDCallback& callback)
14     : next_routing_id_(callback) {
15 }
16
17 MessagePortMessageFilter::~MessagePortMessageFilter() {
18 }
19
20 void MessagePortMessageFilter::OnChannelClosing() {
21   MessagePortService::GetInstance()->OnMessagePortMessageFilterClosing(this);
22 }
23
24 bool MessagePortMessageFilter::OnMessageReceived(const IPC::Message& message,
25                                                  bool* message_was_ok) {
26   bool handled = true;
27   IPC_BEGIN_MESSAGE_MAP_EX(MessagePortMessageFilter, message, *message_was_ok)
28     IPC_MESSAGE_HANDLER(MessagePortHostMsg_CreateMessagePort,
29                         OnCreateMessagePort)
30     IPC_MESSAGE_FORWARD(MessagePortHostMsg_DestroyMessagePort,
31                         MessagePortService::GetInstance(),
32                         MessagePortService::Destroy)
33     IPC_MESSAGE_FORWARD(MessagePortHostMsg_Entangle,
34                         MessagePortService::GetInstance(),
35                         MessagePortService::Entangle)
36     IPC_MESSAGE_FORWARD(MessagePortHostMsg_PostMessage,
37                         MessagePortService::GetInstance(),
38                         MessagePortService::PostMessage)
39     IPC_MESSAGE_FORWARD(MessagePortHostMsg_QueueMessages,
40                         MessagePortService::GetInstance(),
41                         MessagePortService::QueueMessages)
42     IPC_MESSAGE_FORWARD(MessagePortHostMsg_SendQueuedMessages,
43                         MessagePortService::GetInstance(),
44                         MessagePortService::SendQueuedMessages)
45     IPC_MESSAGE_UNHANDLED(handled = false)
46   IPC_END_MESSAGE_MAP_EX()
47
48   return handled;
49 }
50
51 void MessagePortMessageFilter::OnDestruct() const {
52   BrowserThread::DeleteOnIOThread::Destruct(this);
53 }
54
55 int MessagePortMessageFilter::GetNextRoutingID() {
56   return next_routing_id_.Run();
57 }
58
59 void MessagePortMessageFilter::OnCreateMessagePort(int *route_id,
60                                                    int* message_port_id) {
61   *route_id = next_routing_id_.Run();
62   MessagePortService::GetInstance()->Create(*route_id, this, message_port_id);
63 }
64
65 }  // namespace content