void WebWorkerClientImpl::postMessageToWorkerObject(const WebString& message, const WebMessagePortChannelArray& channels) { OwnPtr<MessagePortChannelArray> channels2; if (channels.size()) { channels2 = new MessagePortChannelArray(channels.size()); for (size_t i = 0; i < channels.size(); ++i) { RefPtr<PlatformMessagePortChannel> platform_channel = PlatformMessagePortChannel::create(channels[i]); channels[i]->setClient(platform_channel.get()); (*channels2)[i] = MessagePortChannel::create(platform_channel); } } if (currentThread() != m_workerThreadId) { m_scriptExecutionContext->postTask(createCallbackTask(&postMessageToWorkerObjectTask, AllowCrossThreadAccess(this), String(message), channels2.release())); return; } postMessageToWorkerObjectTask(m_scriptExecutionContext.get(), this, message, channels2.release()); }
static bool tryGetMessageFrom( WebMessagePortChannel& webChannel, RefPtr<SerializedScriptValue>& message, std::unique_ptr<MessagePortChannelArray>& channels) { WebString messageString; WebMessagePortChannelArray webChannels; if (!webChannel.tryGetMessage(&messageString, webChannels)) return false; if (webChannels.size()) { channels = wrapUnique(new MessagePortChannelArray(webChannels.size())); for (size_t i = 0; i < webChannels.size(); ++i) (*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]); } message = SerializedScriptValue::create(messageString); return true; }
void WebWorkerImpl::postMessageToWorkerContext(const WebString& message, const WebMessagePortChannelArray& webChannels) { OwnPtr<MessagePortChannelArray> channels; if (webChannels.size()) { channels = new MessagePortChannelArray(webChannels.size()); for (size_t i = 0; i < webChannels.size(); ++i) { RefPtr<PlatformMessagePortChannel> platform_channel = PlatformMessagePortChannel::create(webChannels[i]); webChannels[i]->setClient(platform_channel.get()); (*channels)[i] = MessagePortChannel::create(platform_channel); } } workerThread()->runLoop().postTask( createCallbackTask(&postMessageToWorkerContextTask, this, String(message), channels.release())); }
bool PlatformMessagePortChannel::tryGetMessageFromRemote(OwnPtr<MessagePortChannel::EventData>& result) { if (!m_webChannel) return false; WebString message; WebMessagePortChannelArray webChannels; bool rv = m_webChannel->tryGetMessage(&message, webChannels); if (rv) { OwnPtr<MessagePortChannelArray> channels; if (webChannels.size()) { channels = new MessagePortChannelArray(webChannels.size()); for (size_t i = 0; i < webChannels.size(); ++i) { RefPtr<PlatformMessagePortChannel> platformChannel = create(webChannels[i]); webChannels[i]->setClient(platformChannel.get()); (*channels)[i] = MessagePortChannel::create(platformChannel); } } RefPtr<SerializedScriptValue> serializedMessage = SerializedScriptValue::createFromWire(message); result = MessagePortChannel::EventData::create(serializedMessage.release(), channels.release()); } return rv; }