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

Unified Diff: Source/web/ServiceWorkerGlobalScopeProxy.cpp

Issue 185643009: Implement ServiceWorker::postMessage() [Blink] (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased Created 6 years, 9 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/web/ServiceWorkerGlobalScopeProxy.cpp
diff --git a/Source/web/ServiceWorkerGlobalScopeProxy.cpp b/Source/web/ServiceWorkerGlobalScopeProxy.cpp
index 80307f05cd84d2b0a73d0826f7182c8fe0e5f898..15c31d0cc9f2717b8ed287e7eed6705cb4b73af3 100644
--- a/Source/web/ServiceWorkerGlobalScopeProxy.cpp
+++ b/Source/web/ServiceWorkerGlobalScopeProxy.cpp
@@ -32,9 +32,12 @@
#include "ServiceWorkerGlobalScopeProxy.h"
#include "WebEmbeddedWorkerImpl.h"
+#include "WebSerializedScriptValue.h"
#include "WebServiceWorkerContextClient.h"
#include "bindings/v8/WorkerScriptController.h"
#include "core/dom/ExecutionContext.h"
+#include "core/dom/MessagePort.h"
+#include "core/events/MessageEvent.h"
#include "core/events/ThreadLocalEventNames.h"
#include "core/workers/WorkerGlobalScope.h"
#include "modules/serviceworkers/FetchEvent.h"
@@ -74,6 +77,22 @@ void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(int eventID)
observer->didDispatchEvent();
}
+void ServiceWorkerGlobalScopeProxy::dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray& webChannels)
+{
+ ASSERT(m_workerGlobalScope);
+
+ OwnPtr<MessagePortArray> ports;
+ if (!webChannels.isEmpty()) {
+ OwnPtr<MessagePortChannelArray> channels = adoptPtr(new MessagePortChannelArray(webChannels.size()));
+ for (size_t i = 0; i < webChannels.size(); ++i)
adamk 2014/03/19 17:48:58 This loop, too, it would be nice to share, again s
jsbell 2014/03/19 21:06:47 And ditto for this one.
+ (*channels)[i] = adoptPtr(webChannels[i]);
+ ports = MessagePort::entanglePorts(*m_workerGlobalScope, channels.release());
+ }
+
+ WebSerializedScriptValue value = WebSerializedScriptValue::fromString(message);
+ m_workerGlobalScope->dispatchEvent(MessageEvent::create(ports.release(), value));
+}
+
void ServiceWorkerGlobalScopeProxy::reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL)
{
m_client.reportException(errorMessage, lineNumber, columnNumber, sourceURL);

Powered by Google App Engine
This is Rietveld 408576698