2013-08-14 06:56:21 +00: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 03:27:19 +00: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-09-03 14:38:53 +00:00
|
|
|
|
|
|
|
#include "mozilla/dom/MozVoicemailBinding.h"
|
2014-06-11 01:23:34 +00:00
|
|
|
#include "mozilla/dom/MozVoicemailEvent.h"
|
2014-07-17 20:47:41 +00:00
|
|
|
#include "mozilla/dom/MozVoicemailStatusBinding.h"
|
2012-07-19 03:27:19 +00:00
|
|
|
|
2013-10-29 01:58:12 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-07-19 03:27:19 +00:00
|
|
|
#include "mozilla/Services.h"
|
2014-07-17 20:47:41 +00:00
|
|
|
#include "nsContentUtils.h"
|
2012-07-19 03:27:19 +00:00
|
|
|
#include "nsDOMClassInfo.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
|
2013-03-06 09:53:19 +00:00
|
|
|
#define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
|
2013-10-29 01:58:12 +00:00
|
|
|
const char* kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces";
|
2012-07-19 03:27:19 +00:00
|
|
|
|
2013-03-06 09:53:19 +00:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2014-07-07 02:46:15 +00:00
|
|
|
class Voicemail::Listener MOZ_FINAL : public nsIVoicemailListener
|
2013-03-06 09:53:19 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2014-07-11 07:58:01 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
~Listener()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mVoicemail);
|
|
|
|
}
|
2013-03-06 09:53:19 +00:00
|
|
|
};
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(Voicemail::Listener, nsIVoicemailListener)
|
2013-03-06 09:53:19 +00:00
|
|
|
|
|
|
|
Voicemail::Voicemail(nsPIDOMWindow* aWindow,
|
|
|
|
nsIVoicemailProvider* aProvider)
|
2014-04-01 06:13:50 +00:00
|
|
|
: DOMEventTargetHelper(aWindow)
|
2013-09-03 14:38:53 +00:00
|
|
|
, mProvider(aProvider)
|
2012-07-19 03:27:19 +00:00
|
|
|
{
|
2013-03-06 09:53:19 +00: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-19 03:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Voicemail::~Voicemail()
|
|
|
|
{
|
2013-03-06 09:53:19 +00:00
|
|
|
MOZ_ASSERT(mProvider && mListener);
|
|
|
|
|
|
|
|
mListener->Disconnect();
|
|
|
|
mProvider->UnregisterVoicemailMsg(mListener);
|
2012-07-19 03:27:19 +00:00
|
|
|
}
|
|
|
|
|
2013-09-03 14:38:53 +00:00
|
|
|
JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
Voicemail::WrapObject(JSContext* aCx)
|
2013-09-03 14:38:53 +00: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 22:27:17 +00:00
|
|
|
return MozVoicemailBinding::Wrap(aCx, this);
|
2013-09-03 14:38:53 +00:00
|
|
|
}
|
2012-07-19 03:27:19 +00:00
|
|
|
|
2013-10-29 01:58:12 +00:00
|
|
|
bool
|
|
|
|
Voicemail::IsValidServiceId(uint32_t aServiceId) const
|
|
|
|
{
|
|
|
|
uint32_t numClients = mozilla::Preferences::GetUint(kPrefRilNumRadioInterfaces, 1);
|
|
|
|
|
|
|
|
return aServiceId < numClients;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Voicemail::PassedOrDefaultServiceId(const Optional<uint32_t>& aServiceId,
|
|
|
|
uint32_t& aResult) const
|
|
|
|
{
|
|
|
|
if (aServiceId.WasPassed()) {
|
|
|
|
if (!IsValidServiceId(aServiceId.Value())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aResult = aServiceId.Value();
|
|
|
|
} else {
|
|
|
|
mProvider->GetVoicemailDefaultServiceId(&aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-03 14:38:53 +00:00
|
|
|
// MozVoicemail WebIDL
|
|
|
|
|
2014-07-17 20:47:41 +00:00
|
|
|
already_AddRefed<MozVoicemailStatus>
|
2013-10-29 01:58:12 +00:00
|
|
|
Voicemail::GetStatus(const Optional<uint32_t>& aServiceId,
|
|
|
|
ErrorResult& aRv) const
|
2012-07-19 03:27:19 +00:00
|
|
|
{
|
2013-09-03 14:38:53 +00:00
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-07-19 03:27:19 +00:00
|
|
|
|
2013-10-29 01:58:12 +00:00
|
|
|
uint32_t id = 0;
|
|
|
|
if (!PassedOrDefaultServiceId(aServiceId, id)) {
|
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-07-17 20:47:41 +00:00
|
|
|
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
|
|
|
JS::Rooted<JS::Value> status(cx);
|
|
|
|
nsresult rv = mProvider->GetVoicemailStatus(id, &status);
|
2013-09-03 14:38:53 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-07-17 20:47:41 +00:00
|
|
|
if (!status.isObject()) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
JS::Rooted<JSObject*> statusObj(cx, &status.toObject());
|
|
|
|
nsRefPtr<MozVoicemailStatus> res = new MozVoicemailStatus(statusObj, GetParentObject());
|
|
|
|
return res.forget();
|
2012-07-19 03:27:19 +00:00
|
|
|
}
|
|
|
|
|
2013-09-03 14:38:53 +00:00
|
|
|
void
|
2013-10-29 01:58:12 +00:00
|
|
|
Voicemail::GetNumber(const Optional<uint32_t>& aServiceId, nsString& aNumber,
|
|
|
|
ErrorResult& aRv) const
|
2012-07-21 00:19:38 +00:00
|
|
|
{
|
|
|
|
aNumber.SetIsVoid(true);
|
|
|
|
|
2013-09-03 14:38:53 +00:00
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-29 01:58:12 +00:00
|
|
|
uint32_t id = 0;
|
|
|
|
if (!PassedOrDefaultServiceId(aServiceId, id)) {
|
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = mProvider->GetVoicemailNumber(id, aNumber);
|
2012-07-21 00:19:38 +00:00
|
|
|
}
|
|
|
|
|
2013-09-03 14:38:53 +00:00
|
|
|
void
|
2013-10-29 01:58:12 +00:00
|
|
|
Voicemail::GetDisplayName(const Optional<uint32_t>& aServiceId, nsString& aDisplayName,
|
|
|
|
ErrorResult& aRv) const
|
2012-07-21 00:19:38 +00:00
|
|
|
{
|
|
|
|
aDisplayName.SetIsVoid(true);
|
|
|
|
|
2013-09-03 14:38:53 +00:00
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
2012-07-21 00:19:38 +00:00
|
|
|
|
2013-10-29 01:58:12 +00:00
|
|
|
uint32_t id = 0;
|
|
|
|
if (!PassedOrDefaultServiceId(aServiceId, id)) {
|
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = mProvider->GetVoicemailDisplayName(id, aDisplayName);
|
2013-09-03 14:38:53 +00:00
|
|
|
}
|
2012-07-19 03:27:19 +00:00
|
|
|
|
2013-03-06 09:53:19 +00:00
|
|
|
// nsIVoicemailListener
|
2012-07-19 03:27:19 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-07-17 20:47:41 +00:00
|
|
|
Voicemail::NotifyStatusChanged(JS::HandleValue aStatus)
|
2012-07-19 03:27:19 +00:00
|
|
|
{
|
2014-06-11 01:23:34 +00:00
|
|
|
MozVoicemailEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
2014-07-17 20:47:41 +00:00
|
|
|
if (aStatus.isObject()) {
|
|
|
|
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
|
|
|
JS::Rooted<JSObject*> statusObj(cx, &aStatus.toObject());
|
|
|
|
init.mStatus = new MozVoicemailStatus(statusObj, GetParentObject());
|
|
|
|
}
|
2014-06-11 01:23:34 +00:00
|
|
|
|
|
|
|
nsRefPtr<MozVoicemailEvent> event =
|
|
|
|
MozVoicemailEvent::Constructor(this, NS_LITERAL_STRING("statuschanged"), init);
|
|
|
|
return DispatchTrustedEvent(event);
|
2012-07-19 03:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-09-03 14:38:53 +00:00
|
|
|
NS_NewVoicemail(nsPIDOMWindow* aWindow, Voicemail** aVoicemail)
|
2012-07-19 03:27:19 +00:00
|
|
|
{
|
|
|
|
nsPIDOMWindow* innerWindow = aWindow->IsInnerWindow() ?
|
|
|
|
aWindow :
|
|
|
|
aWindow->GetCurrentInnerWindow();
|
|
|
|
|
2013-03-06 09:53:19 +00:00
|
|
|
nsCOMPtr<nsIVoicemailProvider> provider =
|
2012-07-19 03:27:19 +00:00
|
|
|
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
2013-03-06 09:53:19 +00:00
|
|
|
NS_ENSURE_STATE(provider);
|
2012-07-19 03:27:19 +00:00
|
|
|
|
2013-09-03 14:38:53 +00:00
|
|
|
nsRefPtr<Voicemail> voicemail = new Voicemail(innerWindow, provider);
|
2012-07-19 03:27:19 +00:00
|
|
|
voicemail.forget(aVoicemail);
|
|
|
|
return NS_OK;
|
|
|
|
}
|