| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "modules/serviceworkers/ServiceWorkerMessageEvent.h" | |
| 6 | |
| 7 namespace blink { | |
| 8 | |
| 9 ServiceWorkerMessageEvent::ServiceWorkerMessageEvent( | |
| 10 const AtomicString& type, | |
| 11 const ServiceWorkerMessageEventInit& initializer) | |
| 12 : Event(type, initializer) { | |
| 13 if (initializer.hasOrigin()) | |
| 14 m_origin = initializer.origin(); | |
| 15 if (initializer.hasLastEventId()) | |
| 16 m_lastEventId = initializer.lastEventId(); | |
| 17 if (initializer.hasSource()) { | |
| 18 if (initializer.source().isServiceWorker()) | |
| 19 m_sourceAsServiceWorker = initializer.source().getAsServiceWorker(); | |
| 20 else if (initializer.source().isMessagePort()) | |
| 21 m_sourceAsMessagePort = initializer.source().getAsMessagePort(); | |
| 22 } | |
| 23 if (initializer.hasPorts()) | |
| 24 m_ports = new MessagePortArray(initializer.ports()); | |
| 25 } | |
| 26 | |
| 27 ServiceWorkerMessageEvent::ServiceWorkerMessageEvent( | |
| 28 PassRefPtr<SerializedScriptValue> data, | |
| 29 const String& origin, | |
| 30 const String& lastEventId, | |
| 31 ServiceWorker* source, | |
| 32 MessagePortArray* ports) | |
| 33 : Event(EventTypeNames::message, false, false), | |
| 34 m_serializedData(data), | |
| 35 m_origin(origin), | |
| 36 m_lastEventId(lastEventId), | |
| 37 m_sourceAsServiceWorker(source), | |
| 38 m_ports(ports) { | |
| 39 if (m_serializedData) | |
| 40 m_serializedData->registerMemoryAllocatedWithCurrentScriptContext(); | |
| 41 } | |
| 42 | |
| 43 ServiceWorkerMessageEvent::~ServiceWorkerMessageEvent() {} | |
| 44 | |
| 45 MessagePortArray ServiceWorkerMessageEvent::ports(bool& isNull) const { | |
| 46 // TODO(bashi): Currently we return a copied array because the binding | |
| 47 // layer could modify the content of the array while executing JS callbacks. | |
| 48 // Avoid copying once we can make sure that the binding layer won't | |
| 49 // modify the content. | |
| 50 if (m_ports) { | |
| 51 isNull = false; | |
| 52 return *m_ports; | |
| 53 } | |
| 54 isNull = true; | |
| 55 return MessagePortArray(); | |
| 56 } | |
| 57 | |
| 58 MessagePortArray ServiceWorkerMessageEvent::ports() const { | |
| 59 bool unused; | |
| 60 return ports(unused); | |
| 61 } | |
| 62 | |
| 63 void ServiceWorkerMessageEvent::source( | |
| 64 ServiceWorkerOrMessagePort& result) const { | |
| 65 if (m_sourceAsServiceWorker) | |
| 66 result = | |
| 67 ServiceWorkerOrMessagePort::fromServiceWorker(m_sourceAsServiceWorker); | |
| 68 else if (m_sourceAsMessagePort) | |
| 69 result = ServiceWorkerOrMessagePort::fromMessagePort(m_sourceAsMessagePort); | |
| 70 } | |
| 71 | |
| 72 const AtomicString& ServiceWorkerMessageEvent::interfaceName() const { | |
| 73 return EventNames::ServiceWorkerMessageEvent; | |
| 74 } | |
| 75 | |
| 76 DEFINE_TRACE(ServiceWorkerMessageEvent) { | |
| 77 visitor->trace(m_sourceAsServiceWorker); | |
| 78 visitor->trace(m_sourceAsMessagePort); | |
| 79 visitor->trace(m_ports); | |
| 80 Event::trace(visitor); | |
| 81 } | |
| 82 | |
| 83 } // namespace blink | |
| OLD | NEW |