2013-08-13 23:56:21 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-07-18 20:27:19 -07:00
|
|
|
/* 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 "Voicemail.h"
|
2013-02-05 01:02:15 -08:00
|
|
|
#include "nsIDOMMozVoicemailStatus.h"
|
2013-02-05 01:02:18 -08:00
|
|
|
#include "nsIDOMMozVoicemailEvent.h"
|
2012-07-18 20:27:19 -07:00
|
|
|
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "nsDOMClassInfo.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-02-05 01:02:18 -08:00
|
|
|
#include "GeneratedEvents.h"
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
#define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
class Voicemail::Listener : public nsIVoicemailListener
|
|
|
|
{
|
|
|
|
Voicemail* mVoicemail;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_FORWARD_SAFE_NSIVOICEMAILLISTENER(mVoicemail)
|
|
|
|
|
|
|
|
Listener(Voicemail* aVoicemail)
|
|
|
|
: mVoicemail(aVoicemail)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mVoicemail);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Disconnect()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mVoicemail);
|
|
|
|
mVoicemail = nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(Voicemail::Listener, nsIVoicemailListener)
|
|
|
|
|
|
|
|
DOMCI_DATA(MozVoicemail, Voicemail)
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2013-02-07 02:19:08 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN(Voicemail)
|
2012-07-18 20:27:19 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozVoicemail)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozVoicemail)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(Voicemail, nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(Voicemail, nsDOMEventTargetHelper)
|
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
Voicemail::Voicemail(nsPIDOMWindow* aWindow,
|
|
|
|
nsIVoicemailProvider* aProvider)
|
|
|
|
: mProvider(aProvider)
|
2012-07-18 20:27:19 -07:00
|
|
|
{
|
|
|
|
BindToOwner(aWindow);
|
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
mListener = new Listener(this);
|
|
|
|
DebugOnly<nsresult> rv = mProvider->RegisterVoicemailMsg(mListener);
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
|
|
|
"Failed registering voicemail messages with provider");
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Voicemail::~Voicemail()
|
|
|
|
{
|
2013-03-06 01:53:19 -08:00
|
|
|
MOZ_ASSERT(mProvider && mListener);
|
|
|
|
|
|
|
|
mListener->Disconnect();
|
|
|
|
mProvider->UnregisterVoicemailMsg(mListener);
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMMozVoicemail
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Voicemail::GetStatus(nsIDOMMozVoicemailStatus** aStatus)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aStatus = nullptr;
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
NS_ENSURE_STATE(mProvider);
|
|
|
|
return mProvider->GetVoicemailStatus(aStatus);
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
|
|
|
|
2012-07-20 17:19:38 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Voicemail::GetNumber(nsAString& aNumber)
|
|
|
|
{
|
2013-03-06 01:53:19 -08:00
|
|
|
NS_ENSURE_STATE(mProvider);
|
2012-07-20 17:19:38 -07:00
|
|
|
aNumber.SetIsVoid(true);
|
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
return mProvider->GetVoicemailNumber(aNumber);
|
2012-07-20 17:19:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Voicemail::GetDisplayName(nsAString& aDisplayName)
|
|
|
|
{
|
2013-03-06 01:53:19 -08:00
|
|
|
NS_ENSURE_STATE(mProvider);
|
2012-07-20 17:19:38 -07:00
|
|
|
aDisplayName.SetIsVoid(true);
|
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
return mProvider->GetVoicemailDisplayName(aDisplayName);
|
2012-07-20 17:19:38 -07:00
|
|
|
}
|
|
|
|
|
2012-07-18 20:27:19 -07:00
|
|
|
NS_IMPL_EVENT_HANDLER(Voicemail, statuschanged)
|
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
// nsIVoicemailListener
|
2012-07-18 20:27:19 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-03-06 01:53:19 -08:00
|
|
|
Voicemail::NotifyStatusChanged(nsIDOMMozVoicemailStatus* aStatus)
|
2012-07-18 20:27:19 -07:00
|
|
|
{
|
2013-02-05 01:02:18 -08:00
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
2013-03-09 03:34:29 -08:00
|
|
|
NS_NewDOMMozVoicemailEvent(getter_AddRefs(event), this, nullptr, nullptr);
|
2013-02-05 01:02:18 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMMozVoicemailEvent> ce = do_QueryInterface(event);
|
|
|
|
nsresult rv = ce->InitMozVoicemailEvent(NS_LITERAL_STRING("statuschanged"),
|
2012-07-18 20:27:19 -07:00
|
|
|
false, false, aStatus);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-05 01:02:18 -08:00
|
|
|
return DispatchTrustedEvent(ce);
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewVoicemail(nsPIDOMWindow* aWindow, nsIDOMMozVoicemail** aVoicemail)
|
|
|
|
{
|
|
|
|
nsPIDOMWindow* innerWindow = aWindow->IsInnerWindow() ?
|
|
|
|
aWindow :
|
|
|
|
aWindow->GetCurrentInnerWindow();
|
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
nsCOMPtr<nsIVoicemailProvider> provider =
|
2012-07-18 20:27:19 -07:00
|
|
|
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
2013-03-06 01:53:19 -08:00
|
|
|
NS_ENSURE_STATE(provider);
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2013-02-05 01:02:15 -08:00
|
|
|
nsRefPtr<mozilla::dom::Voicemail> voicemail =
|
2013-03-06 01:53:19 -08:00
|
|
|
new mozilla::dom::Voicemail(innerWindow, provider);
|
2012-07-18 20:27:19 -07:00
|
|
|
voicemail.forget(aVoicemail);
|
|
|
|
return NS_OK;
|
|
|
|
}
|