| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 toWebMessagePortChannelArray(std::move(channels)); | 88 toWebMessagePortChannelArray(std::move(channels)); |
| 89 m_entangledChannel->postMessage(messageString, webChannels.release()); | 89 m_entangledChannel->postMessage(messageString, webChannels.release()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // static | 92 // static |
| 93 std::unique_ptr<WebMessagePortChannelArray> | 93 std::unique_ptr<WebMessagePortChannelArray> |
| 94 MessagePort::toWebMessagePortChannelArray( | 94 MessagePort::toWebMessagePortChannelArray( |
| 95 std::unique_ptr<MessagePortChannelArray> channels) { | 95 std::unique_ptr<MessagePortChannelArray> channels) { |
| 96 std::unique_ptr<WebMessagePortChannelArray> webChannels; | 96 std::unique_ptr<WebMessagePortChannelArray> webChannels; |
| 97 if (channels && channels->size()) { | 97 if (channels && channels->size()) { |
| 98 webChannels = wrapUnique(new WebMessagePortChannelArray(channels->size())); | 98 webChannels = |
| 99 WTF::wrapUnique(new WebMessagePortChannelArray(channels->size())); |
| 99 for (size_t i = 0; i < channels->size(); ++i) | 100 for (size_t i = 0; i < channels->size(); ++i) |
| 100 (*webChannels)[i] = (*channels)[i].release(); | 101 (*webChannels)[i] = (*channels)[i].release(); |
| 101 } | 102 } |
| 102 return webChannels; | 103 return webChannels; |
| 103 } | 104 } |
| 104 | 105 |
| 105 // static | 106 // static |
| 106 MessagePortArray* MessagePort::toMessagePortArray( | 107 MessagePortArray* MessagePort::toMessagePortArray( |
| 107 ExecutionContext* context, | 108 ExecutionContext* context, |
| 108 const WebMessagePortChannelArray& webChannels) { | 109 const WebMessagePortChannelArray& webChannels) { |
| 109 std::unique_ptr<MessagePortChannelArray> channels = | 110 std::unique_ptr<MessagePortChannelArray> channels = |
| 110 wrapUnique(new MessagePortChannelArray(webChannels.size())); | 111 WTF::wrapUnique(new MessagePortChannelArray(webChannels.size())); |
| 111 for (size_t i = 0; i < webChannels.size(); ++i) | 112 for (size_t i = 0; i < webChannels.size(); ++i) |
| 112 (*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]); | 113 (*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]); |
| 113 return MessagePort::entanglePorts(*context, std::move(channels)); | 114 return MessagePort::entanglePorts(*context, std::move(channels)); |
| 114 } | 115 } |
| 115 | 116 |
| 116 WebMessagePortChannelUniquePtr MessagePort::disentangle() { | 117 WebMessagePortChannelUniquePtr MessagePort::disentangle() { |
| 117 DCHECK(m_entangledChannel); | 118 DCHECK(m_entangledChannel); |
| 118 m_entangledChannel->setClient(nullptr); | 119 m_entangledChannel->setClient(nullptr); |
| 119 return std::move(m_entangledChannel); | 120 return std::move(m_entangledChannel); |
| 120 } | 121 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 static bool tryGetMessageFrom( | 167 static bool tryGetMessageFrom( |
| 167 WebMessagePortChannel& webChannel, | 168 WebMessagePortChannel& webChannel, |
| 168 RefPtr<SerializedScriptValue>& message, | 169 RefPtr<SerializedScriptValue>& message, |
| 169 std::unique_ptr<MessagePortChannelArray>& channels) { | 170 std::unique_ptr<MessagePortChannelArray>& channels) { |
| 170 WebString messageString; | 171 WebString messageString; |
| 171 WebMessagePortChannelArray webChannels; | 172 WebMessagePortChannelArray webChannels; |
| 172 if (!webChannel.tryGetMessage(&messageString, webChannels)) | 173 if (!webChannel.tryGetMessage(&messageString, webChannels)) |
| 173 return false; | 174 return false; |
| 174 | 175 |
| 175 if (webChannels.size()) { | 176 if (webChannels.size()) { |
| 176 channels = wrapUnique(new MessagePortChannelArray(webChannels.size())); | 177 channels = WTF::wrapUnique(new MessagePortChannelArray(webChannels.size())); |
| 177 for (size_t i = 0; i < webChannels.size(); ++i) | 178 for (size_t i = 0; i < webChannels.size(); ++i) |
| 178 (*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]); | 179 (*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]); |
| 179 } | 180 } |
| 180 message = SerializedScriptValue::create(messageString); | 181 message = SerializedScriptValue::create(messageString); |
| 181 return true; | 182 return true; |
| 182 } | 183 } |
| 183 | 184 |
| 184 bool MessagePort::tryGetMessage( | 185 bool MessagePort::tryGetMessage( |
| 185 RefPtr<SerializedScriptValue>& message, | 186 RefPtr<SerializedScriptValue>& message, |
| 186 std::unique_ptr<MessagePortChannelArray>& channels) { | 187 std::unique_ptr<MessagePortChannelArray>& channels) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 "Port at index " + String::number(i) + " is " + type + "."); | 260 "Port at index " + String::number(i) + " is " + type + "."); |
| 260 return nullptr; | 261 return nullptr; |
| 261 } | 262 } |
| 262 visited.add(port); | 263 visited.add(port); |
| 263 } | 264 } |
| 264 | 265 |
| 265 UseCounter::count(context, UseCounter::MessagePortsTransferred); | 266 UseCounter::count(context, UseCounter::MessagePortsTransferred); |
| 266 | 267 |
| 267 // Passed-in ports passed validity checks, so we can disentangle them. | 268 // Passed-in ports passed validity checks, so we can disentangle them. |
| 268 std::unique_ptr<MessagePortChannelArray> portArray = | 269 std::unique_ptr<MessagePortChannelArray> portArray = |
| 269 wrapUnique(new MessagePortChannelArray(ports.size())); | 270 WTF::wrapUnique(new MessagePortChannelArray(ports.size())); |
| 270 for (unsigned i = 0; i < ports.size(); ++i) | 271 for (unsigned i = 0; i < ports.size(); ++i) |
| 271 (*portArray)[i] = ports[i]->disentangle(); | 272 (*portArray)[i] = ports[i]->disentangle(); |
| 272 return portArray; | 273 return portArray; |
| 273 } | 274 } |
| 274 | 275 |
| 275 MessagePortArray* MessagePort::entanglePorts( | 276 MessagePortArray* MessagePort::entanglePorts( |
| 276 ExecutionContext& context, | 277 ExecutionContext& context, |
| 277 std::unique_ptr<MessagePortChannelArray> channels) { | 278 std::unique_ptr<MessagePortChannelArray> channels) { |
| 278 // https://html.spec.whatwg.org/multipage/comms.html#message-ports | 279 // https://html.spec.whatwg.org/multipage/comms.html#message-ports |
| 279 // |ports| should be an empty array, not null even when there is no ports. | 280 // |ports| should be an empty array, not null even when there is no ports. |
| 280 if (!channels || !channels->size()) | 281 if (!channels || !channels->size()) |
| 281 return new MessagePortArray; | 282 return new MessagePortArray; |
| 282 | 283 |
| 283 MessagePortArray* portArray = new MessagePortArray(channels->size()); | 284 MessagePortArray* portArray = new MessagePortArray(channels->size()); |
| 284 for (unsigned i = 0; i < channels->size(); ++i) { | 285 for (unsigned i = 0; i < channels->size(); ++i) { |
| 285 MessagePort* port = MessagePort::create(context); | 286 MessagePort* port = MessagePort::create(context); |
| 286 port->entangle(std::move((*channels)[i])); | 287 port->entangle(std::move((*channels)[i])); |
| 287 (*portArray)[i] = port; | 288 (*portArray)[i] = port; |
| 288 } | 289 } |
| 289 return portArray; | 290 return portArray; |
| 290 } | 291 } |
| 291 | 292 |
| 292 DEFINE_TRACE(MessagePort) { | 293 DEFINE_TRACE(MessagePort) { |
| 293 ActiveDOMObject::trace(visitor); | 294 ActiveDOMObject::trace(visitor); |
| 294 EventTargetWithInlineData::trace(visitor); | 295 EventTargetWithInlineData::trace(visitor); |
| 295 } | 296 } |
| 296 | 297 |
| 297 } // namespace blink | 298 } // namespace blink |
| OLD | NEW |