From 99f24feecfd8e000897573449b89a04a3bf1b1bd Mon Sep 17 00:00:00 2001 From: Vicamo Yang Date: Fri, 26 Sep 2014 13:00:24 +0800 Subject: [PATCH] Bug 833229 - 3.c/4: implement MozVoicemailStatus in C++. r=smaug --- dom/bindings/Bindings.conf | 4 + dom/system/gonk/RILContentHelper.js | 17 ---- dom/system/gonk/RadioInterfaceLayer.manifest | 2 - dom/voicemail/Voicemail.cpp | 6 +- dom/voicemail/Voicemail.h | 4 +- dom/voicemail/VoicemailStatus.cpp | 83 +++++++++++++++++++ dom/voicemail/VoicemailStatus.h | 64 ++++++++++++++ dom/voicemail/moz.build | 5 ++ .../test_voicemail_statuschanged.js | 12 +-- dom/webidl/MozVoicemailStatus.webidl | 4 +- 10 files changed, 166 insertions(+), 35 deletions(-) create mode 100644 dom/voicemail/VoicemailStatus.cpp create mode 100644 dom/voicemail/VoicemailStatus.h diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 137c0195b97..1a973e50e29 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -755,6 +755,10 @@ DOMInterfaces = { 'nativeType': 'mozilla::dom::Voicemail', }, +'MozVoicemailStatus': { + 'nativeType': 'mozilla::dom::VoicemailStatus', +}, + 'MutationObserver': { 'nativeType': 'nsDOMMutationObserver', }, diff --git a/dom/system/gonk/RILContentHelper.js b/dom/system/gonk/RILContentHelper.js index e525fcbab93..e8bfb78663b 100644 --- a/dom/system/gonk/RILContentHelper.js +++ b/dom/system/gonk/RILContentHelper.js @@ -48,8 +48,6 @@ const GSMICCINFO_CID = Components.ID("{e0fa785b-ad3f-46ed-bc56-fcb0d6fe4fa8}"); const CDMAICCINFO_CID = Components.ID("{3d1f844f-9ec5-48fb-8907-aed2e5421709}"); -const VOICEMAILSTATUS_CID= - Components.ID("{5467f2eb-e214-43ea-9b89-67711241ec8e}"); const CELLBROADCASTMESSAGE_CID = Components.ID("{29474c96-3099-486f-bb4a-3c9a1da834e4}"); const CELLBROADCASTETWSINFO_CID = @@ -179,21 +177,6 @@ VoicemailInfo.prototype = { displayName: null }; -function VoicemailStatus(clientId) { - this.serviceId = clientId; -} -VoicemailStatus.prototype = { - QueryInterface: XPCOMUtils.generateQI([]), - classID: VOICEMAILSTATUS_CID, - contractID: "@mozilla.org/voicemailstatus;1", - - serviceId: -1, - hasMessages: false, - messageCount: -1, // Count unknown. - returnNumber: null, - returnMessage: null -}; - function CellBroadcastMessage(clientId, pdu) { this.serviceId = clientId; this.gsmGeographicalScope = RIL.CB_GSM_GEOGRAPHICAL_SCOPE_NAMES[pdu.geographicalScope]; diff --git a/dom/system/gonk/RadioInterfaceLayer.manifest b/dom/system/gonk/RadioInterfaceLayer.manifest index a434a00a0af..2e0d4266a71 100644 --- a/dom/system/gonk/RadioInterfaceLayer.manifest +++ b/dom/system/gonk/RadioInterfaceLayer.manifest @@ -18,10 +18,8 @@ contract @mozilla.org/ril;1 {2d831c8d-6017-435b-a80c-e5d422810cea} category profile-after-change RadioInterfaceLayer @mozilla.org/ril;1 # RILContentHelper.js -component {5467f2eb-e214-43ea-9b89-67711241ec8e} RILContentHelper.js component {472816e1-1fd6-4405-996c-806f9ea68174} RILContentHelper.js component {08a71987-408c-44ff-93fd-177c0a85c3dd} RILContentHelper.js -contract @mozilla.org/voicemailstatus;1 {5467f2eb-e214-43ea-9b89-67711241ec8e} contract @mozilla.org/ril/content-helper;1 {472816e1-1fd6-4405-996c-806f9ea68174} contract @mozilla.org/dom/icccardlock-error;1 {08a71987-408c-44ff-93fd-177c0a85c3dd} category profile-after-change RILContentHelper @mozilla.org/ril/content-helper;1 diff --git a/dom/voicemail/Voicemail.cpp b/dom/voicemail/Voicemail.cpp index 60c97b0566a..bc87ad5224e 100644 --- a/dom/voicemail/Voicemail.cpp +++ b/dom/voicemail/Voicemail.cpp @@ -103,7 +103,7 @@ Voicemail::PassedOrDefaultServiceId(const Optional& aServiceId, // MozVoicemail WebIDL -already_AddRefed +already_AddRefed Voicemail::GetStatus(const Optional& aServiceId, ErrorResult& aRv) const { @@ -129,7 +129,7 @@ Voicemail::GetStatus(const Optional& aServiceId, return nullptr; } JS::Rooted statusObj(cx, &status.toObject()); - nsRefPtr res = new MozVoicemailStatus(statusObj, GetParentObject()); + nsRefPtr res = new VoicemailStatus(statusObj, GetParentObject()); return res.forget(); } @@ -186,7 +186,7 @@ Voicemail::NotifyStatusChanged(JS::HandleValue aStatus) if (aStatus.isObject()) { JSContext *cx = nsContentUtils::GetCurrentJSContext(); JS::Rooted statusObj(cx, &aStatus.toObject()); - init.mStatus = new MozVoicemailStatus(statusObj, GetParentObject()); + init.mStatus = new VoicemailStatus(statusObj, GetParentObject()); } nsRefPtr event = diff --git a/dom/voicemail/Voicemail.h b/dom/voicemail/Voicemail.h index 78578c6330b..b0cb1259ac8 100644 --- a/dom/voicemail/Voicemail.h +++ b/dom/voicemail/Voicemail.h @@ -20,7 +20,7 @@ class nsPIDOMWindow; namespace mozilla { namespace dom { -class MozVoicemailStatus; +class VoicemailStatus; class Voicemail MOZ_FINAL : public DOMEventTargetHelper, private nsIVoicemailListener @@ -55,7 +55,7 @@ public: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; - already_AddRefed + already_AddRefed GetStatus(const Optional& aServiceId, ErrorResult& aRv) const; diff --git a/dom/voicemail/VoicemailStatus.cpp b/dom/voicemail/VoicemailStatus.cpp new file mode 100644 index 00000000000..12c471dc23c --- /dev/null +++ b/dom/voicemail/VoicemailStatus.cpp @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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 "mozilla/dom/VoicemailStatus.h" + +#include "mozilla/dom/MozVoicemailStatusBinding.h" +#include "nsIVoicemailService.h" +#include "nsPIDOMWindow.h" + +namespace mozilla { +namespace dom { + +// mProvider is owned by internal service. +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VoicemailStatus, mParent) + +NS_IMPL_CYCLE_COLLECTING_ADDREF(VoicemailStatus) +NS_IMPL_CYCLE_COLLECTING_RELEASE(VoicemailStatus) + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(VoicemailStatus) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +VoicemailStatus::VoicemailStatus(nsISupports* aParent, + nsIVoicemailProvider* aProvider) + : mParent(aParent) + , mProvider(aProvider) +{ + MOZ_ASSERT(mParent); + MOZ_ASSERT(mProvider); + + SetIsDOMBinding(); +} + +JSObject* +VoicemailStatus::WrapObject(JSContext* aCx) +{ + return MozVoicemailStatusBinding::Wrap(aCx, this); +} + +uint32_t +VoicemailStatus::ServiceId() const +{ + uint32_t result = 0; + mProvider->GetServiceId(&result); + return result; +} + +bool +VoicemailStatus::HasMessages() const +{ + bool result = false; + mProvider->GetHasMessages(&result); + return result; +} + +int32_t +VoicemailStatus::MessageCount() const +{ + int32_t result = 0; + mProvider->GetMessageCount(&result); + return result; +} + +void +VoicemailStatus::GetReturnNumber(nsString& aReturnNumber) const +{ + aReturnNumber.SetIsVoid(true); + mProvider->GetReturnNumber(aReturnNumber); +} + +void +VoicemailStatus::GetReturnMessage(nsString& aReturnMessage) const +{ + aReturnMessage.SetIsVoid(true); + mProvider->GetReturnMessage(aReturnMessage); +} + +} // namespace dom +} // namespace mozilla diff --git a/dom/voicemail/VoicemailStatus.h b/dom/voicemail/VoicemailStatus.h new file mode 100644 index 00000000000..ee58957b7da --- /dev/null +++ b/dom/voicemail/VoicemailStatus.h @@ -0,0 +1,64 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=2 et sw=2 tw=40: */ +/* 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_voicemail_VoicemailStatus_h__ +#define mozilla_dom_voicemail_VoicemailStatus_h__ + +#include "mozilla/Attributes.h" +#include "nsCOMPtr.h" +#include "nsIVoicemailService.h" // For nsIVoicemailProvider. +#include "nsString.h" +#include "nsWrapperCache.h" + +namespace mozilla { +namespace dom { + +class VoicemailStatus MOZ_FINAL : public nsISupports + , public nsWrapperCache +{ +public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(VoicemailStatus) + + VoicemailStatus(nsISupports* aParent, + nsIVoicemailProvider* aProvider); + + nsISupports* + GetParentObject() const { return mParent; } + + virtual JSObject* + WrapObject(JSContext* aCx) MOZ_OVERRIDE; + + // WebIDL interface + + uint32_t + ServiceId() const; + + bool + HasMessages() const; + + int32_t + MessageCount() const; + + void + GetReturnNumber(nsString& aReturnNumber) const; + + void + GetReturnMessage(nsString& aReturnMessage) const; + +private: + // MOZ_FINAL suppresses -Werror,-Wdelete-non-virtual-dtor + ~VoicemailStatus() {} + +private: + nsCOMPtr mParent; + nsCOMPtr mProvider; +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_voicemail_VoicemailStatus_h__ diff --git a/dom/voicemail/moz.build b/dom/voicemail/moz.build index 6914791a626..559c049c478 100644 --- a/dom/voicemail/moz.build +++ b/dom/voicemail/moz.build @@ -12,6 +12,7 @@ XPIDL_MODULE = 'dom_voicemail' EXPORTS.mozilla.dom += [ 'Voicemail.h', + 'VoicemailStatus.h', ] EXPORTS.mozilla.dom.voicemail += [ @@ -29,6 +30,10 @@ SOURCES += [ 'Voicemail.cpp', ] +UNIFIED_SOURCES += [ + 'VoicemailStatus.cpp', +] + FAIL_ON_WARNINGS = True LOCAL_INCLUDES += [ diff --git a/dom/voicemail/test/marionette/test_voicemail_statuschanged.js b/dom/voicemail/test/marionette/test_voicemail_statuschanged.js index 9130400f29b..7fd61ccdc40 100644 --- a/dom/voicemail/test/marionette/test_voicemail_statuschanged.js +++ b/dom/voicemail/test/marionette/test_voicemail_statuschanged.js @@ -79,8 +79,7 @@ function testLevel2DiscardActive() { function onLevel2Active(event) { let status = event.status; - // TODO: bug 905228 - MozVoicemailStatus is not defined. - //ok(status instanceof MozVoicemailStatus); + ok(status instanceof MozVoicemailStatus); is(status.hasMessages, true); is(status.messageCount, -1); is(status.returnNumber, MWI_LEVEL2_SENDER); @@ -105,8 +104,7 @@ const MWI_LEVEL2_DISCARD_INACTIVE_PDU = function testLevel2DiscardInactive() { function onLevel2Inactive(event) { let status = event.status; - // TODO: bug 905228 - MozVoicemailStatus is not defined. - //ok(status instanceof MozVoicemailStatus); + ok(status instanceof MozVoicemailStatus); is(status.hasMessages, false); is(status.messageCount, 0); is(status.returnNumber, MWI_LEVEL2_SENDER); @@ -150,8 +148,7 @@ function testLevel3DiscardActive() { function onLevel3Active(event) { let status = event.status; - // TODO: bug 905228 - MozVoicemailStatus is not defined. - //ok(status instanceof MozVoicemailStatus); + ok(status instanceof MozVoicemailStatus); is(status.hasMessages, true); is(status.messageCount, MWI_LEVEL3_ACTIVE_UDH_MSG_COUNT); is(status.returnNumber, MWI_LEVEL3_SENDER); @@ -188,8 +185,7 @@ const MWI_LEVEL3_DISCARD_INACTIVE_PDU = function testLevel3DiscardInactive() { function onLevel3Inactive(event) { let status = event.status; - // TODO: bug 905228 - MozVoicemailStatus is not defined. - //ok(status instanceof MozVoicemailStatus); + ok(status instanceof MozVoicemailStatus); is(status.hasMessages, false); is(status.messageCount, 0); is(status.returnNumber, MWI_LEVEL3_SENDER); diff --git a/dom/webidl/MozVoicemailStatus.webidl b/dom/webidl/MozVoicemailStatus.webidl index 7e008b96f43..ea28b573a31 100644 --- a/dom/webidl/MozVoicemailStatus.webidl +++ b/dom/webidl/MozVoicemailStatus.webidl @@ -4,9 +4,7 @@ * 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/. */ -[JSImplementation="@mozilla.org/voicemailstatus;1", -Pref="dom.voicemail.enabled"] - +[Pref="dom.voicemail.enabled"] interface MozVoicemailStatus { readonly attribute unsigned long serviceId;