Bug 1077075 - Part 2: Modify related dom implementations (DOM). r=aknow
☠☠ backed out by cded54c82fb1 ☠ ☠
authorBen Hsu <bhsu@mozilla.com>
Thu, 25 Dec 2014 19:49:00 +0100
changeset 221469 cfddd3baeb0b1538a7c5b7598e01473ab822055b
parent 221468 1cddaf8b16f460b5a08a8edccbd6c9848bc13c3d
child 221470 916a5e9433889e0b7fab605895000d92c67d3b3c
push id53352
push usercbook@mozilla.com
push dateMon, 29 Dec 2014 15:17:49 +0000
treeherdermozilla-inbound@8530f5b7443b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaknow
bugs1077075
milestone37.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 1077075 - Part 2: Modify related dom implementations (DOM). r=aknow
dom/telephony/TelephonyCall.cpp
dom/telephony/TelephonyCall.h
--- a/dom/telephony/TelephonyCall.cpp
+++ b/dom/telephony/TelephonyCall.cpp
@@ -221,105 +221,145 @@ TelephonyCall::GetError() const
 
 already_AddRefed<TelephonyCallGroup>
 TelephonyCall::GetGroup() const
 {
   nsRefPtr<TelephonyCallGroup> group = mGroup;
   return group.forget();
 }
 
-void
+already_AddRefed<Promise>
 TelephonyCall::Answer(ErrorResult& aRv)
 {
+  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
+  if (!global) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+
+  nsRefPtr<Promise> promise = Promise::Create(global, aRv);
+  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
+
   if (mCallState != nsITelephonyService::CALL_STATE_INCOMING) {
-    NS_WARNING("Answer on non-incoming call ignored!");
-    return;
+    NS_WARNING("Answer on non-incoming call is rejected!");
+    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return promise.forget();
   }
 
-  nsresult rv = mTelephony->Service()->AnswerCall(mServiceId, mCallIndex);
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
-    return;
+  nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
+  aRv = mTelephony->Service()->AnswerCall(mServiceId, mCallIndex, callback);
+  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
+
+  ChangeStateInternal(nsITelephonyService::CALL_STATE_CONNECTING, true);
+  return promise.forget();
+}
+
+already_AddRefed<Promise>
+TelephonyCall::HangUp(ErrorResult& aRv)
+{
+  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
+  if (!global) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
   }
 
-  ChangeStateInternal(nsITelephonyService::CALL_STATE_CONNECTING, true);
-}
+  nsRefPtr<Promise> promise = Promise::Create(global, aRv);
+  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
 
-void
-TelephonyCall::HangUp(ErrorResult& aRv)
-{
   if (mCallState == nsITelephonyService::CALL_STATE_DISCONNECTING ||
       mCallState == nsITelephonyService::CALL_STATE_DISCONNECTED) {
-    NS_WARNING("HangUp on previously disconnected call ignored!");
-    return;
+    NS_WARNING("HangUp on previously disconnected call is rejected!");
+    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return promise.forget();
   }
 
-  nsresult rv = mCallState == nsITelephonyService::CALL_STATE_INCOMING ?
-                mTelephony->Service()->RejectCall(mServiceId, mCallIndex) :
-                mTelephony->Service()->HangUp(mServiceId, mCallIndex);
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
-    return;
-  }
+  nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
+  aRv = mCallState == nsITelephonyService::CALL_STATE_INCOMING ?
+    mTelephony->Service()->RejectCall(mServiceId, mCallIndex, callback) :
+    mTelephony->Service()->HangUpCall(mServiceId, mCallIndex, callback);
+  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
 
   ChangeStateInternal(nsITelephonyService::CALL_STATE_DISCONNECTING, true);
+  return promise.forget();
 }
 
