2015-05-03 22:32:37 +03: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-12-04 06:38:25 +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-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
|
|
|
*/
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class CellBroadcast::Listener 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)
|
|
|
|
|
2014-09-24 17:16:53 +04:00
|
|
|
explicit Listener(CellBroadcast* aCellBroadcast)
|
2013-03-06 13:53:15 +04:00
|
|
|
: 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>
|
2016-01-30 20:05:36 +03:00
|
|
|
CellBroadcast::Create(nsPIDOMWindowInner* aWindow, ErrorResult& aRv)
|
2013-08-27 07:38:37 +04:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<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
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
CellBroadcast::CellBroadcast(nsPIDOMWindowInner* aWindow,
|
|
|
|
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);
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"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*
|
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
|
|
|
CellBroadcast::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-08-27 07:38:37 +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 MozCellBroadcastBinding::Wrap(aCx, this, aGivenProto);
|
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,
|
2014-09-23 14:27:03 +04:00
|
|
|
uint32_t aGsmGeographicalScope,
|
2014-08-15 09:13:05 +04:00
|
|
|
uint16_t aMessageCode,
|
|
|
|
uint16_t aMessageId,
|
|
|
|
const nsAString& aLanguage,
|
|
|
|
const nsAString& aBody,
|
2014-09-23 14:27:03 +04:00
|
|
|
uint32_t aMessageClass,
|
2014-08-15 09:13:05 +04:00
|
|
|
DOMTimeStamp aTimestamp,
|
|
|
|
uint32_t aCdmaServiceCategory,
|
|
|
|
bool aHasEtwsInfo,
|
2014-09-23 14:27:03 +04:00
|
|
|
uint32_t aEtwsWarningType,
|
2014-08-15 09:13:05 +04:00
|
|
|
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
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MozCellBroadcastEvent> event =
|
2014-06-11 05:23:34 +04:00
|
|
|
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;
|
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
2014-08-18 13:06:11 +04:00
|
|
|
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();
|
|
|
|
}
|