2008-01-30 04:31:29 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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"
|
|
|
|
#include "mozilla/dom/MessagePortList.h"
|
|
|
|
#include "mozilla/dom/UnionTypes.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"
|
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)
|
2013-03-18 19:50:37 +04:00
|
|
|
tmp->mData = JSVAL_VOID;
|
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)
|
2012-06-11 03:44:50 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_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)
|
2008-01-30 04:31:29 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMessageEvent)
|
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)
|
2014-02-27 14:51:14 +04:00
|
|
|
, mData(JSVAL_VOID)
|
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
|
|
|
{
|
|
|
|
mData = JSVAL_VOID;
|
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*
|
2014-04-09 02:27:18 +04:00
|
|
|
MessageEvent::WrapObject(JSContext* aCx)
|
2013-11-05 18:16:26 +04:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-09 02:27:17 +04:00
|
|
|
return mozilla::dom::MessageEventBinding::Wrap(aCx, this);
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
|
|
|
|
2008-01-30 04:31:29 +03:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:14 +04:00
|
|
|
MessageEvent::GetData(JSContext* aCx, JS::MutableHandle<JS::Value> aData)
|
2008-01-30 04:31:29 +03:00
|
|
|
{
|
2013-05-02 13:12:45 +04:00
|
|
|
ErrorResult rv;
|
2014-06-12 00:26:52 +04:00
|
|
|
GetData(aCx, aData, rv);
|
2013-05-02 13:12:45 +04:00
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
JS::ExposeValueToActiveJS(mData);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:14 +04:00
|
|
|
MessageEvent::GetOrigin(nsAString& aOrigin)
|
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
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-05-02 23:26:47 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:14 +04:00
|
|
|
MessageEvent::GetLastEventId(nsAString& aLastEventId)
|
2008-05-02 23:26:47 +04:00
|
|
|
{
|
|
|
|
aLastEventId = mLastEventId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-01-30 04:31:29 +03:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:14 +04:00
|
|
|
MessageEvent::GetSource(nsIDOMWindow** aSource)
|
2008-01-30 04:31:29 +03:00
|
|
|
{
|
2013-09-11 18:10:01 +04:00
|
|
|
NS_IF_ADDREF(*aSource = mWindowSource);
|
2008-01-30 04:31:29 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-11 18:10:01 +04:00
|
|
|
void
|
2014-02-27 14:51:14 +04:00
|
|
|
MessageEvent::GetSource(Nullable<OwningWindowProxyOrMessagePort>& aValue) const
|
2013-09-11 18:10:01 +04:00
|
|
|
{
|
|
|
|
if (mWindowSource) {
|
|
|
|
aValue.SetValue().SetAsWindowProxy() = mWindowSource;
|
|
|
|
} 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());
|
|
|
|
nsRefPtr<MessageEvent> event = new MessageEvent(t, nullptr, nullptr);
|
2013-09-11 18:10:01 +04:00
|
|
|
|
|
|
|
aRv = event->InitEvent(aType, aParam.mBubbles, aParam.mCancelable);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool trusted = event->Init(t);
|
|
|
|
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());
|
|
|
|
|
|
|
|
if (aParam.mOrigin.WasPassed()) {
|
|
|
|
event->mOrigin = aParam.mOrigin.Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aParam.mLastEventId.WasPassed()) {
|
|
|
|
event->mLastEventId = aParam.mLastEventId.Value();
|
|
|
|
}
|
|
|
|
|
2013-12-20 12:51:03 +04:00
|
|
|
if (!aParam.mSource.IsNull()) {
|
|
|
|
if (aParam.mSource.Value().IsWindowProxy()) {
|
|
|
|
event->mWindowSource = aParam.mSource.Value().GetAsWindowProxy();
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
|
|
|
if (aParam.mPorts.WasPassed() && !aParam.mPorts.Value().IsNull()) {
|
2013-11-05 18:16:26 +04:00
|
|
|
nsTArray<nsRefPtr<MessagePortBase>> ports;
|
2013-09-11 18:10:01 +04:00
|
|
|
for (uint32_t i = 0, len = aParam.mPorts.Value().Value().Length(); i < len; ++i) {
|
|
|
|
ports.AppendElement(aParam.mPorts.Value().Value()[i].get());
|
|
|
|
}
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
event->mPorts = new MessagePortList(static_cast<EventBase*>(event), ports);
|
2013-09-11 18:10:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return event.forget();
|
|
|
|
}
|
|
|
|
|
2008-01-30 04:31:29 +03:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:14 +04:00
|
|
|
MessageEvent::InitMessageEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
|
|
|
JS::Handle<JS::Value> aData,
|
|
|
|
const nsAString& aOrigin,
|
|
|
|
const nsAString& aLastEventId,
|
|
|
|
nsIDOMWindow* aSource)
|
2008-01-30 04:31:29 +03:00
|
|
|
{
|
2014-03-05 04:37:43 +04:00
|
|
|
nsresult rv = Event::InitEvent(aType, aCanBubble, aCancelable);
|
2008-01-30 04:31:29 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mData = aData;
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::HoldJSObjects(this);
|
2008-02-27 06:48:54 +03:00
|
|
|
mOrigin = aOrigin;
|
2008-05-02 23:26:47 +04:00
|
|
|
mLastEventId = aLastEventId;
|
2013-09-11 18:10:01 +04:00
|
|
|
mWindowSource = aSource;
|
2008-01-30 04:31:29 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
2014-02-27 14:51:14 +04:00
|
|
|
MessageEvent::SetPorts(MessagePortList* aPorts)
|
2013-11-05 18:16:26 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mPorts && aPorts);
|
|
|
|
mPorts = aPorts;
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:14 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2008-01-30 04:31:29 +03:00
|
|
|
nsresult
|
|
|
|
NS_NewDOMMessageEvent(nsIDOMEvent** aInstancePtrResult,
|
2014-02-27 14:51:14 +04:00
|
|
|
EventTarget* aOwner,
|
2008-01-30 04:31:29 +03:00
|
|
|
nsPresContext* aPresContext,
|
2013-10-02 07:46:04 +04:00
|
|
|
WidgetEvent* aEvent)
|
2008-01-30 04:31:29 +03:00
|
|
|
{
|
2014-02-27 14:51:14 +04:00
|
|
|
MessageEvent* it = new MessageEvent(aOwner, aPresContext, aEvent);
|
2014-03-18 00:00:11 +04:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = static_cast<Event*>(it);
|
|
|
|
return NS_OK;
|
2008-01-30 04:31:29 +03:00
|
|
|
}
|