Bug 1129882 - add mozInterrupt in telephony object. r=baku
authorAlastor Wu <alwu@mozilla.com>
Thu, 03 Sep 2015 10:14:17 +0800
changeset 296781 5a91d8cf566dc4879a7b7e10dd41fc349cfddf61
parent 296780 5624fdf4b0fe6575a56680aabe013e438f7a8c6f
child 296782 ec3d4122520ade4961dc4a685c028f00bb256a8f
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1129882
milestone43.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 1129882 - add mozInterrupt in telephony object. r=baku
dom/telephony/Telephony.cpp
dom/telephony/Telephony.h
--- a/dom/telephony/Telephony.cpp
+++ b/dom/telephony/Telephony.cpp
@@ -59,17 +59,19 @@ public:
     MOZ_ASSERT(mTelephony);
     mTelephony = nullptr;
   }
 };
 
 Telephony::Telephony(nsPIDOMWindow* aOwner)
   : DOMEventTargetHelper(aOwner),
     mAudioAgentNotify(nsIAudioChannelAgent::AUDIO_AGENT_NOTIFY),
-    mIsAudioStartPlaying(false)
+    mIsAudioStartPlaying(false),
+    mHaveDispatchedInterruptBeginEvent(false),
+    mMuted(AudioChannelService::IsAudioChannelMutedByDefault())
 {
   MOZ_ASSERT(aOwner);
   nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aOwner);
   MOZ_ASSERT(global);
 
   ErrorResult rv;
   nsRefPtr<Promise> promise = Promise::Create(global, rv);
   MOZ_ASSERT(!rv.Failed());
@@ -685,16 +687,32 @@ Telephony::WindowVolumeChanged(float aVo
     rv = aMuted ? mCalls[0]->Hold(callback) : mCalls[0]->Resume(callback);
   } else {
     rv = aMuted ? mGroup->Hold(callback) : mGroup->Resume(callback);
   }
   if (NS_WARN_IF(rv.Failed())) {
     return rv.StealNSResult();
   }
 
+  // These events will be triggered when the telephony is interrupted by other
+  // audio channel.
+  if (mMuted != aMuted) {
+    mMuted = aMuted;
+    // We should not dispatch "mozinterruptend" when the system app initializes
+    // the telephony audio from muted to unmuted at the first time. The event
+    // "mozinterruptend" must be dispatched after the "mozinterruptbegin".
+    if (!mHaveDispatchedInterruptBeginEvent && mMuted) {
+      DispatchTrustedEvent(NS_LITERAL_STRING("mozinterruptbegin"));
+      mHaveDispatchedInterruptBeginEvent = mMuted;
+    } else if (mHaveDispatchedInterruptBeginEvent && !mMuted) {
+      DispatchTrustedEvent(NS_LITERAL_STRING("mozinterruptend"));
+      mHaveDispatchedInterruptBeginEvent = mMuted;
+    }
+  }
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 Telephony::WindowAudioCaptureChanged()
 {
   // Do nothing, it's useless for the telephony object.
   return NS_OK;
--- a/dom/telephony/Telephony.h
+++ b/dom/telephony/Telephony.h
@@ -56,16 +56,18 @@ class Telephony final : public DOMEventT
   nsRefPtr<CallsList> mCallsList;
 
   nsRefPtr<TelephonyCallGroup> mGroup;
 
   nsRefPtr<Promise> mReadyPromise;
 
   uint32_t mAudioAgentNotify;
   bool mIsAudioStartPlaying;
+  bool mHaveDispatchedInterruptBeginEvent;
+  bool mMuted;
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK
   NS_DECL_NSITELEPHONYLISTENER
   NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Telephony,
                                            DOMEventTargetHelper)