OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "public/web/WebDOMMessageEvent.h" | 32 #include "public/web/WebDOMMessageEvent.h" |
33 | 33 |
34 #include "bindings/core/v8/SerializedScriptValue.h" | 34 #include "bindings/core/v8/SerializedScriptValue.h" |
35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
36 #include "core/dom/MessagePort.h" | 36 #include "core/dom/MessagePort.h" |
37 #include "core/events/MessageEvent.h" | 37 #include "core/events/MessageEvent.h" |
38 #include "core/frame/LocalDOMWindow.h" | 38 #include "core/frame/LocalDOMWindow.h" |
39 #include "public/platform/WebString.h" | 39 #include "public/platform/WebString.h" |
| 40 #include "public/web/WebDocument.h" |
40 #include "public/web/WebFrame.h" | 41 #include "public/web/WebFrame.h" |
41 #include "public/web/WebSerializedScriptValue.h" | 42 #include "public/web/WebSerializedScriptValue.h" |
42 #include "web/WebLocalFrameImpl.h" | 43 #include "web/WebLocalFrameImpl.h" |
43 | 44 |
44 namespace blink { | 45 namespace blink { |
45 | 46 |
46 void WebDOMMessageEvent::initMessageEvent(const WebString& type, bool canBubble,
bool cancelable, const WebSerializedScriptValue& messageData, const WebString&
origin, const WebFrame* sourceFrame, const WebString& lastEventId, const WebMess
agePortChannelArray& webChannels) | 47 void WebDOMMessageEvent::initMessageEvent(const WebString& type, bool canBubble,
bool cancelable, const WebSerializedScriptValue& messageData, const WebString&
origin, const WebFrame* sourceFrame, const WebDocument& targetDocument, const We
bString& lastEventId, const WebMessagePortChannelArray& webChannels) |
47 { | 48 { |
48 ASSERT(m_private.get()); | 49 ASSERT(m_private.get()); |
49 ASSERT(isMessageEvent()); | 50 ASSERT(isMessageEvent()); |
50 DOMWindow* window = nullptr; | 51 DOMWindow* window = nullptr; |
51 // TODO(alexmos): Figure out if this is the right thing to do. | |
52 if (sourceFrame) | 52 if (sourceFrame) |
53 window = toCoreFrame(sourceFrame)->domWindow(); | 53 window = toCoreFrame(sourceFrame)->domWindow(); |
54 MessagePortArray* ports = nullptr; | 54 MessagePortArray* ports = nullptr; |
55 // TODO(alexmos): make ports work properly with OOPIF. | 55 if (!targetDocument.isNull()) { |
56 if (sourceFrame && sourceFrame->isWebLocalFrame()) | 56 RefPtrWillBeRawPtr<Document> coreDocument = PassRefPtrWillBeRawPtr<Docum
ent>(targetDocument); |
57 ports = MessagePort::toMessagePortArray(toLocalDOMWindow(window)->docume
nt(), webChannels); | 57 ports = MessagePort::toMessagePortArray(coreDocument.get(), webChannels)
; |
| 58 } |
58 // Use an empty array for |ports| when it is null because this function | 59 // Use an empty array for |ports| when it is null because this function |
59 // is used to implement postMessage(). | 60 // is used to implement postMessage(). |
60 if (!ports) | 61 if (!ports) |
61 ports = new MessagePortArray; | 62 ports = new MessagePortArray; |
62 unwrap<MessageEvent>()->initMessageEvent(type, canBubble, cancelable, messag
eData, origin, lastEventId, window, ports); | 63 unwrap<MessageEvent>()->initMessageEvent(type, canBubble, cancelable, messag
eData, origin, lastEventId, window, ports); |
63 } | 64 } |
64 | 65 |
| 66 void WebDOMMessageEvent::initMessageEvent(const WebString& type, bool canBubble,
bool cancelable, const WebSerializedScriptValue& messageData, const WebString&
origin, const WebFrame* sourceFrame, const WebString& lastEventId, const WebMess
agePortChannelArray& webChannels) |
| 67 { |
| 68 WebDocument document; |
| 69 if (sourceFrame && sourceFrame->isWebLocalFrame()) { |
| 70 DOMWindow* window = toCoreFrame(sourceFrame)->domWindow(); |
| 71 document = toLocalDOMWindow(window)->document(); |
| 72 } |
| 73 initMessageEvent(type, canBubble, cancelable, messageData, origin, sourceFra
me, document, lastEventId, webChannels); |
| 74 } |
| 75 |
65 WebSerializedScriptValue WebDOMMessageEvent::data() const | 76 WebSerializedScriptValue WebDOMMessageEvent::data() const |
66 { | 77 { |
67 return WebSerializedScriptValue(constUnwrap<MessageEvent>()->dataAsSerialize
dScriptValue()); | 78 return WebSerializedScriptValue(constUnwrap<MessageEvent>()->dataAsSerialize
dScriptValue()); |
68 } | 79 } |
69 | 80 |
70 WebString WebDOMMessageEvent::origin() const | 81 WebString WebDOMMessageEvent::origin() const |
71 { | 82 { |
72 return WebString(constUnwrap<MessageEvent>()->origin()); | 83 return WebString(constUnwrap<MessageEvent>()->origin()); |
73 } | 84 } |
74 | 85 |
75 WebMessagePortChannelArray WebDOMMessageEvent::releaseChannels() | 86 WebMessagePortChannelArray WebDOMMessageEvent::releaseChannels() |
76 { | 87 { |
77 MessagePortChannelArray* channels = constUnwrap<MessageEvent>()->channels(); | 88 MessagePortChannelArray* channels = constUnwrap<MessageEvent>()->channels(); |
78 WebMessagePortChannelArray webChannels(channels ? channels->size() : 0); | 89 WebMessagePortChannelArray webChannels(channels ? channels->size() : 0); |
79 if (channels) { | 90 if (channels) { |
80 for (size_t i = 0; i < channels->size(); ++i) | 91 for (size_t i = 0; i < channels->size(); ++i) |
81 webChannels[i] = (*channels)[i].leakPtr(); | 92 webChannels[i] = (*channels)[i].leakPtr(); |
82 } | 93 } |
83 return webChannels; | 94 return webChannels; |
84 } | 95 } |
85 | 96 |
86 } // namespace blink | 97 } // namespace blink |
OLD | NEW |