Bug 1044721 - Part 2: Update nsIMobileMessageCallback interface and implementation to support Promise and setSmscAddress. r=btseng
authorSamael Wang <sawang@mozilla.com>
Wed, 29 Apr 2015 10:58:16 +0800
changeset 273388 4dcf847035a3694a363abc630222eeb62e5d24e5
parent 273387 e7150eb09fa3cc5f4829a17fc1d81624ff13a9e3
child 273389 3286849d9d3a801d6a8a01455a2ecd7aef2a7aea
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbtseng
bugs1044721
milestone40.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 1044721 - Part 2: Update nsIMobileMessageCallback interface and implementation to support Promise and setSmscAddress. r=btseng
dom/mobilemessage/MobileMessageCallback.cpp
dom/mobilemessage/MobileMessageCallback.h
dom/mobilemessage/interfaces/nsIMobileMessageCallback.idl
--- a/dom/mobilemessage/MobileMessageCallback.cpp
+++ b/dom/mobilemessage/MobileMessageCallback.cpp
@@ -12,16 +12,17 @@
 #include "nsPIDOMWindow.h"
 #include "MmsMessage.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "jsapi.h"
 #include "xpcpublic.h"
 #include "nsServiceManagerUtils.h"
 #include "nsTArrayHelpers.h"
 #include "DOMMobileMessageError.h"
+#include "mozilla/dom/Promise.h"
 
 namespace mozilla {
 namespace dom {
 namespace mobilemessage {
 
 static nsAutoString
 ConvertErrorCodeToErrorString(int32_t aError)
 {
@@ -75,16 +76,21 @@ NS_INTERFACE_MAP_BEGIN(MobileMessageCall
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 MobileMessageCallback::MobileMessageCallback(DOMRequest* aDOMRequest)
   : mDOMRequest(aDOMRequest)
 {
 }
 
+MobileMessageCallback::MobileMessageCallback(Promise* aPromise)
+  : mPromise(aPromise)
+{
+}
+
 MobileMessageCallback::~MobileMessageCallback()
 {
 }
 
 
 nsresult
 MobileMessageCallback::NotifySuccess(JS::Handle<JS::Value> aResult, bool aAsync)
 {
@@ -275,11 +281,26 @@ MobileMessageCallback::NotifyGetSmscAddr
 }
 
 NS_IMETHODIMP
 MobileMessageCallback::NotifyGetSmscAddressFailed(int32_t aError)
 {
   return NotifyError(aError);
 }
 
+NS_IMETHODIMP
+MobileMessageCallback::NotifySetSmscAddress()
+{
+  mPromise->MaybeResolve(JS::UndefinedHandleValue);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+MobileMessageCallback::NotifySetSmscAddressFailed(int32_t aError)
+{
+  const nsAString& errorStr = ConvertErrorCodeToErrorString(aError);
+  mPromise->MaybeRejectBrokenly(errorStr);
+  return NS_OK;
+}
+
 } // namesapce mobilemessage
 } // namespace dom
 } // namespace mozilla
--- a/dom/mobilemessage/MobileMessageCallback.h
+++ b/dom/mobilemessage/MobileMessageCallback.h
@@ -5,32 +5,36 @@
 
 #ifndef mozilla_dom_mobilemessage_MobileMessageCallback_h
 #define mozilla_dom_mobilemessage_MobileMessageCallback_h
 
 #include "nsIMobileMessageCallback.h"
 #include "nsCOMPtr.h"
 #include "DOMRequest.h"
 
+class Promise;
+
 namespace mozilla {
 namespace dom {
 namespace mobilemessage {
 
 class MobileMessageCallback final : public nsIMobileMessageCallback
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIMOBILEMESSAGECALLBACK
 
   explicit MobileMessageCallback(DOMRequest* aDOMRequest);
+  explicit MobileMessageCallback(Promise* aPromise);
 
 private:
   ~MobileMessageCallback();
 
   nsRefPtr<DOMRequest> mDOMRequest;
+  nsRefPtr<Promise> mPromise;
 
   nsresult NotifySuccess(JS::Handle<JS::Value> aResult, bool aAsync = false);
   nsresult NotifySuccess(nsISupports *aMessage, bool aAsync = false);
   nsresult NotifyError(int32_t aError, DOMError *aDetailedError = nullptr, bool aAsync = false);
 };
 
 } // namespace mobilemessage
 } // namespace dom
--- a/dom/mobilemessage/interfaces/nsIMobileMessageCallback.idl
+++ b/dom/mobilemessage/interfaces/nsIMobileMessageCallback.idl
@@ -1,15 +1,15 @@
 /* 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 "nsISupports.idl"
 
-[scriptable, uuid(35279dbc-9f1d-419f-b17a-230fcf49f0c7)]
+[scriptable, uuid(b1367554-51c6-4153-b20a-effec50ca827)]
 interface nsIMobileMessageCallback : nsISupports
 {
   /**
    * All SMS related errors.
    * Make sure to keep this list in sync with the list in:
    * embedding/android/GeckoSmsManager.java
    */
   const unsigned short SUCCESS_NO_ERROR          = 0;
@@ -49,9 +49,11 @@ interface nsIMobileMessageCallback : nsI
                                    in long charsAvailableInLastSegment);
   void notifyGetSegmentInfoForTextFailed(in long error);
 
   /**
    *  SMSC Address get/set result
    */
   void notifyGetSmscAddress(in DOMString aSmscAddress);
   void notifyGetSmscAddressFailed(in long error);
+  void notifySetSmscAddress();
+  void notifySetSmscAddressFailed(in long error);
 };