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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
(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 "config.h"
6 #include "modules/serviceworkers/ServiceWorkerMessageEvent.h"
7
8 namespace blink {
9
10 ServiceWorkerMessageEvent::ServiceWorkerMessageEvent()
11 {
12 }
13
14 ServiceWorkerMessageEvent::ServiceWorkerMessageEvent(const AtomicString& type, c onst ServiceWorkerMessageEventInit& initializer)
15 : Event(type, initializer)
16 {
17 if (initializer.hasOrigin())
18 m_origin = initializer.origin();
19 if (initializer.hasLastEventId())
20 m_lastEventId = initializer.lastEventId();
21 if (initializer.hasSource()) {
22 if (initializer.source().isServiceWorker())
23 m_sourceAsServiceWorker = initializer.source().getAsServiceWorker();
24 else if (initializer.source().isMessagePort())
25 m_sourceAsMessagePort = initializer.source().getAsMessagePort();
26 }
27 if (initializer.hasPorts())
28 m_ports = adoptPtrWillBeNoop(new MessagePortArray(initializer.ports()));
29 if (initializer.hasData())
30 m_data = initializer.data();
31 }
32
33 ServiceWorkerMessageEvent::ServiceWorkerMessageEvent(PassRefPtr<SerializedScript Value> data, const String& origin, const String& lastEventId, PassRefPtrWillBeRa wPtr<ServiceWorker> source, PassOwnPtrWillBeRawPtr<MessagePortArray> ports)
34 : Event(EventTypeNames::message, false, false)
35 , m_serializedData(data)
36 , m_origin(origin)
37 , m_lastEventId(lastEventId)
38 , m_sourceAsServiceWorker(source)
39 , m_ports(ports)
40 {
41 if (m_serializedData)
42 m_serializedData->registerMemoryAllocatedWithCurrentScriptContext();
43 }
44
45 ServiceWorkerMessageEvent::~ServiceWorkerMessageEvent()
46 {
47 }
48
49 MessagePortArray ServiceWorkerMessageEvent::ports(bool& isNull) const
50 {
51 if (m_ports) {
52 isNull = false;
53 return *m_ports;
54 }
55 isNull = true;
56 return MessagePortArray();
57 }
58
59 MessagePortArray ServiceWorkerMessageEvent::ports() const
60 {
61 bool unused;
62 return ports(unused);
63 }
64
65 void ServiceWorkerMessageEvent::source(ServiceWorkerOrMessagePort& result) const
66 {
67 if (m_sourceAsServiceWorker)
68 result = ServiceWorkerOrMessagePort::fromServiceWorker(m_sourceAsService Worker);
69 else if (m_sourceAsMessagePort)
70 result = ServiceWorkerOrMessagePort::fromMessagePort(m_sourceAsMessagePo rt);
71 }
72
73 const AtomicString& ServiceWorkerMessageEvent::interfaceName() const
74 {
75 return EventNames::ServiceWorkerMessageEvent;
76 }
77
78 DEFINE_TRACE(ServiceWorkerMessageEvent)
79 {
80 visitor->trace(m_sourceAsServiceWorker);
81 visitor->trace(m_sourceAsMessagePort);
82 #if ENABLE(OILPAN)
83 visitor->trace(m_ports);
84 #endif
85 Event::trace(visitor);
86 }
87
88 } // namespace blink
OLDNEW
« 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