darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Henry Mason (hmason@mac.com) |
darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 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 |
| 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include "config.h" |
darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 29 | #include "MessageEvent.h" |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 30 | |
| 31 | #include "DOMWindow.h" |
| 32 | #include "EventNames.h" |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 33 | |
| 34 | namespace WebCore { |
| 35 | |
commit-queue@webkit.org | 9a6aee2 | 2011-09-28 02:02:18 +0000 | [diff] [blame] | 36 | MessageEventInit::MessageEventInit() |
commit-queue@webkit.org | 9a6aee2 | 2011-09-28 02:02:18 +0000 | [diff] [blame] | 37 | { |
| 38 | } |
| 39 | |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 40 | MessageEvent::MessageEvent() |
haraken@chromium.org | edc286c | 2011-10-20 06:02:42 +0000 | [diff] [blame] | 41 | : m_dataType(DataTypeScriptValue) |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
commit-queue@webkit.org | 9a6aee2 | 2011-09-28 02:02:18 +0000 | [diff] [blame] | 45 | MessageEvent::MessageEvent(const AtomicString& type, const MessageEventInit& initializer) |
| 46 | : Event(type, initializer) |
haraken@chromium.org | edc286c | 2011-10-20 06:02:42 +0000 | [diff] [blame] | 47 | , m_dataType(DataTypeScriptValue) |
| 48 | , m_dataAsScriptValue(initializer.data) |
commit-queue@webkit.org | 9a6aee2 | 2011-09-28 02:02:18 +0000 | [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 | } |
| 55 | |
haraken@chromium.org | edc286c | 2011-10-20 06:02:42 +0000 | [diff] [blame] | 56 | MessageEvent::MessageEvent(const ScriptValue& data, const String& origin, const String& lastEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortArray> ports) |
| 57 | : Event(eventNames().messageEvent, false, false) |
| 58 | , m_dataType(DataTypeScriptValue) |
| 59 | , m_dataAsScriptValue(data) |
| 60 | , m_origin(origin) |
| 61 | , m_lastEventId(lastEventId) |
| 62 | , m_source(source) |
| 63 | , m_ports(ports) |
| 64 | { |
| 65 | } |
| 66 | |
oliver@apple.com | 0ef2c5b | 2009-10-07 02:06:03 +0000 | [diff] [blame] | 67 | MessageEvent::MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortArray> ports) |
atwilson@chromium.org | 70fae52 | 2009-09-15 18:27:45 +0000 | [diff] [blame] | 68 | : Event(eventNames().messageEvent, false, false) |
yutak@chromium.org | 8995217 | 2011-08-25 09:25:16 +0000 | [diff] [blame] | 69 | , m_dataType(DataTypeSerializedScriptValue) |
| 70 | , m_dataAsSerializedScriptValue(data) |
weinig@apple.com | 205006e | 2008-04-27 01:56:37 +0000 | [diff] [blame] | 71 | , m_origin(origin) |
weinig@apple.com | bb5d25f | 2008-05-08 02:13:39 +0000 | [diff] [blame] | 72 | , m_lastEventId(lastEventId) |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 73 | , m_source(source) |
atwilson@chromium.org | 4a7bb13 | 2009-08-26 20:45:24 +0000 | [diff] [blame] | 74 | , m_ports(ports) |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 75 | { |
| 76 | } |
| 77 | |
commit-queue@webkit.org | b5d0a90 | 2012-11-23 11:52:11 +0000 | [diff] [blame] | 78 | MessageEvent::MessageEvent(const String& data, const String& origin) |
yutak@chromium.org | 8995217 | 2011-08-25 09:25:16 +0000 | [diff] [blame] | 79 | : Event(eventNames().messageEvent, false, false) |
| 80 | , m_dataType(DataTypeString) |
| 81 | , m_dataAsString(data) |
commit-queue@webkit.org | b5d0a90 | 2012-11-23 11:52:11 +0000 | [diff] [blame] | 82 | , m_origin(origin) |
yutak@chromium.org | 8995217 | 2011-08-25 09:25:16 +0000 | [diff] [blame] | 83 | , m_lastEventId("") |
| 84 | { |
| 85 | } |
| 86 | |
commit-queue@webkit.org | b5d0a90 | 2012-11-23 11:52:11 +0000 | [diff] [blame] | 87 | MessageEvent::MessageEvent(PassRefPtr<Blob> data, const String& origin) |
yutak@chromium.org | eadc20d | 2011-08-30 03:38:50 +0000 | [diff] [blame] | 88 | : Event(eventNames().messageEvent, false, false) |
| 89 | , m_dataType(DataTypeBlob) |
| 90 | , m_dataAsBlob(data) |
commit-queue@webkit.org | b5d0a90 | 2012-11-23 11:52:11 +0000 | [diff] [blame] | 91 | , m_origin(origin) |
yutak@chromium.org | eadc20d | 2011-08-30 03:38:50 +0000 | [diff] [blame] | 92 | , m_lastEventId("") |
| 93 | { |
| 94 | } |
| 95 | |
commit-queue@webkit.org | b5d0a90 | 2012-11-23 11:52:11 +0000 | [diff] [blame] | 96 | MessageEvent::MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin) |
yutak@chromium.org | 6c30c976 | 2011-08-31 08:33:38 +0000 | [diff] [blame] | 97 | : Event(eventNames().messageEvent, false, false) |
| 98 | , m_dataType(DataTypeArrayBuffer) |
| 99 | , m_dataAsArrayBuffer(data) |
commit-queue@webkit.org | b5d0a90 | 2012-11-23 11:52:11 +0000 | [diff] [blame] | 100 | , m_origin(origin) |
yutak@chromium.org | 6c30c976 | 2011-08-31 08:33:38 +0000 | [diff] [blame] | 101 | , m_lastEventId("") |
| 102 | { |
| 103 | } |
| 104 | |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 105 | MessageEvent::~MessageEvent() |
| 106 | { |
| 107 | } |
| 108 | |
haraken@chromium.org | edc286c | 2011-10-20 06:02:42 +0000 | [diff] [blame] | 109 | void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const ScriptValue& data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray> ports) |
| 110 | { |
| 111 | if (dispatched()) |
| 112 | return; |
| 113 | |
| 114 | initEvent(type, canBubble, cancelable); |
| 115 | |
| 116 | m_dataType = DataTypeScriptValue; |
| 117 | m_dataAsScriptValue = data; |
| 118 | m_origin = origin; |
| 119 | m_lastEventId = lastEventId; |
| 120 | m_source = source; |
| 121 | m_ports = ports; |
| 122 | } |
| 123 | |
oliver@apple.com | 0ef2c5b | 2009-10-07 02:06:03 +0000 | [diff] [blame] | 124 | void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray> ports) |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 125 | { |
| 126 | if (dispatched()) |
| 127 | return; |
commit-queue@webkit.org | 9a6aee2 | 2011-09-28 02:02:18 +0000 | [diff] [blame] | 128 | |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 129 | initEvent(type, canBubble, cancelable); |
yutak@chromium.org | 8995217 | 2011-08-25 09:25:16 +0000 | [diff] [blame] | 130 | |
| 131 | m_dataType = DataTypeSerializedScriptValue; |
| 132 | m_dataAsSerializedScriptValue = data; |
weinig@apple.com | 205006e | 2008-04-27 01:56:37 +0000 | [diff] [blame] | 133 | m_origin = origin; |
weinig@apple.com | bb5d25f | 2008-05-08 02:13:39 +0000 | [diff] [blame] | 134 | m_lastEventId = lastEventId; |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 135 | m_source = source; |
atwilson@chromium.org | 4a7bb13 | 2009-08-26 20:45:24 +0000 | [diff] [blame] | 136 | m_ports = ports; |
| 137 | } |
| 138 | |
yutak@chromium.org | 8995217 | 2011-08-25 09:25:16 +0000 | [diff] [blame] | 139 | // FIXME: Remove this when we have custom ObjC binding support. |
| 140 | SerializedScriptValue* MessageEvent::data() const |
| 141 | { |
| 142 | // WebSocket is not exposed in ObjC bindings, thus the data type should always be SerializedScriptValue. |
| 143 | ASSERT(m_dataType == DataTypeSerializedScriptValue); |
| 144 | return m_dataAsSerializedScriptValue.get(); |
| 145 | } |
| 146 | |
atwilson@chromium.org | 4a7bb13 | 2009-08-26 20:45:24 +0000 | [diff] [blame] | 147 | MessagePort* MessageEvent::messagePort() |
| 148 | { |
| 149 | if (!m_ports) |
| 150 | return 0; |
| 151 | ASSERT(m_ports->size() == 1); |
| 152 | return (*m_ports)[0].get(); |
| 153 | } |
| 154 | |
oliver@apple.com | 0ef2c5b | 2009-10-07 02:06:03 +0000 | [diff] [blame] | 155 | void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, DOMWindow* source, MessagePort* port) |
atwilson@chromium.org | 4a7bb13 | 2009-08-26 20:45:24 +0000 | [diff] [blame] | 156 | { |
abarth@webkit.org | 462d90a | 2011-04-27 21:25:22 +0000 | [diff] [blame] | 157 | OwnPtr<MessagePortArray> ports; |
atwilson@chromium.org | 4a7bb13 | 2009-08-26 20:45:24 +0000 | [diff] [blame] | 158 | if (port) { |
abarth@webkit.org | 462d90a | 2011-04-27 21:25:22 +0000 | [diff] [blame] | 159 | ports = adoptPtr(new MessagePortArray); |
atwilson@chromium.org | 4a7bb13 | 2009-08-26 20:45:24 +0000 | [diff] [blame] | 160 | ports->append(port); |
| 161 | } |
abarth@webkit.org | 462d90a | 2011-04-27 21:25:22 +0000 | [diff] [blame] | 162 | initMessageEvent(type, canBubble, cancelable, data, origin, lastEventId, source, ports.release()); |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 163 | } |
| 164 | |
abarth@webkit.org | 090fa4b | 2011-10-21 00:00:37 +0000 | [diff] [blame] | 165 | const AtomicString& MessageEvent::interfaceName() const |
| 166 | { |
| 167 | return eventNames().interfaceForMessageEvent; |
| 168 | } |
| 169 | |
darin@apple.com | c8da90b | 2008-01-01 00:18:16 +0000 | [diff] [blame] | 170 | } // namespace WebCore |