| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/broadcastchannel/BroadcastChannel.h" | 5 #include "modules/broadcastchannel/BroadcastChannel.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/SerializedScriptValue.h" | 7 #include "bindings/core/v8/SerializedScriptValue.h" |
| 8 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
| 9 #include "core/events/EventQueue.h" | 9 #include "core/events/EventQueue.h" |
| 10 #include "core/events/MessageEvent.h" | 10 #include "core/events/MessageEvent.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 void BroadcastChannel::contextDestroyed() { | 98 void BroadcastChannel::contextDestroyed() { |
| 99 close(); | 99 close(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 DEFINE_TRACE(BroadcastChannel) { | 102 DEFINE_TRACE(BroadcastChannel) { |
| 103 ContextLifecycleObserver::trace(visitor); | 103 ContextLifecycleObserver::trace(visitor); |
| 104 EventTargetWithInlineData::trace(visitor); | 104 EventTargetWithInlineData::trace(visitor); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void BroadcastChannel::OnMessage(mojo::WTFArray<uint8_t> message) { | 107 void BroadcastChannel::OnMessage(const WTF::Vector<uint8_t>& message) { |
| 108 // Queue a task to dispatch the event. | 108 // Queue a task to dispatch the event. |
| 109 RefPtr<SerializedScriptValue> value = SerializedScriptValue::create( | 109 RefPtr<SerializedScriptValue> value = SerializedScriptValue::create( |
| 110 reinterpret_cast<const char*>(&message.front()), message.size()); | 110 message.isEmpty() ? nullptr |
| 111 : reinterpret_cast<const char*>(&message.first()), |
| 112 message.size()); |
| 111 MessageEvent* event = MessageEvent::create( | 113 MessageEvent* event = MessageEvent::create( |
| 112 nullptr, value.release(), | 114 nullptr, value.release(), |
| 113 getExecutionContext()->getSecurityOrigin()->toString()); | 115 getExecutionContext()->getSecurityOrigin()->toString()); |
| 114 event->setTarget(this); | 116 event->setTarget(this); |
| 115 bool success = getExecutionContext()->getEventQueue()->enqueueEvent(event); | 117 bool success = getExecutionContext()->getEventQueue()->enqueueEvent(event); |
| 116 DCHECK(success); | 118 DCHECK(success); |
| 117 ALLOW_UNUSED_LOCAL(success); | 119 ALLOW_UNUSED_LOCAL(success); |
| 118 } | 120 } |
| 119 | 121 |
| 120 void BroadcastChannel::onError() { | 122 void BroadcastChannel::onError() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 150 &remoteCientRequest); | 152 &remoteCientRequest); |
| 151 m_remoteClient.Bind(std::move(remoteClientInfo)); | 153 m_remoteClient.Bind(std::move(remoteClientInfo)); |
| 152 m_remoteClient.set_connection_error_handler(convertToBaseCallback( | 154 m_remoteClient.set_connection_error_handler(convertToBaseCallback( |
| 153 WTF::bind(&BroadcastChannel::onError, wrapWeakPersistent(this)))); | 155 WTF::bind(&BroadcastChannel::onError, wrapWeakPersistent(this)))); |
| 154 | 156 |
| 155 provider->ConnectToChannel(m_origin, m_name, std::move(localClientInfo), | 157 provider->ConnectToChannel(m_origin, m_name, std::move(localClientInfo), |
| 156 std::move(remoteCientRequest)); | 158 std::move(remoteCientRequest)); |
| 157 } | 159 } |
| 158 | 160 |
| 159 } // namespace blink | 161 } // namespace blink |
| OLD | NEW |