Bug 1043165 - Part 2: Add TelephonyCall.disconnectedReason (dom). r=hsinyi
authorSzu-Yu Chen [:aknow] <szchen@mozilla.com>
Thu, 26 Mar 2015 16:39:39 +0800
changeset 265972 7fe43cd64f4dff94259ff8149735a49b1561ee3e
parent 265971 a391057b98933956ff8b6f54949dbf294e751a1d
child 265973 f42d8e5bb0c3cefc18b59005cfddabc86fc4e8bb
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi
bugs1043165
milestone39.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 1043165 - Part 2: Add TelephonyCall.disconnectedReason (dom). r=hsinyi
dom/telephony/Telephony.cpp
dom/telephony/TelephonyCall.cpp
dom/telephony/TelephonyCall.h
--- a/dom/telephony/Telephony.cpp
+++ b/dom/telephony/Telephony.cpp
@@ -680,17 +680,19 @@ Telephony::NotifyError(uint32_t aService
   nsRefPtr<TelephonyCall> callToNotify =
     GetCallFromEverywhere(aServiceId, aCallIndex);
   if (!callToNotify) {
     NS_ERROR("Don't call me with a bad call index!");
     return NS_ERROR_UNEXPECTED;
   }
 
   // Set the call state to 'disconnected' and remove it from the calls list.
+  callToNotify->UpdateDisconnectedReason(aError);
   callToNotify->NotifyError(aError);
+  callToNotify->ChangeState(nsITelephonyService::CALL_STATE_DISCONNECTED);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 Telephony::NotifyCdmaCallWaiting(uint32_t aServiceId, const nsAString& aNumber,
                                  uint16_t aNumberPresentation,
                                  const nsAString& aName,
--- a/dom/telephony/TelephonyCall.cpp
+++ b/dom/telephony/TelephonyCall.cpp
@@ -10,16 +10,35 @@
 #include "mozilla/dom/telephony/TelephonyCallback.h"
 
 #include "mozilla/dom/DOMError.h"
 #include "nsPrintfCString.h"
 
 #include "Telephony.h"
 #include "TelephonyCallGroup.h"
 
+#ifdef CONVERT_STRING_TO_NULLABLE_ENUM
+#undef CONVERT_STRING_TO_NULLABLE_ENUM
+#endif
+
+#define CONVERT_STRING_TO_NULLABLE_ENUM(_string, _enumType, _enum)      \
+{                                                                       \
+  _enum.SetNull();                                                      \
+                                                                        \
+  uint32_t i = 0;                                                       \
+  for (const EnumEntry* entry = _enumType##Values::strings;             \
+       entry->value;                                                    \
+       ++entry, ++i) {                                                  \
+    if (_string.EqualsASCII(entry->value)) {                            \
+      _enum.SetValue(static_cast<_enumType>(i));                        \
+      break;                                                            \
+    }                                                                   \
+  }                                                                     \
+}
+
 using namespace mozilla::dom;
 using namespace mozilla::dom::telephony;
 using mozilla::ErrorResult;
 
 // static
 already_AddRefed<TelephonyCall>
 TelephonyCall::Create(Telephony* aTelephony, TelephonyCallId* aId,
                       uint32_t aServiceId, uint32_t aCallIndex,
@@ -110,16 +129,17 @@ TelephonyCall::ChangeStateInternal(uint1
   if (aCallState == nsITelephonyService::CALL_STATE_DISCONNECTED) {
     NS_ASSERTION(mLive, "Should be live!");
     mLive = false;
     if (mGroup) {
       mGroup->RemoveCall(this);
     } else {
       mTelephony->RemoveCall(this);
     }
+    UpdateDisconnectedReason(NS_LITERAL_STRING("NormalCallClearingError"));
   } else if (!mLive) {
     mLive = true;
     if (mGroup) {
       mGroup->AddCall(this);
     } else {
       mTelephony->AddCall(this);
     }
   }
@@ -177,26 +197,39 @@ TelephonyCall::CreatePromise(ErrorResult
 void
 TelephonyCall::NotifyError(const nsAString& aError)
 {
   // Set the error string
   NS_ASSERTION(!mError, "Already have an error?");
 
   mError = new DOMError(GetOwner(), aError);
 
-  // Do the state transitions
-  ChangeStateInternal(nsITelephonyService::CALL_STATE_DISCONNECTED, true);
-
   nsresult rv = DispatchCallEvent(NS_LITERAL_STRING("error"), this);
   if (NS_FAILED(rv)) {
     NS_WARNING("Failed to dispatch error event!");
   }
 }
 
 void
+TelephonyCall::UpdateDisconnectedReason(const nsAString& aDisconnectedReason)
+{
+  NS_ASSERTION(Substring(aDisconnectedReason, aDisconnectedReason.Length() - 5).EqualsLiteral("Error"),
+               "Disconnected reason should end with 'Error'");
+
+  if (mDisconnectedReason.IsNull()) {
+    // There is no 'Error' suffix in the corresponding enum. We should skip
+    // that part for comparison.
+    CONVERT_STRING_TO_NULLABLE_ENUM(
+        Substring(aDisconnectedReason, 0, aDisconnectedReason.Length() - 5),
+        TelephonyCallDisconnectedReason,
+        mDisconnectedReason);
+  }
+}
+
+void
 TelephonyCall::ChangeGroup(TelephonyCallGroup* aGroup)
 {
   mGroup = aGroup;
 
   nsresult rv = DispatchCallEvent(NS_LITERAL_STRING("groupchange"), this);
   if (NS_FAILED(rv)) {
     NS_WARNING("Failed to dispatch error event!");
   }
--- a/dom/telephony/TelephonyCall.h
+++ b/dom/telephony/TelephonyCall.h
@@ -4,16 +4,17 @@
  * 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/TelephonyCallBinding.h"
 #include "mozilla/dom/TelephonyCallId.h"
 #include "mozilla/dom/telephony/TelephonyCommon.h"
 
 class nsPIDOMWindow;
 
 namespace mozilla {
 namespace dom {
 
@@ -24,16 +25,18 @@ class TelephonyCall final : public DOMEv
 
   nsRefPtr<TelephonyCallId> mId;
   nsRefPtr<TelephonyCallId> mSecondId;
 
   uint32_t mServiceId;
   nsString mState;
   bool mEmergency;
   nsRefPtr<DOMError> mError;
+  Nullable<TelephonyCallDisconnectedReason> mDisconnectedReason;
+
   bool mSwitchable;
   bool mMergeable;
 
   uint32_t mCallIndex;
   uint16_t mCallState;
   bool mLive;
 
 public:
@@ -82,16 +85,22 @@ public:
   Mergeable() const
   {
     return mMergeable;
   }
 
   already_AddRefed<DOMError>
   GetError() const;
 
+  Nullable<TelephonyCallDisconnectedReason>
+  GetDisconnectedReason() const
+  {
+    return mDisconnectedReason;
+  }
+
   already_AddRefed<TelephonyCallGroup>
   GetGroup() const;
 
   already_AddRefed<Promise>
   Answer(ErrorResult& aRv);
 
   already_AddRefed<Promise>
   HangUp(ErrorResult& aRv);
@@ -161,16 +170,19 @@ public:
   UpdateSecondId(TelephonyCallId* aId) {
     mSecondId = aId;
   }
 
   void
   NotifyError(const nsAString& aError);
 
   void
+  UpdateDisconnectedReason(const nsAString& aDisconnectedReason);
+
+  void
   ChangeGroup(TelephonyCallGroup* aGroup);
 
 private:
   explicit TelephonyCall(nsPIDOMWindow* aOwner);
 
   ~TelephonyCall();
 
   void