Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: third_party/WebKit/Source/modules/broadcastchannel/BroadcastChannel.cpp

Issue 2171843002: Use array<uint8> rather than string to pass BroadcastChannel messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 void BroadcastChannel::postMessage(const ScriptValue& message, ExceptionState& e xceptionState) 56 void BroadcastChannel::postMessage(const ScriptValue& message, ExceptionState& e xceptionState)
57 { 57 {
58 if (!m_binding.is_bound()) { 58 if (!m_binding.is_bound()) {
59 exceptionState.throwDOMException(InvalidStateError, "Channel is closed") ; 59 exceptionState.throwDOMException(InvalidStateError, "Channel is closed") ;
60 return; 60 return;
61 } 61 }
62 RefPtr<SerializedScriptValue> value = SerializedScriptValue::serialize(messa ge.isolate(), message.v8Value(), nullptr, nullptr, exceptionState); 62 RefPtr<SerializedScriptValue> value = SerializedScriptValue::serialize(messa ge.isolate(), message.v8Value(), nullptr, nullptr, exceptionState);
63 if (exceptionState.hadException()) 63 if (exceptionState.hadException())
64 return; 64 return;
65 65
66 String data = value->toWireString(); 66 Vector<char> data;
esprehn 2016/07/23 08:53:50 you want to call reserveInitialCapacity on both of
Marijn Kruisselbrink 2016/07/23 19:14:18 Not sure what resized and copies that would avoid?
67 m_remoteClient->OnMessage(data); 67 value->toWireBytes(data);
68 Vector<uint8_t> mojoData;
69 mojoData.appendVector(data);
dcheng 2016/07/22 02:33:03 It's sad that this results in copying the data now
Marijn Kruisselbrink 2016/07/22 03:23:12 Yeah... but reinterpret_casting a Vector didn't se
70 m_remoteClient->OnMessage(std::move(mojoData));
68 } 71 }
69 72
70 void BroadcastChannel::close() 73 void BroadcastChannel::close()
71 { 74 {
72 m_remoteClient.reset(); 75 m_remoteClient.reset();
73 if (m_binding.is_bound()) 76 if (m_binding.is_bound())
74 m_binding.Close(); 77 m_binding.Close();
75 } 78 }
76 79
77 const AtomicString& BroadcastChannel::interfaceName() const 80 const AtomicString& BroadcastChannel::interfaceName() const
(...skipping 10 matching lines...) Expand all
88 { 91 {
89 close(); 92 close();
90 } 93 }
91 94
92 DEFINE_TRACE(BroadcastChannel) 95 DEFINE_TRACE(BroadcastChannel)
93 { 96 {
94 ContextLifecycleObserver::trace(visitor); 97 ContextLifecycleObserver::trace(visitor);
95 EventTargetWithInlineData::trace(visitor); 98 EventTargetWithInlineData::trace(visitor);
96 } 99 }
97 100
98 void BroadcastChannel::OnMessage(const String& message) 101 void BroadcastChannel::OnMessage(mojo::WTFArray<uint8_t> message)
99 { 102 {
100 // Queue a task to dispatch the event. 103 // Queue a task to dispatch the event.
101 RefPtr<SerializedScriptValue> value = SerializedScriptValue::create(message) ; 104 RefPtr<SerializedScriptValue> value = SerializedScriptValue::create(reinterp ret_cast<const char*>(&message.front()), message.size());
102 MessageEvent* event = MessageEvent::create(nullptr, value.release(), getExec utionContext()->getSecurityOrigin()->toString()); 105 MessageEvent* event = MessageEvent::create(nullptr, value.release(), getExec utionContext()->getSecurityOrigin()->toString());
103 event->setTarget(this); 106 event->setTarget(this);
104 bool success = getExecutionContext()->getEventQueue()->enqueueEvent(event); 107 bool success = getExecutionContext()->getEventQueue()->enqueueEvent(event);
105 DCHECK(success); 108 DCHECK(success);
106 ALLOW_UNUSED_LOCAL(success); 109 ALLOW_UNUSED_LOCAL(success);
107 } 110 }
108 111
109 void BroadcastChannel::onError() 112 void BroadcastChannel::onError()
110 { 113 {
111 close(); 114 close();
(...skipping 17 matching lines...) Expand all
129 mojom::blink::BroadcastChannelClientAssociatedPtrInfo remoteClientInfo; 132 mojom::blink::BroadcastChannelClientAssociatedPtrInfo remoteClientInfo;
130 mojo::AssociatedInterfaceRequest<mojom::blink::BroadcastChannelClient> remot eCientRequest; 133 mojo::AssociatedInterfaceRequest<mojom::blink::BroadcastChannelClient> remot eCientRequest;
131 provider.associated_group()->CreateAssociatedInterface(mojo::AssociatedGroup ::WILL_PASS_REQUEST, &remoteClientInfo, &remoteCientRequest); 134 provider.associated_group()->CreateAssociatedInterface(mojo::AssociatedGroup ::WILL_PASS_REQUEST, &remoteClientInfo, &remoteCientRequest);
132 m_remoteClient.Bind(std::move(remoteClientInfo)); 135 m_remoteClient.Bind(std::move(remoteClientInfo));
133 m_remoteClient.set_connection_error_handler(convertToBaseCallback(WTF::bind( &BroadcastChannel::onError, wrapWeakPersistent(this)))); 136 m_remoteClient.set_connection_error_handler(convertToBaseCallback(WTF::bind( &BroadcastChannel::onError, wrapWeakPersistent(this))));
134 137
135 provider->ConnectToChannel(m_origin, m_name, std::move(localClientInfo), std ::move(remoteCientRequest)); 138 provider->ConnectToChannel(m_origin, m_name, std::move(localClientInfo), std ::move(remoteCientRequest));
136 } 139 }
137 140
138 } // namespace blink 141 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698