|
|
|
|
| 3 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
3 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
6 |
|
| 7 |
#include "mozilla/dom/MessageEvent.h" |
7 |
#include "mozilla/dom/MessageEvent.h" |
| 8 |
#include "mozilla/dom/MessageEventBinding.h" |
8 |
#include "mozilla/dom/MessageEventBinding.h" |
| 9 |
#include "mozilla/dom/MessagePort.h" |
9 |
#include "mozilla/dom/MessagePort.h" |
| 10 |
#include "mozilla/dom/MessagePortBinding.h" |
10 |
#include "mozilla/dom/MessagePortBinding.h" |
|
|
11 |
#include "mozilla/dom/workers/bindings/ServiceWorker.h" |
| 11 |
|
12 |
|
| 12 |
#include "mozilla/HoldDropJSObjects.h" |
13 |
#include "mozilla/HoldDropJSObjects.h" |
| 13 |
#include "jsapi.h" |
14 |
#include "jsapi.h" |
| 14 |
#include "nsGlobalWindow.h" // So we can assign an nsGlobalWindow* to mWindowSource |
15 |
#include "nsGlobalWindow.h" // So we can assign an nsGlobalWindow* to mWindowSource |
| 15 |
|
16 |
|
| 16 |
namespace mozilla { |
17 |
namespace mozilla { |
| 17 |
namespace dom { |
18 |
namespace dom { |
| 18 |
|
19 |
|
|
Lines 79-100
MessageEvent::GetOrigin(nsAString& aOrig
|
Link Here
|
|---|
|
| 79 |
|
80 |
|
| 80 |
void |
81 |
void |
| 81 |
MessageEvent::GetLastEventId(nsAString& aLastEventId) const |
82 |
MessageEvent::GetLastEventId(nsAString& aLastEventId) const |
| 82 |
{ |
83 |
{ |
| 83 |
aLastEventId = mLastEventId; |
84 |
aLastEventId = mLastEventId; |
| 84 |
} |
85 |
} |
| 85 |
|
86 |
|
| 86 |
void |
87 |
void |
| 87 |
MessageEvent::GetSource(Nullable<OwningWindowProxyOrMessagePort>& aValue) const |
88 |
MessageEvent::GetSource(Nullable<OwningWindowProxyOrMessagePortOrServiceWorker>& aValue) const |
| 88 |
{ |
89 |
{ |
| 89 |
if (mWindowSource) { |
90 |
if (mWindowSource) { |
| 90 |
aValue.SetValue().SetAsWindowProxy() = mWindowSource->GetOuterWindow(); |
91 |
aValue.SetValue().SetAsWindowProxy() = mWindowSource->GetOuterWindow(); |
| 91 |
} else if (mPortSource) { |
92 |
} else if (mPortSource) { |
| 92 |
aValue.SetValue().SetAsMessagePort() = mPortSource; |
93 |
aValue.SetValue().SetAsMessagePort() = mPortSource; |
|
|
94 |
} else if (mServiceWorker) { |
| 95 |
aValue.SetValue().SetAsServiceWorker() = mServiceWorker; |
| 93 |
} |
96 |
} |
| 94 |
} |
97 |
} |
| 95 |
|
98 |
|
| 96 |
/* static */ already_AddRefed<MessageEvent> |
99 |
/* static */ already_AddRefed<MessageEvent> |
| 97 |
MessageEvent::Constructor(const GlobalObject& aGlobal, |
100 |
MessageEvent::Constructor(const GlobalObject& aGlobal, |
| 98 |
const nsAString& aType, |
101 |
const nsAString& aType, |
| 99 |
const MessageEventInit& aParam, |
102 |
const MessageEventInit& aParam, |
| 100 |
ErrorResult& aRv) |
103 |
ErrorResult& aRv) |
|
Lines 118-154
MessageEvent::Constructor(EventTarget* a
|
Link Here
|
|---|
|
| 118 |
event->mData = aParam.mData; |
121 |
event->mData = aParam.mData; |
| 119 |
|
122 |
|
| 120 |
mozilla::HoldJSObjects(event.get()); |
123 |
mozilla::HoldJSObjects(event.get()); |
| 121 |
|
124 |
|
| 122 |
event->mOrigin = aParam.mOrigin; |
125 |
event->mOrigin = aParam.mOrigin; |
| 123 |
event->mLastEventId = aParam.mLastEventId; |
126 |
event->mLastEventId = aParam.mLastEventId; |
| 124 |
|
127 |
|
| 125 |
if (!aParam.mSource.IsNull()) { |
128 |
if (!aParam.mSource.IsNull()) { |
| 126 |
if (aParam.mSource.Value().IsWindow()) { |
129 |
if (aParam.mSource.Value().IsWindowProxy()) { |
| 127 |
event->mWindowSource = aParam.mSource.Value().GetAsWindow()->AsInner(); |
130 |
event->mWindowSource = aParam.mSource.Value().GetAsWindowProxy()->AsInner(); |
|
|
131 |
} else if (aParam.mSource.Value().IsMessagePort()) { |
| 132 |
event->mPortSource = aParam.mSource.Value().GetAsMessagePort(); |
| 128 |
} else { |
133 |
} else { |
| 129 |
event->mPortSource = aParam.mSource.Value().GetAsMessagePort(); |
134 |
event->mServiceWorker = aParam.mSource.Value().GetAsServiceWorker(); |
| 130 |
} |
135 |
} |
| 131 |
|
136 |
|
| 132 |
MOZ_ASSERT(event->mWindowSource || event->mPortSource); |
137 |
MOZ_ASSERT(event->mWindowSource || event->mPortSource); |
| 133 |
} |
138 |
} |
| 134 |
|
139 |
|
| 135 |
event->mPorts.AppendElements(aParam.mPorts); |
140 |
event->mPorts.AppendElements(aParam.mPorts); |
| 136 |
|
141 |
|
| 137 |
return event.forget(); |
142 |
return event.forget(); |
| 138 |
} |
143 |
} |
| 139 |
|
144 |
|
| 140 |
void |
145 |
void |
| 141 |
MessageEvent::InitMessageEvent(JSContext* aCx, const nsAString& aType, |
146 |
MessageEvent::InitMessageEvent(JSContext* aCx, const nsAString& aType, |
| 142 |
bool aCanBubble, bool aCancelable, |
147 |
bool aCanBubble, bool aCancelable, |
| 143 |
JS::Handle<JS::Value> aData, |
148 |
JS::Handle<JS::Value> aData, |
| 144 |
const nsAString& aOrigin, |
149 |
const nsAString& aOrigin, |
| 145 |
const nsAString& aLastEventId, |
150 |
const nsAString& aLastEventId, |
| 146 |
const Nullable<WindowProxyOrMessagePort>& aSource, |
151 |
const Nullable<WindowProxyOrMessagePortOrServiceWorker>& aSource, |
| 147 |
const Sequence<OwningNonNull<MessagePort>>& aPorts) |
152 |
const Sequence<OwningNonNull<MessagePort>>& aPorts) |
| 148 |
{ |
153 |
{ |
| 149 |
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched); |
154 |
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched); |
| 150 |
|
155 |
|
| 151 |
Event::InitEvent(aType, aCanBubble, aCancelable); |
156 |
Event::InitEvent(aType, aCanBubble, aCancelable); |
| 152 |
mData = aData; |
157 |
mData = aData; |
| 153 |
mozilla::HoldJSObjects(this); |
158 |
mozilla::HoldJSObjects(this); |
| 154 |
mOrigin = aOrigin; |
159 |
mOrigin = aOrigin; |
|
Lines 156-173
MessageEvent::InitMessageEvent(JSContext
|
Link Here
|
|---|
|
| 156 |
|
161 |
|
| 157 |
mWindowSource = nullptr; |
162 |
mWindowSource = nullptr; |
| 158 |
mPortSource = nullptr; |
163 |
mPortSource = nullptr; |
| 159 |
|
164 |
|
| 160 |
if (!aSource.IsNull()) { |
165 |
if (!aSource.IsNull()) { |
| 161 |
if (aSource.Value().IsWindowProxy()) { |
166 |
if (aSource.Value().IsWindowProxy()) { |
| 162 |
auto* windowProxy = aSource.Value().GetAsWindowProxy(); |
167 |
auto* windowProxy = aSource.Value().GetAsWindowProxy(); |
| 163 |
mWindowSource = windowProxy ? windowProxy->GetCurrentInnerWindow() : nullptr; |
168 |
mWindowSource = windowProxy ? windowProxy->GetCurrentInnerWindow() : nullptr; |
|
|
169 |
} else if (aSource.Value().IsMessagePort()) { |
| 170 |
mPortSource = &aSource.Value().GetAsMessagePort(); |
| 164 |
} else { |
171 |
} else { |
| 165 |
mPortSource = &aSource.Value().GetAsMessagePort(); |
172 |
mServiceWorker = &aSource.Value().GetAsServiceWorker(); |
| 166 |
} |
173 |
} |
| 167 |
} |
174 |
} |
| 168 |
|
175 |
|
| 169 |
mPorts.Clear(); |
176 |
mPorts.Clear(); |
| 170 |
mPorts.AppendElements(aPorts); |
177 |
mPorts.AppendElements(aPorts); |
| 171 |
MessageEventBinding::ClearCachedPortsValue(this); |
178 |
MessageEventBinding::ClearCachedPortsValue(this); |
| 172 |
} |
179 |
} |
| 173 |
|
180 |
|