2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-01-30 04:31:29 +03:00
|
|
|
|
2014-02-27 14:51:14 +04:00
|
|
|
#include "mozilla/dom/MessageEvent.h"
|
2013-11-05 18:16:26 +04:00
|
|
|
#include "mozilla/dom/MessageEventBinding.h"
|
2013-09-11 18:10:01 +04:00
|
|
|
#include "mozilla/dom/MessagePort.h"
|
|
|
|
#include "mozilla/dom/MessagePortBinding.h"
|
2013-08-17 00:10:17 +04:00
|
|
|
|
2013-09-10 19:29:43 +04:00
|
|
|
#include "mozilla/HoldDropJSObjects.h"
|
2011-05-23 22:53:31 +04:00
|
|
|
#include "jsapi.h"
|
2014-10-29 22:06:20 +03:00
|
|
|
#include "nsGlobalWindow.h" // So we can assign an nsGlobalWindow* to mWindowSource
|
2008-01-30 04:31:29 +03:00
|
|
|
|
2014-02-27 14:51:14 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-05-02 13:12:45 +04:00
|
|
|
|
2014-02-27 14:51:14 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(MessageEvent)
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MessageEvent, Event)
|
2015-01-14 10:59:06 +03:00
|
|
|
tmp->mData.setUndefined();
|
2013-09-11 18:10:01 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindowSource)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPortSource)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPorts)
|
2008-01-30 04:31:29 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MessageEvent, Event)
|
2013-09-11 18:10:01 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindowSource)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPortSource)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPorts)
|
2008-01-30 04:31:29 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(MessageEvent, Event)
|
2016-02-22 21:11:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mData)
|
2011-05-23 22:53:31 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2014-02-27 14:51:14 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MessageEvent)
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(Event)
|
2008-01-30 04:31:29 +03:00
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(MessageEvent, Event)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(MessageEvent, Event)
|
2008-01-30 04:31:29 +03:00
|
|
|
|
2014-02-27 14:51:14 +04:00
|
|
|
MessageEvent::MessageEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent)
|
2014-03-05 04:37:43 +04:00
|
|
|
: Event(aOwner, aPresContext, aEvent)
|
2015-01-14 10:59:06 +03:00
|
|
|
, mData(JS::UndefinedValue())
|
2016-10-24 20:14:38 +03:00
|
|
|
, mPortsSet(false)
|
2011-05-23 22:53:31 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:14 +04:00
|
|
|
MessageEvent::~MessageEvent()
|
2011-05-23 22:53:31 +04:00
|
|
|
{
|
2015-01-14 10:59:06 +03:00
|
|
|
mData.setUndefined();
|
2014-02-27 14:51:14 +04:00
|
|
|
DropJSObjects(this);
|
2011-05-23 22:53:31 +04:00
|
|
|
}
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
MessageEvent::WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-11-05 18:16:26 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return mozilla::dom::MessageEventBinding::Wrap(aCx, this, aGivenProto);
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void
|
|
|
|
MessageEvent::GetData(JSContext* aCx, JS::MutableHandle<JS::Value> aData,
|
|
|
|
ErrorResult& aRv)
|
2013-05-02 13:12:45 +04:00
|
|
|
{
|
2014-06-12 00:26:52 +04:00
|
|
|
aData.set(mData);
|
|
|
|
if (!JS_WrapValue(aCx, aData)) {
|
2013-05-02 13:12:45 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
}
|
2008-01-30 04:31:29 +03:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
void
|
|
|
|
MessageEvent::GetOrigin(nsAString& aOrigin) const
|
2008-01-30 04:31:29 +03:00
|
|
|
{
|
2008-02-27 06:48:54 +03:00
|
|
|
aOrigin = mOrigin;
|
2008-01-30 04:31:29 +03:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
void
|
|
|
|
MessageEvent::GetLastEventId(nsAString& aLastEventId) const
|
2008-05-02 23:26:47 +04:00
|
|
|
{
|
|
|
|
aLastEventId = mLastEventId;
|
2008-01-30 04:31:29 +03:00
|
|
|
}
|
|
|
|
|
2013-09-11 18:10:01 +04:00
|
|
|
void
|
2015-11-10 09:31:41 +03:00
|
|
|
MessageEvent::GetSource(Nullable<OwningWindowProxyOrMessagePort>& aValue) const
|
2013-09-11 18:10:01 +04:00
|
|
|
{
|
|
|
|
if (mWindowSource) {
|
2016-01-30 20:05:36 +03:00
|
|
|
aValue.SetValue().SetAsWindowProxy() = mWindowSource->GetOuterWindow();
|
2013-09-11 18:10:01 +04:00
|
|
|
} else if (mPortSource) {
|
|
|
|
aValue.SetValue().SetAsMessagePort() = mPortSource;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:14 +04:00
|
|
|
/* static */ already_AddRefed<MessageEvent>
|
|
|
|
MessageEvent::Constructor(const GlobalObject& aGlobal,
|
2014-06-16 20:52:00 +04:00
|
|
|
const nsAString& aType,
|
2014-02-27 14:51:14 +04:00
|
|
|
const MessageEventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
2013-09-11 18:10:01 +04:00
|
|
|
{
|
2014-02-27 14:51:14 +04:00
|
|
|
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2015-01-15 19:58:40 +03:00
|
|
|
return Constructor(t, aType, aParam, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ already_AddRefed<MessageEvent>
|
|
|
|
MessageEvent::Constructor(EventTarget* aEventTarget,
|
|
|
|
const nsAString& aType,
|
|
|
|
const MessageEventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MessageEvent> event = new MessageEvent(aEventTarget, nullptr, nullptr);
|
2013-09-11 18:10:01 +04:00
|
|
|
|
2015-11-13 03:09:42 +03:00
|
|
|
event->InitEvent(aType, aParam.mBubbles, aParam.mCancelable);
|
2015-01-15 19:58:40 +03:00
|
|
|
bool trusted = event->Init(aEventTarget);
|
2013-09-11 18:10:01 +04:00
|
|
|
event->SetTrusted(trusted);
|
|
|
|
|
2014-02-19 19:13:38 +04:00
|
|
|
event->mData = aParam.mData;
|
2013-09-11 18:10:01 +04:00
|
|
|
|
|
|
|
mozilla::HoldJSObjects(event.get());
|
|
|
|
|
2016-10-24 20:14:38 +03:00
|
|
|
if (aParam.mOrigin.WasPassed()) {
|
|
|
|
event->mOrigin = aParam.mOrigin.Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aParam.mLastEventId.WasPassed()) {
|
|
|
|
event->mLastEventId = aParam.mLastEventId.Value();
|
|
|
|
}
|
2013-09-11 18:10:01 +04:00
|
|
|
|
2013-12-20 12:51:03 +04:00
|
|
|
if (!aParam.mSource.IsNull()) {
|
2014-10-29 22:06:20 +03:00
|
|
|
if (aParam.mSource.Value().IsWindow()) {
|
2016-01-30 20:05:36 +03:00
|
|
|
event->mWindowSource = aParam.mSource.Value().GetAsWindow()->AsInner();
|
2013-12-20 12:51:03 +04:00
|
|
|
} else {
|
|
|
|
event->mPortSource = aParam.mSource.Value().GetAsMessagePort();
|
2013-09-11 18:10:01 +04:00
|
|
|
}
|
|
|
|
|
2013-12-20 12:51:03 +04:00
|
|
|
MOZ_ASSERT(event->mWindowSource || event->mPortSource);
|
2013-09-11 18:10:01 +04:00
|
|
|
}
|
|
|
|
|
2016-10-24 20:14:38 +03:00
|
|
|
if (aParam.mPorts.WasPassed() && !aParam.mPorts.Value().IsNull()) {
|
|
|
|
event->mPorts.AppendElements(aParam.mPorts.Value().Value());
|
|
|
|
event->mPortsSet = true;
|
|
|
|
}
|
2013-09-11 18:10:01 +04:00
|
|
|
|
|
|
|
return event.forget();
|
|
|
|
}
|
|
|
|
|
2015-10-08 19:44:58 +03:00
|
|
|
void
|
|
|
|
MessageEvent::InitMessageEvent(JSContext* aCx, const nsAString& aType,
|
|
|
|
bool aCanBubble, bool aCancelable,
|
|
|
|
JS::Handle<JS::Value> aData,
|
|
|
|
const nsAString& aOrigin,
|
|
|
|
const nsAString& aLastEventId,
|
|
|
|
const Nullable<WindowProxyOrMessagePort>& aSource,
|
2016-10-24 20:14:38 +03:00
|
|
|
const Nullable<Sequence<OwningNonNull<MessagePort>>>& aPorts)
|
2015-10-08 19:44:58 +03:00
|
|
|
{
|
2015-11-13 03:09:42 +03:00
|
|
|
Event::InitEvent(aType, aCanBubble, aCancelable);
|
2015-10-08 19:44:58 +03:00
|
|
|
mData = aData;
|
|
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
mOrigin = aOrigin;
|
|
|
|
mLastEventId = aLastEventId;
|
|
|
|
|
|
|
|
mWindowSource = nullptr;
|
|
|
|
mPortSource = nullptr;
|
|
|
|
|
|
|
|
if (!aSource.IsNull()) {
|
|
|
|
if (aSource.Value().IsWindowProxy()) {
|
2016-01-30 20:05:36 +03:00
|
|
|
auto* windowProxy = aSource.Value().GetAsWindowProxy();
|
|
|
|
mWindowSource = windowProxy ? windowProxy->GetCurrentInnerWindow() : nullptr;
|
2015-10-08 19:44:58 +03:00
|
|
|
} else {
|
|
|
|
mPortSource = &aSource.Value().GetAsMessagePort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-13 16:19:24 +03:00
|
|
|
mPorts.Clear();
|
2016-10-24 20:14:38 +03:00
|
|
|
mPortsSet = false;
|
|
|
|
|
|
|
|
if (!aPorts.IsNull()) {
|
|
|
|
mPorts.AppendElements(aPorts.Value());
|
|
|
|
mPortsSet = true;
|
|
|
|
}
|
|
|
|
|
2016-10-13 16:19:24 +03:00
|
|
|
MessageEventBinding::ClearCachedPortsValue(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-24 20:14:38 +03:00
|
|
|
MessageEvent::GetPorts(Nullable<nsTArray<RefPtr<MessagePort>>>& aPorts)
|
2016-10-13 16:19:24 +03:00
|
|
|
{
|
2016-10-24 20:14:38 +03:00
|
|
|
if (!mPortsSet) {
|
|
|
|
aPorts.SetNull();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aPorts.SetValue(mPorts);
|
2015-10-08 19:44:58 +03:00
|
|
|
}
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
2016-10-13 16:19:24 +03:00
|
|
|
MessageEvent::SetPorts(nsTArray<RefPtr<MessagePort>>&& aPorts)
|
2013-11-05 18:16:26 +04:00
|
|
|
{
|
2016-10-24 20:14:38 +03:00
|
|
|
MOZ_ASSERT(mPorts.IsEmpty() && !mPortsSet);
|
2016-10-13 16:19:24 +03:00
|
|
|
mPorts = Move(aPorts);
|
2016-10-24 20:14:38 +03:00
|
|
|
mPortsSet = true;
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
|
|
|
|
2015-02-06 14:06:35 +03:00
|
|
|
void
|
|
|
|
MessageEvent::SetSource(mozilla::dom::MessagePort* aPort)
|
|
|
|
{
|
|
|
|
mPortSource = aPort;
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:14 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|