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 |
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) | |
48 { | |
49 ASSERT(m_private.get()); | |
50 ASSERT(isMessageEvent()); | |
51 DOMWindow* window = nullptr; | |
52 if (sourceFrame) | |
53 window = toCoreFrame(sourceFrame)->domWindow(); | |
54 RefPtrWillBeRawPtr<Document> coreDocument = PassRefPtrWillBeRawPtr<Document> (targetDocument); | |
55 MessagePortArray* ports = MessagePort::toMessagePortArray(coreDocument.get() , webChannels); | |
56 // Use an empty array for |ports| when it is null because this function | |
57 // is used to implement postMessage(). | |
58 if (!ports) | |
59 ports = new MessagePortArray; | |
60 unwrap<MessageEvent>()->initMessageEvent(type, canBubble, cancelable, messag eData, origin, lastEventId, window, ports); | |
61 } | |
62 | |
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) | 63 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 { | 64 { |
48 ASSERT(m_private.get()); | 65 ASSERT(m_private.get()); |
dcheng
2015/08/15 05:12:30
Can we re-express this in terms of the new interfa
sgurun-gerrit only
2015/08/18 15:17:30
Done.
| |
49 ASSERT(isMessageEvent()); | 66 ASSERT(isMessageEvent()); |
50 DOMWindow* window = nullptr; | 67 DOMWindow* window = nullptr; |
51 // TODO(alexmos): Figure out if this is the right thing to do. | 68 // TODO(alexmos): Figure out if this is the right thing to do. |
52 if (sourceFrame) | 69 if (sourceFrame) |
53 window = toCoreFrame(sourceFrame)->domWindow(); | 70 window = toCoreFrame(sourceFrame)->domWindow(); |
54 MessagePortArray* ports = nullptr; | 71 MessagePortArray* ports = nullptr; |
55 // TODO(alexmos): make ports work properly with OOPIF. | 72 // TODO(alexmos): make ports work properly with OOPIF. |
56 if (sourceFrame && sourceFrame->isWebLocalFrame()) | 73 if (sourceFrame && sourceFrame->isWebLocalFrame()) |
57 ports = MessagePort::toMessagePortArray(toLocalDOMWindow(window)->docume nt(), webChannels); | 74 ports = MessagePort::toMessagePortArray(toLocalDOMWindow(window)->docume nt(), webChannels); |
58 // Use an empty array for |ports| when it is null because this function | 75 // Use an empty array for |ports| when it is null because this function |
(...skipping 18 matching lines...) Expand all Loading... | |
77 MessagePortChannelArray* channels = constUnwrap<MessageEvent>()->channels(); | 94 MessagePortChannelArray* channels = constUnwrap<MessageEvent>()->channels(); |
78 WebMessagePortChannelArray webChannels(channels ? channels->size() : 0); | 95 WebMessagePortChannelArray webChannels(channels ? channels->size() : 0); |
79 if (channels) { | 96 if (channels) { |
80 for (size_t i = 0; i < channels->size(); ++i) | 97 for (size_t i = 0; i < channels->size(); ++i) |
81 webChannels[i] = (*channels)[i].leakPtr(); | 98 webChannels[i] = (*channels)[i].leakPtr(); |
82 } | 99 } |
83 return webChannels; | 100 return webChannels; |
84 } | 101 } |
85 | 102 |
86 } // namespace blink | 103 } // namespace blink |
OLD | NEW |