diff options
Diffstat (limited to 'chromium/third_party/WebKit/Source/core/dom/default')
4 files changed, 0 insertions, 654 deletions
diff --git a/chromium/third_party/WebKit/Source/core/dom/default/PlatformMessagePortChannel.cpp b/chromium/third_party/WebKit/Source/core/dom/default/PlatformMessagePortChannel.cpp deleted file mode 100644 index 28375179859..00000000000 --- a/chromium/third_party/WebKit/Source/core/dom/default/PlatformMessagePortChannel.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. All rights reserved. - * Copyright (C) 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "core/dom/default/PlatformMessagePortChannel.h" - -#include "core/dom/MessagePort.h" -#include "core/dom/ScriptExecutionContext.h" - -namespace WebCore { - -PassOwnPtr<PlatformMessagePortChannel::EventData> PlatformMessagePortChannel::EventData::create(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray> channels) -{ - return adoptPtr(new EventData(message, channels)); -} - -PlatformMessagePortChannel::EventData::EventData(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray> channels) - : m_message(message) - , m_channels(channels) -{ -} - -void MessagePortChannel::createChannel(PassRefPtr<MessagePort> port1, PassRefPtr<MessagePort> port2) -{ - RefPtr<PlatformMessagePortChannel::MessagePortQueue> queue1 = PlatformMessagePortChannel::MessagePortQueue::create(); - RefPtr<PlatformMessagePortChannel::MessagePortQueue> queue2 = PlatformMessagePortChannel::MessagePortQueue::create(); - - OwnPtr<MessagePortChannel> channel1 = adoptPtr(new MessagePortChannel(PlatformMessagePortChannel::create(queue1, queue2))); - OwnPtr<MessagePortChannel> channel2 = adoptPtr(new MessagePortChannel(PlatformMessagePortChannel::create(queue2, queue1))); - - channel1->m_channel->m_entangledChannel = channel2->m_channel; - channel2->m_channel->m_entangledChannel = channel1->m_channel; - - port1->entangle(channel2.release()); - port2->entangle(channel1.release()); -} - -MessagePortChannel::MessagePortChannel(PassRefPtr<PlatformMessagePortChannel> channel) - : m_channel(channel) -{ -} - -MessagePortChannel::~MessagePortChannel() -{ - close(); -} - -bool MessagePortChannel::entangleIfOpen(MessagePort* port) -{ - // We can't call member functions on our remote pair while holding our mutex or we'll deadlock, - // but we need to guard against the remote port getting closed/freed, so create a standalone reference. - RefPtr<PlatformMessagePortChannel> remote = m_channel->entangledChannel(); - if (!remote) - return false; - remote->setRemotePort(port); - return true; -} - -void MessagePortChannel::disentangle() -{ - RefPtr<PlatformMessagePortChannel> remote = m_channel->entangledChannel(); - if (remote) - remote->setRemotePort(0); -} - -void MessagePortChannel::postMessageToRemote(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray> channels) -{ - MutexLocker lock(m_channel->m_mutex); - if (!m_channel->m_outgoingQueue) - return; - bool wasEmpty = m_channel->m_outgoingQueue->appendAndCheckEmpty(PlatformMessagePortChannel::EventData::create(message, channels)); - if (wasEmpty && m_channel->m_remotePort) - m_channel->m_remotePort->messageAvailable(); -} - -bool MessagePortChannel::tryGetMessageFromRemote(RefPtr<SerializedScriptValue>& message, OwnPtr<MessagePortChannelArray>& channels) -{ - MutexLocker lock(m_channel->m_mutex); - OwnPtr<PlatformMessagePortChannel::EventData> result = m_channel->m_incomingQueue->tryGetMessage(); - if (!result) - return false; - - message = result->message(); - channels = result->channels(); - - return true; -} - -void MessagePortChannel::close() -{ - RefPtr<PlatformMessagePortChannel> remote = m_channel->entangledChannel(); - if (!remote) - return; - m_channel->closeInternal(); - remote->closeInternal(); -} - -bool MessagePortChannel::isConnectedTo(MessagePort* port) -{ - // FIXME: What guarantees that the result remains the same after we release the lock? - MutexLocker lock(m_channel->m_mutex); - return m_channel->m_remotePort == port; -} - -bool MessagePortChannel::hasPendingActivity() -{ - // FIXME: What guarantees that the result remains the same after we release the lock? - MutexLocker lock(m_channel->m_mutex); - return !m_channel->m_incomingQueue->isEmpty(); -} - -MessagePort* MessagePortChannel::locallyEntangledPort(const ScriptExecutionContext* context) -{ - MutexLocker lock(m_channel->m_mutex); - // See if both contexts are run by the same thread (are the same context, or are both documents). - if (m_channel->m_remotePort) { - // The remote port's ScriptExecutionContext is guaranteed not to change here - MessagePort::contextDestroyed() - // will close the port before the context goes away, and close() will block because we are holding the mutex. - ScriptExecutionContext* remoteContext = m_channel->m_remotePort->scriptExecutionContext(); - if (remoteContext == context || (remoteContext && remoteContext->isDocument() && context->isDocument())) - return m_channel->m_remotePort; - } - return 0; -} - -PassRefPtr<PlatformMessagePortChannel> PlatformMessagePortChannel::create(PassRefPtr<MessagePortQueue> incoming, PassRefPtr<MessagePortQueue> outgoing) -{ - return adoptRef(new PlatformMessagePortChannel(incoming, outgoing)); -} - -PlatformMessagePortChannel::PlatformMessagePortChannel(PassRefPtr<MessagePortQueue> incoming, PassRefPtr<MessagePortQueue> outgoing) - : m_incomingQueue(incoming) - , m_outgoingQueue(outgoing) - , m_remotePort(0) -{ -} - -PlatformMessagePortChannel::~PlatformMessagePortChannel() -{ -} - -void PlatformMessagePortChannel::setRemotePort(MessagePort* port) -{ - MutexLocker lock(m_mutex); - // Should never set port if it is already set. - ASSERT(!port || !m_remotePort); - m_remotePort = port; -} - -PassRefPtr<PlatformMessagePortChannel> PlatformMessagePortChannel::entangledChannel() -{ - // FIXME: What guarantees that the result remains the same after we release the lock? - // This lock only guarantees that the returned pointer will not be pointing to released memory, - // but not that it will still be pointing to this object's entangled port channel. - MutexLocker lock(m_mutex); - return m_entangledChannel; -} - -void PlatformMessagePortChannel::closeInternal() -{ - MutexLocker lock(m_mutex); - // Disentangle ourselves from the other end. We still maintain a reference to our incoming queue, since previously-existing messages should still be delivered. - m_remotePort = 0; - m_entangledChannel = 0; - m_outgoingQueue = 0; -} - -} // namespace WebCore diff --git a/chromium/third_party/WebKit/Source/core/dom/default/PlatformMessagePortChannel.h b/chromium/third_party/WebKit/Source/core/dom/default/PlatformMessagePortChannel.h deleted file mode 100644 index f8dffd04d0d..00000000000 --- a/chromium/third_party/WebKit/Source/core/dom/default/PlatformMessagePortChannel.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef PlatformMessagePortChannel_h -#define PlatformMessagePortChannel_h - -#include "core/dom/MessagePortChannel.h" - -#include "wtf/MessageQueue.h" -#include "wtf/PassRefPtr.h" -#include "wtf/Threading.h" - -namespace WebCore { - - class MessagePort; - - // PlatformMessagePortChannel is a platform-dependent interface to the remote side of a message channel. - // This default implementation supports multiple threads running within a single process. Implementations for multi-process platforms should define these public APIs in their own platform-specific PlatformMessagePortChannel file. - // The goal of this implementation is to eliminate contention except when cloning or closing the port, so each side of the channel has its own separate mutex. - class PlatformMessagePortChannel : public ThreadSafeRefCounted<PlatformMessagePortChannel> { - public: - class EventData { - WTF_MAKE_NONCOPYABLE(EventData); WTF_MAKE_FAST_ALLOCATED; - public: - static PassOwnPtr<EventData> create(PassRefPtr<SerializedScriptValue>, PassOwnPtr<MessagePortChannelArray>); - - PassRefPtr<SerializedScriptValue> message() { return m_message; } - PassOwnPtr<MessagePortChannelArray> channels() { return m_channels.release(); } - - private: - EventData(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray>); - RefPtr<SerializedScriptValue> m_message; - OwnPtr<MessagePortChannelArray> m_channels; - }; - - // Wrapper for MessageQueue that allows us to do thread safe sharing by two proxies. - class MessagePortQueue : public ThreadSafeRefCounted<MessagePortQueue> { - public: - static PassRefPtr<MessagePortQueue> create() { return adoptRef(new MessagePortQueue()); } - - PassOwnPtr<PlatformMessagePortChannel::EventData> tryGetMessage() - { - return m_queue.tryGetMessage(); - } - - bool appendAndCheckEmpty(PassOwnPtr<PlatformMessagePortChannel::EventData> message) - { - return m_queue.appendAndCheckEmpty(message); - } - - bool isEmpty() - { - return m_queue.isEmpty(); - } - - private: - MessagePortQueue() { } - - MessageQueue<PlatformMessagePortChannel::EventData> m_queue; - }; - - ~PlatformMessagePortChannel(); - - static PassRefPtr<PlatformMessagePortChannel> create(PassRefPtr<MessagePortQueue> incoming, PassRefPtr<MessagePortQueue> outgoing); - PlatformMessagePortChannel(PassRefPtr<MessagePortQueue> incoming, PassRefPtr<MessagePortQueue> outgoing); - - PassRefPtr<PlatformMessagePortChannel> entangledChannel(); - - void setRemotePort(MessagePort*); - void closeInternal(); - - // Mutex used to ensure exclusive access to the object internals. - Mutex m_mutex; - - // Pointer to our entangled pair - cleared when close() is called. - RefPtr<PlatformMessagePortChannel> m_entangledChannel; - - // Reference to the message queue for the (local) entangled port. - RefPtr<MessagePortQueue> m_incomingQueue; - RefPtr<MessagePortQueue> m_outgoingQueue; - - // The port we are connected to (the remote port) - this is the port that is notified when new messages arrive. - MessagePort* m_remotePort; - }; - -} // namespace WebCore - -#endif // PlatformMessagePortChannel_h diff --git a/chromium/third_party/WebKit/Source/core/dom/default/chromium/PlatformMessagePortChannelChromium.cpp b/chromium/third_party/WebKit/Source/core/dom/default/chromium/PlatformMessagePortChannelChromium.cpp deleted file mode 100644 index 466502fc98a..00000000000 --- a/chromium/third_party/WebKit/Source/core/dom/default/chromium/PlatformMessagePortChannelChromium.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "core/dom/default/chromium/PlatformMessagePortChannelChromium.h" - -#include "bindings/v8/SerializedScriptValue.h" -#include "core/dom/MessagePort.h" - -#include "public/platform/Platform.h" -#include "public/platform/WebMessagePortChannel.h" -#include "public/platform/WebString.h" - -namespace WebCore { - -PassOwnPtr<MessagePortChannel> MessagePortChannel::create(PassRefPtr<PlatformMessagePortChannel> channel) -{ - return adoptPtr(new MessagePortChannel(channel)); -} - -void MessagePortChannel::createChannel(PassRefPtr<MessagePort> port1, PassRefPtr<MessagePort> port2) -{ - PlatformMessagePortChannel::createChannel(port1, port2); -} - -MessagePortChannel::MessagePortChannel(PassRefPtr<PlatformMessagePortChannel> channel) - : m_channel(channel) -{ -} - -MessagePortChannel::~MessagePortChannel() -{ - // Make sure we close our platform channel when the base is freed, to keep the channel objects from leaking. - m_channel->close(); -} - -bool MessagePortChannel::entangleIfOpen(MessagePort* port) -{ - return m_channel->entangleIfOpen(port); -} - -void MessagePortChannel::disentangle() -{ - m_channel->disentangle(); -} - -void MessagePortChannel::postMessageToRemote(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray> channels) -{ - m_channel->postMessageToRemote(message, channels); -} - -bool MessagePortChannel::tryGetMessageFromRemote(RefPtr<SerializedScriptValue>& message, OwnPtr<MessagePortChannelArray>& channels) -{ - return m_channel->tryGetMessageFromRemote(message, channels); -} - -void MessagePortChannel::close() -{ - m_channel->close(); -} - -bool MessagePortChannel::isConnectedTo(MessagePort* port) -{ - return m_channel->isConnectedTo(port); -} - -bool MessagePortChannel::hasPendingActivity() -{ - return m_channel->hasPendingActivity(); -} - -MessagePort* MessagePortChannel::locallyEntangledPort(const ScriptExecutionContext* context) -{ - // This is just an optimization, so return 0 always. - return 0; -} - - -PassRefPtr<PlatformMessagePortChannel> PlatformMessagePortChannel::create() -{ - return adoptRef(new PlatformMessagePortChannel()); -} - -PassRefPtr<PlatformMessagePortChannel> PlatformMessagePortChannel::create( - WebKit::WebMessagePortChannel* channel) -{ - return adoptRef(new PlatformMessagePortChannel(channel)); -} - - -PlatformMessagePortChannel::PlatformMessagePortChannel() - : m_localPort(0) -{ - m_webChannel = WebKit::Platform::current()->createMessagePortChannel(); - if (m_webChannel) - m_webChannel->setClient(this); -} - -PlatformMessagePortChannel::PlatformMessagePortChannel(WebKit::WebMessagePortChannel* channel) - : m_localPort(0) - , m_webChannel(channel) -{ -} - -PlatformMessagePortChannel::~PlatformMessagePortChannel() -{ - if (m_webChannel) - m_webChannel->destroy(); -} - -void PlatformMessagePortChannel::createChannel(PassRefPtr<MessagePort> port1, PassRefPtr<MessagePort> port2) -{ - // Create proxies for each endpoint. - RefPtr<PlatformMessagePortChannel> channel1 = PlatformMessagePortChannel::create(); - RefPtr<PlatformMessagePortChannel> channel2 = PlatformMessagePortChannel::create(); - - // Entangle the two endpoints. - channel1->setEntangledChannel(channel2); - channel2->setEntangledChannel(channel1); - - // Now entangle the proxies with the appropriate local ports. - port1->entangle(MessagePortChannel::create(channel2)); - port2->entangle(MessagePortChannel::create(channel1)); -} - -void PlatformMessagePortChannel::messageAvailable() -{ - MutexLocker lock(m_mutex); - if (m_localPort) - m_localPort->messageAvailable(); -} - -bool PlatformMessagePortChannel::entangleIfOpen(MessagePort* port) -{ - MutexLocker lock(m_mutex); - m_localPort = port; - return true; -} - -void PlatformMessagePortChannel::disentangle() -{ - MutexLocker lock(m_mutex); - m_localPort = 0; -} - -void PlatformMessagePortChannel::postMessageToRemote(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray> channels) -{ - if (!m_localPort || !m_webChannel) - return; - - WebKit::WebString messageString = message->toWireString(); - WebKit::WebMessagePortChannelArray* webChannels = 0; - if (channels && channels->size()) { - webChannels = new WebKit::WebMessagePortChannelArray(channels->size()); - for (size_t i = 0; i < channels->size(); ++i) { - PlatformMessagePortChannel* platformChannel = (*channels)[i]->channel(); - (*webChannels)[i] = platformChannel->webChannelRelease(); - (*webChannels)[i]->setClient(0); - } - } - m_webChannel->postMessage(messageString, webChannels); -} - -bool PlatformMessagePortChannel::tryGetMessageFromRemote(RefPtr<SerializedScriptValue>& serializedMessage, OwnPtr<MessagePortChannelArray>& channels) -{ - if (!m_webChannel) - return false; - - WebKit::WebString message; - WebKit::WebMessagePortChannelArray webChannels; - bool rv = m_webChannel->tryGetMessage(&message, webChannels); - if (rv) { - if (webChannels.size()) { - channels = adoptPtr(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); - } - } - serializedMessage = SerializedScriptValue::createFromWire(message); - } - - return rv; -} - -void PlatformMessagePortChannel::close() -{ - MutexLocker lock(m_mutex); - // Disentangle ourselves from the other end. We still maintain a reference to m_webChannel, - // since previously-existing messages should still be delivered. - m_localPort = 0; - m_entangledChannel = 0; -} - -bool PlatformMessagePortChannel::isConnectedTo(MessagePort* port) -{ - MutexLocker lock(m_mutex); - return m_entangledChannel && m_entangledChannel->m_localPort == port; -} - -bool PlatformMessagePortChannel::hasPendingActivity() -{ - MutexLocker lock(m_mutex); - return m_localPort; -} - -void PlatformMessagePortChannel::setEntangledChannel(PassRefPtr<PlatformMessagePortChannel> remote) -{ - if (m_webChannel) - m_webChannel->entangle(remote->m_webChannel); - - MutexLocker lock(m_mutex); - m_entangledChannel = remote; -} - -WebKit::WebMessagePortChannel* PlatformMessagePortChannel::webChannelRelease() -{ - WebKit::WebMessagePortChannel* rv = m_webChannel; - m_webChannel = 0; - return rv; -} - -} // namespace WebCore diff --git a/chromium/third_party/WebKit/Source/core/dom/default/chromium/PlatformMessagePortChannelChromium.h b/chromium/third_party/WebKit/Source/core/dom/default/chromium/PlatformMessagePortChannelChromium.h deleted file mode 100644 index 7c54ada6abc..00000000000 --- a/chromium/third_party/WebKit/Source/core/dom/default/chromium/PlatformMessagePortChannelChromium.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef PlatformMessagePortChannelChromium_h -#define PlatformMessagePortChannelChromium_h - -#include "core/dom/MessagePortChannel.h" -#include "public/platform/WebMessagePortChannelClient.h" -#include "wtf/PassRefPtr.h" -#include "wtf/ThreadingPrimitives.h" - -namespace WebKit { -class WebMessagePortChannel; -} - -namespace WebCore { - -class MessagePort; - -// PlatformMessagePortChannel is a platform-dependent interface to the remote side of a message channel. -class PlatformMessagePortChannel : public ThreadSafeRefCounted<PlatformMessagePortChannel>, - public WebKit::WebMessagePortChannelClient { -public: - static void createChannel(PassRefPtr<MessagePort>, PassRefPtr<MessagePort>); - static PassRefPtr<PlatformMessagePortChannel> create(); - static PassRefPtr<PlatformMessagePortChannel> create(WebKit::WebMessagePortChannel*); - - // APIs delegated from core/dom/MessagePortChannel.h - bool entangleIfOpen(MessagePort*); - void disentangle(); - void postMessageToRemote(PassRefPtr<SerializedScriptValue>, PassOwnPtr<MessagePortChannelArray>); - bool tryGetMessageFromRemote(RefPtr<SerializedScriptValue>&, OwnPtr<MessagePortChannelArray>&); - void close(); - bool isConnectedTo(MessagePort*); - bool hasPendingActivity(); - - // Releases ownership of the contained web channel. - WebKit::WebMessagePortChannel* webChannelRelease(); - - virtual ~PlatformMessagePortChannel(); - -private: - PlatformMessagePortChannel(); - PlatformMessagePortChannel(WebKit::WebMessagePortChannel*); - - void setEntangledChannel(PassRefPtr<PlatformMessagePortChannel>); - - // WebKit::WebMessagePortChannelClient implementation - virtual void messageAvailable(); - - // Mutex used to ensure exclusive access to the object internals. - Mutex m_mutex; - - // Pointer to our entangled pair - cleared when close() is called. - RefPtr<PlatformMessagePortChannel> m_entangledChannel; - - // The port we are connected to - this is the port that is notified when new messages arrive. - MessagePort* m_localPort; - - WebKit::WebMessagePortChannel* m_webChannel; -}; - -} // namespace WebCore - -#endif // PlatformMessagePortChannelChromium_h |