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

Unified Diff: third_party/WebKit/Source/core/dom/MessagePort.cpp

Issue 2422793002: HTML MessagePort as mojo::MessagePipeHandle (Closed)
Patch Set: Add missing ScopedAsyncTaskScheduler instance for the new unit tests; required by a recent change t… Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/MessagePort.cpp
diff --git a/third_party/WebKit/Source/core/dom/MessagePort.cpp b/third_party/WebKit/Source/core/dom/MessagePort.cpp
index 136192f9601fdaf82bf4ae1c2d594d0763460335..99d3222bc316012403fcf1cc22c7b1b58c019419 100644
--- a/third_party/WebKit/Source/core/dom/MessagePort.cpp
+++ b/third_party/WebKit/Source/core/dom/MessagePort.cpp
@@ -76,40 +76,34 @@ void MessagePort::postMessage(ScriptState* scriptState,
return;
}
}
- std::unique_ptr<MessagePortChannelArray> channels =
+ MessagePortChannelArray channels =
MessagePort::disentanglePorts(scriptState->getExecutionContext(), ports,
exceptionState);
if (exceptionState.hadException())
return;
WebString messageString = message->toWireString();
- std::unique_ptr<WebMessagePortChannelArray> webChannels =
+ WebMessagePortChannelArray webChannels =
toWebMessagePortChannelArray(std::move(channels));
- m_entangledChannel->postMessage(messageString, webChannels.release());
+ m_entangledChannel->postMessage(messageString, std::move(webChannels));
}
// static
-std::unique_ptr<WebMessagePortChannelArray>
-MessagePort::toWebMessagePortChannelArray(
- std::unique_ptr<MessagePortChannelArray> channels) {
- std::unique_ptr<WebMessagePortChannelArray> webChannels;
- if (channels && channels->size()) {
- webChannels =
- WTF::wrapUnique(new WebMessagePortChannelArray(channels->size()));
- for (size_t i = 0; i < channels->size(); ++i)
- (*webChannels)[i] = (*channels)[i].release();
- }
+WebMessagePortChannelArray MessagePort::toWebMessagePortChannelArray(
+ MessagePortChannelArray channels) {
+ WebMessagePortChannelArray webChannels(channels.size());
+ for (size_t i = 0; i < channels.size(); ++i)
+ webChannels[i] = std::move(channels[i]);
return webChannels;
}
// static
MessagePortArray* MessagePort::toMessagePortArray(
ExecutionContext* context,
- const WebMessagePortChannelArray& webChannels) {
- std::unique_ptr<MessagePortChannelArray> channels =
- WTF::wrapUnique(new MessagePortChannelArray(webChannels.size()));
+ WebMessagePortChannelArray webChannels) {
+ MessagePortChannelArray channels(webChannels.size());
for (size_t i = 0; i < webChannels.size(); ++i)
- (*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]);
+ channels[i] = std::move(webChannels[i]);
return MessagePort::entanglePorts(*context, std::move(channels));
}
@@ -165,27 +159,25 @@ const AtomicString& MessagePort::interfaceName() const {
return EventTargetNames::MessagePort;
}
-static bool tryGetMessageFrom(
- WebMessagePortChannel& webChannel,
- RefPtr<SerializedScriptValue>& message,
- std::unique_ptr<MessagePortChannelArray>& channels) {
+static bool tryGetMessageFrom(WebMessagePortChannel& webChannel,
+ RefPtr<SerializedScriptValue>& message,
+ MessagePortChannelArray& channels) {
WebString messageString;
WebMessagePortChannelArray webChannels;
if (!webChannel.tryGetMessage(&messageString, webChannels))
return false;
if (webChannels.size()) {
- channels = WTF::wrapUnique(new MessagePortChannelArray(webChannels.size()));
+ channels.resize(webChannels.size());
for (size_t i = 0; i < webChannels.size(); ++i)
- (*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]);
+ channels[i] = std::move(webChannels[i]);
}
message = SerializedScriptValue::create(messageString);
return true;
}
-bool MessagePort::tryGetMessage(
- RefPtr<SerializedScriptValue>& message,
- std::unique_ptr<MessagePortChannelArray>& channels) {
+bool MessagePort::tryGetMessage(RefPtr<SerializedScriptValue>& message,
+ MessagePortChannelArray& channels) {
if (!m_entangledChannel)
return false;
return tryGetMessageFrom(*m_entangledChannel, message, channels);
@@ -214,7 +206,7 @@ void MessagePort::dispatchMessages() {
}
RefPtr<SerializedScriptValue> message;
- std::unique_ptr<MessagePortChannelArray> channels;
+ MessagePortChannelArray channels;
if (!tryGetMessage(message, channels))
break;
@@ -235,12 +227,12 @@ bool MessagePort::hasPendingActivity() const {
return m_started && isEntangled();
}
-std::unique_ptr<MessagePortChannelArray> MessagePort::disentanglePorts(
+MessagePortChannelArray MessagePort::disentanglePorts(
ExecutionContext* context,
const MessagePortArray& ports,
ExceptionState& exceptionState) {
if (!ports.size())
- return nullptr;
+ return MessagePortChannelArray();
HeapHashSet<Member<MessagePort>> visited;
@@ -259,7 +251,7 @@ std::unique_ptr<MessagePortChannelArray> MessagePort::disentanglePorts(
exceptionState.throwDOMException(
DataCloneError,
"Port at index " + String::number(i) + " is " + type + ".");
- return nullptr;
+ return MessagePortChannelArray();
}
visited.insert(port);
}
@@ -267,25 +259,20 @@ std::unique_ptr<MessagePortChannelArray> MessagePort::disentanglePorts(
UseCounter::count(context, UseCounter::MessagePortsTransferred);
// Passed-in ports passed validity checks, so we can disentangle them.
- std::unique_ptr<MessagePortChannelArray> portArray =
- WTF::wrapUnique(new MessagePortChannelArray(ports.size()));
+ MessagePortChannelArray portArray(ports.size());
for (unsigned i = 0; i < ports.size(); ++i)
- (*portArray)[i] = ports[i]->disentangle();
+ portArray[i] = ports[i]->disentangle();
return portArray;
}
-MessagePortArray* MessagePort::entanglePorts(
- ExecutionContext& context,
- std::unique_ptr<MessagePortChannelArray> channels) {
+MessagePortArray* MessagePort::entanglePorts(ExecutionContext& context,
+ MessagePortChannelArray channels) {
// https://html.spec.whatwg.org/multipage/comms.html#message-ports
// |ports| should be an empty array, not null even when there is no ports.
- if (!channels || !channels->size())
- return new MessagePortArray;
-
- MessagePortArray* portArray = new MessagePortArray(channels->size());
- for (unsigned i = 0; i < channels->size(); ++i) {
+ MessagePortArray* portArray = new MessagePortArray(channels.size());
+ for (unsigned i = 0; i < channels.size(); ++i) {
MessagePort* port = MessagePort::create(context);
- port->entangle(std::move((*channels)[i]));
+ port->entangle(std::move(channels[i]));
(*portArray)[i] = port;
}
return portArray;
« no previous file with comments | « third_party/WebKit/Source/core/dom/MessagePort.h ('k') | third_party/WebKit/Source/core/events/MessageEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698