Bug 889737 - Part 04: Refactoring: Change Telephony::Callback to TelephonyCallback. r=vicamo

This commit is contained in:
Szu-Yu Chen [:aknow] 2014-09-22 01:34:00 -04:00
parent 90448a0509
commit b5e29e70ee
5 changed files with 104 additions and 51 deletions

View File

@ -5,19 +5,20 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "Telephony.h"
#include "mozilla/dom/CallEvent.h"
#include "mozilla/dom/TelephonyBinding.h"
#include "mozilla/dom/Promise.h"
#include "nsIURI.h"
#include "nsPIDOMWindow.h"
#include "nsIPermissionManager.h"
#include "mozilla/dom/UnionTypes.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/CallEvent.h"
#include "mozilla/dom/MozMobileConnectionBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/TelephonyBinding.h"
#include "mozilla/dom/UnionTypes.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsContentUtils.h"
#include "nsIPermissionManager.h"
#include "nsIURI.h"
#include "nsNetUtil.h"
#include "nsPIDOMWindow.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
@ -25,6 +26,7 @@
#include "TelephonyCall.h"
#include "TelephonyCallGroup.h"
#include "TelephonyCallId.h"
#include "TelephonyCallback.h"
// Service instantiation
#include "ipc/TelephonyIPCService.h"
@ -34,6 +36,7 @@
#include "nsXULAppAPI.h" // For XRE_GetProcessType()
using namespace mozilla::dom;
using namespace mozilla::dom::telephony;
using mozilla::ErrorResult;
class Telephony::Listener : public nsITelephonyListener
@ -60,43 +63,6 @@ public:
}
};
class Telephony::Callback : public nsITelephonyCallback
{
nsRefPtr<Telephony> mTelephony;
nsRefPtr<Promise> mPromise;
uint32_t mServiceId;
virtual ~Callback() {}
public:
NS_DECL_ISUPPORTS
Callback(Telephony* aTelephony, Promise* aPromise, uint32_t aServiceId)
: mTelephony(aTelephony), mPromise(aPromise), mServiceId(aServiceId)
{
MOZ_ASSERT(mTelephony);
}
NS_IMETHODIMP
NotifyDialError(const nsAString& aError)
{
mPromise->MaybeRejectBrokenly(aError);
return NS_OK;
}
NS_IMETHODIMP
NotifyDialCallSuccess(uint32_t aCallIndex, const nsAString& aNumber)
{
nsRefPtr<TelephonyCallId> id = mTelephony->CreateCallId(aNumber);
nsRefPtr<TelephonyCall> call =
mTelephony->CreateCall(id, mServiceId, aCallIndex,
nsITelephonyService::CALL_STATE_DIALING);
mPromise->MaybeResolve(call);
return NS_OK;
}
};
class Telephony::EnumerationAck : public nsRunnable
{
nsRefPtr<Telephony> mTelephony;
@ -270,7 +236,8 @@ Telephony::DialInternal(uint32_t aServiceId, const nsAString& aNumber,
}
nsCOMPtr<nsITelephonyCallback> callback =
new Callback(this, promise, aServiceId);
new TelephonyCallback(this, promise, aServiceId);
nsresult rv = mService->Dial(aServiceId, aNumber, aEmergency, callback);
if (NS_FAILED(rv)) {
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
@ -381,7 +348,6 @@ NS_IMPL_ADDREF_INHERITED(Telephony, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(Telephony, DOMEventTargetHelper)
NS_IMPL_ISUPPORTS(Telephony::Listener, nsITelephonyListener)
NS_IMPL_ISUPPORTS(Telephony::Callback, nsITelephonyCallback)
// Telephony WebIDL

View File

@ -21,6 +21,11 @@ class nsPIDOMWindow;
namespace mozilla {
namespace dom {
namespace telephony {
class TelephonyCallback;
} // namespace telephony
class OwningTelephonyCallOrTelephonyCallGroup;
@ -35,12 +40,10 @@ class Telephony MOZ_FINAL : public DOMEventTargetHelper,
* also bug 775997 comment #51.
*/
class Listener;
class Callback;
friend class Callback;
class EnumerationAck;
friend class EnumerationAck;
friend class telephony::TelephonyCallback;
nsCOMPtr<nsITelephonyService> mService;
nsRefPtr<Listener> mListener;

View File

@ -0,0 +1,43 @@
/* 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/. */
#include "TelephonyCallback.h"
#include "mozilla/dom/Promise.h"
#include "Telephony.h"
using namespace mozilla::dom;
using namespace mozilla::dom::telephony;
NS_IMPL_ISUPPORTS(TelephonyCallback, nsITelephonyCallback)
TelephonyCallback::TelephonyCallback(Telephony* aTelephony,
Promise* aPromise,
uint32_t aServiceId)
: mTelephony(aTelephony), mPromise(aPromise), mServiceId(aServiceId)
{
MOZ_ASSERT(mTelephony);
}
// nsITelephonyCallback
NS_IMETHODIMP
TelephonyCallback::NotifyDialError(const nsAString& aError)
{
mPromise->MaybeRejectBrokenly(aError);
return NS_OK;
}
NS_IMETHODIMP
TelephonyCallback::NotifyDialCallSuccess(uint32_t aCallIndex,
const nsAString& aNumber)
{
nsRefPtr<TelephonyCallId> id = mTelephony->CreateCallId(aNumber);
nsRefPtr<TelephonyCall> call =
mTelephony->CreateCall(id, mServiceId, aCallIndex,
nsITelephonyService::CALL_STATE_DIALING);
mPromise->MaybeResolve(call);
return NS_OK;
}

View File

@ -0,0 +1,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_TelephonyCallback_h
#define mozilla_dom_TelephonyCallback_h
#include "nsCOMPtr.h"
#include "nsITelephonyService.h"
namespace mozilla {
namespace dom {
class Promise;
class Telephony;
namespace telephony {
class TelephonyCallback MOZ_FINAL : public nsITelephonyCallback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSITELEPHONYCALLBACK
TelephonyCallback(Telephony* aTelephony, Promise* aPromise,
uint32_t aServiceId);
private:
~TelephonyCallback() {}
nsRefPtr<Telephony> mTelephony;
nsRefPtr<Promise> mPromise;
uint32_t mServiceId;
};
} // namespace telephony
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_TelephonyCallback_h

View File

@ -31,6 +31,7 @@ UNIFIED_SOURCES += [
'ipc/TelephonyParent.cpp',
'Telephony.cpp',
'TelephonyCall.cpp',
'TelephonyCallback.cpp',
'TelephonyCallGroup.cpp',
'TelephonyCallId.cpp',
]