コード例 #1
0
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());
}
コード例 #2
0
ファイル: MessagePort.cpp プロジェクト: ollie314/chromium
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;
}
コード例 #3
0
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()));
}
コード例 #4
0
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;
}