Bug 1044721 - Part 2: Update nsIMobileMessageCallback interface and implementation to support Promise and setSmscAddress. r=btseng

This commit is contained in:
Samael Wang 2015-04-29 10:58:16 +08:00
parent 58d99ac4d1
commit bb649cfe0e
3 changed files with 28 additions and 1 deletions

View File

@ -17,6 +17,7 @@
#include "nsServiceManagerUtils.h"
#include "nsTArrayHelpers.h"
#include "DOMMobileMessageError.h"
#include "mozilla/dom/Promise.h"
namespace mozilla {
namespace dom {
@ -80,6 +81,11 @@ MobileMessageCallback::MobileMessageCallback(DOMRequest* aDOMRequest)
{
}
MobileMessageCallback::MobileMessageCallback(Promise* aPromise)
: mPromise(aPromise)
{
}
MobileMessageCallback::~MobileMessageCallback()
{
}
@ -280,6 +286,21 @@ 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

View File

@ -10,6 +10,8 @@
#include "nsCOMPtr.h"
#include "DOMRequest.h"
class Promise;
namespace mozilla {
namespace dom {
namespace mobilemessage {
@ -21,11 +23,13 @@ public:
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);

View File

@ -4,7 +4,7 @@
#include "nsISupports.idl"
[scriptable, uuid(35279dbc-9f1d-419f-b17a-230fcf49f0c7)]
[scriptable, uuid(b1367554-51c6-4153-b20a-effec50ca827)]
interface nsIMobileMessageCallback : nsISupports
{
/**
@ -54,4 +54,6 @@ interface nsIMobileMessageCallback : nsISupports
*/
void notifyGetSmscAddress(in DOMString aSmscAddress);
void notifyGetSmscAddressFailed(in long error);
void notifySetSmscAddress();
void notifySetSmscAddressFailed(in long error);
};