Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Henry Mason (hmason@mac.com) |
| 3 | * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include "config.h" |
| 29 | #include "core/dom/MessageEvent.h" |
| 30 | |
| 31 | #include "core/dom/EventNames.h" |
| 32 | #include "core/page/DOMWindow.h" |
| 33 | |
| 34 | namespace WebCore { |
| 35 | |
| 36 | MessageEventInit::MessageEventInit() |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | MessageEvent::MessageEvent() |
| 41 | : m_dataType(DataTypeScriptValue) |
| 42 | { |
| 43 | ScriptWrappable::init(this); |
| 44 | } |
| 45 | |
| 46 | MessageEvent::MessageEvent(const AtomicString& type, const MessageEventInit& initializer) |
| 47 | : Event(type, initializer) |
| 48 | , m_dataType(DataTypeScriptValue) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 49 | , m_origin(initializer.origin) |
| 50 | , m_lastEventId(initializer.lastEventId) |
| 51 | , m_source(initializer.source) |
| 52 | , m_ports(adoptPtr(new MessagePortArray(initializer.ports))) |
| 53 | { |
| 54 | ScriptWrappable::init(this); |
| 55 | } |
| 56 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 57 | MessageEvent::MessageEvent(const String& origin, const String& lastEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortArray> ports) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 58 | : Event(eventNames().messageEvent, false, false) |
| 59 | , m_dataType(DataTypeScriptValue) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 60 | , m_origin(origin) |
| 61 | , m_lastEventId(lastEventId) |
| 62 | , m_source(source) |
| 63 | , m_ports(ports) |
| 64 | { |
| 65 | ScriptWrappable::init(this); |
| 66 | } |
| 67 | |
| 68 | MessageEvent::MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortArray> ports) |
| 69 | : Event(eventNames().messageEvent, false, false) |
| 70 | , m_dataType(DataTypeSerializedScriptValue) |
| 71 | , m_dataAsSerializedScriptValue(data) |
| 72 | , m_origin(origin) |
| 73 | , m_lastEventId(lastEventId) |
| 74 | , m_source(source) |
| 75 | , m_ports(ports) |
| 76 | { |
| 77 | ScriptWrappable::init(this); |
| 78 | if (m_dataAsSerializedScriptValue) |
| 79 | m_dataAsSerializedScriptValue->registerMemoryAllocatedWithCurrentScriptContext(); |
| 80 | } |
| 81 | |
| 82 | MessageEvent::MessageEvent(const String& data, const String& origin) |
| 83 | : Event(eventNames().messageEvent, false, false) |
| 84 | , m_dataType(DataTypeString) |
| 85 | , m_dataAsString(data) |
| 86 | , m_origin(origin) |
| 87 | , m_lastEventId("") |
| 88 | { |
| 89 | ScriptWrappable::init(this); |
| 90 | } |
| 91 | |
| 92 | MessageEvent::MessageEvent(PassRefPtr<Blob> data, const String& origin) |
| 93 | : Event(eventNames().messageEvent, false, false) |
| 94 | , m_dataType(DataTypeBlob) |
| 95 | , m_dataAsBlob(data) |
| 96 | , m_origin(origin) |
| 97 | , m_lastEventId("") |
| 98 | { |
| 99 | ScriptWrappable::init(this); |
| 100 | } |
| 101 | |
| 102 | MessageEvent::MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin) |
| 103 | : Event(eventNames().messageEvent, false, false) |
| 104 | , m_dataType(DataTypeArrayBuffer) |
| 105 | , m_dataAsArrayBuffer(data) |
| 106 | , m_origin(origin) |
| 107 | , m_lastEventId("") |
| 108 | { |
| 109 | ScriptWrappable::init(this); |
| 110 | } |
| 111 | |
| 112 | MessageEvent::~MessageEvent() |
| 113 | { |
| 114 | } |
| 115 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 116 | void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray> ports) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 117 | { |
| 118 | if (dispatched()) |
| 119 | return; |
| 120 | |
| 121 | initEvent(type, canBubble, cancelable); |
| 122 | |
| 123 | m_dataType = DataTypeScriptValue; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 124 | m_origin = origin; |
| 125 | m_lastEventId = lastEventId; |
| 126 | m_source = source; |
| 127 | m_ports = ports; |
| 128 | } |
| 129 | |
| 130 | void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray> ports) |
| 131 | { |
| 132 | if (dispatched()) |
| 133 | return; |
| 134 | |
| 135 | initEvent(type, canBubble, cancelable); |
| 136 | |
| 137 | m_dataType = DataTypeSerializedScriptValue; |
| 138 | m_dataAsSerializedScriptValue = data; |
| 139 | m_origin = origin; |
| 140 | m_lastEventId = lastEventId; |
| 141 | m_source = source; |
| 142 | m_ports = ports; |
| 143 | |
| 144 | if (m_dataAsSerializedScriptValue) |
| 145 | m_dataAsSerializedScriptValue->registerMemoryAllocatedWithCurrentScriptContext(); |
| 146 | } |
| 147 | |
| 148 | const AtomicString& MessageEvent::interfaceName() const |
| 149 | { |
| 150 | return eventNames().interfaceForMessageEvent; |
| 151 | } |
| 152 | |
| 153 | } // namespace WebCore |