Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: content/browser/message_port_message_filter.cc

Issue 2422793002: HTML MessagePort as mojo::MessagePipeHandle (Closed)
Patch Set: Add missing ScopedAsyncTaskScheduler instance for the new unit tests; required by a recent change t… Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/message_port_message_filter.h ('k') | content/browser/message_port_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 <stddef.h>
8
9 #include "content/browser/message_port_service.h"
10 #include "content/common/frame_messages.h"
11 #include "content/common/message_port_messages.h"
12
13 namespace content {
14
15 MessagePortMessageFilter::MessagePortMessageFilter(
16 const NextRoutingIDCallback& callback)
17 : BrowserMessageFilter(MessagePortMsgStart),
18 next_routing_id_(callback) {
19 }
20
21 MessagePortMessageFilter::~MessagePortMessageFilter() {
22 }
23
24 void MessagePortMessageFilter::OnChannelClosing() {
25 MessagePortService::GetInstance()->OnMessagePortDelegateClosing(this);
26 }
27
28 bool MessagePortMessageFilter::OnMessageReceived(const IPC::Message& message) {
29 bool handled = true;
30 IPC_BEGIN_MESSAGE_MAP(MessagePortMessageFilter, message)
31 IPC_MESSAGE_HANDLER(MessagePortHostMsg_CreateMessagePort,
32 OnCreateMessagePort)
33 IPC_MESSAGE_FORWARD(MessagePortHostMsg_DestroyMessagePort,
34 MessagePortService::GetInstance(),
35 MessagePortService::Destroy)
36 IPC_MESSAGE_FORWARD(MessagePortHostMsg_Entangle,
37 MessagePortService::GetInstance(),
38 MessagePortService::Entangle)
39 IPC_MESSAGE_FORWARD(MessagePortHostMsg_PostMessage,
40 MessagePortService::GetInstance(),
41 MessagePortService::PostMessage)
42 IPC_MESSAGE_FORWARD(MessagePortHostMsg_QueueMessages,
43 MessagePortService::GetInstance(),
44 MessagePortService::QueueMessages)
45 IPC_MESSAGE_FORWARD(MessagePortHostMsg_SendQueuedMessages,
46 MessagePortService::GetInstance(),
47 MessagePortService::SendQueuedMessages)
48 IPC_MESSAGE_FORWARD(MessagePortHostMsg_ReleaseMessages,
49 MessagePortService::GetInstance(),
50 MessagePortService::ReleaseMessages)
51 IPC_MESSAGE_UNHANDLED(handled = false)
52 IPC_END_MESSAGE_MAP()
53
54 return handled;
55 }
56
57 void MessagePortMessageFilter::OnDestruct() const {
58 BrowserThread::DeleteOnIOThread::Destruct(this);
59 }
60
61 int MessagePortMessageFilter::GetNextRoutingID() {
62 return next_routing_id_.Run();
63 }
64
65 void MessagePortMessageFilter::SendMessage(
66 int route_id,
67 const base::string16& message,
68 const std::vector<int>& sent_message_ports) {
69 // Generate new routing ids for all ports that were sent around. This avoids
70 // waiting for the created ports to send a sync message back to get routing
71 // ids.
72 std::vector<int> new_routing_ids;
73 UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids);
74 Send(new MessagePortMsg_Message(route_id, message, sent_message_ports,
75 new_routing_ids));
76 }
77
78 void MessagePortMessageFilter::SendMessagesAreQueued(int route_id) {
79 Send(new MessagePortMsg_MessagesQueued(route_id));
80 }
81
82 void MessagePortMessageFilter::UpdateMessagePortsWithNewRoutes(
83 const std::vector<int>& message_ports,
84 std::vector<int>* new_routing_ids) {
85 DCHECK(new_routing_ids);
86 new_routing_ids->clear();
87 new_routing_ids->resize(message_ports.size());
88
89 for (size_t i = 0; i < message_ports.size(); ++i) {
90 (*new_routing_ids)[i] = GetNextRoutingID();
91 MessagePortService::GetInstance()->UpdateMessagePort(
92 message_ports[i],
93 this,
94 (*new_routing_ids)[i]);
95 }
96 }
97
98 void MessagePortMessageFilter::RouteMessageEventWithMessagePorts(
99 int routing_id,
100 const FrameMsg_PostMessage_Params& params) {
101 FrameMsg_PostMessage_Params new_params(params);
102 UpdateMessagePortsWithNewRoutes(params.message_ports,
103 &new_params.new_routing_ids);
104 Send(new FrameMsg_PostMessageEvent(routing_id, new_params));
105 }
106
107 void MessagePortMessageFilter::OnCreateMessagePort(int *route_id,
108 int* message_port_id) {
109 *route_id = next_routing_id_.Run();
110 MessagePortService::GetInstance()->Create(*route_id, this, message_port_id);
111 }
112
113 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/message_port_message_filter.h ('k') | content/browser/message_port_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698