OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "content/browser/navigator_connect/service_port_service_impl.h" | 5 #include "content/browser/navigator_connect/service_port_service_impl.h" |
6 | 6 |
7 #include "content/browser/message_port_message_filter.h" | 7 #include "content/browser/message_port_message_filter.h" |
8 #include "content/browser/message_port_service.h" | 8 #include "content/browser/message_port_service.h" |
9 #include "content/browser/navigator_connect/navigator_connect_context_impl.h" | 9 #include "content/browser/navigator_connect/navigator_connect_context_impl.h" |
10 #include "content/common/service_port_type_converters.h" | 10 #include "content/common/service_port_type_converters.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // without holding messages mojo IPC might overtake regular IPC resulting in a | 45 // without holding messages mojo IPC might overtake regular IPC resulting in a |
46 // non-functional port. When WebMessagePortChannelImpl instances are | 46 // non-functional port. When WebMessagePortChannelImpl instances are |
47 // constructed in the renderer, they will send | 47 // constructed in the renderer, they will send |
48 // MessagePortHostMsg_ReleaseMessages to release messages. | 48 // MessagePortHostMsg_ReleaseMessages to release messages. |
49 for (const auto& port : sent_message_ports) | 49 for (const auto& port : sent_message_ports) |
50 MessagePortService::GetInstance()->HoldMessages(port.id); | 50 MessagePortService::GetInstance()->HoldMessages(port.id); |
51 | 51 |
52 std::vector<int> new_routing_ids; | 52 std::vector<int> new_routing_ids; |
53 message_port_message_filter_->UpdateMessagePortsWithNewRoutes( | 53 message_port_message_filter_->UpdateMessagePortsWithNewRoutes( |
54 sent_message_ports, &new_routing_ids); | 54 sent_message_ports, &new_routing_ids); |
55 client_->PostMessage( | 55 client_->PostMessageToPort( |
56 port_id, mojo::String::From(message.message_as_string), | 56 port_id, mojo::String::From(message.message_as_string), |
57 mojo::Array<MojoTransferredMessagePortPtr>::From(sent_message_ports), | 57 mojo::Array<MojoTransferredMessagePortPtr>::From(sent_message_ports), |
58 mojo::Array<int32_t>::From(new_routing_ids)); | 58 mojo::Array<int32_t>::From(new_routing_ids)); |
59 } | 59 } |
60 | 60 |
61 // static | 61 // static |
62 void ServicePortServiceImpl::CreateOnIOThread( | 62 void ServicePortServiceImpl::CreateOnIOThread( |
63 const scoped_refptr<NavigatorConnectContextImpl>& navigator_connect_context, | 63 const scoped_refptr<NavigatorConnectContextImpl>& navigator_connect_context, |
64 const scoped_refptr<MessagePortMessageFilter>& message_port_message_filter, | 64 const scoped_refptr<MessagePortMessageFilter>& message_port_message_filter, |
65 mojo::InterfaceRequest<ServicePortService> request) { | 65 mojo::InterfaceRequest<ServicePortService> request) { |
(...skipping 21 matching lines...) Expand all Loading... |
87 | 87 |
88 void ServicePortServiceImpl::Connect(const mojo::String& target_url, | 88 void ServicePortServiceImpl::Connect(const mojo::String& target_url, |
89 const mojo::String& origin, | 89 const mojo::String& origin, |
90 const ConnectCallback& callback) { | 90 const ConnectCallback& callback) { |
91 navigator_connect_context_->Connect( | 91 navigator_connect_context_->Connect( |
92 GURL(target_url), GURL(origin), this, | 92 GURL(target_url), GURL(origin), this, |
93 base::Bind(&ServicePortServiceImpl::OnConnectResult, | 93 base::Bind(&ServicePortServiceImpl::OnConnectResult, |
94 weak_ptr_factory_.GetWeakPtr(), callback)); | 94 weak_ptr_factory_.GetWeakPtr(), callback)); |
95 } | 95 } |
96 | 96 |
97 void ServicePortServiceImpl::PostMessage( | 97 void ServicePortServiceImpl::PostMessageToPort( |
98 int32_t port_id, | 98 int32_t port_id, |
99 const mojo::String& message, | 99 const mojo::String& message, |
100 mojo::Array<MojoTransferredMessagePortPtr> ports) { | 100 mojo::Array<MojoTransferredMessagePortPtr> ports) { |
101 // TODO(mek): Similar to http://crbug.com/490222 this code should make sure | 101 // TODO(mek): Similar to http://crbug.com/490222 this code should make sure |
102 // port_id belongs to the process this IPC was received from. | 102 // port_id belongs to the process this IPC was received from. |
103 std::vector<TransferredMessagePort> transferred_ports = | 103 std::vector<TransferredMessagePort> transferred_ports = |
104 ports.To<std::vector<TransferredMessagePort>>(); | 104 ports.To<std::vector<TransferredMessagePort>>(); |
105 | 105 |
106 MessagePortService* mps = MessagePortService::GetInstance(); | 106 MessagePortService* mps = MessagePortService::GetInstance(); |
107 // First, call QueueMessages for all transferred ports, since the ports | 107 // First, call QueueMessages for all transferred ports, since the ports |
(...skipping 13 matching lines...) Expand all Loading... |
121 | 121 |
122 void ServicePortServiceImpl::OnConnectResult(const ConnectCallback& callback, | 122 void ServicePortServiceImpl::OnConnectResult(const ConnectCallback& callback, |
123 int message_port_id, | 123 int message_port_id, |
124 bool success) { | 124 bool success) { |
125 callback.Run(success ? SERVICE_PORT_CONNECT_RESULT_ACCEPT | 125 callback.Run(success ? SERVICE_PORT_CONNECT_RESULT_ACCEPT |
126 : SERVICE_PORT_CONNECT_RESULT_REJECT, | 126 : SERVICE_PORT_CONNECT_RESULT_REJECT, |
127 message_port_id); | 127 message_port_id); |
128 } | 128 } |
129 | 129 |
130 } // namespace content | 130 } // namespace content |
OLD | NEW |