2013-08-14 10:56:21 +04: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-19 07:27:19 +04: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-26 09:00:24 +04:00
|
|
|
#include "mozilla/dom/Voicemail.h"
|
2013-09-03 18:38:53 +04:00
|
|
|
|
|
|
|
#include "mozilla/dom/MozVoicemailBinding.h"
|
2014-06-11 05:23:34 +04:00
|
|
|
#include "mozilla/dom/MozVoicemailEvent.h"
|
2014-07-18 00:47:41 +04:00
|
|
|
#include "mozilla/dom/MozVoicemailStatusBinding.h"
|
2012-07-19 07:27:19 +04:00
|
|
|
|
2013-10-29 05:58:12 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-07-19 07:27:19 +04:00
|
|
|
#include "mozilla/Services.h"
|
2014-07-18 00:47:41 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-07-19 07:27:19 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
|
2014-09-26 09:00:25 +04: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 13:53:19 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-09-26 09:00:24 +04:00
|
|
|
using mozilla::ErrorResult;
|
2013-03-06 13:53:19 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class Voicemail::Listener final : public nsIVoicemailListener
|
2013-03-06 13:53:19 +04:00
|
|
|
{
|
|
|
|
Voicemail* mVoicemail;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_FORWARD_SAFE_NSIVOICEMAILLISTENER(mVoicemail)
|
|
|
|
|
2014-09-24 17:16:53 +04:00
|
|
|
explicit Listener(Voicemail* aVoicemail)
|
2013-03-06 13:53:19 +04:00
|
|
|
: mVoicemail(aVoicemail)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mVoicemail);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Disconnect()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mVoicemail);
|
|
|
|
mVoicemail = nullptr;
|
|
|
|
}
|
2014-07-11 11:58:01 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
~Listener()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mVoicemail);
|
|
|
|
}
|
2013-03-06 13:53:19 +04:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(Voicemail::Listener, nsIVoicemailListener)
|
2013-03-06 13:53:19 +04:00
|
|
|
|
2014-09-26 09:00:24 +04: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>
|
2016-01-30 20:05:36 +03:00
|
|
|
Voicemail::Create(nsPIDOMWindowInner* aWindow,
|
2014-09-26 09:00:24 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIVoicemailService> service =
|
|
|
|
do_GetService(NS_VOICEMAIL_SERVICE_CONTRACTID);
|
|
|
|
if (!service) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
RefPtr<Voicemail> voicemail = new Voicemail(aWindow, service);
|
2014-09-26 09:00:24 +04:00
|
|
|
return voicemail.forget();
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
Voicemail::Voicemail(nsPIDOMWindowInner* aWindow,
|
2014-09-26 09:00:23 +04:00
|
|
|
nsIVoicemailService* aService)
|
2014-04-01 10:13:50 +04:00
|
|
|
: DOMEventTargetHelper(aWindow)
|
2014-09-26 09:00:23 +04:00
|
|
|
, mService(aService)
|
2012-07-19 07:27:19 +04:00
|
|
|
{
|
2014-09-26 09:00:24 +04:00
|
|
|
MOZ_ASSERT(mService);
|
|
|
|
|
2013-03-06 13:53:19 +04:00
|
|
|
mListener = new Listener(this);
|
2014-09-26 09:00:24 +04:00
|
|
|
DebugOnly<nsresult> rv = mService->RegisterListener(mListener);
|
2013-03-06 13:53:19 +04:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
2014-09-26 09:00:23 +04:00
|
|
|
"Failed registering voicemail messages with service");
|
2014-09-26 09:00:24 +04:00
|
|
|
|
|
|
|
uint32_t length = 0;
|
|
|
|
if (NS_SUCCEEDED(mService->GetNumItems(&length)) && length != 0) {
|
|
|
|
mStatuses.SetLength(length);
|
|
|
|
}
|
2012-07-19 07:27:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Voicemail::~Voicemail()
|
|
|
|
{
|
2014-09-26 09:00:24 +04:00
|
|
|
MOZ_ASSERT(!mService && !mListener);
|
|
|
|
}
|
2013-03-06 13:53:19 +04:00
|
|
|
|
2014-09-26 09:00:24 +04:00
|
|
|
void
|
|
|
|
Voicemail::Shutdown()
|
|
|
|
{
|
2013-03-06 13:53:19 +04:00
|
|
|
mListener->Disconnect();
|
2014-09-26 09:00:24 +04:00
|
|
|
mService->UnregisterListener(mListener);
|
2012-07-19 07:27:19 +04:00
|
|
|
|
2014-09-26 09:00:24 +04:00
|
|
|
mListener = nullptr;
|
|
|
|
mService = nullptr;
|
|
|
|
mStatuses.Clear();
|
|
|
|
}
|
2014-08-20 05:01:49 +04:00
|
|
|
|
2013-09-03 18:38:53 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
Voicemail::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-09-03 18:38:53 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return MozVoicemailBinding::Wrap(aCx, this, aGivenProto);
|
2013-09-03 18:38:53 +04:00
|
|
|
}
|
2012-07-19 07:27:19 +04:00
|
|
|
|
2014-09-26 09:00:24 +04:00
|
|
|
already_AddRefed<nsIVoicemailProvider>
|
|
|
|
Voicemail::GetItemByServiceId(const Optional<uint32_t>& aOptionalServiceId,
|
|
|
|
uint32_t& aActualServiceId) const
|
2013-10-29 05:58:12 +04:00
|
|
|
{
|
2014-09-26 09:00:24 +04:00
|
|
|
if (!mService) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-10-29 05:58:12 +04:00
|
|
|
|
2014-09-26 09:00:24 +04: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-29 05:58:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-26 09:00:24 +04:00
|
|
|
already_AddRefed<VoicemailStatus>
|
|
|
|
Voicemail::GetOrCreateStatus(uint32_t aServiceId,
|
|
|
|
nsIVoicemailProvider* aProvider)
|
2013-10-29 05:58:12 +04:00
|
|
|
{
|
2014-09-26 09:00:24 +04:00
|
|
|
MOZ_ASSERT(aServiceId < mStatuses.Length());
|
|
|
|
MOZ_ASSERT(aProvider);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<VoicemailStatus> res = mStatuses[aServiceId];
|
2014-09-26 09:00:24 +04:00
|
|
|
if (!res) {
|
|
|
|
mStatuses[aServiceId] = res = new VoicemailStatus(GetOwner(), aProvider);
|
2013-10-29 05:58:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-26 09:00:24 +04:00
|
|
|
return res.forget();
|
2013-10-29 05:58:12 +04:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:38:53 +04:00
|
|
|
// MozVoicemail WebIDL
|
|
|
|
|
2014-09-26 09:00:24 +04:00
|
|
|
already_AddRefed<VoicemailStatus>
|
2013-10-29 05:58:12 +04:00
|
|
|
Voicemail::GetStatus(const Optional<uint32_t>& aServiceId,
|
2014-09-26 09:00:24 +04:00
|
|
|
ErrorResult& aRv)
|
2012-07-19 07:27:19 +04:00
|
|
|
{
|
2014-09-26 09:00:24 +04:00
|
|
|
uint32_t actualServiceId = 0;
|
|
|
|
nsCOMPtr<nsIVoicemailProvider> provider =
|
|
|
|
GetItemByServiceId(aServiceId, actualServiceId);
|
|
|
|
if (!provider) {
|
2013-09-03 18:38:53 +04:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-07-19 07:27:19 +04:00
|
|
|
|
2014-09-26 09:00:24 +04:00
|
|
|
return GetOrCreateStatus(actualServiceId, provider);
|
2012-07-19 07:27:19 +04:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:38:53 +04:00
|
|
|
void
|
2014-09-26 09:00:23 +04:00
|
|
|
Voicemail::GetNumber(const Optional<uint32_t>& aServiceId,
|
|
|
|
nsString& aNumber,
|
2013-10-29 05:58:12 +04:00
|
|
|
ErrorResult& aRv) const
|
2012-07-21 04:19:38 +04:00
|
|
|
{
|
|
|
|
aNumber.SetIsVoid(true);
|
|
|
|
|
2014-09-26 09:00:24 +04:00
|
|
|
uint32_t unused = 0;
|
|
|
|
nsCOMPtr<nsIVoicemailProvider> provider =
|
|
|
|
GetItemByServiceId(aServiceId, unused);
|
|
|
|
if (!provider) {
|
2013-09-03 18:38:53 +04:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-26 09:00:24 +04:00
|
|
|
aRv = provider->GetNumber(aNumber);
|
2012-07-21 04:19:38 +04:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:38:53 +04:00
|
|
|
void
|
2014-09-26 09:00:23 +04:00
|
|
|
Voicemail::GetDisplayName(const Optional<uint32_t>& aServiceId,
|
|
|
|
nsString& aDisplayName,
|
2013-10-29 05:58:12 +04:00
|
|
|
ErrorResult& aRv) const
|
2012-07-21 04:19:38 +04:00
|
|
|
{
|
|
|
|
aDisplayName.SetIsVoid(true);
|
|
|
|
|
2014-09-26 09:00:24 +04:00
|
|
|
uint32_t unused = 0;
|
|
|
|
nsCOMPtr<nsIVoicemailProvider> provider =
|
|
|
|
GetItemByServiceId(aServiceId, unused);
|
|
|
|
if (!provider) {
|
2013-09-03 18:38:53 +04:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
2012-07-21 04:19:38 +04:00
|
|
|
|
2014-09-26 09:00:24 +04:00
|
|
|
aRv = provider->GetDisplayName(aDisplayName);
|
2013-09-03 18:38:53 +04:00
|
|
|
}
|
2012-07-19 07:27:19 +04:00
|
|
|
|
2013-03-06 13:53:19 +04:00
|
|
|
// nsIVoicemailListener
|
2012-07-19 07:27:19 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-09-26 09:00:24 +04:00
|
|
|
Voicemail::NotifyInfoChanged(nsIVoicemailProvider* aProvider)
|
2012-07-19 07:27:19 +04:00
|
|
|
{
|
2014-09-26 09:00:24 +04: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-11 05:23:34 +04:00
|
|
|
MozVoicemailEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
2014-09-26 09:00:24 +04:00
|
|
|
init.mStatus = GetOrCreateStatus(serviceId, aProvider);
|
2014-06-11 05:23:34 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MozVoicemailEvent> event =
|
2014-06-11 05:23:34 +04:00
|
|
|
MozVoicemailEvent::Constructor(this, NS_LITERAL_STRING("statuschanged"), init);
|
|
|
|
return DispatchTrustedEvent(event);
|
2012-07-19 07:27:19 +04:00
|
|
|
}
|
2014-09-26 09:00:25 +04:00
|
|
|
|
|
|
|
already_AddRefed<nsIVoicemailService>
|
|
|
|
NS_CreateVoicemailService()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIVoicemailService> service;
|
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
2014-09-26 09:00:25 +04:00
|
|
|
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();
|
|
|
|
}
|