Bug 814634 - part3 - DOM. r=khuey
authorHsin-Yi Tsai <htsai@mozilla.com>
Tue, 29 Oct 2013 09:58:12 +0800
changeset 153756 3f4814326443762d6fa7d9601dbd1e3ce218d1f6
parent 153755 f1f17c5ae015d6a4ad7953284570ceb4ecd12eae
child 153757 95d8eeb0f741b7ed1afab16545b544e905e580fb
push id25605
push usercbook@mozilla.com
push dateWed, 06 Nov 2013 12:11:28 +0000
treeherdermozilla-central@7ba5fb33e59f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs814634
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 814634 - part3 - DOM. r=khuey
dom/voicemail/Voicemail.cpp
dom/voicemail/Voicemail.h
--- a/dom/voicemail/Voicemail.cpp
+++ b/dom/voicemail/Voicemail.cpp
@@ -5,22 +5,24 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "Voicemail.h"
 
 #include "mozilla/dom/MozVoicemailBinding.h"
 #include "nsIDOMMozVoicemailStatus.h"
 #include "nsIDOMMozVoicemailEvent.h"
 
+#include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "nsDOMClassInfo.h"
 #include "nsServiceManagerUtils.h"
 #include "GeneratedEvents.h"
 
 #define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
+const char* kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces";
 
 using namespace mozilla::dom;
 
 class Voicemail::Listener : public nsIVoicemailListener
 {
   Voicemail* mVoicemail;
 
 public:
@@ -62,60 +64,104 @@ Voicemail::~Voicemail()
 }
 
 JSObject*
 Voicemail::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
 {
   return MozVoicemailBinding::Wrap(aCx, aScope, this);
 }
 
+bool
+Voicemail::IsValidServiceId(uint32_t aServiceId) const
+{
+  uint32_t numClients = mozilla::Preferences::GetUint(kPrefRilNumRadioInterfaces, 1);
+
+  return aServiceId < numClients;
+}
+
+bool
+Voicemail::PassedOrDefaultServiceId(const Optional<uint32_t>& aServiceId,
+                                    uint32_t& aResult) const
+{
+  if (aServiceId.WasPassed()) {
+    if (!IsValidServiceId(aServiceId.Value())) {
+      return false;
+    }
+    aResult = aServiceId.Value();
+  } else {
+    mProvider->GetVoicemailDefaultServiceId(&aResult);
+  }
+
+  return true;
+}
+
 // MozVoicemail WebIDL
 
 already_AddRefed<nsIDOMMozVoicemailStatus>
-Voicemail::GetStatus(ErrorResult& aRv) const
+Voicemail::GetStatus(const Optional<uint32_t>& aServiceId,
+                     ErrorResult& aRv) const
 {
   if (!mProvider) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return nullptr;
   }
 
+  uint32_t id = 0;
+  if (!PassedOrDefaultServiceId(aServiceId, id)) {
+    aRv.Throw(NS_ERROR_INVALID_ARG);
+    return nullptr;
+  }
   nsCOMPtr<nsIDOMMozVoicemailStatus> status;
-  nsresult rv = mProvider->GetVoicemailStatus(getter_AddRefs(status));
+  nsresult rv = mProvider->GetVoicemailStatus(id, getter_AddRefs(status));
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return nullptr;
   }
 
   return status.forget();
 }
 
 void
-Voicemail::GetNumber(nsString& aNumber, ErrorResult& aRv) const
+Voicemail::GetNumber(const Optional<uint32_t>& aServiceId, nsString& aNumber,
+                     ErrorResult& aRv) const
 {
   aNumber.SetIsVoid(true);
 
   if (!mProvider) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return;
   }
 
-  aRv = mProvider->GetVoicemailNumber(aNumber);
+  uint32_t id = 0;
+  if (!PassedOrDefaultServiceId(aServiceId, id)) {
+    aRv.Throw(NS_ERROR_INVALID_ARG);
+    return;
+  }
+
+  aRv = mProvider->GetVoicemailNumber(id, aNumber);
 }
 
 void
-Voicemail::GetDisplayName(nsString& aDisplayName, ErrorResult& aRv) const
+Voicemail::GetDisplayName(const Optional<uint32_t>& aServiceId, nsString& aDisplayName,
+                          ErrorResult& aRv) const
 {
   aDisplayName.SetIsVoid(true);
 
   if (!mProvider) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return;
   }
 
-  aRv = mProvider->GetVoicemailDisplayName(aDisplayName);
+  uint32_t id = 0;
+  if (!PassedOrDefaultServiceId(aServiceId, id)) {
+    aRv.Throw(NS_ERROR_INVALID_ARG);
+    return;
+  }
+
+  aRv = mProvider->GetVoicemailDisplayName(id, aDisplayName);
 }
 
 // nsIVoicemailListener
 
 NS_IMETHODIMP
 Voicemail::NotifyStatusChanged(nsIDOMMozVoicemailStatus* aStatus)
 {
   nsCOMPtr<nsIDOMEvent> event;
--- a/dom/voicemail/Voicemail.h
+++ b/dom/voicemail/Voicemail.h
@@ -47,29 +47,38 @@ public:
   {
     return GetOwner();
   }
 
   virtual JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
   already_AddRefed<nsIDOMMozVoicemailStatus>
-  GetStatus(ErrorResult& aRv) const;
+  GetStatus(const Optional<uint32_t>& aServiceId, ErrorResult& aRv) const;
 
   void
-  GetNumber(nsString& aNumber, ErrorResult& aRv) const;
+  GetNumber(const Optional<uint32_t>& aServiceId, nsString& aNumber,
+            ErrorResult& aRv) const;
 
   void
-  GetDisplayName(nsString& aDisplayName, ErrorResult& aRv) const;
+  GetDisplayName(const Optional<uint32_t>& aServiceId, nsString& aDisplayName,
+                 ErrorResult& aRv) const;
 
   IMPL_EVENT_HANDLER(statuschanged)
 
 private:
   nsCOMPtr<nsIVoicemailProvider> mProvider;
   nsRefPtr<Listener> mListener;
+
+  bool
+  IsValidServiceId(uint32_t aServiceId) const;
+
+  bool
+  PassedOrDefaultServiceId(const Optional<uint32_t>& aServiceId,
+                           uint32_t& aResult) const;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 nsresult
 NS_NewVoicemail(nsPIDOMWindow* aWindow,
                 mozilla::dom::Voicemail** aVoicemail);