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

Side by Side Diff: content/child/webmessageportchannel_impl.cc

Issue 2755223002: Enable Blink to pass extra Mojo handles across MessagePorts
Patch Set: Finish plumbing Created 3 years, 9 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/child/webmessageportchannel_impl.h ('k') | content/common/message_port.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/child/webmessageportchannel_impl.h" 5 #include "content/child/webmessageportchannel_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "third_party/WebKit/public/platform/WebMessagePortChannelClient.h" 12 #include "third_party/WebKit/public/platform/WebMessagePortChannelClient.h"
13 #include "third_party/WebKit/public/platform/WebString.h" 13 #include "third_party/WebKit/public/platform/WebString.h"
14 14
15 using blink::WebMessagePortChannel; 15 using blink::WebMessagePortChannel;
16 using blink::WebMessagePortChannelArray; 16 using blink::WebMessagePortChannelArray;
17 using blink::WebMessagePortChannelClient; 17 using blink::WebMessagePortChannelClient;
18 using blink::WebString; 18 using blink::WebString;
19 using blink::WebVector;
19 20
20 namespace content { 21 namespace content {
21 22
22 WebMessagePortChannelImpl::~WebMessagePortChannelImpl() { 23 WebMessagePortChannelImpl::~WebMessagePortChannelImpl() {
23 setClient(nullptr); 24 setClient(nullptr);
24 } 25 }
25 26
26 WebMessagePortChannelImpl::WebMessagePortChannelImpl( 27 WebMessagePortChannelImpl::WebMessagePortChannelImpl(
27 MessagePort message_port) 28 MessagePort message_port)
28 : port_(message_port.ReleaseHandle()) { 29 : port_(message_port.ReleaseHandle()) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 port_.SetCallback( 88 port_.SetCallback(
88 base::Bind(&WebMessagePortChannelClient::messageAvailable, 89 base::Bind(&WebMessagePortChannelClient::messageAvailable,
89 base::Unretained(client))); 90 base::Unretained(client)));
90 } else { 91 } else {
91 port_.ClearCallback(); 92 port_.ClearCallback();
92 } 93 }
93 } 94 }
94 95
95 void WebMessagePortChannelImpl::postMessage( 96 void WebMessagePortChannelImpl::postMessage(
96 const WebString& encoded_message, 97 const WebString& encoded_message,
97 WebMessagePortChannelArray channels) { 98 WebMessagePortChannelArray channels,
99 WebVector<mojo::ScopedHandle> handles) {
98 std::vector<MessagePort> ports; 100 std::vector<MessagePort> ports;
99 if (!channels.isEmpty()) { 101 if (!channels.isEmpty()) {
100 ports.resize(channels.size()); 102 ports.resize(channels.size());
101 for (size_t i = 0; i < channels.size(); ++i) { 103 for (size_t i = 0; i < channels.size(); ++i) {
102 ports[i] = static_cast<WebMessagePortChannelImpl*>(channels[i].get())-> 104 ports[i] = static_cast<WebMessagePortChannelImpl*>(channels[i].get())->
103 ReleaseMessagePort(); 105 ReleaseMessagePort();
104 } 106 }
105 } 107 }
106 port_.PostMessage(encoded_message.utf16(), std::move(ports)); 108 std::vector<mojo::ScopedHandle> extra_handles;
109 for (size_t i = 0; i < handles.size(); ++i)
110 extra_handles.emplace_back(std::move(handles[i]));
111 port_.PostMessage(encoded_message.utf16(), std::move(ports),
112 std::move(extra_handles));
107 } 113 }
108 114
109 bool WebMessagePortChannelImpl::tryGetMessage( 115 bool WebMessagePortChannelImpl::tryGetMessage(
110 WebString* encoded_message, 116 WebString* encoded_message,
111 WebMessagePortChannelArray& channels) { 117 WebMessagePortChannelArray& channels,
118 WebVector<mojo::ScopedHandle>& handles) {
112 base::string16 buffer; 119 base::string16 buffer;
113 std::vector<MessagePort> ports; 120 std::vector<MessagePort> ports;
114 if (!port_.GetMessage(&buffer, &ports)) 121 std::vector<mojo::ScopedHandle> extra_handles;
122 if (!port_.GetMessage(&buffer, &ports, &extra_handles))
115 return false; 123 return false;
116 124
117 *encoded_message = WebString::fromUTF16(buffer); 125 *encoded_message = WebString::fromUTF16(buffer);
118 126
119 if (!ports.empty()) { 127 if (!ports.empty()) {
120 channels = WebMessagePortChannelArray(ports.size()); 128 channels = WebMessagePortChannelArray(ports.size());
121 for (size_t i = 0; i < ports.size(); ++i) 129 for (size_t i = 0; i < ports.size(); ++i)
122 channels[i] = base::MakeUnique<WebMessagePortChannelImpl>(ports[i]); 130 channels[i] = base::MakeUnique<WebMessagePortChannelImpl>(ports[i]);
123 } 131 }
132 if (!extra_handles.empty()) {
133 handles = WebVector<mojo::ScopedHandle>(extra_handles.size());
134 for (size_t i = 0; i < extra_handles.size(); ++i)
135 handles[i] = std::move(extra_handles[i]);
136 }
124 return true; 137 return true;
125 } 138 }
126 139
127 } // namespace content 140 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webmessageportchannel_impl.h ('k') | content/common/message_port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698