From f35f9f431a6908b1aa33d19b29d2fc3b1df86761 Mon Sep 17 00:00:00 2001 From: Jose Antonio Olivera Ortega Date: Fri, 25 Jan 2013 19:45:16 +0100 Subject: [PATCH] Bug 827280 - Part 2: DOMEvent. r=philikon a=tef+ --- content/base/src/nsGkAtomList.h | 1 + dom/base/nsDOMClassInfo.cpp | 9 +++ dom/base/nsDOMClassInfoClasses.h | 1 + dom/network/src/CFStateChangeEvent.cpp | 90 ++++++++++++++++++++++++++ dom/network/src/CFStateChangeEvent.h | 70 ++++++++++++++++++++ dom/network/src/Makefile.in | 1 + dom/webidl/CFStateChangeEvent.webidl | 12 ++++ dom/webidl/WebIDL.mk | 1 + 8 files changed, 185 insertions(+) create mode 100644 dom/network/src/CFStateChangeEvent.cpp create mode 100644 dom/network/src/CFStateChangeEvent.h create mode 100644 dom/webidl/CFStateChangeEvent.webidl diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index b995a61d08cc..956f82a5f5b5 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -646,6 +646,7 @@ GK_ATOM(oncached, "oncached") GK_ATOM(oncallschanged, "oncallschanged") GK_ATOM(oncancel, "oncancel") GK_ATOM(oncardstatechange, "oncardstatechange") +GK_ATOM(oncfstatechange, "oncfstatechange") GK_ATOM(onchange, "onchange") GK_ATOM(onchargingchange, "onchargingchange") GK_ATOM(onchargingtimechange, "onchargingtimechange") diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index d6153b0864fd..9e2aa1a91e70 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -520,6 +520,7 @@ using mozilla::dom::indexedDB::IDBWrapperCache; #include "StkCommandEvent.h" #include "nsIDOMMozCellBroadcast.h" #include "nsIDOMMozCellBroadcastEvent.h" +#include "CFStateChangeEvent.h" #endif // MOZ_B2G_RIL #ifdef MOZ_B2G_FM @@ -1544,6 +1545,9 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(MozCellBroadcast, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) + + NS_DEFINE_CLASSINFO_DATA(CFStateChangeEvent, nsDOMGenericSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS) #endif NS_DEFINE_CLASSINFO_DATA(USSDReceivedEvent, nsDOMGenericSH, @@ -4199,6 +4203,11 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozCellBroadcastEvent) DOM_CLASSINFO_EVENT_MAP_ENTRIES DOM_CLASSINFO_MAP_END + + DOM_CLASSINFO_MAP_BEGIN(CFStateChangeEvent, nsIDOMCFStateChangeEvent) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCFStateChangeEvent) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent) + DOM_CLASSINFO_MAP_END #endif // MOZ_B2G_RIL DOM_CLASSINFO_MAP_BEGIN(USSDReceivedEvent, nsIDOMUSSDReceivedEvent) diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index 1b5ed0441691..93ed86bfc9bc 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -411,6 +411,7 @@ DOMCI_CLASS(MozConnection) #ifdef MOZ_B2G_RIL DOMCI_CLASS(MozMobileConnection) DOMCI_CLASS(MozCellBroadcast) +DOMCI_CLASS(CFStateChangeEvent) #endif DOMCI_CLASS(USSDReceivedEvent) diff --git a/dom/network/src/CFStateChangeEvent.cpp b/dom/network/src/CFStateChangeEvent.cpp new file mode 100644 index 000000000000..d3b7fa9d8b8f --- /dev/null +++ b/dom/network/src/CFStateChangeEvent.cpp @@ -0,0 +1,90 @@ +/* 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/. */ + +#include "CFStateChangeEvent.h" +#include "nsIDOMClassInfo.h" +#include "nsDOMClassInfoID.h" +#include "nsContentUtils.h" + +DOMCI_DATA(CFStateChangeEvent, mozilla::dom::network::CFStateChangeEvent) + +namespace mozilla { +namespace dom { +namespace network { + +already_AddRefed +CFStateChangeEvent::Create(bool aSuccess, + uint16_t aAction, + uint16_t aReason, + nsAString& aNumber, + uint16_t aTimeSeconds, + uint16_t aServiceClass) +{ + NS_ASSERTION(!aNumber.IsEmpty(), "Empty number!"); + + nsRefPtr event = new CFStateChangeEvent(); + + event->mSuccess = aSuccess; + event->mAction = aAction; + event->mReason = aReason; + event->mNumber = aNumber; + event->mTimeSeconds = aTimeSeconds; + event->mServiceClass = aServiceClass; + + return event.forget(); +} + +NS_IMPL_ADDREF_INHERITED(CFStateChangeEvent, nsDOMEvent) +NS_IMPL_RELEASE_INHERITED(CFStateChangeEvent, nsDOMEvent) + +NS_INTERFACE_MAP_BEGIN(CFStateChangeEvent) + NS_INTERFACE_MAP_ENTRY(nsIDOMCFStateChangeEvent) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CFStateChangeEvent) +NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent) + +NS_IMETHODIMP +CFStateChangeEvent::GetSuccess(bool* aSuccess) +{ + *aSuccess = mSuccess; + return NS_OK; +} + +NS_IMETHODIMP +CFStateChangeEvent::GetAction(uint16_t* aAction) +{ + *aAction = mAction; + return NS_OK; +} + +NS_IMETHODIMP +CFStateChangeEvent::GetReason(uint16_t* aReason) +{ + *aReason = mReason; + return NS_OK; +} + +NS_IMETHODIMP +CFStateChangeEvent::GetNumber(nsAString& aNumber) +{ + aNumber.Assign(mNumber); + return NS_OK; +} + +NS_IMETHODIMP +CFStateChangeEvent::GetTimeSeconds(uint16_t* aTimeSeconds) +{ + *aTimeSeconds = mTimeSeconds; + return NS_OK; +} + +NS_IMETHODIMP +CFStateChangeEvent::GetServiceClass(uint16_t* aServiceClass) +{ + *aServiceClass = mServiceClass; + return NS_OK; +} + +} +} +} diff --git a/dom/network/src/CFStateChangeEvent.h b/dom/network/src/CFStateChangeEvent.h new file mode 100644 index 000000000000..c377692fd47a --- /dev/null +++ b/dom/network/src/CFStateChangeEvent.h @@ -0,0 +1,70 @@ +/* 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/. */ +#ifndef mozilla_dom_network_cfstatechangeevent_h +#define mozilla_dom_network_cfstatechangeevent_h + +#include "nsIDOMCFStateChangeEvent.h" +#include "nsDOMEvent.h" + +namespace mozilla { +namespace dom { +namespace network { + +class CFStateChangeEvent : public nsDOMEvent, + public nsIDOMCFStateChangeEvent +{ + bool mSuccess; + uint16_t mAction; + uint16_t mReason; + nsString mNumber; + uint16_t mTimeSeconds; + uint16_t mServiceClass; + +public: + NS_DECL_ISUPPORTS_INHERITED + NS_FORWARD_TO_NSDOMEVENT + NS_DECL_NSIDOMCFSTATECHANGEEVENT + + static already_AddRefed + Create(bool aSuccess, + uint16_t aAction, + uint16_t aReason, + nsAString& aNumber, + uint16_t aTimeSeconds, + uint16_t aServiceClass); + + nsresult + Dispatch(nsIDOMEventTarget* aTarget, const nsAString& aEventType) + { + NS_ASSERTION(aTarget, "Null pointer!"); + NS_ASSERTION(!aEventType.IsEmpty(), "Empty event type!"); + + nsresult rv = InitEvent(aEventType, false, false); + NS_ENSURE_SUCCESS(rv, rv); + + SetTrusted(true); + + nsDOMEvent* thisEvent = this; + + bool dummy; + rv = aTarget->DispatchEvent(thisEvent, &dummy); + NS_ENSURE_SUCCESS(rv, rv); + + return NS_OK; + } + +private: + CFStateChangeEvent() + : nsDOMEvent(nullptr, nullptr) + { } + + ~CFStateChangeEvent() + { } +}; + +} +} +} + +#endif // mozilla_dom_network_cfstatechangeevent_h diff --git a/dom/network/src/Makefile.in b/dom/network/src/Makefile.in index 0bb3693ab92c..d4a0791ba7a1 100644 --- a/dom/network/src/Makefile.in +++ b/dom/network/src/Makefile.in @@ -56,6 +56,7 @@ CPPSRCS = \ ifdef MOZ_B2G_RIL CPPSRCS += \ MobileConnection.cpp \ + CFStateChangeEvent.cpp \ $(NULL) endif diff --git a/dom/webidl/CFStateChangeEvent.webidl b/dom/webidl/CFStateChangeEvent.webidl new file mode 100644 index 000000000000..6e425c84ba7b --- /dev/null +++ b/dom/webidl/CFStateChangeEvent.webidl @@ -0,0 +1,12 @@ +/* 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/. */ + +dictionary CFStateChangeEventDict { + boolean success = false; + short action = -1; + short reason = -1; + DOMString? number = null; + short timeSeconds = -1; + short serviceClass = -1; +}; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 65509eef3e89..e0a6d4e43225 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -57,6 +57,7 @@ endif ifdef MOZ_B2G_RIL webidl_files += \ USSDReceivedEvent.webidl \ + CFStateChangeEvent.webidl \ $(NULL) endif