mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1100895 - Part 2: Implement ready attribute. r=hsinyi
This commit is contained in:
parent
b3cce064fa
commit
f756e7d379
@ -62,27 +62,17 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class Telephony::EnumerationAck : public nsRunnable
|
||||
{
|
||||
nsRefPtr<Telephony> mTelephony;
|
||||
|
||||
public:
|
||||
explicit EnumerationAck(Telephony* aTelephony)
|
||||
: mTelephony(aTelephony)
|
||||
{
|
||||
MOZ_ASSERT(mTelephony);
|
||||
}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
mTelephony->NotifyEvent(NS_LITERAL_STRING("ready"));
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
Telephony::Telephony(nsPIDOMWindow* aOwner)
|
||||
: DOMEventTargetHelper(aOwner), mEnumerated(false)
|
||||
: DOMEventTargetHelper(aOwner)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aOwner);
|
||||
MOZ_ASSERT(global);
|
||||
|
||||
ErrorResult rv;
|
||||
nsRefPtr<Promise> promise = Promise::Create(global, rv);
|
||||
MOZ_ASSERT(!rv.Failed());
|
||||
|
||||
mReadyPromise = promise;
|
||||
}
|
||||
|
||||
Telephony::~Telephony()
|
||||
@ -327,6 +317,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Telephony,
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCalls)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCallsList)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGroup)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReadyPromise)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Telephony,
|
||||
@ -335,6 +326,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Telephony,
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCalls)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCallsList)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGroup)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReadyPromise)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Telephony)
|
||||
@ -462,14 +454,16 @@ Telephony::ConferenceGroup() const
|
||||
return group.forget();
|
||||
}
|
||||
|
||||
// EventTarget
|
||||
|
||||
void
|
||||
Telephony::EventListenerAdded(nsIAtom* aType)
|
||||
already_AddRefed<Promise>
|
||||
Telephony::GetReady(ErrorResult& aRv) const
|
||||
{
|
||||
if (aType == nsGkAtoms::onready) {
|
||||
EnqueueEnumerationAck();
|
||||
if (!mReadyPromise) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<Promise> promise = mReadyPromise;
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
// nsITelephonyListener
|
||||
@ -548,8 +542,6 @@ Telephony::ConferenceCallStateChanged(uint16_t aCallState)
|
||||
NS_IMETHODIMP
|
||||
Telephony::EnumerateCallStateComplete()
|
||||
{
|
||||
MOZ_ASSERT(!mEnumerated);
|
||||
|
||||
// Set conference state.
|
||||
if (mGroup->CallsArray().Length() >= 2) {
|
||||
const nsTArray<nsRefPtr<TelephonyCall> > &calls = mGroup->CallsArray();
|
||||
@ -565,10 +557,8 @@ Telephony::EnumerateCallStateComplete()
|
||||
mGroup->ChangeState(callState);
|
||||
}
|
||||
|
||||
mEnumerated = true;
|
||||
|
||||
if (NS_FAILED(NotifyEvent(NS_LITERAL_STRING("ready")))) {
|
||||
NS_WARNING("Failed to notify ready!");
|
||||
if (mReadyPromise) {
|
||||
mReadyPromise->MaybeResolve(JS::UndefinedHandleValue);
|
||||
}
|
||||
|
||||
if (NS_FAILED(mService->RegisterListener(mListener))) {
|
||||
@ -693,19 +683,6 @@ Telephony::DispatchCallEvent(const nsAString& aType,
|
||||
return DispatchTrustedEvent(event);
|
||||
}
|
||||
|
||||
void
|
||||
Telephony::EnqueueEnumerationAck()
|
||||
{
|
||||
if (!mEnumerated) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRunnable> task = new EnumerationAck(this);
|
||||
if (NS_FAILED(NS_DispatchToCurrentThread(task))) {
|
||||
NS_WARNING("Failed to dispatch to current thread!");
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<nsITelephonyService>
|
||||
NS_CreateTelephonyService()
|
||||
{
|
||||
|
@ -40,9 +40,7 @@ class Telephony MOZ_FINAL : public DOMEventTargetHelper,
|
||||
* also bug 775997 comment #51.
|
||||
*/
|
||||
class Listener;
|
||||
class EnumerationAck;
|
||||
|
||||
friend class EnumerationAck;
|
||||
friend class telephony::TelephonyDialCallback;
|
||||
|
||||
nsCOMPtr<nsITelephonyService> mService;
|
||||
@ -53,7 +51,7 @@ class Telephony MOZ_FINAL : public DOMEventTargetHelper,
|
||||
|
||||
nsRefPtr<TelephonyCallGroup> mGroup;
|
||||
|
||||
bool mEnumerated;
|
||||
nsRefPtr<Promise> mReadyPromise;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
@ -109,7 +107,9 @@ public:
|
||||
already_AddRefed<TelephonyCallGroup>
|
||||
ConferenceGroup() const;
|
||||
|
||||
IMPL_EVENT_HANDLER(ready)
|
||||
already_AddRefed<Promise>
|
||||
GetReady(ErrorResult& aRv) const;
|
||||
|
||||
IMPL_EVENT_HANDLER(incoming)
|
||||
IMPL_EVENT_HANDLER(callschanged)
|
||||
IMPL_EVENT_HANDLER(remoteheld)
|
||||
@ -146,8 +146,6 @@ public:
|
||||
return mCalls;
|
||||
}
|
||||
|
||||
virtual void EventListenerAdded(nsIAtom* aType) MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
explicit Telephony(nsPIDOMWindow* aOwner);
|
||||
~Telephony();
|
||||
@ -198,9 +196,6 @@ private:
|
||||
nsresult
|
||||
DispatchCallEvent(const nsAString& aType, TelephonyCall* aCall);
|
||||
|
||||
void
|
||||
EnqueueEnumerationAck();
|
||||
|
||||
already_AddRefed<TelephonyCall>
|
||||
GetCall(uint32_t aServiceId, uint32_t aCallIndex);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user