| 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 30 matching lines...) Expand all Loading... |
| 41 #include "public/web/WebSerializedScriptValue.h" | 41 #include "public/web/WebSerializedScriptValue.h" |
| 42 #include "web/WebLocalFrameImpl.h" | 42 #include "web/WebLocalFrameImpl.h" |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 WebDOMMessageEvent::WebDOMMessageEvent( | 46 WebDOMMessageEvent::WebDOMMessageEvent( |
| 47 const WebSerializedScriptValue& messageData, | 47 const WebSerializedScriptValue& messageData, |
| 48 const WebString& origin, | 48 const WebString& origin, |
| 49 const WebFrame* sourceFrame, | 49 const WebFrame* sourceFrame, |
| 50 const WebDocument& targetDocument, | 50 const WebDocument& targetDocument, |
| 51 const WebMessagePortChannelArray& channels) | 51 WebMessagePortChannelArray channels) |
| 52 : WebDOMMessageEvent(MessageEvent::create()) { | 52 : WebDOMMessageEvent(MessageEvent::create()) { |
| 53 DOMWindow* window = nullptr; | 53 DOMWindow* window = nullptr; |
| 54 if (sourceFrame) | 54 if (sourceFrame) |
| 55 window = sourceFrame->toImplBase()->frame()->domWindow(); | 55 window = sourceFrame->toImplBase()->frame()->domWindow(); |
| 56 MessagePortArray* ports = nullptr; | 56 MessagePortArray* ports = nullptr; |
| 57 if (!targetDocument.isNull()) { | 57 if (!targetDocument.isNull()) { |
| 58 Document* coreDocument = targetDocument; | 58 Document* coreDocument = targetDocument; |
| 59 ports = MessagePort::toMessagePortArray(coreDocument, channels); | 59 ports = MessagePort::toMessagePortArray(coreDocument, std::move(channels)); |
| 60 } | 60 } |
| 61 // Use an empty array for |ports| when it is null because this function | 61 // Use an empty array for |ports| when it is null because this function |
| 62 // is used to implement postMessage(). | 62 // is used to implement postMessage(). |
| 63 if (!ports) | 63 if (!ports) |
| 64 ports = new MessagePortArray; | 64 ports = new MessagePortArray; |
| 65 // TODO(esprehn): Chromium always passes empty string for lastEventId, is that | 65 // TODO(esprehn): Chromium always passes empty string for lastEventId, is that |
| 66 // right? | 66 // right? |
| 67 unwrap<MessageEvent>()->initMessageEvent("message", false, false, messageData, | 67 unwrap<MessageEvent>()->initMessageEvent("message", false, false, messageData, |
| 68 origin, "" /*lastEventId*/, window, | 68 origin, "" /*lastEventId*/, window, |
| 69 ports); | 69 ports); |
| 70 } | 70 } |
| 71 | 71 |
| 72 WebSerializedScriptValue WebDOMMessageEvent::data() const { | 72 WebSerializedScriptValue WebDOMMessageEvent::data() const { |
| 73 return WebSerializedScriptValue( | 73 return WebSerializedScriptValue( |
| 74 constUnwrap<MessageEvent>()->dataAsSerializedScriptValue()); | 74 constUnwrap<MessageEvent>()->dataAsSerializedScriptValue()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 WebString WebDOMMessageEvent::origin() const { | 77 WebString WebDOMMessageEvent::origin() const { |
| 78 return WebString(constUnwrap<MessageEvent>()->origin()); | 78 return WebString(constUnwrap<MessageEvent>()->origin()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 WebMessagePortChannelArray WebDOMMessageEvent::releaseChannels() { | 81 WebMessagePortChannelArray WebDOMMessageEvent::releaseChannels() { |
| 82 MessagePortChannelArray* channels = constUnwrap<MessageEvent>()->channels(); | 82 MessagePortChannelArray channels = unwrap<MessageEvent>()->releaseChannels(); |
| 83 WebMessagePortChannelArray webChannels(channels ? channels->size() : 0); | 83 WebMessagePortChannelArray webChannels(channels.size()); |
| 84 if (channels) { | 84 for (size_t i = 0; i < channels.size(); ++i) |
| 85 for (size_t i = 0; i < channels->size(); ++i) | 85 webChannels[i] = std::move(channels[i]); |
| 86 webChannels[i] = (*channels)[i].release(); | |
| 87 } | |
| 88 return webChannels; | 86 return webChannels; |
| 89 } | 87 } |
| 90 | 88 |
| 91 } // namespace blink | 89 } // namespace blink |
| OLD | NEW |