2012-12-04 06:38:25 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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-08-15 09:13:05 +04:00
|
|
|
#include "mozilla/dom/CellBroadcast.h"
|
|
|
|
#include "mozilla/dom/CellBroadcastMessage.h"
|
2013-08-27 07:38:37 +04:00
|
|
|
#include "mozilla/dom/MozCellBroadcastBinding.h"
|
2014-06-11 05:23:34 +04:00
|
|
|
#include "mozilla/dom/MozCellBroadcastEvent.h"
|
2013-08-27 07:38:37 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2012-12-04 06:38:25 +04:00
|
|
|
|
2014-08-18 13:06:11 +04:00
|
|
|
// Service instantiation
|
|
|
|
#include "ipc/CellBroadcastIPCService.h"
|
|
|
|
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
|
|
|
#include "nsIGonkCellBroadcastService.h"
|
|
|
|
#endif
|
|
|
|
#include "nsXULAppAPI.h" // For XRE_GetProcessType()
|
2012-12-04 06:38:25 +04:00
|
|
|
|
2013-03-06 13:53:15 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-08-15 09:13:05 +04:00
|
|
|
using mozilla::ErrorResult;
|
2012-12-04 06:38:25 +04:00
|
|
|
|
2012-12-04 06:40:47 +04:00
|
|
|
/**
|
2013-03-06 13:53:15 +04:00
|
|
|
* CellBroadcast::Listener Implementation.
|
2012-12-04 06:40:47 +04:00
|
|
|
*/
|
|
|
|
|
2014-07-07 06:46:15 +04:00
|
|
|
class CellBroadcast::Listener MOZ_FINAL : public nsICellBroadcastListener
|
2012-12-04 06:40:47 +04:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
CellBroadcast* mCellBroadcast;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2013-03-06 13:53:15 +04:00
|
|
|
NS_FORWARD_SAFE_NSICELLBROADCASTLISTENER(mCellBroadcast)
|
|
|
|
|
|
|
|
Listener(CellBroadcast* aCellBroadcast)
|
|
|
|
: mCellBroadcast(aCellBroadcast)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCellBroadcast);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Disconnect()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCellBroadcast);
|
|
|
|
mCellBroadcast = nullptr;
|
|
|
|
}
|
2014-07-11 11:58:01 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
~Listener()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mCellBroadcast);
|
|
|
|
}
|
2012-12-04 06:40:47 +04:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(CellBroadcast::Listener, nsICellBroadcastListener)
|
2012-12-04 06:40:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CellBroadcast Implementation.
|
|
|
|
*/
|
|
|
|
|
2013-08-27 07:38:37 +04:00
|
|
|
// static
|
|
|
|
already_AddRefed<CellBroadcast>
|
|
|
|
CellBroadcast::Create(nsPIDOMWindow* aWindow, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
MOZ_ASSERT(aWindow->IsInnerWindow());
|
2012-12-04 06:38:25 +04:00
|
|
|
|
2014-08-13 14:28:34 +04:00
|
|
|
nsCOMPtr<nsICellBroadcastService> service =
|
2014-08-18 13:06:11 +04:00
|
|
|
do_GetService(CELLBROADCAST_SERVICE_CONTRACTID);
|
2014-08-13 14:28:34 +04:00
|
|
|
if (!service) {
|
2013-08-27 07:38:37 +04:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-12-04 06:38:25 +04:00
|
|
|
|
2014-08-13 14:28:34 +04:00
|
|
|
nsRefPtr<CellBroadcast> cb = new CellBroadcast(aWindow, service);
|
2013-08-27 07:38:37 +04:00
|
|
|
return cb.forget();
|
|
|
|
}
|
2012-12-04 06:38:25 +04:00
|
|
|
|
2012-12-04 06:40:47 +04:00
|
|
|
CellBroadcast::CellBroadcast(nsPIDOMWindow *aWindow,
|
2014-08-13 14:28:34 +04:00
|
|
|
nsICellBroadcastService *aService)
|
2014-04-01 10:13:50 +04:00
|
|
|
: DOMEventTargetHelper(aWindow)
|
2012-12-04 06:38:25 +04:00
|
|
|
{
|
2013-03-06 13:53:15 +04:00
|
|
|
mListener = new Listener(this);
|
2014-08-13 14:28:34 +04:00
|
|
|
DebugOnly<nsresult> rv = aService->RegisterListener(mListener);
|
2012-12-04 06:40:47 +04:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
2014-08-13 14:28:34 +04:00
|
|
|
"Failed registering Cell Broadcast callback");
|
2012-12-04 06:40:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CellBroadcast::~CellBroadcast()
|
|
|
|
{
|
2014-08-13 14:28:34 +04:00
|
|
|
MOZ_ASSERT(mListener);
|
2012-12-04 06:40:47 +04:00
|
|
|
|
2013-03-06 13:53:15 +04:00
|
|
|
mListener->Disconnect();
|
2014-08-13 14:28:34 +04:00
|
|
|
nsCOMPtr<nsICellBroadcastService> service =
|
2014-08-18 13:06:11 +04:00
|
|
|
do_GetService(CELLBROADCAST_SERVICE_CONTRACTID);
|
2014-08-13 14:28:34 +04:00
|
|
|
if (service) {
|
|
|
|
service->UnregisterListener(mListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
mListener = nullptr;
|
2012-12-04 06:38:25 +04:00
|
|
|
}
|
|
|
|
|
2014-08-20 05:01:49 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(CellBroadcast, DOMEventTargetHelper)
|
|
|
|
|
2013-08-27 07:38:37 +04:00
|
|
|
JSObject*
|
2014-04-09 02:27:18 +04:00
|
|
|
CellBroadcast::WrapObject(JSContext* aCx)
|
2013-08-27 07:38:37 +04: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-09 02:27:17 +04:00
|
|
|
return MozCellBroadcastBinding::Wrap(aCx, this);
|
2013-08-27 07:38:37 +04:00
|
|
|
}
|
2012-12-04 06:38:25 +04:00
|
|
|
|
2013-03-06 13:53:15 +04:00
|
|
|
// Forwarded nsICellBroadcastListener methods
|
2012-12-04 06:40:47 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-08-15 09:13:05 +04:00
|
|
|
CellBroadcast::NotifyMessageReceived(uint32_t aServiceId,
|
|
|
|
const nsAString& aGsmGeographicalScope,
|
|
|
|
uint16_t aMessageCode,
|
|
|
|
uint16_t aMessageId,
|
|
|
|
const nsAString& aLanguage,
|
|
|
|
const nsAString& aBody,
|
|
|
|
const nsAString& aMessageClass,
|
|
|
|
DOMTimeStamp aTimestamp,
|
|
|
|
uint32_t aCdmaServiceCategory,
|
|
|
|
bool aHasEtwsInfo,
|
|
|
|
const nsAString& aEtwsWarningType,
|
|
|
|
bool aEtwsEmergencyUserAlert,
|
|
|
|
bool aEtwsPopup) {
|
2014-06-11 05:23:34 +04:00
|
|
|
MozCellBroadcastEventInit init;
|
|
|
|
init.mBubbles = true;
|
|
|
|
init.mCancelable = false;
|
2014-08-15 09:13:05 +04:00
|
|
|
init.mMessage = new CellBroadcastMessage(GetOwner(),
|
|
|
|
aServiceId,
|
|
|
|
aGsmGeographicalScope,
|
|
|
|
aMessageCode,
|
|
|
|
aMessageId,
|
|
|
|
aLanguage,
|
|
|
|
aBody,
|
|
|
|
aMessageClass,
|
|
|
|
aTimestamp,
|
|
|
|
aCdmaServiceCategory,
|
|
|
|
aHasEtwsInfo,
|
|
|
|
aEtwsWarningType,
|
|
|
|
aEtwsEmergencyUserAlert,
|
|
|
|
aEtwsPopup);
|
2014-06-11 05:23:34 +04:00
|
|
|
|
|
|
|
nsRefPtr<MozCellBroadcastEvent> event =
|
|
|
|
MozCellBroadcastEvent::Constructor(this, NS_LITERAL_STRING("received"), init);
|
|
|
|
return DispatchTrustedEvent(event);
|
2012-12-04 06:40:47 +04:00
|
|
|
}
|
2014-08-18 13:06:11 +04:00
|
|
|
|
|
|
|
already_AddRefed<nsICellBroadcastService>
|
|
|
|
NS_CreateCellBroadcastService()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsICellBroadcastService> service;
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
service = new mozilla::dom::cellbroadcast::CellBroadcastIPCService();
|
|
|
|
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
|
|
|
} else {
|
|
|
|
service = do_GetService(GONK_CELLBROADCAST_SERVICE_CONTRACTID);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return service.forget();
|
|
|
|
}
|