提交 8209d97c 编写于 作者: E Elliott Sprehn

Remove postMessage, MessageChannel and MessagePort.

Sky uses Mojo services to communicate between embedded applications, not
postMessage and its friends.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/676723003
上级 c1d26b1d
......@@ -34,7 +34,6 @@
#include "bindings/core/v8/V8Element.h"
#include "bindings/core/v8/V8EventTarget.h"
#include "bindings/core/v8/V8MediaKeyError.h"
#include "bindings/core/v8/V8MessagePort.h"
#include "bindings/core/v8/V8Path2D.h"
#include "bindings/core/v8/V8VoidCallback.h"
#include "bindings/core/v8/V8Window.h"
......
......@@ -32,7 +32,6 @@
#include "bindings/core/v8/ScriptValue.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8BindingMacros.h"
#include "core/dom/MessagePort.h"
#include "core/events/EventListener.h"
#include "wtf/HashMap.h"
#include "wtf/HashSet.h"
......
......@@ -34,7 +34,6 @@
#include "bindings/core/v8/V8Element.h"
#include "bindings/core/v8/V8EventTarget.h"
#include "bindings/core/v8/V8MediaKeyError.h"
#include "bindings/core/v8/V8MessagePort.h"
#include "bindings/core/v8/V8Path2D.h"
#include "bindings/core/v8/V8VoidCallback.h"
#include "bindings/core/v8/V8Window.h"
......@@ -261,22 +260,6 @@ bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, RefP
return true;
}
template <>
bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, MessagePortArray& value)
{
v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value))
return false;
ASSERT(dictionary.isolate());
ASSERT(dictionary.isolate() == v8::Isolate::GetCurrent());
if (blink::isUndefinedOrNull(v8Value))
return true;
bool success = false;
value = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort>(v8Value, key, dictionary.isolate(), &success);
return success;
}
template <>
bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, HashSet<AtomicString>& value)
{
......@@ -608,16 +591,4 @@ template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
template bool DictionaryHelper::convert(const Dictionary&, Dictionary::ConversionContext&, const String& key, RefPtrWillBeMember<MediaKeyError>& value);
template bool DictionaryHelper::convert(const Dictionary&, Dictionary::ConversionContext&, const String& key, RefPtrWillBeMember<EventTarget>& value);
template <>
bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::ConversionContext& context, const String& key, MessagePortArray& value)
{
Dictionary::ConversionContextScope scope(context);
v8::Local<v8::Value> v8Value;
if (!dictionary.get(key, v8Value))
return true;
return DictionaryHelper::get(dictionary, key, value);
}
} // namespace blink
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PostMessage_h
#define PostMessage_h
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/SerializedScriptValue.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8BindingMacros.h"
#include "core/dom/MessagePort.h"
#include "wtf/ArrayBuffer.h"
#include <v8.h>
namespace blink {
class ExecutionContext;
// FIXME: This should be auto-generated by a code generator template.
template <class Type>
void postMessageMethodCommon(const char* interfaceName, Type* instance, const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage", interfaceName, info.Holder(), info.GetIsolate());
MessagePortArray ports;
ArrayBufferArray arrayBuffers;
if (info.Length() > 1) {
const int transferablesArgIndex = 1;
if (!SerializedScriptValue::extractTransferables(info[transferablesArgIndex], transferablesArgIndex, ports, arrayBuffers, exceptionState, info.GetIsolate())) {
exceptionState.throwIfNeeded();
return;
}
}
RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(info[0], &ports, &arrayBuffers, exceptionState, info.GetIsolate());
if (exceptionState.throwIfNeeded())
return;
// FIXME: Only pass context/exceptionState if instance really requires it.
ExecutionContext* context = currentExecutionContext(info.GetIsolate());
instance->postMessage(context, message.release(), &ports, exceptionState);
exceptionState.throwIfNeeded();
}
} // namespace blink
#endif // PostMessage_h
......@@ -34,7 +34,6 @@
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8ImageData.h"
#include "bindings/core/v8/V8MessagePort.h"
#include "bindings/core/v8/custom/V8ArrayBufferCustom.h"
#include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h"
#include "bindings/core/v8/custom/V8DataViewCustom.h"
......@@ -48,7 +47,6 @@
#include "bindings/core/v8/custom/V8Uint8ArrayCustom.h"
#include "bindings/core/v8/custom/V8Uint8ClampedArrayCustom.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/MessagePort.h"
#include "core/html/ImageData.h"
#include "core/html/canvas/DataView.h"
#include "platform/SharedBuffer.h"
......@@ -183,7 +181,6 @@ enum SerializationTag {
Int32Tag = 'I', // value:ZigZag-encoded int32 -> Integer
Uint32Tag = 'U', // value:uint32_t -> Integer
DateTag = 'D', // value:double -> Date (ref)
MessagePortTag = 'M', // index:int -> MessagePort. Fills the result with transferred MessagePort.
NumberTag = 'N', // value:double -> Number
ImageDataTag = '#', // width:uint32_t, height:uint32_t, pixelDataLength:uint32_t, data:byte[pixelDataLength] -> ImageData (ref)
ObjectTag = '{', // numProperties:uint32_t -> pops the last object from the open stack;
......@@ -437,12 +434,6 @@ public:
doWriteUint32(static_cast<uint32_t>(flags));
}
void writeTransferredMessagePort(uint32_t index)
{
append(MessagePortTag);
doWriteUint32(index);
}
void writeTransferredArrayBuffer(uint32_t index)
{
append(ArrayBufferTransferTag);
......@@ -616,15 +607,6 @@ private:
unsigned m_position;
};
static v8::Handle<v8::Object> toV8Object(MessagePort* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
if (!impl)
return v8::Handle<v8::Object>();
v8::Handle<v8::Value> wrapper = toV8(impl, creationContext, isolate);
ASSERT(wrapper->IsObject());
return wrapper.As<v8::Object>();
}
static v8::Handle<v8::ArrayBuffer> toV8Object(ArrayBuffer* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
if (!impl)
......@@ -644,7 +626,7 @@ public:
JSException
};
Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, v8::TryCatch& tryCatch, ScriptState* scriptState)
Serializer(Writer& writer, ArrayBufferArray* arrayBuffers, v8::TryCatch& tryCatch, ScriptState* scriptState)
: m_scriptState(scriptState)
, m_writer(writer)
, m_tryCatch(tryCatch)
......@@ -654,10 +636,6 @@ public:
{
ASSERT(!tryCatch.HasCaught());
v8::Handle<v8::Object> creationContext = m_scriptState->context()->Global();
if (messagePorts) {
for (size_t i = 0; i < messagePorts->size(); i++)
m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get(), creationContext, isolate()), i);
}
if (arrayBuffers) {
for (size_t i = 0; i < arrayBuffers->size(); i++) {
v8::Handle<v8::Object> v8ArrayBuffer = toV8Object(arrayBuffers->at(i).get(), creationContext, isolate());
......@@ -1104,7 +1082,6 @@ private:
String m_errorMessage;
typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool;
ObjectPool m_objectPool;
ObjectPool m_transferredMessagePorts;
ObjectPool m_transferredArrayBuffers;
uint32_t m_nextObjectReference;
};
......@@ -1151,13 +1128,6 @@ Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Stat
return writeAndGreyArrayBufferView(value.As<v8::Object>(), next);
} else if (value->IsString()) {
writeString(value);
} else if (V8MessagePort::hasInstance(value, isolate())) {
uint32_t messagePortIndex;
if (m_transferredMessagePorts.tryGet(value.As<v8::Object>(), &messagePortIndex)) {
m_writer.writeTransferredMessagePort(messagePortIndex);
} else {
return handleError(DataCloneError, "A MessagePort could not be cloned.", next);
}
} else if (V8ArrayBuffer::hasInstance(value, isolate()) && m_transferredArrayBuffers.tryGet(value.As<v8::Object>(), &arrayBufferIndex)) {
return writeTransferredArrayBuffer(value, arrayBufferIndex, next);
} else {
......@@ -1202,7 +1172,6 @@ public:
virtual uint32_t objectReferenceCount() = 0;
virtual void pushObjectReference(const v8::Handle<v8::Value>&) = 0;
virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Handle<v8::Value>*) = 0;
virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Handle<v8::Value>*) = 0;
virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Handle<v8::Value>*) = 0;
virtual bool newSparseArray(uint32_t length) = 0;
virtual bool newDenseArray(uint32_t length) = 0;
......@@ -1397,16 +1366,6 @@ public:
return false;
return true;
}
case MessagePortTag: {
if (!m_version)
return false;
uint32_t index;
if (!doReadUint32(&index))
return false;
if (!creator.tryGetTransferredMessagePort(index, value))
return false;
break;
}
case ArrayBufferTransferTag: {
if (!m_version)
return false;
......@@ -1763,9 +1722,8 @@ typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray;
class Deserializer FINAL : public CompositeCreator {
public:
Deserializer(Reader& reader, MessagePortArray* messagePorts, ArrayBufferContentsArray* arrayBufferContents)
Deserializer(Reader& reader, ArrayBufferContentsArray* arrayBufferContents)
: m_reader(reader)
, m_transferredMessagePorts(messagePorts)
, m_arrayBufferContents(arrayBufferContents)
, m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0)
, m_version(0)
......@@ -1882,17 +1840,6 @@ public:
m_objectPool.append(object);
}
virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Handle<v8::Value>* object) OVERRIDE
{
if (!m_transferredMessagePorts)
return false;
if (index >= m_transferredMessagePorts->size())
return false;
v8::Handle<v8::Object> creationContext = m_reader.scriptState()->context()->Global();
*object = toV8(m_transferredMessagePorts->at(index).get(), creationContext, m_reader.scriptState()->isolate());
return true;
}
virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Handle<v8::Value>* object) OVERRIDE
{
if (!m_arrayBufferContents)
......@@ -1991,7 +1938,6 @@ private:
Vector<v8::Local<v8::Value> > m_stack;
Vector<v8::Handle<v8::Value> > m_objectPool;
Vector<uint32_t> m_openCompositeReferenceStack;
RawPtrWillBeMember<MessagePortArray> m_transferredMessagePorts;
ArrayBufferContentsArray* m_arrayBufferContents;
Vector<v8::Handle<v8::Object> > m_arrayBuffers;
uint32_t m_version;
......@@ -1999,21 +1945,21 @@ private:
} // namespace
PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, ExceptionState& exceptionState, v8::Isolate* isolate)
PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::Value> value, ArrayBufferArray* arrayBuffers, ExceptionState& exceptionState, v8::Isolate* isolate)
{
return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers, exceptionState, isolate));
return adoptRef(new SerializedScriptValue(value, arrayBuffers, exceptionState, isolate));
}
PassRefPtr<SerializedScriptValue> SerializedScriptValue::createAndSwallowExceptions(v8::Handle<v8::Value> value, v8::Isolate* isolate)
{
TrackExceptionState exceptionState;
return adoptRef(new SerializedScriptValue(value, 0, 0, exceptionState, isolate));
return adoptRef(new SerializedScriptValue(value, 0, exceptionState, isolate));
}
PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const ScriptValue& value, ExceptionState& exceptionState, v8::Isolate* isolate)
{
ASSERT(isolate->InContext());
return adoptRef(new SerializedScriptValue(value.v8Value(), 0, 0, exceptionState, isolate));
return adoptRef(new SerializedScriptValue(value.v8Value(), 0, exceptionState, isolate));
}
PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const String& data)
......@@ -2137,7 +2083,7 @@ PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu
return contents.release();
}
SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, ExceptionState& exceptionState, v8::Isolate* isolate)
SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, ArrayBufferArray* arrayBuffers, ExceptionState& exceptionState, v8::Isolate* isolate)
: m_externallyAllocatedMemory(0)
{
Writer writer;
......@@ -2145,7 +2091,7 @@ SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag
String errorMessage;
{
v8::TryCatch tryCatch;
Serializer serializer(writer, messagePorts, arrayBuffers, tryCatch, ScriptState::current(isolate));
Serializer serializer(writer, arrayBuffers, tryCatch, ScriptState::current(isolate));
status = serializer.serialize(value);
if (status == Serializer::JSException) {
// If there was a JS exception thrown, re-throw it.
......@@ -2178,12 +2124,12 @@ SerializedScriptValue::SerializedScriptValue(const String& wireData)
m_data = wireData.isolatedCopy();
}
v8::Handle<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messagePorts)
v8::Handle<v8::Value> SerializedScriptValue::deserialize()
{
return deserialize(v8::Isolate::GetCurrent(), messagePorts);
return deserialize(v8::Isolate::GetCurrent());
}
v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, MessagePortArray* messagePorts)
v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate)
{
if (!m_data.impl())
return v8::Null(isolate);
......@@ -2194,7 +2140,7 @@ v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M
// information stored in m_data isn't even encoded in UTF-16. Instead,
// unicode characters are encoded as UTF-8 with two code units per UChar.
Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters16()), 2 * m_data.length(), ScriptState::current(isolate));
Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.get());
Deserializer deserializer(reader, m_arrayBufferContentsArray.get());
// deserialize() can run arbitrary script (e.g., setters), which could result in |this| being destroyed.
// Holding a RefPtr ensures we are alive (along with our internal data) throughout the operation.
......@@ -2202,65 +2148,6 @@ v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M
return deserializer.deserialize();
}
bool SerializedScriptValue::extractTransferables(v8::Local<v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, ExceptionState& exceptionState, v8::Isolate* isolate)
{
if (isUndefinedOrNull(value)) {
ports.resize(0);
arrayBuffers.resize(0);
return true;
}
uint32_t length = 0;
if (value->IsArray()) {
v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value);
length = array->Length();
} else if (toV8Sequence(value, length, isolate).IsEmpty()) {
exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex + 1));
return false;
}
v8::Local<v8::Object> transferrables = v8::Local<v8::Object>::Cast(value);
// Validate the passed array of transferrables.
for (unsigned i = 0; i < length; ++i) {
v8::Local<v8::Value> transferrable = transferrables->Get(i);
// Validation of non-null objects, per HTML5 spec 10.3.3.
if (isUndefinedOrNull(transferrable)) {
exceptionState.throwDOMException(DataCloneError, "Value at index " + String::number(i) + " is an untransferable " + (transferrable->IsUndefined() ? "'undefined'" : "'null'") + " value.");
return false;
}
// Validation of Objects implementing an interface, per WebIDL spec 4.1.15.
if (V8MessagePort::hasInstance(transferrable, isolate)) {
RefPtrWillBeRawPtr<MessagePort> port = V8MessagePort::toNative(v8::Handle<v8::Object>::Cast(transferrable));
// Check for duplicate MessagePorts.
if (ports.contains(port)) {
exceptionState.throwDOMException(DataCloneError, "Message port at index " + String::number(i) + " is a duplicate of an earlier port.");
return false;
}
ports.append(port.release());
} else if (V8ArrayBuffer::hasInstance(transferrable, isolate)) {
RefPtr<ArrayBuffer> arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Object>::Cast(transferrable));
if (arrayBuffers.contains(arrayBuffer)) {
exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer.");
return false;
}
arrayBuffers.append(arrayBuffer.release());
} else {
exceptionState.throwDOMException(DataCloneError, "Value at index " + String::number(i) + " does not have a transferable type.");
return false;
}
}
return true;
}
void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext()
{
if (m_externallyAllocatedMemory)
return;
m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length());
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_externallyAllocatedMemory);
}
SerializedScriptValue::~SerializedScriptValue()
{
// If the allocated memory was not registered before, then this class is likely
......
......@@ -46,9 +46,7 @@ class ArrayBufferContents;
namespace blink {
class ExceptionState;
class MessagePort;
typedef WillBeHeapVector<RefPtrWillBeMember<MessagePort>, 1> MessagePortArray;
typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray;
class SerializedScriptValue FINAL : public ThreadSafeRefCounted<SerializedScriptValue> {
......@@ -69,7 +67,7 @@ public:
// be thrown using v8::ThrowException(), and sets |didThrow|. In this case
// the caller must not invoke any V8 operations until control returns to
// V8. When serialization is successful, |didThrow| is false.
static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferArray*, ExceptionState&, v8::Isolate*);
static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, ArrayBufferArray*, ExceptionState&, v8::Isolate*);
static PassRefPtr<SerializedScriptValue> createFromWire(const String&);
static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<uint8_t>&);
static PassRefPtr<SerializedScriptValue> create(const String&);
......@@ -87,20 +85,8 @@ public:
// Deserializes the value (in the current context). Returns a null value in
// case of failure.
v8::Handle<v8::Value> deserialize(MessagePortArray* = 0);
v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0);
// Helper function which pulls the values out of a JS sequence and into a MessagePortArray.
// Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3
// of the HTML5 spec and generates exceptions as appropriate.
// Returns true if the array was filled, or false if the passed value was not of an appropriate type.
static bool extractTransferables(v8::Local<v8::Value>, int, MessagePortArray&, ArrayBufferArray&, ExceptionState&, v8::Isolate*);
// Informs the V8 about external memory allocated and owned by this object. Large values should contribute
// to GC counters to eventually trigger a GC, otherwise flood of postMessage() can cause OOM.
// Ok to invoke multiple times (only adds memory once).
// The memory registration is revoked automatically in destructor.
void registerMemoryAllocatedWithCurrentScriptContext();
v8::Handle<v8::Value> deserialize();
v8::Handle<v8::Value> deserialize(v8::Isolate*);
private:
enum StringDataMode {
......@@ -110,7 +96,7 @@ private:
typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray;
SerializedScriptValue();
SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferArray*, ExceptionState&, v8::Isolate*);
SerializedScriptValue(v8::Handle<v8::Value>, ArrayBufferArray*, ExceptionState&, v8::Isolate*);
explicit SerializedScriptValue(const String& wireData);
static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBufferArray&, ExceptionState&, v8::Isolate*);
......
......@@ -62,7 +62,7 @@ void V8History::stateAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Va
void V8History::pushStateMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExceptionState exceptionState(ExceptionState::ExecutionContext, "pushState", "History", info.Holder(), info.GetIsolate());
RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(info[0], 0, 0, exceptionState, info.GetIsolate());
RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(info[0], 0, exceptionState, info.GetIsolate());
if (exceptionState.throwIfNeeded())
return;
......
/*
* 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 "bindings/core/v8/V8MessageChannel.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8HiddenValue.h"
#include "bindings/core/v8/V8MessagePort.h"
#include "core/dom/MessageChannel.h"
#include "wtf/RefPtr.h"
namespace blink {
void V8MessageChannel::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExecutionContext* context = currentExecutionContext(info.GetIsolate());
RefPtrWillBeRawPtr<MessageChannel> obj = MessageChannel::create(context);
v8::Local<v8::Object> wrapper = info.Holder();
// Create references from the MessageChannel wrapper to the two
// MessagePort wrappers to make sure that the MessagePort wrappers
// stay alive as long as the MessageChannel wrapper is around.
V8HiddenValue::setHiddenValue(info.GetIsolate(), wrapper, V8HiddenValue::port1(info.GetIsolate()), toV8(obj->port1(), info.Holder(), info.GetIsolate()));
V8HiddenValue::setHiddenValue(info.GetIsolate(), wrapper, V8HiddenValue::port2(info.GetIsolate()), toV8(obj->port2(), info.Holder(), info.GetIsolate()));
V8DOMWrapper::associateObjectWithWrapper<V8MessageChannel>(obj.release(), &wrapperTypeInfo, wrapper, info.GetIsolate());
info.GetReturnValue().Set(wrapper);
}
} // namespace blink
/*
* 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 "bindings/core/v8/V8MessageEvent.h"
#include "bindings/core/v8/SerializedScriptValue.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8HiddenValue.h"
#include "bindings/core/v8/V8MessagePort.h"
#include "bindings/core/v8/V8Window.h"
#include "bindings/core/v8/custom/V8ArrayBufferCustom.h"
#include "core/events/MessageEvent.h"
namespace blink {
// Ensures a wrapper is created for the data to return now so that V8 knows how
// much memory is used via the wrapper. To keep the wrapper alive, it's set to
// the wrapper of the MessageEvent as a hidden value.
static void ensureWrapperCreatedAndAssociated(MessageEvent* eventImpl, v8::Handle<v8::Object> eventWrapper, v8::Isolate* isolate)
{
switch (eventImpl->dataType()) {
case MessageEvent::DataTypeScriptValue:
case MessageEvent::DataTypeSerializedScriptValue:
break;
case MessageEvent::DataTypeString: {
String stringValue = eventImpl->dataAsString();
V8HiddenValue::setHiddenValue(isolate, eventWrapper, V8HiddenValue::stringData(isolate), v8String(isolate, stringValue));
break;
}
case MessageEvent::DataTypeArrayBuffer:
V8HiddenValue::setHiddenValue(isolate, eventWrapper, V8HiddenValue::arrayBufferData(isolate), toV8(eventImpl->dataAsArrayBuffer(), eventWrapper, isolate));
break;
}
}
v8::Handle<v8::Object> wrap(MessageEvent* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
ASSERT(impl);
ASSERT(!DOMDataStore::containsWrapper<V8MessageEvent>(impl, isolate));
v8::Handle<v8::Object> wrapper = V8MessageEvent::createWrapper(impl, creationContext, isolate);
ensureWrapperCreatedAndAssociated(impl, wrapper, isolate);
return wrapper;
}
void V8MessageEvent::dataAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info)
{
MessageEvent* event = V8MessageEvent::toNative(info.Holder());
v8::Handle<v8::Value> result;
switch (event->dataType()) {
case MessageEvent::DataTypeScriptValue: {
result = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::data(info.GetIsolate()));
if (result.IsEmpty()) {
if (!event->dataAsSerializedScriptValue()) {
// If we're in an isolated world and the event was created in the main world,
// we need to find the 'data' property on the main world wrapper and clone it.
v8::Local<v8::Value> mainWorldData = V8HiddenValue::getHiddenValueFromMainWorldWrapper(info.GetIsolate(), event, V8HiddenValue::data(info.GetIsolate()));
if (!mainWorldData.IsEmpty())
event->setSerializedData(SerializedScriptValue::createAndSwallowExceptions(mainWorldData, info.GetIsolate()));
}
if (event->dataAsSerializedScriptValue())
result = event->dataAsSerializedScriptValue()->deserialize(info.GetIsolate());
else
result = v8::Null(info.GetIsolate());
}
break;
}
case MessageEvent::DataTypeSerializedScriptValue:
if (SerializedScriptValue* serializedValue = event->dataAsSerializedScriptValue()) {
MessagePortArray ports = event->ports();
result = serializedValue->deserialize(info.GetIsolate(), &ports);
} else {
result = v8::Null(info.GetIsolate());
}
break;
case MessageEvent::DataTypeString: {
result = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::stringData(info.GetIsolate()));
if (result.IsEmpty()) {
String stringValue = event->dataAsString();
result = v8String(info.GetIsolate(), stringValue);
}
break;
}
case MessageEvent::DataTypeArrayBuffer:
result = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::arrayBufferData(info.GetIsolate()));
if (result.IsEmpty())
result = toV8(event->dataAsArrayBuffer(), info.Holder(), info.GetIsolate());
break;
}
// Overwrite the data attribute so it returns the cached result in future invocations.
// This custom getter handler will not be called again.
v8::PropertyAttribute dataAttr = static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly);
info.Holder()->ForceSet(v8AtomicString(info.GetIsolate(), "data"), result, dataAttr);
v8SetReturnValue(info, result);
}
void V8MessageEvent::initMessageEventMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
MessageEvent* event = V8MessageEvent::toNative(info.Holder());
TOSTRING_VOID(V8StringResource<>, typeArg, info[0]);
TONATIVE_VOID(bool, canBubbleArg, info[1]->BooleanValue());
TONATIVE_VOID(bool, cancelableArg, info[2]->BooleanValue());
v8::Handle<v8::Value> dataArg = info[3];
TOSTRING_VOID(V8StringResource<>, originArg, info[4]);
TOSTRING_VOID(V8StringResource<>, lastEventIdArg, info[5]);
LocalDOMWindow* sourceArg = toDOMWindow(info[6], info.GetIsolate());
OwnPtrWillBeRawPtr<MessagePortArray> portArray = nullptr;
const int portArrayIndex = 7;
if (!isUndefinedOrNull(info[portArrayIndex])) {
portArray = adoptPtrWillBeNoop(new MessagePortArray);
bool success = false;
*portArray = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort>(info[portArrayIndex], portArrayIndex + 1, info.GetIsolate(), &success);
if (!success)
return;
}
event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, originArg, lastEventIdArg, sourceArg, portArray.release());
if (!dataArg.IsEmpty()) {
V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::data(info.GetIsolate()), dataArg);
if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld())
event->setSerializedData(SerializedScriptValue::createAndSwallowExceptions(dataArg, info.GetIsolate()));
}
}
} // namespace blink
/*
* Copyright (C) 2009, 2011 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 "bindings/core/v8/V8MessagePort.h"
#include "bindings/core/v8/PostMessage.h"
#include "bindings/core/v8/V8Binding.h"
namespace blink {
// FIXME: This stub should be replaced by generated code.
void V8MessagePort::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
postMessageMethodCommon("MessagePort", V8MessagePort::toNative(info.Holder()), info);
}
} // namespace blink
......@@ -45,7 +45,6 @@
#include "bindings/core/v8/V8HiddenValue.h"
#include "bindings/core/v8/V8Node.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/MessagePort.h"
#include "core/dom/Element.h"
#include "core/dom/Node.h"
#include "core/frame/DOMTimer.h"
......
......@@ -30,9 +30,6 @@
'V8Int32ArrayCustom.h',
'V8Int8ArrayCustom.h',
'V8LocationCustom.cpp',
'V8MessageChannelCustom.cpp',
'V8MessageEventCustom.cpp',
'V8MessagePortCustom.cpp',
'V8MutationObserverCustom.cpp',
'V8NodeCustom.cpp',
'V8PopStateEventCustom.cpp',
......
......@@ -39,7 +39,6 @@
'ExceptionStatePlaceholder.cpp',
'ExceptionStatePlaceholder.h',
'Nullable.h',
'PostMessage.h',
'RetainedDOMInfo.cpp',
'RetainedDOMInfo.h',
'RetainedObjectInfo.h',
......
......@@ -175,7 +175,7 @@ if (!std::isnan({{argument.name}}NativeValue))
IDL integer types have same internal C++ type (int or unsigned) #}
{{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeValue);
{% elif argument.idl_type == 'SerializedScriptValue' %}
{{argument.name}} = SerializedScriptValue::create(info[{{argument.index}}], 0, 0, exceptionState, info.GetIsolate());
{{argument.name}} = SerializedScriptValue::create(info[{{argument.index}}], 0, exceptionState, info.GetIsolate());
if (exceptionState.hadException()) {
{{throw_from_exception_state(method)}};
return;
......
......@@ -415,9 +415,6 @@ sky_core_files = [
"dom/ExecutionContext.h",
"dom/IncrementLoadEventDelayCount.cpp",
"dom/IncrementLoadEventDelayCount.h",
"dom/MessageChannel.cpp",
"dom/MessageChannel.h",
"dom/MessagePort.cpp",
"dom/Microtask.cpp",
"dom/Microtask.h",
"dom/MutationCallback.h",
......@@ -651,8 +648,6 @@ sky_core_files = [
"events/GestureEvent.h",
"events/HashChangeEvent.h",
"events/KeyboardEvent.cpp",
"events/MessageEvent.cpp",
"events/MessageEvent.h",
"events/MouseEvent.cpp",
"events/MouseRelatedEvent.cpp",
"events/NodeEventContext.cpp",
......@@ -1280,8 +1275,6 @@ core_idl_files = get_path_info([
"dom/Document.idl",
"dom/DocumentFragment.idl",
"dom/Element.idl",
"dom/MessageChannel.idl",
"dom/MessagePort.idl",
"dom/MutationObserver.idl",
"dom/MutationRecord.idl",
"dom/NamedNodeMap.idl",
......@@ -1305,7 +1298,6 @@ core_idl_files = get_path_info([
"events/FocusEvent.idl",
"events/HashChangeEvent.idl",
"events/KeyboardEvent.idl",
"events/MessageEvent.idl",
"events/MouseEvent.idl",
"events/OverflowEvent.idl",
"events/PageTransitionEvent.idl",
......@@ -1427,7 +1419,6 @@ core_event_idl_files = get_path_info([
"events/FocusEvent.idl",
"events/HashChangeEvent.idl",
"events/KeyboardEvent.idl",
"events/MessageEvent.idl",
"events/MouseEvent.idl",
"events/OverflowEvent.idl",
"events/PageTransitionEvent.idl",
......
/*
* Copyright (C) 2008 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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/MessageChannel.h"
#include "core/dom/MessagePort.h"
#include "public/platform/Platform.h"
#include "public/platform/WebMessagePortChannel.h"
namespace blink {
DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(MessageChannel);
static void createChannel(MessagePort* port1, MessagePort* port2)
{
WebMessagePortChannel* channel1;
WebMessagePortChannel* channel2;
Platform::current()->createMessageChannel(&channel1, &channel2);
ASSERT(channel1 && channel2);
// Now entangle the proxies with the appropriate local ports.
port1->entangle(adoptPtr(channel2));
port2->entangle(adoptPtr(channel1));
}
MessageChannel::MessageChannel(ExecutionContext* context)
: m_port1(MessagePort::create(*context))
, m_port2(MessagePort::create(*context))
{
ScriptWrappable::init(this);
createChannel(m_port1.get(), m_port2.get());
}
void MessageChannel::trace(Visitor* visitor)
{
visitor->trace(m_port1);
visitor->trace(m_port2);
}
} // namespace blink
/*
* Copyright (C) 2008 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 MessageChannel_h
#define MessageChannel_h
#include "bindings/core/v8/ScriptWrappable.h"
#include "platform/heap/Handle.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
namespace blink {
class MessagePort;
class ExecutionContext;
class MessageChannel FINAL : public RefCountedWillBeGarbageCollected<MessageChannel>, public ScriptWrappable {
DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(MessageChannel);
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtrWillBeRawPtr<MessageChannel> create(ExecutionContext* context)
{
return adoptRefWillBeNoop(new MessageChannel(context));
}
MessagePort* port1() const { return m_port1.get(); }
MessagePort* port2() const { return m_port2.get(); }
void trace(Visitor*);
private:
explicit MessageChannel(ExecutionContext*);
RefPtrWillBeMember<MessagePort> m_port1;
RefPtrWillBeMember<MessagePort> m_port2;
};
} // namespace blink
#endif // MessageChannel_h
/*
* Copyright (C) 2008, 2010 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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.
*
*/
[
CustomConstructor,
WillBeGarbageCollected
] interface MessageChannel {
readonly attribute MessagePort port1;
readonly attribute MessagePort port2;
};
/*
* Copyright (C) 2008 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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/MessagePort.h"
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/ExceptionStatePlaceholder.h"
#include "bindings/core/v8/SerializedScriptValue.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
#include "core/events/MessageEvent.h"
#include "core/frame/LocalDOMWindow.h"
#include "public/platform/WebString.h"
#include "wtf/Functional.h"
#include "wtf/text/AtomicString.h"
namespace blink {
PassRefPtrWillBeRawPtr<MessagePort> MessagePort::create(ExecutionContext& executionContext)
{
RefPtrWillBeRawPtr<MessagePort> port = adoptRefWillBeNoop(new MessagePort(executionContext));
port->suspendIfNeeded();
return port.release();
}
MessagePort::MessagePort(ExecutionContext& executionContext)
: ActiveDOMObject(&executionContext)
, m_started(false)
, m_closed(false)
, m_weakFactory(this)
{
ScriptWrappable::init(this);
}
MessagePort::~MessagePort()
{
close();
}
void MessagePort::postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionState)
{
if (!isEntangled())
return;
ASSERT(executionContext());
ASSERT(m_entangledChannel);
OwnPtr<MessagePortChannelArray> channels;
// Make sure we aren't connected to any of the passed-in ports.
if (ports) {
for (unsigned i = 0; i < ports->size(); ++i) {
MessagePort* dataPort = (*ports)[i].get();
if (dataPort == this) {
exceptionState.throwDOMException(DataCloneError, "Port at index " + String::number(i) + " contains the source port.");
return;
}
}
channels = MessagePort::disentanglePorts(ports, exceptionState);
if (exceptionState.hadException())
return;
}
WebString messageString = message->toWireString();
OwnPtr<WebMessagePortChannelArray> webChannels = toWebMessagePortChannelArray(channels.release());
m_entangledChannel->postMessage(messageString, webChannels.leakPtr());
}
// static
PassOwnPtr<WebMessagePortChannelArray> MessagePort::toWebMessagePortChannelArray(PassOwnPtr<MessagePortChannelArray> channels)
{
OwnPtr<WebMessagePortChannelArray> webChannels;
if (channels && channels->size()) {
webChannels = adoptPtr(new WebMessagePortChannelArray(channels->size()));
for (size_t i = 0; i < channels->size(); ++i)
(*webChannels)[i] = (*channels)[i].leakPtr();
}
return webChannels.release();
}
// static
PassOwnPtrWillBeRawPtr<MessagePortArray> MessagePort::toMessagePortArray(ExecutionContext* context, const WebMessagePortChannelArray& webChannels)
{
OwnPtrWillBeRawPtr<MessagePortArray> ports = nullptr;
if (!webChannels.isEmpty()) {
OwnPtr<MessagePortChannelArray> channels = adoptPtr(new MessagePortChannelArray(webChannels.size()));
for (size_t i = 0; i < webChannels.size(); ++i)
(*channels)[i] = adoptPtr(webChannels[i]);
ports = MessagePort::entanglePorts(*context, channels.release());
}
return ports.release();
}
PassOwnPtr<WebMessagePortChannel> MessagePort::disentangle()
{
ASSERT(m_entangledChannel);
m_entangledChannel->setClient(0);
return m_entangledChannel.release();
}
// Invoked to notify us that there are messages available for this port.
// This code may be called from another thread, and so should not call any non-threadsafe APIs (i.e. should not call into the entangled channel or access mutable variables).
void MessagePort::messageAvailable()
{
callOnMainThread(bind(&MessagePort::dispatchMessages, m_weakFactory.createWeakPtr()));
}
void MessagePort::start()
{
// Do nothing if we've been cloned or closed.
if (!isEntangled())
return;
ASSERT(executionContext());
if (m_started)
return;
m_started = true;
messageAvailable();
}
void MessagePort::close()
{
if (isEntangled())
m_entangledChannel->setClient(0);
m_closed = true;
}
void MessagePort::entangle(PassOwnPtr<WebMessagePortChannel> remote)
{
// Only invoked to set our initial entanglement.
ASSERT(!m_entangledChannel);
ASSERT(executionContext());
m_entangledChannel = remote;
m_entangledChannel->setClient(this);
}
const AtomicString& MessagePort::interfaceName() const
{
return EventTargetNames::MessagePort;
}
static bool tryGetMessageFrom(WebMessagePortChannel& webChannel, RefPtr<SerializedScriptValue>& message, OwnPtr<MessagePortChannelArray>& channels)
{
WebString messageString;
WebMessagePortChannelArray webChannels;
if (!webChannel.tryGetMessage(&messageString, webChannels))
return false;
if (webChannels.size()) {
channels = adoptPtr(new MessagePortChannelArray(webChannels.size()));
for (size_t i = 0; i < webChannels.size(); ++i)
(*channels)[i] = adoptPtr(webChannels[i]);
}
message = SerializedScriptValue::createFromWire(messageString);
return true;
}
void MessagePort::dispatchMessages()
{
// Messages for contexts that are not fully active get dispatched too, but JSAbstractEventListener::handleEvent() doesn't call handlers for these.
// The HTML5 spec specifies that any messages sent to a document that is not fully active should be dropped, so this behavior is OK.
if (!started())
return;
RefPtr<SerializedScriptValue> message;
OwnPtr<MessagePortChannelArray> channels;
while (m_entangledChannel && tryGetMessageFrom(*m_entangledChannel, message, channels)) {
OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::entanglePorts(*executionContext(), channels.release());
RefPtrWillBeRawPtr<Event> evt = MessageEvent::create(ports.release(), message.release());
dispatchEvent(evt.release(), ASSERT_NO_EXCEPTION);
}
}
bool MessagePort::hasPendingActivity() const
{
// The spec says that entangled message ports should always be treated as if they have a strong reference.
// We'll also stipulate that the queue needs to be open (if the app drops its reference to the port before start()-ing it, then it's not really entangled as it's unreachable).
return m_started && isEntangled();
}
PassOwnPtr<MessagePortChannelArray> MessagePort::disentanglePorts(const MessagePortArray* ports, ExceptionState& exceptionState)
{
if (!ports || !ports->size())
return nullptr;
// HashSet used to efficiently check for duplicates in the passed-in array.
HashSet<MessagePort*> portSet;
// Walk the incoming array - if there are any duplicate ports, or null ports or cloned ports, throw an error (per section 8.3.3 of the HTML5 spec).
for (unsigned i = 0; i < ports->size(); ++i) {
MessagePort* port = (*ports)[i].get();
if (!port || port->isNeutered() || portSet.contains(port)) {
String type;
if (!port)
type = "null";
else if (port->isNeutered())
type = "already neutered";
else
type = "a duplicate";
exceptionState.throwDOMException(DataCloneError, "Port at index " + String::number(i) + " is " + type + ".");
return nullptr;
}
portSet.add(port);
}
// Passed-in ports passed validity checks, so we can disentangle them.
OwnPtr<MessagePortChannelArray> portArray = adoptPtr(new MessagePortChannelArray(ports->size()));
for (unsigned i = 0; i < ports->size(); ++i)
(*portArray)[i] = (*ports)[i]->disentangle();
return portArray.release();
}
PassOwnPtrWillBeRawPtr<MessagePortArray> MessagePort::entanglePorts(ExecutionContext& context, PassOwnPtr<MessagePortChannelArray> channels)
{
if (!channels || !channels->size())
return nullptr;
OwnPtrWillBeRawPtr<MessagePortArray> portArray = adoptPtrWillBeNoop(new MessagePortArray(channels->size()));
for (unsigned i = 0; i < channels->size(); ++i) {
RefPtrWillBeRawPtr<MessagePort> port = MessagePort::create(context);
port->entangle((*channels)[i].release());
(*portArray)[i] = port.release();
}
return portArray.release();
}
} // namespace blink
/*
* Copyright (C) 2008 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 MessagePort_h
#define MessagePort_h
#include "core/dom/ActiveDOMObject.h"
#include "core/events/EventListener.h"
#include "core/events/EventTarget.h"
#include "public/platform/WebMessagePortChannel.h"
#include "public/platform/WebMessagePortChannelClient.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
#include "wtf/Vector.h"
#include "wtf/WeakPtr.h"
namespace blink {
class ExceptionState;
class MessagePort;
class ExecutionContext;
class SerializedScriptValue;
// The overwhelmingly common case is sending a single port, so handle that efficiently with an inline buffer of size 1.
typedef WillBeHeapVector<RefPtrWillBeMember<MessagePort>, 1> MessagePortArray;
// Not to be confused with WebMessagePortChannelArray; this one uses Vector and OwnPtr instead of WebVector and raw pointers.
typedef Vector<OwnPtr<WebMessagePortChannel>, 1> MessagePortChannelArray;
class MessagePort FINAL : public RefCountedWillBeGarbageCollectedFinalized<MessagePort>
, public ActiveDOMObject
, public EventTargetWithInlineData
, public WebMessagePortChannelClient {
DEFINE_WRAPPERTYPEINFO();
REFCOUNTED_EVENT_TARGET(MessagePort);
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MessagePort);
public:
static PassRefPtrWillBeRawPtr<MessagePort> create(ExecutionContext&);
virtual ~MessagePort();
void postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> message, const MessagePortArray*, ExceptionState&);
void start();
void close();
void entangle(PassOwnPtr<WebMessagePortChannel>);
PassOwnPtr<WebMessagePortChannel> disentangle();
static PassOwnPtr<WebMessagePortChannelArray> toWebMessagePortChannelArray(PassOwnPtr<MessagePortChannelArray>);
static PassOwnPtrWillBeRawPtr<MessagePortArray> toMessagePortArray(ExecutionContext*, const WebMessagePortChannelArray&);
// Returns 0 if there is an exception, or if the passed-in array is 0/empty.
static PassOwnPtr<MessagePortChannelArray> disentanglePorts(const MessagePortArray*, ExceptionState&);
// Returns 0 if the passed array is 0/empty.
static PassOwnPtrWillBeRawPtr<MessagePortArray> entanglePorts(ExecutionContext&, PassOwnPtr<MessagePortChannelArray>);
bool started() const { return m_started; }
virtual const AtomicString& interfaceName() const OVERRIDE;
virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveDOMObject::executionContext(); }
virtual MessagePort* toMessagePort() OVERRIDE { return this; }
// ActiveDOMObject implementation.
virtual bool hasPendingActivity() const OVERRIDE;
virtual void stop() OVERRIDE { close(); }
void setOnmessage(PassRefPtr<EventListener> listener)
{
setAttributeEventListener(EventTypeNames::message, listener);
start();
}
EventListener* onmessage() { return getAttributeEventListener(EventTypeNames::message); }
// A port starts out its life entangled, and remains entangled until it is closed or is cloned.
bool isEntangled() const { return !m_closed && !isNeutered(); }
// A port gets neutered when it is transferred to a new owner via postMessage().
bool isNeutered() const { return !m_entangledChannel; }
private:
explicit MessagePort(ExecutionContext&);
// WebMessagePortChannelClient implementation.
virtual void messageAvailable() OVERRIDE;
void dispatchMessages();
OwnPtr<WebMessagePortChannel> m_entangledChannel;
bool m_started;
bool m_closed;
WeakPtrFactory<MessagePort> m_weakFactory;
};
} // namespace blink
#endif // MessagePort_h
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
* Copyright (C) 2011 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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.
*
*/
[
ActiveDOMObject,
WillBeGarbageCollected
] interface MessagePort : EventTarget {
[Custom, RaisesException] void postMessage(any message, optional sequence<Transferable> transfer);
void start();
void close();
// event handler attributes
attribute EventHandler onmessage;
};
......@@ -26,6 +26,7 @@
#ifndef CustomEvent_h
#define CustomEvent_h
#include "bindings/core/v8/SerializedScriptValue.h"
#include "core/events/Event.h"
namespace blink {
......
......@@ -76,11 +76,6 @@ LocalDOMWindow* EventTarget::toDOMWindow()
return 0;
}
MessagePort* EventTarget::toMessagePort()
{
return 0;
}
inline LocalDOMWindow* EventTarget::executingWindow()
{
if (ExecutionContext* context = executionContext())
......
......@@ -42,7 +42,6 @@ namespace blink {
class LocalDOMWindow;
class Event;
class ExceptionState;
class MessagePort;
class Node;
struct FiringEventIterator {
......@@ -106,7 +105,6 @@ public:
virtual Node* toNode();
virtual LocalDOMWindow* toDOMWindow();
virtual MessagePort* toMessagePort();
// FIXME: first 2 args to addEventListener and removeEventListener should
// be required (per spec), but throwing TypeError breaks legacy content.
......
......@@ -3,7 +3,6 @@ namespace="EventTarget"
core/animation/AnimationPlayer
core/css/FontFaceSet
core/css/MediaQueryList
core/dom/MessagePort
core/dom/Node
core/html/MediaController
core/html/ime/InputMethodContext
......
/*
* Copyright (C) 2007 Henry Mason (hmason@mac.com)
* Copyright (C) 2003, 2005, 2006, 2007, 2008 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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/events/MessageEvent.h"
#include "bindings/core/v8/ExceptionMessages.h"
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/custom/V8ArrayBufferCustom.h"
namespace blink {
static inline bool isValidSource(EventTarget* source)
{
return !source || source->toDOMWindow() || source->toMessagePort();
}
MessageEventInit::MessageEventInit()
{
}
MessageEvent::MessageEvent()
: m_dataType(DataTypeScriptValue)
{
ScriptWrappable::init(this);
}
MessageEvent::MessageEvent(const AtomicString& type, const MessageEventInit& initializer)
: Event(type, initializer)
, m_dataType(DataTypeScriptValue)
, m_origin(initializer.origin)
, m_lastEventId(initializer.lastEventId)
, m_source(isValidSource(initializer.source.get()) ? initializer.source : nullptr)
, m_ports(adoptPtrWillBeNoop(new MessagePortArray(initializer.ports)))
{
ScriptWrappable::init(this);
ASSERT(isValidSource(m_source.get()));
}
MessageEvent::MessageEvent(const String& origin, const String& lastEventId, PassRefPtrWillBeRawPtr<EventTarget> source, PassOwnPtrWillBeRawPtr<MessagePortArray> ports)
: Event(EventTypeNames::message, false, false)
, m_dataType(DataTypeScriptValue)
, m_origin(origin)
, m_lastEventId(lastEventId)
, m_source(source)
, m_ports(ports)
{
ScriptWrappable::init(this);
ASSERT(isValidSource(m_source.get()));
}
MessageEvent::MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, PassRefPtrWillBeRawPtr<EventTarget> source, PassOwnPtrWillBeRawPtr<MessagePortArray> ports)
: Event(EventTypeNames::message, false, false)
, m_dataType(DataTypeSerializedScriptValue)
, m_dataAsSerializedScriptValue(data)
, m_origin(origin)
, m_lastEventId(lastEventId)
, m_source(source)
, m_ports(ports)
{
ScriptWrappable::init(this);
if (m_dataAsSerializedScriptValue)
m_dataAsSerializedScriptValue->registerMemoryAllocatedWithCurrentScriptContext();
ASSERT(isValidSource(m_source.get()));
}
MessageEvent::MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, PassRefPtrWillBeRawPtr<EventTarget> source, PassOwnPtr<MessagePortChannelArray> channels)
: Event(EventTypeNames::message, false, false)
, m_dataType(DataTypeSerializedScriptValue)
, m_dataAsSerializedScriptValue(data)
, m_origin(origin)
, m_lastEventId(lastEventId)
, m_source(source)
, m_channels(channels)
{
ScriptWrappable::init(this);
if (m_dataAsSerializedScriptValue)
m_dataAsSerializedScriptValue->registerMemoryAllocatedWithCurrentScriptContext();
ASSERT(isValidSource(m_source.get()));
}
MessageEvent::MessageEvent(const String& data, const String& origin)
: Event(EventTypeNames::message, false, false)
, m_dataType(DataTypeString)
, m_dataAsString(data)
, m_origin(origin)
{
ScriptWrappable::init(this);
}
MessageEvent::MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin)
: Event(EventTypeNames::message, false, false)
, m_dataType(DataTypeArrayBuffer)
, m_dataAsArrayBuffer(data)
, m_origin(origin)
{
ScriptWrappable::init(this);
}
MessageEvent::~MessageEvent()
{
}
PassRefPtrWillBeRawPtr<MessageEvent> MessageEvent::create(const AtomicString& type, const MessageEventInit& initializer, ExceptionState& exceptionState)
{
if (initializer.source.get() && !isValidSource(initializer.source.get())) {
exceptionState.throwTypeError("The optional 'source' property is neither a Window nor MessagePort.");
return nullptr;
}
return adoptRefWillBeNoop(new MessageEvent(type, initializer));
}
void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const String& origin, const String& lastEventId, LocalDOMWindow* source, PassOwnPtrWillBeRawPtr<MessagePortArray> ports)
{
if (dispatched())
return;
initEvent(type, canBubble, cancelable);
m_dataType = DataTypeScriptValue;
m_origin = origin;
m_lastEventId = lastEventId;
m_source = source;
m_ports = ports;
}
void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, LocalDOMWindow* source, PassOwnPtrWillBeRawPtr<MessagePortArray> ports)
{
if (dispatched())
return;
initEvent(type, canBubble, cancelable);
m_dataType = DataTypeSerializedScriptValue;
m_dataAsSerializedScriptValue = data;
m_origin = origin;
m_lastEventId = lastEventId;
m_source = source;
m_ports = ports;
if (m_dataAsSerializedScriptValue)
m_dataAsSerializedScriptValue->registerMemoryAllocatedWithCurrentScriptContext();
}
const AtomicString& MessageEvent::interfaceName() const
{
return EventNames::MessageEvent;
}
void MessageEvent::entangleMessagePorts(ExecutionContext* context)
{
m_ports = MessagePort::entanglePorts(*context, m_channels.release());
}
void MessageEvent::trace(Visitor* visitor)
{
visitor->trace(m_source);
#if ENABLE(OILPAN)
visitor->trace(m_ports);
#endif
Event::trace(visitor);
}
v8::Handle<v8::Object> MessageEvent::wrap(v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
v8::Handle<v8::Object> wrapper = Event::wrap(creationContext, isolate);
switch (dataType()) {
case MessageEvent::DataTypeScriptValue:
case MessageEvent::DataTypeSerializedScriptValue:
break;
case MessageEvent::DataTypeString:
V8HiddenValue::setHiddenValue(isolate, wrapper, V8HiddenValue::stringData(isolate), v8String(isolate, dataAsString()));
break;
case MessageEvent::DataTypeArrayBuffer:
V8HiddenValue::setHiddenValue(isolate, wrapper, V8HiddenValue::arrayBufferData(isolate), toV8(dataAsArrayBuffer(), wrapper, isolate));
break;
}
return wrapper;
}
} // namespace blink
/*
* Copyright (C) 2007 Henry Mason (hmason@mac.com)
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 MessageEvent_h
#define MessageEvent_h
#include "bindings/core/v8/SerializedScriptValue.h"
#include "core/events/Event.h"
#include "core/events/EventTarget.h"
#include "core/dom/MessagePort.h"
#include "core/frame/LocalDOMWindow.h"
#include "wtf/ArrayBuffer.h"
namespace blink {
struct MessageEventInit : public EventInit {
MessageEventInit();
String origin;
String lastEventId;
RefPtrWillBeMember<EventTarget> source;
MessagePortArray ports;
};
class MessageEvent FINAL : public Event {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtrWillBeRawPtr<MessageEvent> create()
{
return adoptRefWillBeNoop(new MessageEvent);
}
static PassRefPtrWillBeRawPtr<MessageEvent> create(PassOwnPtrWillBeRawPtr<MessagePortArray> ports, const String& origin = String(), const String& lastEventId = String(), PassRefPtrWillBeRawPtr<EventTarget> source = nullptr)
{
return adoptRefWillBeNoop(new MessageEvent(origin, lastEventId, source, ports));
}
static PassRefPtrWillBeRawPtr<MessageEvent> create(PassOwnPtrWillBeRawPtr<MessagePortArray> ports, PassRefPtr<SerializedScriptValue> data, const String& origin = String(), const String& lastEventId = String(), PassRefPtrWillBeRawPtr<EventTarget> source = nullptr)
{
return adoptRefWillBeNoop(new MessageEvent(data, origin, lastEventId, source, ports));
}
static PassRefPtrWillBeRawPtr<MessageEvent> create(PassOwnPtr<MessagePortChannelArray> channels, PassRefPtr<SerializedScriptValue> data, const String& origin = String(), const String& lastEventId = String(), PassRefPtrWillBeRawPtr<EventTarget> source = nullptr)
{
return adoptRefWillBeNoop(new MessageEvent(data, origin, lastEventId, source, channels));
}
static PassRefPtrWillBeRawPtr<MessageEvent> create(const String& data, const String& origin = String())
{
return adoptRefWillBeNoop(new MessageEvent(data, origin));
}
static PassRefPtrWillBeRawPtr<MessageEvent> create(PassRefPtr<ArrayBuffer> data, const String& origin = String())
{
return adoptRefWillBeNoop(new MessageEvent(data, origin));
}
static PassRefPtrWillBeRawPtr<MessageEvent> create(const AtomicString& type, const MessageEventInit& initializer, ExceptionState&);
virtual ~MessageEvent();
void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const String& origin, const String& lastEventId, LocalDOMWindow* source, PassOwnPtrWillBeRawPtr<MessagePortArray>);
void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, LocalDOMWindow* source, PassOwnPtrWillBeRawPtr<MessagePortArray>);
const String& origin() const { return m_origin; }
const String& lastEventId() const { return m_lastEventId; }
EventTarget* source() const { return m_source.get(); }
MessagePortArray ports() const { return m_ports ? *m_ports : MessagePortArray(); }
MessagePortChannelArray* channels() const { return m_channels ? m_channels.get() : 0; }
virtual const AtomicString& interfaceName() const OVERRIDE;
enum DataType {
DataTypeScriptValue,
DataTypeSerializedScriptValue,
DataTypeString,
DataTypeArrayBuffer
};
DataType dataType() const { return m_dataType; }
SerializedScriptValue* dataAsSerializedScriptValue() const { ASSERT(m_dataType == DataTypeScriptValue || m_dataType == DataTypeSerializedScriptValue); return m_dataAsSerializedScriptValue.get(); }
String dataAsString() const { ASSERT(m_dataType == DataTypeString); return m_dataAsString; }
ArrayBuffer* dataAsArrayBuffer() const { ASSERT(m_dataType == DataTypeArrayBuffer); return m_dataAsArrayBuffer.get(); }
void setSerializedData(PassRefPtr<SerializedScriptValue> data)
{
ASSERT(!m_dataAsSerializedScriptValue);
m_dataAsSerializedScriptValue = data;
}
void entangleMessagePorts(ExecutionContext*);
virtual void trace(Visitor*) OVERRIDE;
virtual v8::Handle<v8::Object> wrap(v8::Handle<v8::Object> creationContext, v8::Isolate*) OVERRIDE;
private:
MessageEvent();
MessageEvent(const AtomicString&, const MessageEventInit&);
MessageEvent(const String& origin, const String& lastEventId, PassRefPtrWillBeRawPtr<EventTarget> source, PassOwnPtrWillBeRawPtr<MessagePortArray>);
MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, PassRefPtrWillBeRawPtr<EventTarget> source, PassOwnPtrWillBeRawPtr<MessagePortArray>);
MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, PassRefPtrWillBeRawPtr<EventTarget> source, PassOwnPtr<MessagePortChannelArray>);
MessageEvent(const String& data, const String& origin);
MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin);
DataType m_dataType;
RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue;
String m_dataAsString;
RefPtr<ArrayBuffer> m_dataAsArrayBuffer;
String m_origin;
String m_lastEventId;
RefPtrWillBeMember<EventTarget> m_source;
// m_ports are the MessagePorts in an engtangled state, and m_channels are
// the MessageChannels in a disentangled state. Only one of them can be
// non-empty at a time. entangleMessagePorts() moves between the states.
OwnPtrWillBeMember<MessagePortArray> m_ports;
OwnPtr<MessagePortChannelArray> m_channels;
};
} // namespace blink
#endif // MessageEvent_h
/*
* Copyright (C) 2007 Henry Mason <hmason@mac.com>
* Copyright (C) 2011 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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.
*
*/
[
EventConstructor,
RaisesException=Constructor,
Custom=Wrap,
] interface MessageEvent : Event {
[InitializedByEventConstructor] readonly attribute DOMString origin;
[InitializedByEventConstructor] readonly attribute DOMString lastEventId;
[InitializedByEventConstructor] readonly attribute EventTarget? source; // May be a Window or a MessagePort
[InitializedByEventConstructor, Custom=Getter] readonly attribute any data;
[InitializedByEventConstructor] readonly attribute MessagePort[] ports;
[Custom, MeasureAs=InitMessageEvent] void initMessageEvent([Default=Undefined] optional DOMString typeArg,
[Default=Undefined] optional boolean canBubbleArg,
[Default=Undefined] optional boolean cancelableArg,
[Default=Undefined] optional any dataArg,
[Default=Undefined] optional DOMString originArg,
[Default=Undefined] optional DOMString lastEventIdArg,
[Default=Undefined] optional Window sourceArg,
[Default=Undefined] optional MessagePort[] messagePorts);
};
......@@ -50,7 +50,6 @@
#include "core/events/DOMWindowEventQueue.h"
#include "core/events/EventListener.h"
#include "core/events/HashChangeEvent.h"
#include "core/events/MessageEvent.h"
#include "core/events/PageTransitionEvent.h"
#include "core/events/PopStateEvent.h"
#include "core/frame/Console.h"
......
......@@ -28,6 +28,7 @@
#define LocalDOMWindow_h
#include "bindings/core/v8/Dictionary.h"
#include "bindings/core/v8/SerializedScriptValue.h"
#include "core/events/EventTarget.h"
#include "core/frame/DOMWindowBase64.h"
#include "core/frame/FrameDestructionObserver.h"
......@@ -64,7 +65,6 @@ class IDBFactory;
class LocalFrame;
class Location;
class MediaQueryList;
class MessageEvent;
class Node;
class Page;
class RequestAnimationFrameCallback;
......@@ -74,8 +74,6 @@ class ScriptCallStack;
class SerializedScriptValue;
class StyleMedia;
typedef WillBeHeapVector<RefPtrWillBeMember<MessagePort>, 1> MessagePortArray;
enum PageshowEventPersistence {
PageshowEventNotPersisted = 0,
PageshowEventPersisted = 1
......
......@@ -132,21 +132,6 @@
[Custom, NotEnumerable] getter Window (DOMString name);
};
// http://www.whatwg.org/specs/web-apps/current-work/#transferable-objects
//
// Expressing the Transferable typedef in IDL depends on http://crbug.com/240176.
// The postMessage() methods taking a Transferable array argument have custom
// binding code that is able to handle the Transferables that we currently
// recognize. To be able to declare a postMessage() signature that matches
// the implementation, we provide a Transferable typedef but with an
// incomplete type.
//
// FIXME: make this typedef accurate once enough of http://crbug.com/240176
// is in place.
// FIXME: consider putting this typedef in an .idl file containing spec-wide
// utility type definitions.
typedef MessagePort Transferable;
Window implements WindowBase64;
Window implements WindowEventHandlers;
Window implements WindowTimers;
......@@ -52,7 +52,6 @@ namespace blink {
class IntSize;
class KURL;
class LocalFrame;
class MessageEvent;
class Page;
class ResourceError;
class ResourceHandle;
......
......@@ -60,7 +60,6 @@ class WebFlingAnimator;
class WebGestureCurveTarget;
class WebGestureCurve;
class WebGraphicsContext3DProvider;
class WebMessagePortChannel;
class WebMimeRegistry;
class WebPublicSuffixList;
class WebSandboxSupport;
......@@ -169,14 +168,6 @@ public:
// See comments on ImageDecoder::m_maxDecodedBytes.
virtual size_t maxDecodedImageBytes() { return noDecodedImageByteLimit; }
// Message Ports -------------------------------------------------------
// Creates a Message Port Channel pair. This can be called on any thread.
// The returned objects should only be used on the thread they were created on.
virtual void createMessageChannel(WebMessagePortChannel** channel1, WebMessagePortChannel** channel2) { *channel1 = 0; *channel2 = 0; }
// Network -------------------------------------------------------------
// Returns a new WebURLLoader instance.
......
/*
* 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 WebMessagePortChannel_h
#define WebMessagePortChannel_h
#include "WebCommon.h"
#include "WebVector.h"
namespace blink {
class WebMessagePortChannelClient;
class WebString;
typedef WebVector<class WebMessagePortChannel*> WebMessagePortChannelArray;
// Provides an interface to a Message Port Channel implementation. The object owns itself and
// is signalled that its not needed anymore with the destroy() call.
class WebMessagePortChannel {
public:
virtual void setClient(WebMessagePortChannelClient*) = 0;
virtual void destroy() = 0;
// Callee receives ownership of the passed vector.
// FIXME: Blob refs should be passed to maintain ref counts. crbug.com/351753
virtual void postMessage(const WebString&, WebMessagePortChannelArray*) = 0;
virtual bool tryGetMessage(WebString*, WebMessagePortChannelArray&) = 0;
protected:
~WebMessagePortChannel() { }
};
} // namespace blink
#if INSIDE_BLINK
namespace WTF {
template<typename T> struct OwnedPtrDeleter;
template<> struct OwnedPtrDeleter<blink::WebMessagePortChannel> {
static void deletePtr(blink::WebMessagePortChannel* channel)
{
if (channel)
channel->destroy();
}
};
} // namespace WTF
#endif // INSIDE_BLINK
#endif // WebMessagePortChannel_h
/*
* 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 WebMessagePortChannelClient_h
#define WebMessagePortChannelClient_h
namespace blink {
// Provides an interface for users of WebMessagePortChannel to be notified
// when messages are available.
class WebMessagePortChannelClient {
public:
// Alerts that new messages have arrived, which are retrieved by calling
// WebMessagePortChannel::tryGetMessage. Note that this may be called
// on any thread.
virtual void messageAvailable() = 0;
protected:
~WebMessagePortChannelClient() { }
};
} // namespace blink
#endif
......@@ -83,7 +83,6 @@ public:
BLINK_EXPORT bool isCompositionEvent() const;
BLINK_EXPORT bool isDragEvent() const;
BLINK_EXPORT bool isClipboardEvent() const;
BLINK_EXPORT bool isMessageEvent() const;
BLINK_EXPORT bool isWheelEvent() const;
BLINK_EXPORT bool isBeforeTextInsertedEvent() const;
BLINK_EXPORT bool isOverflowEvent() const;
......
/*
* Copyright (C) 2011 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 WebDOMMessageEvent_h
#define WebDOMMessageEvent_h
#include "../platform/WebMessagePortChannel.h"
#include "WebDOMEvent.h"
#include "WebSerializedScriptValue.h"
#if BLINK_IMPLEMENTATION
#include "core/events/Event.h"
#include "core/events/MessageEvent.h"
#endif
namespace blink {
class WebFrame;
class WebString;
class WebDOMMessageEvent : public WebDOMEvent {
public:
WebDOMMessageEvent() { }
BLINK_EXPORT void initMessageEvent(const WebString& type, bool canBubble, bool cancelable, const WebSerializedScriptValue& messageData, const WebString& origin, const WebFrame* sourceFrame, const WebString& lastEventId, const WebMessagePortChannelArray& channels = WebMessagePortChannelArray());
BLINK_EXPORT WebSerializedScriptValue data() const;
BLINK_EXPORT WebString origin() const;
BLINK_EXPORT WebMessagePortChannelArray releaseChannels();
#if BLINK_IMPLEMENTATION
explicit WebDOMMessageEvent(const PassRefPtrWillBeRawPtr<MessageEvent>& e) : WebDOMEvent(e) { }
#endif
};
} // namespace blink
#endif
......@@ -36,7 +36,6 @@
#include "WebNode.h"
#include "WebURLLoaderOptions.h"
#include "public/platform/WebCanvas.h"
#include "public/platform/WebMessagePortChannel.h"
#include "public/platform/WebPrivateOwnPtr.h"
#include "public/platform/WebReferrerPolicy.h"
#include "public/platform/WebURL.h"
......
......@@ -33,7 +33,6 @@
#include "../platform/WebColor.h"
#include "WebAXObject.h"
#include "WebDOMMessageEvent.h"
#include "WebFrame.h"
#include "WebIconURL.h"
#include "WebNavigationPolicy.h"
......
......@@ -72,7 +72,6 @@ component("web") {
"WebDOMCustomEvent.cpp",
"WebDOMError.cpp",
"WebDOMEvent.cpp",
"WebDOMMessageEvent.cpp",
"WebDOMMouseEvent.cpp",
"WebDOMProgressEvent.cpp",
"WebDOMResourceProgressEvent.cpp",
......
......@@ -34,7 +34,6 @@
#include "bindings/core/v8/ScriptController.h"
#include "core/dom/Document.h"
#include "core/events/MessageEvent.h"
#include "core/events/MouseEvent.h"
#include "core/frame/FrameView.h"
#include "core/frame/Settings.h"
......
......@@ -147,12 +147,6 @@ bool WebDOMEvent::isClipboardEvent() const
return m_private->isClipboardEvent();
}
bool WebDOMEvent::isMessageEvent() const
{
ASSERT(m_private.get());
return m_private->hasInterface(EventNames::MessageEvent);
}
bool WebDOMEvent::isWheelEvent() const
{
ASSERT(m_private.get());
......
/*
* Copyright (C) 2011 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 "public/web/WebDOMMessageEvent.h"
#include "bindings/core/v8/SerializedScriptValue.h"
#include "core/dom/Document.h"
#include "core/dom/MessagePort.h"
#include "core/events/MessageEvent.h"
#include "core/frame/LocalDOMWindow.h"
#include "public/platform/WebString.h"
#include "public/web/WebFrame.h"
#include "public/web/WebSerializedScriptValue.h"
#include "web/WebLocalFrameImpl.h"
namespace blink {
void WebDOMMessageEvent::initMessageEvent(const WebString& type, bool canBubble, bool cancelable, const WebSerializedScriptValue& messageData, const WebString& origin, const WebFrame* sourceFrame, const WebString& lastEventId, const WebMessagePortChannelArray& webChannels)
{
ASSERT(m_private.get());
ASSERT(isMessageEvent());
LocalDOMWindow* window = 0;
if (sourceFrame)
window = toWebLocalFrameImpl(sourceFrame)->frame()->domWindow();
OwnPtrWillBeRawPtr<MessagePortArray> ports = nullptr;
if (sourceFrame)
ports = MessagePort::toMessagePortArray(window->document(), webChannels);
unwrap<MessageEvent>()->initMessageEvent(type, canBubble, cancelable, messageData, origin, lastEventId, window, ports.release());
}
WebSerializedScriptValue WebDOMMessageEvent::data() const
{
return WebSerializedScriptValue(constUnwrap<MessageEvent>()->dataAsSerializedScriptValue());
}
WebString WebDOMMessageEvent::origin() const
{
return WebString(constUnwrap<MessageEvent>()->origin());
}
WebMessagePortChannelArray WebDOMMessageEvent::releaseChannels()
{
MessagePortChannelArray* channels = constUnwrap<MessageEvent>()->channels();
WebMessagePortChannelArray webChannels(channels ? channels->size() : 0);
if (channels) {
for (size_t i = 0; i < channels->size(); ++i)
webChannels[i] = (*channels)[i].leakPtr();
}
return webChannels;
}
} // namespace blink
......@@ -81,7 +81,6 @@
#include "bindings/core/v8/V8GCController.h"
#include "bindings/core/v8/V8PerIsolateData.h"
#include "core/dom/Document.h"
#include "core/dom/MessagePort.h"
#include "core/dom/Node.h"
#include "core/dom/NodeTraversal.h"
#include "core/dom/shadow/ShadowRoot.h"
......
......@@ -45,7 +45,7 @@ WebSerializedScriptValue WebSerializedScriptValue::fromString(const WebString& s
WebSerializedScriptValue WebSerializedScriptValue::serialize(v8::Handle<v8::Value> value)
{
TrackExceptionState exceptionState;
WebSerializedScriptValue serializedValue = SerializedScriptValue::create(value, 0, 0, exceptionState, v8::Isolate::GetCurrent());
WebSerializedScriptValue serializedValue = SerializedScriptValue::create(value, 0, exceptionState, v8::Isolate::GetCurrent());
if (exceptionState.hadException())
return createInvalid();
return serializedValue;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册