-void
+already_AddRefed<Promise>
 TelephonyCall::Hold(ErrorResult& aRv)
 {
+  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
+  if (!global) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+
+  nsRefPtr<Promise> promise = Promise::Create(global, aRv);
+  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
+
   if (mCallState != nsITelephonyService::CALL_STATE_CONNECTED) {
-    NS_WARNING("Hold non-connected call ignored!");
-    return;
+    NS_WARNING("Hold non-connected call is rejected!");
+    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return promise.forget();
   }
 
   if (mGroup) {
-    NS_WARNING("Hold a call in conference ignored!");
-    return;
+    NS_WARNING("Hold a call in conference is rejected!");
+    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return promise.forget();
   }
 
   if (!mSwitchable) {
-    NS_WARNING("Hold a non-switchable call ignored!");
-    return;
+    NS_WARNING("Hold a non-switchable call is rejected!");
+    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return promise.forget();
   }
 
-  nsresult rv = mTelephony->Service()->HoldCall(mServiceId, mCallIndex);
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
-    return;
-  }
+  nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
+  aRv = mTelephony->Service()->HoldCall(mServiceId, mCallIndex, callback);
+  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
 
   if (mSecondId) {
     // No state transition when we switch two numbers within one TelephonyCall
     // object. Otherwise, the state here will be inconsistent with the backend
     // RIL and will never be right.
-    return;
+    return promise.forget();
   }
 
   ChangeStateInternal(nsITelephonyService::CALL_STATE_HOLDING, true);
+  return promise.forget();
 }
 
-void
+already_AddRefed<Promise>
 TelephonyCall::Resume(ErrorResult& aRv)
 {
+  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
+  if (!global) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+
+  nsRefPtr<Promise> promise = Promise::Create(global, aRv);
+  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
+
   if (mCallState != nsITelephonyService::CALL_STATE_HELD) {
-    NS_WARNING("Resume non-held call ignored!");
-    return;
+    NS_WARNING("Resume non-held call is rejected!");
+    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return promise.forget();
   }
 
   if (mGroup) {
-    NS_WARNING("Resume a call in conference ignored!");
-    return;
+    NS_WARNING("Resume a call in conference is rejected!");
+    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return promise.forget();
   }
 
   if (!mSwitchable) {
-    NS_WARNING("Resume a non-switchable call ignored!");
-    return;
+    NS_WARNING("Resume a non-switchable call is rejected!");
+    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return promise.forget();
   }
 
-  nsresult rv = mTelephony->Service()->ResumeCall(mServiceId, mCallIndex);
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
-    return;
-  }
+  nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
+  aRv = mTelephony->Service()->ResumeCall(mServiceId, mCallIndex, callback);
+  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
 
   ChangeStateInternal(nsITelephonyService::CALL_STATE_RESUMING, true);
+  return promise.forget();
 }
--- a/dom/telephony/TelephonyCall.h
+++ b/dom/telephony/TelephonyCall.h
@@ -2,22 +2,21 @@
 /* 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_telephony_telephonycall_h__
 #define mozilla_dom_telephony_telephonycall_h__
 
+#include "mozilla/dom/DOMError.h"
+#include "mozilla/dom/Promise.h"
+#include "mozilla/dom/TelephonyCallId.h"
 #include "mozilla/dom/telephony/TelephonyCommon.h"
 
-#include "mozilla/dom/DOMError.h"
-
-#include "TelephonyCallId.h"
-
 class nsPIDOMWindow;
 
 namespace mozilla {
 namespace dom {
 
 class TelephonyCall MOZ_FINAL : public DOMEventTargetHelper
 {
   nsRefPtr<Telephony> mTelephony;
@@ -86,26 +85,26 @@ public:
   }
 
   already_AddRefed<DOMError>
   GetError() const;
 
   already_AddRefed<TelephonyCallGroup>
   GetGroup() const;
 
-  void
+  already_AddRefed<Promise>
   Answer(ErrorResult& aRv);
 
-  void
+  already_AddRefed<Promise>
   HangUp(ErrorResult& aRv);
 
-  void
+  already_AddRefed<Promise>
   Hold(ErrorResult& aRv);
 
-  void
+  already_AddRefed<Promise>
   Resume(ErrorResult& aRv);
 
   IMPL_EVENT_HANDLER(statechange)
   IMPL_EVENT_HANDLER(dialing)
   IMPL_EVENT_HANDLER(alerting)
   IMPL_EVENT_HANDLER(connecting)
   IMPL_EVENT_HANDLER(connected)
   IMPL_EVENT_HANDLER(disconnecting)