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

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

Issue 1130113006: ServiceWorker: Introduce ServiceWorkerMessageEvent to replace MessageEvent (3/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: make more tests pass Created 5 years, 6 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/ServiceWorkerMessageEvent.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorkerMessageEvent.cpp b/Source/modules/serviceworkers/ServiceWorkerMessageEvent.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..322fcc852d1917be4155808f0603d3a8dd53676a
--- /dev/null
+++ b/Source/modules/serviceworkers/ServiceWorkerMessageEvent.cpp
@@ -0,0 +1,88 @@
+// 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/ServiceWorkerMessageEvent.h"
+
+namespace blink {
+
+ServiceWorkerMessageEvent::ServiceWorkerMessageEvent()
+{
+}
+
+ServiceWorkerMessageEvent::ServiceWorkerMessageEvent(const AtomicString& type, const ServiceWorkerMessageEventInit& initializer)
+ : Event(type, initializer)
+{
+ if (initializer.hasOrigin())
+ m_origin = initializer.origin();
+ if (initializer.hasLastEventId())
+ m_lastEventId = initializer.lastEventId();
+ if (initializer.hasSource()) {
+ if (initializer.source().isServiceWorker())
+ m_sourceAsServiceWorker = initializer.source().getAsServiceWorker();
+ else if (initializer.source().isMessagePort())
+ m_sourceAsMessagePort = initializer.source().getAsMessagePort();
+ }
+ if (initializer.hasPorts())
+ m_ports = adoptPtrWillBeNoop(new MessagePortArray(initializer.ports()));
+ if (initializer.hasData())
+ m_data = initializer.data();
+}
+
+ServiceWorkerMessageEvent::ServiceWorkerMessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, PassRefPtrWillBeRawPtr<ServiceWorker> source, PassOwnPtrWillBeRawPtr<MessagePortArray> ports)
+ : Event(EventTypeNames::message, false, false)
+ , m_serializedData(data)
+ , m_origin(origin)
+ , m_lastEventId(lastEventId)
+ , m_sourceAsServiceWorker(source)
+ , m_ports(ports)
+{
+ if (m_serializedData)
+ m_serializedData->registerMemoryAllocatedWithCurrentScriptContext();
+}
+
+ServiceWorkerMessageEvent::~ServiceWorkerMessageEvent()
+{
+}
+
+MessagePortArray ServiceWorkerMessageEvent::ports(bool& isNull) const
+{
+ if (m_ports) {
+ isNull = false;
+ return *m_ports;
+ }
+ isNull = true;
+ return MessagePortArray();
+}
+
+MessagePortArray ServiceWorkerMessageEvent::ports() const
+{
+ bool unused;
+ return ports(unused);
+}
+
+void ServiceWorkerMessageEvent::source(ServiceWorkerOrMessagePort& result) const
+{
+ if (m_sourceAsServiceWorker)
+ result = ServiceWorkerOrMessagePort::fromServiceWorker(m_sourceAsServiceWorker);
+ else if (m_sourceAsMessagePort)
+ result = ServiceWorkerOrMessagePort::fromMessagePort(m_sourceAsMessagePort);
+}
+
+const AtomicString& ServiceWorkerMessageEvent::interfaceName() const
+{
+ return EventNames::ServiceWorkerMessageEvent;
+}
+
+DEFINE_TRACE(ServiceWorkerMessageEvent)
+{
+ visitor->trace(m_sourceAsServiceWorker);
+ visitor->trace(m_sourceAsMessagePort);
+#if ENABLE(OILPAN)
+ visitor->trace(m_ports);
+#endif
+ Event::trace(visitor);
+}
+
+} // namespace blink
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerMessageEvent.h ('k') | Source/modules/serviceworkers/ServiceWorkerMessageEvent.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698