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

Unified Diff: Source/modules/serviceworkers/StashedMessagePort.cpp

Issue 1008533005: Initial implementation of stashed message ports, blink side (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 5 years, 7 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: Source/modules/serviceworkers/StashedMessagePort.cpp
diff --git a/Source/modules/serviceworkers/StashedMessagePort.cpp b/Source/modules/serviceworkers/StashedMessagePort.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..34fa00e3b794b9354603a7e25c172e41a175a67f
--- /dev/null
+++ b/Source/modules/serviceworkers/StashedMessagePort.cpp
@@ -0,0 +1,73 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "modules/serviceworkers/StashedMessagePort.h"
+
+#include "bindings/core/v8/SerializedScriptValue.h"
+#include "core/dom/CrossThreadTask.h"
+#include "core/events/MessageEvent.h"
+#include "modules/serviceworkers/ServiceWorkerGlobalScope.h"
+#include "modules/serviceworkers/StashedPortCollection.h"
+#include "public/platform/WebTraceLocation.h"
+
+namespace blink {
+
+PassRefPtrWillBeRawPtr<StashedMessagePort> StashedMessagePort::create(ExecutionContext& executionContext, PassOwnPtr<WebMessagePortChannel> remote, const String& name)
+{
+ RefPtrWillBeRawPtr<StashedMessagePort> port = adoptRefWillBeNoop(new StashedMessagePort(executionContext, remote, name));
+ port->suspendIfNeeded();
+ return port.release();
+}
+
+StashedMessagePort::StashedMessagePort(ExecutionContext& executionContext, PassOwnPtr<WebMessagePortChannel> remote, const String& name)
+ : MessagePort(executionContext), m_name(name), m_weakFactory(this)
+{
+ entangle(remote);
+ start();
+}
+
+StashedMessagePort::~StashedMessagePort()
+{
+}
+
+PassOwnPtrWillBeRawPtr<StashedMessagePortArray> StashedMessagePort::toStashedMessagePortArray(ExecutionContext* context, const WebMessagePortChannelArray& webChannels, const WebVector<WebString>& channelKeys)
+{
+ OwnPtrWillBeRawPtr<StashedMessagePortArray> ports = adoptPtrWillBeNoop(new StashedMessagePortArray(webChannels.size()));
+ for (size_t i = 0; i < webChannels.size(); ++i) {
+ OwnPtr<WebMessagePortChannel> channel(adoptPtr(webChannels[i]));
+ (*ports)[i] = StashedMessagePort::create(*context, channel.release(), channelKeys[i]);
+ }
+ return ports.release();
+}
+
+String StashedMessagePort::name() const
+{
+ return m_name;
+}
+
+void StashedMessagePort::messageAvailable()
+{
+ ASSERT(executionContext());
+ executionContext()->postTask(FROM_HERE, createCrossThreadTask(&StashedMessagePort::dispatchMessages, m_weakFactory.createWeakPtr()));
+}
+
+void StashedMessagePort::dispatchMessages()
+{
+ if (!isEntangled())
+ return;
+ ASSERT(executionContext()->isServiceWorkerGlobalScope());
+ RefPtr<StashedPortCollection> stashedPorts = toServiceWorkerGlobalScope(executionContext())->ports();
+
+ RefPtr<SerializedScriptValue> message;
+ OwnPtr<MessagePortChannelArray> channels;
+ while (tryGetMessage(message, channels)) {
+ OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::entanglePorts(*executionContext(), channels.release());
+ RefPtrWillBeRawPtr<Event> evt = MessageEvent::create(ports.release(), message.release(), String(), String(), this);
+
+ stashedPorts->dispatchEvent(evt.release(), ASSERT_NO_EXCEPTION);
+ }
+}
+
+} // namespace blink
« no previous file with comments | « Source/modules/serviceworkers/StashedMessagePort.h ('k') | Source/modules/serviceworkers/StashedMessagePort.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698