Bug 735305 - Update WebTelephony impl to use the new DOMEventTargetHelper API [r=smaug,bent]
authorFabrice Desré <fabrice@mozilla.com>
Tue, 13 Mar 2012 15:11:16 -0700
changeset 88953 c71845b3b2a6
parent 88952 956e2f735262
child 89004 5cddc46dcaf3
child 90697 e008004a2bf6
child 105978 7eb3fbbd50d7
push id22240
push userfdesre@mozilla.com
push date2012-03-13 22:12 +0000
treeherdermozilla-central@c71845b3b2a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, bent
bugs735305
milestone14.0a1
first release with
nightly linux32
c71845b3b2a6 / 14.0a1 / 20120314031139 / files
nightly linux64
c71845b3b2a6 / 14.0a1 / 20120314031139 / files
nightly mac
c71845b3b2a6 / 14.0a1 / 20120314031139 / files
nightly win32
c71845b3b2a6 / 14.0a1 / 20120314031139 / files
nightly win64
c71845b3b2a6 / 14.0a1 / 20120314031139 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 735305 - Update WebTelephony impl to use the new DOMEventTargetHelper API [r=smaug,bent]
dom/telephony/Telephony.cpp
dom/telephony/Telephony.h
dom/telephony/TelephonyCall.cpp
--- a/dom/telephony/Telephony.cpp
+++ b/dom/telephony/Telephony.cpp
@@ -159,18 +159,18 @@ Telephony::Create(nsPIDOMWindow* aOwner,
   nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aOwner);
   NS_ENSURE_TRUE(sgo, nsnull);
 
   nsCOMPtr<nsIScriptContext> scriptContext = sgo->GetContext();
   NS_ENSURE_TRUE(scriptContext, nsnull);
 
   nsRefPtr<Telephony> telephony = new Telephony();
 
-  telephony->mOwner = aOwner;
-  telephony->mScriptContext.swap(scriptContext);
+  telephony->BindToOwner(aOwner);
+
   telephony->mRIL = aRIL;
   telephony->mRILTelephonyCallback = new RILTelephonyCallback(telephony);
 
   nsresult rv = aRIL->EnumerateCalls(telephony->mRILTelephonyCallback);
   NS_ENSURE_SUCCESS(rv, nsnull);
 
   rv = aRIL->RegisterCallback(telephony->mRILTelephonyCallback);
   NS_ENSURE_SUCCESS(rv, nsnull);
@@ -323,41 +323,52 @@ Telephony::SetSpeakerEnabled(bool aSpeak
 NS_IMETHODIMP
 Telephony::GetActive(jsval* aActive)
 {
   if (!mActiveCall) {
     aActive->setNull();
     return NS_OK;
   }
 
-  nsresult rv =
-    nsContentUtils::WrapNative(mScriptContext->GetNativeContext(),
-                               mScriptContext->GetNativeGlobal(),
-                               mActiveCall->ToISupports(), aActive);
+  nsresult rv;
+  nsIScriptContext* sc = GetContextForEventHandlers(&rv);
   NS_ENSURE_SUCCESS(rv, rv);
-
+  if (sc) {
+    rv =
+      nsContentUtils::WrapNative(sc->GetNativeContext(),
+                                 sc->GetNativeGlobal(),
+                                 mActiveCall->ToISupports(), aActive);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 Telephony::GetCalls(jsval* aCalls)
 {
   JSObject* calls = mCallsArray;
   if (!calls) {
-    nsresult rv =
-      nsTArrayToJSArray(mScriptContext->GetNativeContext(),
-                        mScriptContext->GetNativeGlobal(), mCalls, &calls);
+    nsresult rv;
+    nsIScriptContext* sc = GetContextForEventHandlers(&rv);
     NS_ENSURE_SUCCESS(rv, rv);
+    if (sc) {
+      rv =
+        nsTArrayToJSArray(sc->GetNativeContext(),
+                          sc->GetNativeGlobal(), mCalls, &calls);
+      NS_ENSURE_SUCCESS(rv, rv);
 
-    if (!mRooted) {
-      NS_HOLD_JS_OBJECTS(this, Telephony);
-      mRooted = true;
+      if (!mRooted) {
+        NS_HOLD_JS_OBJECTS(this, Telephony);
+        mRooted = true;
+      }
+
+      mCallsArray = calls;
+    } else {
+      NS_ENSURE_SUCCESS(rv, rv);
     }
-
-    mCallsArray = calls;
   }
 
   aCalls->setObject(*calls);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 Telephony::StartTone(const nsAString& aDTMFChar)
--- a/dom/telephony/Telephony.h
+++ b/dom/telephony/Telephony.h
@@ -113,28 +113,16 @@ public:
   }
 
   nsIRadioInterfaceLayer*
   RIL() const
   {
     return mRIL;
   }
 
-  nsPIDOMWindow*
-  Owner() const
-  {
-    return mOwner;
-  }
-
-  nsIScriptContext*
-  ScriptContext() const
-  {
-    return mScriptContext;
-  }
-
 private:
   Telephony();
   ~Telephony();
 
   already_AddRefed<TelephonyCall>
   CreateNewDialingCall(const nsAString& aNumber);
 
   void
--- a/dom/telephony/TelephonyCall.cpp
+++ b/dom/telephony/TelephonyCall.cpp
@@ -52,18 +52,18 @@ TelephonyCall::Create(Telephony* aTeleph
                       PRUint16 aCallState, PRUint32 aCallIndex)
 {
   NS_ASSERTION(aTelephony, "Null pointer!");
   NS_ASSERTION(!aNumber.IsEmpty(), "Empty number!");
   NS_ASSERTION(aCallIndex >= 1, "Invalid call index!");
 
   nsRefPtr<TelephonyCall> call = new TelephonyCall();
 
-  call->mOwner = aTelephony->Owner();
-  call->mScriptContext = aTelephony->ScriptContext();
+  call->BindToOwner(aTelephony->GetOwner());
+
   call->mTelephony = aTelephony;
   call->mNumber = aNumber;
   call->mCallIndex = aCallIndex;
 
   call->ChangeStateInternal(aCallState, false);
 
   return call.forget();
 }