Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Henry Mason (hmason@mac.com) | 2 * Copyright (C) 2007 Henry Mason (hmason@mac.com) |
| 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 * | 25 * |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #ifndef MessageEvent_h | 28 #ifndef MessageEvent_h |
| 29 #define MessageEvent_h | 29 #define MessageEvent_h |
| 30 | 30 |
| 31 #include "bindings/v8/SerializedScriptValue.h" | 31 #include "bindings/v8/SerializedScriptValue.h" |
| 32 #include "core/dom/Event.h" | 32 #include "core/dom/Event.h" |
| 33 #include "core/dom/EventTarget.h" | |
| 33 #include "core/dom/MessagePort.h" | 34 #include "core/dom/MessagePort.h" |
| 34 #include "core/fileapi/Blob.h" | 35 #include "core/fileapi/Blob.h" |
| 35 #include "core/page/DOMWindow.h" | 36 #include "core/page/DOMWindow.h" |
| 36 #include "wtf/ArrayBuffer.h" | 37 #include "wtf/ArrayBuffer.h" |
| 37 | 38 |
| 38 namespace WebCore { | 39 namespace WebCore { |
| 39 | 40 |
| 40 class DOMWindow; | |
| 41 | |
| 42 struct MessageEventInit : public EventInit { | 41 struct MessageEventInit : public EventInit { |
| 43 MessageEventInit(); | 42 MessageEventInit(); |
| 44 | 43 |
| 45 String origin; | 44 String origin; |
| 46 String lastEventId; | 45 String lastEventId; |
| 47 RefPtr<DOMWindow> source; | 46 RefPtr<DOMWindow> source; |
| 48 MessagePortArray ports; | 47 MessagePortArray ports; |
| 49 }; | 48 }; |
| 50 | 49 |
| 51 class MessageEvent : public Event { | 50 class MessageEvent : public Event { |
| 52 public: | 51 public: |
| 53 static PassRefPtr<MessageEvent> create() | 52 static PassRefPtr<MessageEvent> create() |
| 54 { | 53 { |
| 55 return adoptRef(new MessageEvent); | 54 return adoptRef(new MessageEvent); |
| 56 } | 55 } |
| 56 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, P assRefPtr<MessagePort> source = 0) | |
|
do-not-use
2013/08/19 19:45:57
This factory takes a MessagePort, the others take
| |
| 57 { | |
| 58 return adoptRef(new MessageEvent("", "", source, ports)); | |
| 59 } | |
| 57 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, c onst String& origin = "", const String& lastEventId = "", PassRefPtr<DOMWindow> source = 0) | 60 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, c onst String& origin = "", const String& lastEventId = "", PassRefPtr<DOMWindow> source = 0) |
| 58 { | 61 { |
| 59 return adoptRef(new MessageEvent(origin, lastEventId, source, ports)); | 62 return adoptRef(new MessageEvent(origin, lastEventId, source, ports)); |
| 60 } | 63 } |
| 61 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, P assRefPtr<SerializedScriptValue> data, const String& origin = "", const String& lastEventId = "", PassRefPtr<DOMWindow> source = 0) | 64 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, P assRefPtr<SerializedScriptValue> data, const String& origin = "", const String& lastEventId = "", PassRefPtr<DOMWindow> source = 0) |
| 62 { | 65 { |
| 63 return adoptRef(new MessageEvent(data, origin, lastEventId, source, port s)); | 66 return adoptRef(new MessageEvent(data, origin, lastEventId, source, port s)); |
| 64 } | 67 } |
| 65 static PassRefPtr<MessageEvent> create(const String& data, const String& ori gin = "") | 68 static PassRefPtr<MessageEvent> create(const String& data, const String& ori gin = "") |
| 66 { | 69 { |
| 67 return adoptRef(new MessageEvent(data, origin)); | 70 return adoptRef(new MessageEvent(data, origin)); |
| 68 } | 71 } |
| 69 static PassRefPtr<MessageEvent> create(PassRefPtr<Blob> data, const String& origin = "") | 72 static PassRefPtr<MessageEvent> create(PassRefPtr<Blob> data, const String& origin = "") |
| 70 { | 73 { |
| 71 return adoptRef(new MessageEvent(data, origin)); | 74 return adoptRef(new MessageEvent(data, origin)); |
| 72 } | 75 } |
| 73 static PassRefPtr<MessageEvent> create(PassRefPtr<ArrayBuffer> data, const S tring& origin = "") | 76 static PassRefPtr<MessageEvent> create(PassRefPtr<ArrayBuffer> data, const S tring& origin = "") |
| 74 { | 77 { |
| 75 return adoptRef(new MessageEvent(data, origin)); | 78 return adoptRef(new MessageEvent(data, origin)); |
| 76 } | 79 } |
| 77 static PassRefPtr<MessageEvent> create(const AtomicString& type, const Messa geEventInit& initializer) | 80 static PassRefPtr<MessageEvent> create(const AtomicString& type, const Messa geEventInit& initializer) |
|
abarth-chromium
2013/08/19 20:01:51
This constructor is the problematic one. With you
| |
| 78 { | 81 { |
| 79 return adoptRef(new MessageEvent(type, initializer)); | 82 return adoptRef(new MessageEvent(type, initializer)); |
| 80 } | 83 } |
| 81 virtual ~MessageEvent(); | 84 virtual ~MessageEvent(); |
| 82 | 85 |
| 83 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela ble, const String& origin, const String& lastEventId, DOMWindow* source, PassOwn Ptr<MessagePortArray>); | 86 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela ble, const String& origin, const String& lastEventId, DOMWindow* source, PassOwn Ptr<MessagePortArray>); |
| 84 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela ble, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray>); | 87 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela ble, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray>); |
| 85 | 88 |
| 86 const String& origin() const { return m_origin; } | 89 const String& origin() const { return m_origin; } |
| 87 const String& lastEventId() const { return m_lastEventId; } | 90 const String& lastEventId() const { return m_lastEventId; } |
| 88 DOMWindow* source() const { return m_source.get(); } | 91 EventTarget* source() const { return m_source.get(); } |
| 89 MessagePortArray ports() const { return m_ports ? *m_ports : MessagePortArra y(); } | 92 MessagePortArray ports() const { return m_ports ? *m_ports : MessagePortArra y(); } |
| 90 | 93 |
| 91 virtual const AtomicString& interfaceName() const; | 94 virtual const AtomicString& interfaceName() const; |
| 92 | 95 |
| 93 enum DataType { | 96 enum DataType { |
| 94 DataTypeScriptValue, | 97 DataTypeScriptValue, |
| 95 DataTypeSerializedScriptValue, | 98 DataTypeSerializedScriptValue, |
| 96 DataTypeString, | 99 DataTypeString, |
| 97 DataTypeBlob, | 100 DataTypeBlob, |
| 98 DataTypeArrayBuffer | 101 DataTypeArrayBuffer |
| 99 }; | 102 }; |
| 100 DataType dataType() const { return m_dataType; } | 103 DataType dataType() const { return m_dataType; } |
| 101 SerializedScriptValue* dataAsSerializedScriptValue() const { ASSERT(m_dataTy pe == DataTypeScriptValue || m_dataType == DataTypeSerializedScriptValue); retur n m_dataAsSerializedScriptValue.get(); } | 104 SerializedScriptValue* dataAsSerializedScriptValue() const { ASSERT(m_dataTy pe == DataTypeScriptValue || m_dataType == DataTypeSerializedScriptValue); retur n m_dataAsSerializedScriptValue.get(); } |
| 102 String dataAsString() const { ASSERT(m_dataType == DataTypeString); return m _dataAsString; } | 105 String dataAsString() const { ASSERT(m_dataType == DataTypeString); return m _dataAsString; } |
| 103 Blob* dataAsBlob() const { ASSERT(m_dataType == DataTypeBlob); return m_data AsBlob.get(); } | 106 Blob* dataAsBlob() const { ASSERT(m_dataType == DataTypeBlob); return m_data AsBlob.get(); } |
| 104 ArrayBuffer* dataAsArrayBuffer() const { ASSERT(m_dataType == DataTypeArrayB uffer); return m_dataAsArrayBuffer.get(); } | 107 ArrayBuffer* dataAsArrayBuffer() const { ASSERT(m_dataType == DataTypeArrayB uffer); return m_dataAsArrayBuffer.get(); } |
| 105 | 108 |
| 106 void setSerializedData(PassRefPtr<SerializedScriptValue> data) | 109 void setSerializedData(PassRefPtr<SerializedScriptValue> data) |
| 107 { | 110 { |
| 108 ASSERT(!m_dataAsSerializedScriptValue); | 111 ASSERT(!m_dataAsSerializedScriptValue); |
| 109 m_dataAsSerializedScriptValue = data; | 112 m_dataAsSerializedScriptValue = data; |
| 110 } | 113 } |
| 111 | 114 |
| 112 private: | 115 private: |
| 113 MessageEvent(); | 116 MessageEvent(); |
| 114 MessageEvent(const AtomicString&, const MessageEventInit&); | 117 MessageEvent(const AtomicString&, const MessageEventInit&); |
| 115 MessageEvent(const String& origin, const String& lastEventId, PassRefPtr<DOM Window> source, PassOwnPtr<MessagePortArray>); | 118 MessageEvent(const String& origin, const String& lastEventId, PassRefPtr<Eve ntTarget> source, PassOwnPtr<MessagePortArray>); |
| 116 MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, c onst String& lastEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortAr ray>); | 119 MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, c onst String& lastEventId, PassRefPtr<EventTarget> source, PassOwnPtr<MessagePort Array>); |
| 117 | 120 |
| 118 explicit MessageEvent(const String& data, const String& origin); | 121 explicit MessageEvent(const String& data, const String& origin); |
| 119 explicit MessageEvent(PassRefPtr<Blob> data, const String& origin); | 122 explicit MessageEvent(PassRefPtr<Blob> data, const String& origin); |
| 120 explicit MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin); | 123 explicit MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin); |
| 121 | 124 |
| 122 DataType m_dataType; | 125 DataType m_dataType; |
| 123 RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue; | 126 RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue; |
| 124 String m_dataAsString; | 127 String m_dataAsString; |
| 125 RefPtr<Blob> m_dataAsBlob; | 128 RefPtr<Blob> m_dataAsBlob; |
| 126 RefPtr<ArrayBuffer> m_dataAsArrayBuffer; | 129 RefPtr<ArrayBuffer> m_dataAsArrayBuffer; |
| 127 String m_origin; | 130 String m_origin; |
| 128 String m_lastEventId; | 131 String m_lastEventId; |
| 129 RefPtr<DOMWindow> m_source; | 132 RefPtr<EventTarget> m_source; // A Window or a MessagePort. |
|
abarth-chromium
2013/08/19 19:24:58
Can we ASSERT this fact somewhere rather than havi
do-not-use
2013/08/19 19:45:57
Yes, I can add an assertion but this would mean ad
| |
| 130 OwnPtr<MessagePortArray> m_ports; | 133 OwnPtr<MessagePortArray> m_ports; |
| 131 }; | 134 }; |
| 132 | 135 |
| 133 } // namespace WebCore | 136 } // namespace WebCore |
| 134 | 137 |
| 135 #endif // MessageEvent_h | 138 #endif // MessageEvent_h |
| OLD | NEW |