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/. */
|
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
#include "mozilla/dom/Voicemail.h"
|
2013-09-03 07:38:53 -07:00
|
|
|
|
|
|
|
#include "mozilla/dom/MozVoicemailBinding.h"
|
2014-06-10 18:23:34 -07:00
|
|
|
#include "mozilla/dom/MozVoicemailEvent.h"
|
2014-07-17 13:47:41 -07:00
|
|
|
#include "mozilla/dom/MozVoicemailStatusBinding.h"
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2013-10-28 18:58:12 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-07-18 20:27:19 -07:00
|
|
|
#include "mozilla/Services.h"
|
2014-07-17 13:47:41 -07:00
|
|
|
#include "nsContentUtils.h"
|
2012-07-18 20:27:19 -07:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
|
2014-09-25 22:00:25 -07:00
|
|
|
// Service instantiation
|
|
|
|
#include "ipc/VoicemailIPCService.h"
|
|
|
|
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
|
|
|
#include "nsIGonkVoicemailService.h"
|
|
|
|
#endif
|
|
|
|
#include "nsXULAppAPI.h" // For XRE_GetProcessType()
|
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
using namespace mozilla::dom;
|
2014-09-25 22:00:24 -07:00
|
|
|
using mozilla::ErrorResult;
|
2013-03-06 01:53:19 -08:00
|
|
|
|
2014-07-06 19:46:15 -07:00
|
|
|
class Voicemail::Listener MOZ_FINAL : public nsIVoicemailListener
|
2013-03-06 01:53:19 -08:00
|
|
|
{
|
|
|
|
Voicemail* mVoicemail;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_FORWARD_SAFE_NSIVOICEMAILLISTENER(mVoicemail)
|
|
|
|
|
2014-09-24 06:16:53 -07:00
|
|
|
explicit Listener(Voicemail* aVoicemail)
|
2013-03-06 01:53:19 -08:00
|
|
|
: mVoicemail(aVoicemail)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mVoicemail);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Disconnect()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mVoicemail);
|
|
|
|
mVoicemail = nullptr;
|
|
|
|
}
|
2014-07-11 00:58:01 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
~Listener()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mVoicemail);
|
|
|
|
}
|
2013-03-06 01:53:19 -08:00
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(Voicemail::Listener, nsIVoicemailListener)
|
2013-03-06 01:53:19 -08:00
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(Voicemail, DOMEventTargetHelper,
|
|
|
|
mStatuses)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Voicemail)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(Voicemail, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(Voicemail, DOMEventTargetHelper)
|
|
|
|
|
|
|
|
/* static */ already_AddRefed<Voicemail>
|
|
|
|
Voicemail::Create(nsPIDOMWindow* aWindow,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIVoicemailService> service =
|
|
|
|
do_GetService(NS_VOICEMAIL_SERVICE_CONTRACTID);
|
|
|
|
if (!service) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPIDOMWindow* innerWindow = aWindow->IsInnerWindow() ?
|
|
|
|
aWindow :
|
|
|
|
aWindow->GetCurrentInnerWindow();
|
|
|
|
|
|
|
|
nsRefPtr<Voicemail> voicemail = new Voicemail(innerWindow, service);
|
|
|
|
return voicemail.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
Voicemail::Voicemail(nsPIDOMWindow* aWindow,
|
2014-09-25 22:00:23 -07:00
|
|
|
nsIVoicemailService* aService)
|
2014-03-31 23:13:50 -07:00
|
|
|
: DOMEventTargetHelper(aWindow)
|
2014-09-25 22:00:23 -07:00
|
|
|
, mService(aService)
|
2012-07-18 20:27:19 -07:00
|
|
|
{
|
2014-09-25 22:00:24 -07:00
|
|
|
MOZ_ASSERT(mService);
|
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
mListener = new Listener(this);
|
2014-09-25 22:00:24 -07:00
|
|
|
DebugOnly<nsresult> rv = mService->RegisterListener(mListener);
|
2013-03-06 01:53:19 -08:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
2014-09-25 22:00:23 -07:00
|
|
|
"Failed registering voicemail messages with service");
|
2014-09-25 22:00:24 -07:00
|
|
|
|
|
|
|
uint32_t length = 0;
|
|
|
|
if (NS_SUCCEEDED(mService->GetNumItems(&length)) && length != 0) {
|
|
|
|
mStatuses.SetLength(length);
|
|
|
|
}
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Voicemail::~Voicemail()
|
|
|
|
{
|
2014-09-25 22:00:24 -07:00
|
|
|
MOZ_ASSERT(!mService && !mListener);
|
|
|
|
}
|
2013-03-06 01:53:19 -08:00
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
void
|
|
|
|
Voicemail::Shutdown()
|
|
|
|
{
|
2013-03-06 01:53:19 -08:00
|
|
|
mListener->Disconnect();
|
2014-09-25 22:00:24 -07:00
|
|
|
mService->UnregisterListener(mListener);
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
mListener = nullptr;
|
|
|
|
mService = nullptr;
|
|
|
|
mStatuses.Clear();
|
|
|
|
}
|
2014-08-19 18:01:49 -07:00
|
|
|
|
2013-09-03 07:38:53 -07:00
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
Voicemail::WrapObject(JSContext* aCx)
|
2013-09-03 07:38:53 -07:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return MozVoicemailBinding::Wrap(aCx, this);
|
2013-09-03 07:38:53 -07:00
|
|
|
}
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
already_AddRefed<nsIVoicemailProvider>
|
|
|
|
Voicemail::GetItemByServiceId(const Optional<uint32_t>& aOptionalServiceId,
|
|
|
|
uint32_t& aActualServiceId) const
|
2013-10-28 18:58:12 -07:00
|
|
|
{
|
2014-09-25 22:00:24 -07:00
|
|
|
if (!mService) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-10-28 18:58:12 -07:00
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
nsCOMPtr<nsIVoicemailProvider> provider;
|
|
|
|
if (aOptionalServiceId.WasPassed()) {
|
|
|
|
aActualServiceId = aOptionalServiceId.Value();
|
|
|
|
mService->GetItemByServiceId(aActualServiceId,
|
|
|
|
getter_AddRefs(provider));
|
|
|
|
} else {
|
|
|
|
mService->GetDefaultItem(getter_AddRefs(provider));
|
|
|
|
if (provider) {
|
|
|
|
NS_ENSURE_SUCCESS(provider->GetServiceId(&aActualServiceId), nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For all retrieved providers, they should have service id
|
|
|
|
// < mStatuses.Length().
|
|
|
|
MOZ_ASSERT(!provider || aActualServiceId < mStatuses.Length());
|
|
|
|
return provider.forget();
|
2013-10-28 18:58:12 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
already_AddRefed<VoicemailStatus>
|
|
|
|
Voicemail::GetOrCreateStatus(uint32_t aServiceId,
|
|
|
|
nsIVoicemailProvider* aProvider)
|
2013-10-28 18:58:12 -07:00
|
|
|
{
|
2014-09-25 22:00:24 -07:00
|
|
|
MOZ_ASSERT(aServiceId < mStatuses.Length());
|
|
|
|
MOZ_ASSERT(aProvider);
|
|
|
|
|
|
|
|
nsRefPtr<VoicemailStatus> res = mStatuses[aServiceId];
|
|
|
|
if (!res) {
|
|
|
|
mStatuses[aServiceId] = res = new VoicemailStatus(GetOwner(), aProvider);
|
2013-10-28 18:58:12 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
return res.forget();
|
2013-10-28 18:58:12 -07:00
|
|
|
}
|
|
|
|
|
2013-09-03 07:38:53 -07:00
|
|
|
// MozVoicemail WebIDL
|
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
already_AddRefed<VoicemailStatus>
|
2013-10-28 18:58:12 -07:00
|
|
|
Voicemail::GetStatus(const Optional<uint32_t>& aServiceId,
|
2014-09-25 22:00:24 -07:00
|
|
|
ErrorResult& aRv)
|
2012-07-18 20:27:19 -07:00
|
|
|
{
|
2014-09-25 22:00:24 -07:00
|
|
|
uint32_t actualServiceId = 0;
|
|
|
|
nsCOMPtr<nsIVoicemailProvider> provider =
|
|
|
|
GetItemByServiceId(aServiceId, actualServiceId);
|
|
|
|
if (!provider) {
|
2013-09-03 07:38:53 -07:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
return GetOrCreateStatus(actualServiceId, provider);
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
|
|
|
|
2013-09-03 07:38:53 -07:00
|
|
|
void
|
2014-09-25 22:00:23 -07:00
|
|
|
Voicemail::GetNumber(const Optional<uint32_t>& aServiceId,
|
|
|
|
nsString& aNumber,
|
2013-10-28 18:58:12 -07:00
|
|
|
ErrorResult& aRv) const
|
2012-07-20 17:19:38 -07:00
|
|
|
{
|
|
|
|
aNumber.SetIsVoid(true);
|
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
uint32_t unused = 0;
|
|
|
|
nsCOMPtr<nsIVoicemailProvider> provider =
|
|
|
|
GetItemByServiceId(aServiceId, unused);
|
|
|
|
if (!provider) {
|
2013-09-03 07:38:53 -07:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
aRv = provider->GetNumber(aNumber);
|
2012-07-20 17:19:38 -07:00
|
|
|
}
|
|
|
|
|
2013-09-03 07:38:53 -07:00
|
|
|
void
|
2014-09-25 22:00:23 -07:00
|
|
|
Voicemail::GetDisplayName(const Optional<uint32_t>& aServiceId,
|
|
|
|
nsString& aDisplayName,
|
2013-10-28 18:58:12 -07:00
|
|
|
ErrorResult& aRv) const
|
2012-07-20 17:19:38 -07:00
|
|
|
{
|
|
|
|
aDisplayName.SetIsVoid(true);
|
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
uint32_t unused = 0;
|
|
|
|
nsCOMPtr<nsIVoicemailProvider> provider =
|
|
|
|
GetItemByServiceId(aServiceId, unused);
|
|
|
|
if (!provider) {
|
2013-09-03 07:38:53 -07:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
2012-07-20 17:19:38 -07:00
|
|
|
|
2014-09-25 22:00:24 -07:00
|
|
|
aRv = provider->GetDisplayName(aDisplayName);
|
2013-09-03 07:38:53 -07:00
|
|
|
}
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2013-03-06 01:53:19 -08:00
|
|
|
// nsIVoicemailListener
|
2012-07-18 20:27:19 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-09-25 22:00:24 -07:00
|
|
|
Voicemail::NotifyInfoChanged(nsIVoicemailProvider* aProvider)
|
2012-07-18 20:27:19 -07:00
|
|
|
{
|
2014-09-25 22:00:24 -07:00
|
|
|
// Ignored.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Voicemail::NotifyStatusChanged(nsIVoicemailProvider* aProvider)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aProvider);
|
|
|
|
|
|
|
|
uint32_t serviceId = 0;
|
|
|
|
if (NS_FAILED(aProvider->GetServiceId(&serviceId))) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2014-06-10 18:23:34 -07:00
|
|
|
MozVoicemailEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
2014-09-25 22:00:24 -07:00
|
|
|
init.mStatus = GetOrCreateStatus(serviceId, aProvider);
|
2014-06-10 18:23:34 -07:00
|
|
|
|
|
|
|
nsRefPtr<MozVoicemailEvent> event =
|
|
|
|
MozVoicemailEvent::Constructor(this, NS_LITERAL_STRING("statuschanged"), init);
|
|
|
|
return DispatchTrustedEvent(event);
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
2014-09-25 22:00:25 -07:00
|
|
|
|
|
|
|
already_AddRefed<nsIVoicemailService>
|
|
|
|
NS_CreateVoicemailService()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIVoicemailService> service;
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
service = new mozilla::dom::voicemail::VoicemailIPCService();
|
|
|
|
} else {
|
|
|
|
#if defined(MOZ_B2G_RIL)
|
|
|
|
#if defined(MOZ_WIDGET_GONK)
|
|
|
|
service = do_GetService(GONK_VOICEMAIL_SERVICE_CONTRACTID);
|
|
|
|
#endif // MOZ_WIDGET_GONK
|
|
|
|
#endif // MOZ_B2G_RIL
|
|
|
|
}
|
|
|
|
|
|
|
|
return service.forget();
|
|
|
|
}
|