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

Side by Side Diff: webkit/api/src/PlatformMessagePortChannel.cpp

Issue 173193: Updating Worker.postMessage(), DOMWindow.postMessage(), and... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « webkit/api/public/WebWorkerClient.h ('k') | webkit/glue/webworker_impl.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 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 MutexLocker lock(m_mutex); 172 MutexLocker lock(m_mutex);
173 m_localPort = 0; 173 m_localPort = 0;
174 } 174 }
175 175
176 void PlatformMessagePortChannel::postMessageToRemote(PassOwnPtr<MessagePortChannel::EventData> message) 176 void PlatformMessagePortChannel::postMessageToRemote(PassOwnPtr<MessagePortChannel::EventData> message)
177 { 177 {
178 if (!m_localPort || !m_webChannel) 178 if (!m_localPort || !m_webChannel)
179 return; 179 return;
180 180
181 WebString messageString = message->message(); 181 WebString messageString = message->message();
182 OwnPtr<WebCore::MessagePortChannel> channel = message->channel(); 182 OwnPtr<WebCore::MessagePortChannelArray> channels = message->channels();
183 WebMessagePortChannel* webChannel = NULL; 183 WebMessagePortChannelArray* webChannels = NULL;
184 if (channel.get()) { 184 if (channels.get() && channels->size()) {
185 WebCore::PlatformMessagePortChannel* platformChannel = channel->channel(); 185 webChannels = new WebMessagePortChannelArray(channels->size());
186 webChannel = platformChannel->webChannelRelease(); 186 for (size_t i = 0; i < channels->size(); ++i) {
187 webChannel->setClient(0); 187 WebCore::PlatformMessagePortChannel* platformChannel = (*channels)[i]->channel();
188 (*webChannels)[i] = platformChannel->webChannelRelease();
189 (*webChannels)[i]->setClient(0);
190 }
188 } 191 }
189 m_webChannel->postMessage(messageString, webChannel); 192 m_webChannel->postMessage(messageString, webChannels);
190 } 193 }
191 194
192 bool PlatformMessagePortChannel::tryGetMessageFromRemote(OwnPtr<MessagePortChannel::EventData>& result) 195 bool PlatformMessagePortChannel::tryGetMessageFromRemote(OwnPtr<MessagePortChannel::EventData>& result)
193 { 196 {
194 if (!m_webChannel) 197 if (!m_webChannel)
195 return false; 198 return false;
196 199
197 WebString message; 200 WebString message;
198 WebMessagePortChannel* webChannel = NULL; 201 WebMessagePortChannelArray webChannels;
199 bool rv = m_webChannel->tryGetMessage(&message, &webChannel); 202 bool rv = m_webChannel->tryGetMessage(&message, webChannels);
200 if (rv) { 203 if (rv) {
201 OwnPtr<MessagePortChannel> channel; 204 OwnPtr<MessagePortChannelArray> channels;
202 if (webChannel) { 205 if (webChannels.size()) {
203 RefPtr<PlatformMessagePortChannel> platformChannel = create(webChannel); 206 channels = new MessagePortChannelArray(webChannels.size());
204 webChannel->setClient(platformChannel.get()); 207 for (size_t i = 0; i < webChannels.size(); ++i) {
205 channel = MessagePortChannel::create(platformChannel); 208 RefPtr<PlatformMessagePortChannel> platformChannel = create(webChannels[i]);
209 webChannels[i]->setClient(platformChannel.get());
210 (*channels)[i] = MessagePortChannel::create(platformChannel);
211 }
206 } 212 }
207 result = MessagePortChannel::EventData::create(message, channel.release()); 213 result = MessagePortChannel::EventData::create(message, channels.release());
208 } 214 }
209 215
210 return rv; 216 return rv;
211 } 217 }
212 218
213 void PlatformMessagePortChannel::close() 219 void PlatformMessagePortChannel::close()
214 { 220 {
215 MutexLocker lock(m_mutex); 221 MutexLocker lock(m_mutex);
216 // Disentangle ourselves from the other end. We still maintain a reference to m_webChannel, 222 // Disentangle ourselves from the other end. We still maintain a reference to m_webChannel,
217 // since previously-existing messages should still be delivered. 223 // since previously-existing messages should still be delivered.
(...skipping 23 matching lines...) Expand all
241 } 247 }
242 248
243 WebMessagePortChannel* PlatformMessagePortChannel::webChannelRelease() 249 WebMessagePortChannel* PlatformMessagePortChannel::webChannelRelease()
244 { 250 {
245 WebMessagePortChannel* rv = m_webChannel; 251 WebMessagePortChannel* rv = m_webChannel;
246 m_webChannel = 0; 252 m_webChannel = 0;
247 return rv; 253 return rv;
248 } 254 }
249 255
250 } // namespace WebCore 256 } // namespace WebCore
OLDNEW
« no previous file with comments | « webkit/api/public/WebWorkerClient.h ('k') | webkit/glue/webworker_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698