2012-07-18 20:27:19 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=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/. */
|
|
|
|
|
|
|
|
#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 "nsContentUtils.h"
|
|
|
|
#include "nsDOMClassInfo.h"
|
|
|
|
#include "nsRadioInterfaceLayer.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-02-05 01:02:18 -08:00
|
|
|
#include "GeneratedEvents.h"
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2013-02-05 01:02:15 -08:00
|
|
|
DOMCI_DATA(MozVoicemail, mozilla::dom::Voicemail)
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2013-02-05 01:02:15 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
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)
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(Voicemail::RILVoicemailCallback, nsIRILVoicemailCallback)
|
|
|
|
|
|
|
|
Voicemail::Voicemail(nsPIDOMWindow* aWindow, nsIRILContentHelper* aRIL)
|
|
|
|
: mRIL(aRIL)
|
|
|
|
{
|
|
|
|
BindToOwner(aWindow);
|
|
|
|
|
|
|
|
mRILVoicemailCallback = new RILVoicemailCallback(this);
|
|
|
|
|
|
|
|
nsresult rv = aRIL->RegisterVoicemailCallback(mRILVoicemailCallback);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed registering voicemail callback with RIL");
|
|
|
|
}
|
2012-10-09 03:07:11 -07:00
|
|
|
|
|
|
|
rv = aRIL->RegisterVoicemailMsg();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed registering voicemail messages with RIL");
|
|
|
|
}
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Voicemail::~Voicemail()
|
|
|
|
{
|
|
|
|
if (mRIL && mRILVoicemailCallback) {
|
|
|
|
mRIL->UnregisterVoicemailCallback(mRILVoicemailCallback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
NS_ENSURE_STATE(mRIL);
|
|
|
|
return mRIL->GetVoicemailStatus(aStatus);
|
|
|
|
}
|
|
|
|
|
2012-07-20 17:19:38 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Voicemail::GetNumber(nsAString& aNumber)
|
|
|
|
{
|
|
|
|
NS_ENSURE_STATE(mRIL);
|
|
|
|
aNumber.SetIsVoid(true);
|
|
|
|
|
|
|
|
return mRIL->GetVoicemailNumber(aNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Voicemail::GetDisplayName(nsAString& aDisplayName)
|
|
|
|
{
|
|
|
|
NS_ENSURE_STATE(mRIL);
|
|
|
|
aDisplayName.SetIsVoid(true);
|
|
|
|
|
|
|
|
return mRIL->GetVoicemailDisplayName(aDisplayName);
|
|
|
|
}
|
|
|
|
|
2012-07-18 20:27:19 -07:00
|
|
|
NS_IMPL_EVENT_HANDLER(Voicemail, statuschanged)
|
|
|
|
|
|
|
|
// nsIRILVoicemailCallback
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Voicemail::VoicemailNotification(nsIDOMMozVoicemailStatus* aStatus)
|
|
|
|
{
|
2013-02-05 01:02:18 -08:00
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
NS_NewDOMMozVoicemailEvent(getter_AddRefs(event), nullptr, nullptr);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-02-05 01:02:15 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-07-18 20:27:19 -07:00
|
|
|
nsresult
|
|
|
|
NS_NewVoicemail(nsPIDOMWindow* aWindow, nsIDOMMozVoicemail** aVoicemail)
|
|
|
|
{
|
|
|
|
nsPIDOMWindow* innerWindow = aWindow->IsInnerWindow() ?
|
|
|
|
aWindow :
|
|
|
|
aWindow->GetCurrentInnerWindow();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRILContentHelper> ril =
|
|
|
|
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
|
|
|
NS_ENSURE_STATE(ril);
|
|
|
|
|
2013-02-05 01:02:15 -08:00
|
|
|
nsRefPtr<mozilla::dom::Voicemail> voicemail =
|
|
|
|
new mozilla::dom::Voicemail(innerWindow, ril);
|
2012-07-18 20:27:19 -07:00
|
|
|
voicemail.forget(aVoicemail);
|
|
|
|
return NS_OK;
|
|
|
|
}
|