Bug 1306779 - Remove DOM/fmradio and related code. r=jst

MozReview-Commit-ID: EAoALauFEco

--HG--
extra : rebase_source : fd3b9963f27f2fd2ae76538eff489d9783eee6a6
This commit is contained in:
Michelangelo De Simone 2016-10-03 16:22:41 -07:00
parent ed24fe7708
commit a35ec87644
44 changed files with 1 additions and 4182 deletions

View File

@ -91,10 +91,6 @@
#include "AudioChannelManager.h"
#endif
#ifdef MOZ_B2G_FM
#include "mozilla/dom/FMRadio.h"
#endif
#include "nsIDOMGlobalPropertyInitializer.h"
#include "nsJSUtils.h"
@ -292,13 +288,6 @@ Navigator::Invalidate()
mBatteryPromise = nullptr;
#ifdef MOZ_B2G_FM
if (mFMRadio) {
mFMRadio->Shutdown();
mFMRadio = nullptr;
}
#endif
if (mPowerManager) {
mPowerManager->Shutdown();
mPowerManager = nullptr;
@ -1546,30 +1535,6 @@ Navigator::GetMozNotification(ErrorResult& aRv)
return mNotification;
}
#ifdef MOZ_B2G_FM
using mozilla::dom::FMRadio;
FMRadio*
Navigator::GetMozFMRadio(ErrorResult& aRv)
{
if (!mFMRadio) {
if (!mWindow) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
mFMRadio = new FMRadio();
mFMRadio->Init(mWindow);
}
return mFMRadio;
}
#endif // MOZ_B2G_FM
//*****************************************************************************
// Navigator::nsINavigatorBattery
//*****************************************************************************

View File

@ -57,10 +57,6 @@ namespace battery {
class BatteryManager;
} // namespace battery
#ifdef MOZ_B2G_FM
class FMRadio;
#endif
class Promise;
class DesktopNotificationCenter;
@ -248,9 +244,6 @@ public:
#endif // MOZ_GAMEPAD
already_AddRefed<Promise> GetVRDisplays(ErrorResult& aRv);
void GetActiveVRDisplays(nsTArray<RefPtr<VRDisplay>>& aDisplays) const;
#ifdef MOZ_B2G_FM
FMRadio* GetMozFMRadio(ErrorResult& aRv);
#endif
#ifdef MOZ_B2G_BT
bluetooth::BluetoothManager* GetMozBluetooth(ErrorResult& aRv);
#endif // MOZ_B2G_BT
@ -340,9 +333,6 @@ private:
RefPtr<DesktopNotificationCenter> mNotification;
RefPtr<battery::BatteryManager> mBatteryManager;
RefPtr<Promise> mBatteryPromise;
#ifdef MOZ_B2G_FM
RefPtr<FMRadio> mFMRadio;
#endif
RefPtr<PowerManager> mPowerManager;
RefPtr<IccManager> mIccManager;
RefPtr<MobileMessageManager> mMobileMessageManager;

View File

@ -437,7 +437,6 @@ LOCAL_INCLUDES += [
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
LOCAL_INCLUDES += [
'../fmradio',
'../system/gonk',
]
@ -450,7 +449,7 @@ include('/ipc/chromium/chromium-config.mozbuild')
FINAL_LIBRARY = 'xul'
for var in ('MOZ_B2G_RIL', 'MOZ_B2G_FM'):
for var in ('MOZ_B2G_RIL'):
if CONFIG[var]:
DEFINES[var] = True

View File

@ -100,10 +100,6 @@
#include "nsWrapperCacheInlines.h"
#include "mozilla/dom/HTMLCollectionBinding.h"
#ifdef MOZ_B2G_FM
#include "FMRadio.h"
#endif
#include "nsDebug.h"
#include "mozilla/dom/BindingUtils.h"

View File

@ -1,500 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "mozilla/dom/FMRadio.h"
#include "nsContentUtils.h"
#include "mozilla/Hal.h"
#include "mozilla/HalTypes.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/FMRadioBinding.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/PFMRadioChild.h"
#include "mozilla/dom/FMRadioService.h"
#include "mozilla/dom/TypedArray.h"
#include "AudioChannelService.h"
#include "DOMRequest.h"
#include "nsDOMClassInfo.h"
#include "nsIDocShell.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIAudioManager.h"
#undef LOG
#define LOG(args...) FM_LOG("FMRadio", args)
// The pref indicates if the device has an internal antenna.
// If the pref is true, the antanna will be always available.
#define DOM_FM_ANTENNA_INTERNAL_PREF "dom.fmradio.antenna.internal"
using mozilla::Preferences;
BEGIN_FMRADIO_NAMESPACE
class FMRadioRequest final : public FMRadioReplyRunnable
, public DOMRequest
{
public:
NS_DECL_ISUPPORTS_INHERITED
FMRadioRequest(nsPIDOMWindowInner* aWindow, FMRadio* aFMRadio)
: DOMRequest(aWindow)
, mType(FMRadioRequestArgs::T__None)
{
// |FMRadio| inherits from |nsIDOMEventTarget| and |nsISupportsWeakReference|
// which both inherits from nsISupports, so |nsISupports| is an ambiguous
// base of |FMRadio|, we have to cast |aFMRadio| to one of the base classes.
mFMRadio = do_GetWeakReference(static_cast<nsIDOMEventTarget*>(aFMRadio));
}
FMRadioRequest(nsPIDOMWindowInner* aWindow, FMRadio* aFMRadio,
FMRadioRequestArgs::Type aType)
: DOMRequest(aWindow)
{
MOZ_ASSERT(aType >= FMRadioRequestArgs::T__None &&
aType <= FMRadioRequestArgs::T__Last,
"Wrong FMRadioRequestArgs in FMRadioRequest");
mFMRadio = do_GetWeakReference(static_cast<nsIDOMEventTarget*>(aFMRadio));
mType = aType;
}
NS_IMETHOD
Run() override
{
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
nsCOMPtr<nsIDOMEventTarget> target = do_QueryReferent(mFMRadio);
if (!target) {
return NS_OK;
}
FMRadio* fmRadio = static_cast<FMRadio*>(
static_cast<nsIDOMEventTarget*>(target));
if (fmRadio->mIsShutdown) {
return NS_OK;
}
switch (mResponseType.type()) {
case FMRadioResponseType::TErrorResponse:
FireError(mResponseType.get_ErrorResponse().error());
break;
case FMRadioResponseType::TSuccessResponse:
if (mType == FMRadioRequestArgs::TEnableRequestArgs) {
fmRadio->EnableAudioChannelAgent();
}
FireSuccess(JS::UndefinedHandleValue);
break;
default:
MOZ_CRASH();
}
return NS_OK;
}
protected:
~FMRadioRequest() { }
private:
FMRadioRequestArgs::Type mType;
nsWeakPtr mFMRadio;
};
NS_IMPL_ISUPPORTS_INHERITED0(FMRadioRequest, DOMRequest)
FMRadio::FMRadio()
: mHeadphoneState(hal::SWITCH_STATE_OFF)
, mRdsGroupMask(0)
, mAudioChannelAgentEnabled(false)
, mHasInternalAntenna(false)
, mIsShutdown(false)
{
LOG("FMRadio is initialized.");
}
FMRadio::~FMRadio()
{
}
void
FMRadio::Init(nsPIDOMWindowInner *aWindow)
{
BindToOwner(aWindow);
IFMRadioService::Singleton()->AddObserver(this);
mHasInternalAntenna = Preferences::GetBool(DOM_FM_ANTENNA_INTERNAL_PREF,
/* default = */ false);
if (mHasInternalAntenna) {
LOG("We have an internal antenna.");
} else {
mHeadphoneState = hal::GetCurrentSwitchState(hal::SWITCH_HEADPHONES);
hal::RegisterSwitchObserver(hal::SWITCH_HEADPHONES, this);
}
nsCOMPtr<nsIAudioChannelAgent> audioChannelAgent =
do_CreateInstance("@mozilla.org/audiochannelagent;1");
NS_ENSURE_TRUE_VOID(audioChannelAgent);
audioChannelAgent->InitWithWeakCallback(
GetOwner(),
nsIAudioChannelAgent::AUDIO_AGENT_CHANNEL_CONTENT,
this);
// Once all necessary resources are got successfully, we just enabled
// mAudioChannelAgent.
mAudioChannelAgent = audioChannelAgent;
}
void
FMRadio::Shutdown()
{
IFMRadioService::Singleton()->RemoveObserver(this);
if (!mHasInternalAntenna) {
hal::UnregisterSwitchObserver(hal::SWITCH_HEADPHONES, this);
}
mIsShutdown = true;
}
JSObject*
FMRadio::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return FMRadioBinding::Wrap(aCx, this, aGivenProto);
}
void
FMRadio::Notify(const hal::SwitchEvent& aEvent)
{
MOZ_ASSERT(!mHasInternalAntenna);
if (mHeadphoneState != aEvent.status()) {
mHeadphoneState = aEvent.status();
DispatchTrustedEvent(NS_LITERAL_STRING("antennaavailablechange"));
}
}
void
FMRadio::Notify(const FMRadioEventType& aType)
{
switch (aType) {
case FrequencyChanged:
DispatchTrustedEvent(NS_LITERAL_STRING("frequencychange"));
break;
case EnabledChanged:
if (Enabled()) {
DispatchTrustedEvent(NS_LITERAL_STRING("enabled"));
} else {
if (mAudioChannelAgentEnabled) {
mAudioChannelAgent->NotifyStoppedPlaying();
mAudioChannelAgentEnabled = false;
}
DispatchTrustedEvent(NS_LITERAL_STRING("disabled"));
}
break;
case RDSEnabledChanged:
if (RdsEnabled()) {
DispatchTrustedEvent(NS_LITERAL_STRING("rdsenabled"));
} else {
DispatchTrustedEvent(NS_LITERAL_STRING("rdsdisabled"));
}
break;
case PIChanged:
DispatchTrustedEvent(NS_LITERAL_STRING("pichange"));
break;
case PSChanged:
DispatchTrustedEvent(NS_LITERAL_STRING("pschange"));
break;
case RadiotextChanged:
DispatchTrustedEvent(NS_LITERAL_STRING("rtchange"));
break;
case PTYChanged:
DispatchTrustedEvent(NS_LITERAL_STRING("ptychange"));
break;
case NewRDSGroup:
DispatchTrustedEvent(NS_LITERAL_STRING("newrdsgroup"));
break;
default:
MOZ_CRASH();
}
}
/* static */
bool
FMRadio::Enabled()
{
return IFMRadioService::Singleton()->IsEnabled();
}
bool
FMRadio::RdsEnabled()
{
return IFMRadioService::Singleton()->IsRDSEnabled();
}
bool
FMRadio::AntennaAvailable() const
{
return mHasInternalAntenna ? true : (mHeadphoneState != hal::SWITCH_STATE_OFF) &&
(mHeadphoneState != hal::SWITCH_STATE_UNKNOWN);
}
Nullable<double>
FMRadio::GetFrequency() const
{
return Enabled() ?
Nullable<double>(IFMRadioService::Singleton()->GetFrequency()) :
Nullable<double>();
}
double
FMRadio::FrequencyUpperBound() const
{
return IFMRadioService::Singleton()->GetFrequencyUpperBound();
}
double
FMRadio::FrequencyLowerBound() const
{
return IFMRadioService::Singleton()->GetFrequencyLowerBound();
}
double
FMRadio::ChannelWidth() const
{
return IFMRadioService::Singleton()->GetChannelWidth();
}
uint32_t
FMRadio::RdsGroupMask() const
{
return mRdsGroupMask;
}
void
FMRadio::SetRdsGroupMask(uint32_t aRdsGroupMask)
{
mRdsGroupMask = aRdsGroupMask;
IFMRadioService::Singleton()->SetRDSGroupMask(aRdsGroupMask);
}
Nullable<unsigned short>
FMRadio::GetPi() const
{
return IFMRadioService::Singleton()->GetPi();
}
Nullable<uint8_t>
FMRadio::GetPty() const
{
return IFMRadioService::Singleton()->GetPty();
}
void
FMRadio::GetPs(DOMString& aPsname) const
{
if (!IFMRadioService::Singleton()->GetPs(aPsname)) {
aPsname.SetNull();
}
}
void
FMRadio::GetRt(DOMString& aRadiotext) const
{
if (!IFMRadioService::Singleton()->GetRt(aRadiotext)) {
aRadiotext.SetNull();
}
}
void
FMRadio::GetRdsgroup(JSContext* cx, JS::MutableHandle<JSObject*> retval)
{
uint64_t group;
if (!IFMRadioService::Singleton()->GetRdsgroup(group)) {
return;
}
JSObject *rdsgroup = Uint16Array::Create(cx, this, 4);
JS::AutoCheckCannotGC nogc;
bool isShared = false;
uint16_t *data = JS_GetUint16ArrayData(rdsgroup, &isShared, nogc);
MOZ_ASSERT(!isShared); // Because created above.
data[3] = group & 0xFFFF;
group >>= 16;
data[2] = group & 0xFFFF;
group >>= 16;
data[1] = group & 0xFFFF;
group >>= 16;
data[0] = group & 0xFFFF;
JS::ExposeObjectToActiveJS(rdsgroup);
retval.set(rdsgroup);
}
already_AddRefed<DOMRequest>
FMRadio::Enable(double aFrequency)
{
nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
if (!win) {
return nullptr;
}
RefPtr<FMRadioRequest> r =
new FMRadioRequest(win, this, FMRadioRequestArgs::TEnableRequestArgs);
IFMRadioService::Singleton()->Enable(aFrequency, r);
return r.forget();
}
already_AddRefed<DOMRequest>
FMRadio::Disable()
{
nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
if (!win) {
return nullptr;
}
RefPtr<FMRadioRequest> r = new FMRadioRequest(win, this);
IFMRadioService::Singleton()->Disable(r);
return r.forget();
}
already_AddRefed<DOMRequest>
FMRadio::SetFrequency(double aFrequency)
{
nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
if (!win) {
return nullptr;
}
RefPtr<FMRadioRequest> r = new FMRadioRequest(win, this);
IFMRadioService::Singleton()->SetFrequency(aFrequency, r);
return r.forget();
}
already_AddRefed<DOMRequest>
FMRadio::SeekUp()
{
nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
if (!win) {
return nullptr;
}
RefPtr<FMRadioRequest> r = new FMRadioRequest(win, this);
IFMRadioService::Singleton()->Seek(hal::FM_RADIO_SEEK_DIRECTION_UP, r);
return r.forget();
}
already_AddRefed<DOMRequest>
FMRadio::SeekDown()
{
nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
if (!win) {
return nullptr;
}
RefPtr<FMRadioRequest> r = new FMRadioRequest(win, this);
IFMRadioService::Singleton()->Seek(hal::FM_RADIO_SEEK_DIRECTION_DOWN, r);
return r.forget();
}
already_AddRefed<DOMRequest>
FMRadio::CancelSeek()
{
nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
if (!win) {
return nullptr;
}
RefPtr<FMRadioRequest> r = new FMRadioRequest(win, this);
IFMRadioService::Singleton()->CancelSeek(r);
return r.forget();
}
already_AddRefed<DOMRequest>
FMRadio::EnableRDS()
{
nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
if (!win) {
return nullptr;
}
RefPtr<FMRadioRequest> r = new FMRadioRequest(win, this);
IFMRadioService::Singleton()->EnableRDS(r);
return r.forget();
}
already_AddRefed<DOMRequest>
FMRadio::DisableRDS()
{
nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
if (!win) {
return nullptr;
}
RefPtr<FMRadioRequest> r = new FMRadioRequest(win, this);
FMRadioService::Singleton()->DisableRDS(r);
return r.forget();
}
void
FMRadio::EnableAudioChannelAgent()
{
NS_ENSURE_TRUE_VOID(mAudioChannelAgent);
AudioPlaybackConfig config;
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config,
AudioChannelService::AudibleState::eAudible);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
WindowVolumeChanged(config.mVolume, config.mMuted);
WindowSuspendChanged(config.mSuspend);
mAudioChannelAgentEnabled = true;
}
NS_IMETHODIMP
FMRadio::WindowVolumeChanged(float aVolume, bool aMuted)
{
// TODO : Not support to change volume now, so we just close it.
IFMRadioService::Singleton()->EnableAudio(!aMuted);
return NS_OK;
}
NS_IMETHODIMP
FMRadio::WindowSuspendChanged(nsSuspendedTypes aSuspend)
{
bool enable = (aSuspend == nsISuspendedTypes::NONE_SUSPENDED);
IFMRadioService::Singleton()->EnableAudio(enable);
return NS_OK;
}
NS_IMETHODIMP
FMRadio::WindowAudioCaptureChanged(bool aCapture)
{
return NS_OK;
}
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FMRadio)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIAudioChannelAgentCallback)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(FMRadio, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(FMRadio, DOMEventTargetHelper)
END_FMRADIO_NAMESPACE

View File

@ -1,126 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_FMRadio_h
#define mozilla_dom_FMRadio_h
#include "AudioChannelAgent.h"
#include "FMRadioCommon.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/HalTypes.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWeakReference.h"
BEGIN_FMRADIO_NAMESPACE
class DOMRequest;
class FMRadio final : public DOMEventTargetHelper
, public hal::SwitchObserver
, public FMRadioEventObserver
, public nsSupportsWeakReference
, public nsIAudioChannelAgentCallback
{
friend class FMRadioRequest;
public:
FMRadio();
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
void Init(nsPIDOMWindowInner *aWindow);
void Shutdown();
/* hal::SwitchObserver */
virtual void Notify(const hal::SwitchEvent& aEvent) override;
/* FMRadioEventObserver */
virtual void Notify(const FMRadioEventType& aType) override;
nsPIDOMWindowInner* GetParentObject() const
{
return GetOwner();
}
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
static bool Enabled();
bool RdsEnabled();
bool AntennaAvailable() const;
Nullable<double> GetFrequency() const;
double FrequencyUpperBound() const;
double FrequencyLowerBound() const;
double ChannelWidth() const;
uint32_t RdsGroupMask() const;
void SetRdsGroupMask(uint32_t aRdsGroupMask);
Nullable<unsigned short> GetPi() const;
Nullable<uint8_t> GetPty() const;
void GetPs(DOMString& aPsname) const;
void GetRt(DOMString& aRadiotext) const;
void GetRdsgroup(JSContext* cx, JS::MutableHandle<JSObject*> retval);
already_AddRefed<DOMRequest> Enable(double aFrequency);
already_AddRefed<DOMRequest> Disable();
already_AddRefed<DOMRequest> SetFrequency(double aFrequency);
already_AddRefed<DOMRequest> SeekUp();
already_AddRefed<DOMRequest> SeekDown();
already_AddRefed<DOMRequest> CancelSeek();
already_AddRefed<DOMRequest> EnableRDS();
already_AddRefed<DOMRequest> DisableRDS();
IMPL_EVENT_HANDLER(enabled);
IMPL_EVENT_HANDLER(disabled);
IMPL_EVENT_HANDLER(rdsenabled);
IMPL_EVENT_HANDLER(rdsdisabled);
IMPL_EVENT_HANDLER(antennaavailablechange);
IMPL_EVENT_HANDLER(frequencychange);
IMPL_EVENT_HANDLER(pichange);
IMPL_EVENT_HANDLER(ptychange);
IMPL_EVENT_HANDLER(pschange);
IMPL_EVENT_HANDLER(rtchange);
IMPL_EVENT_HANDLER(newrdsgroup);
private:
~FMRadio();
void EnableAudioChannelAgent();
hal::SwitchState mHeadphoneState;
uint32_t mRdsGroupMask;
bool mAudioChannelAgentEnabled;
bool mHasInternalAntenna;
bool mIsShutdown;
nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent;
};
END_FMRADIO_NAMESPACE
#endif // mozilla_dom_FMRadio_h

View File

@ -1,48 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef FMRADIOCOMMON_H_
#define FMRADIOCOMMON_H_
#include "mozilla/Observer.h"
#undef FM_LOG
#if defined(ANDROID)
#include <android/log.h>
#define FM_LOG(FMRADIO_LOG_INFO, args...) \
__android_log_print(ANDROID_LOG_INFO, \
FMRADIO_LOG_INFO, \
## args)
#else
#define FM_LOG(args...)
#endif
#define BEGIN_FMRADIO_NAMESPACE \
namespace mozilla { namespace dom {
#define END_FMRADIO_NAMESPACE \
} /* namespace dom */ } /* namespace mozilla */
BEGIN_FMRADIO_NAMESPACE
enum FMRadioEventType
{
FrequencyChanged,
EnabledChanged,
RDSEnabledChanged,
PIChanged,
PSChanged,
PTYChanged,
RadiotextChanged,
NewRDSGroup
};
typedef mozilla::Observer<FMRadioEventType> FMRadioEventObserver;
typedef mozilla::ObserverList<FMRadioEventType> FMRadioEventObserverList;
END_FMRADIO_NAMESPACE
#endif /* FMRADIOCOMMON_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -1,270 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_fmradioservice_h__
#define mozilla_dom_fmradioservice_h__
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/PFMRadioRequest.h"
#include "FMRadioCommon.h"
#include "mozilla/Hal.h"
#include "mozilla/Mutex.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/Services.h"
#include "nsThreadUtils.h"
#include "nsIObserver.h"
#include "nsXULAppAPI.h"
BEGIN_FMRADIO_NAMESPACE
class FMRadioReplyRunnable : public Runnable
{
public:
FMRadioReplyRunnable() : mResponseType(SuccessResponse()) {}
virtual ~FMRadioReplyRunnable() {}
void
SetReply(const FMRadioResponseType& aResponseType)
{
mResponseType = aResponseType;
}
protected:
FMRadioResponseType mResponseType;
};
/**
* The FMRadio Service Interface for FMRadio.
*
* There are two concrete classes which implement this interface:
* - FMRadioService
* It's used in the main process, implements all the logics about FM Radio.
*
* - FMRadioChild
* It's used in subprocess. It's a kind of proxy which just sends all
* the requests to main process through IPC channel.
*
* All the requests coming from the content page will be redirected to the
* concrete class object.
*
* Consider navigator.mozFMRadio.enable(). Here is the call sequence:
* - OOP
* Child:
* (1) Call navigator.mozFMRadio.enable().
* (2) Return a DOMRequest object, and call FMRadioChild.Enable() with a
* FMRadioReplyRunnable object.
* (3) Send IPC message to main process.
* Parent:
* (4) Call FMRadioService::Enable() with a FMRadioReplyRunnable object.
* (5) Call hal::EnableFMRadio().
* (6) Notify FMRadioService object when FM radio HW is enabled.
* (7) Dispatch the FMRadioReplyRunnable object created in (4).
* (8) Send IPC message back to child process.
* Child:
* (9) Dispatch the FMRadioReplyRunnable object created in (2).
* (10) Fire success callback of the DOMRequest Object created in (2).
* _ _ _ _ _ _ _ _ _ _ _ _ _ _
* | OOP |
* | |
* Page FMRadio | FMRadioChild IPC | FMRadioService Hal
* | (1) | | | | | | |
* |----->| (2) | | | | | |
* | |--------|--------->| (3) | | | |
* | | | |-----------> | | (4) | |
* | | | | |--|---------->| (5) |
* | | | | | | |--------->|
* | | | | | | | (6) |
* | | | | | | (7) |<---------|
* | | | | (8) |<-|-----------| |
* | | (9) | |<----------- | | | |
* | (10) |<-------|----------| | | | |
* |<-----| | | | | | |
* | |
* |_ _ _ _ _ _ _ _ _ _ _ _ _ _|
* - non-OOP
* In non-OOP model, we don't need to send messages between processes, so
* the call sequences are much more simpler, it almost just follows the
* sequences presented in OOP model: (1) (2) (5) (6) (9) and (10).
*
*/
class IFMRadioService
{
protected:
virtual ~IFMRadioService() { }
public:
virtual bool IsEnabled() const = 0;
virtual bool IsRDSEnabled() const = 0;
virtual double GetFrequency() const = 0;
virtual double GetFrequencyUpperBound() const = 0;
virtual double GetFrequencyLowerBound() const = 0;
virtual double GetChannelWidth() const = 0;
virtual Nullable<unsigned short> GetPi() const = 0;
virtual Nullable<uint8_t> GetPty() const = 0;
virtual bool GetPs(nsString& aPsname) = 0;
virtual bool GetRt(nsString& aRadiotext) = 0;
virtual bool GetRdsgroup(uint64_t& aRDSGroup) = 0;
virtual void Enable(double aFrequency, FMRadioReplyRunnable* aReplyRunnable) = 0;
virtual void Disable(FMRadioReplyRunnable* aReplyRunnable) = 0;
virtual void SetFrequency(double aFrequency, FMRadioReplyRunnable* aReplyRunnable) = 0;
virtual void Seek(mozilla::hal::FMRadioSeekDirection aDirection,
FMRadioReplyRunnable* aReplyRunnable) = 0;
virtual void CancelSeek(FMRadioReplyRunnable* aReplyRunnable) = 0;
virtual void SetRDSGroupMask(uint32_t aRDSGroupMask) = 0;
virtual void EnableRDS(FMRadioReplyRunnable* aReplyRunnable) = 0;
virtual void DisableRDS(FMRadioReplyRunnable* aReplyRunnable) = 0;
/**
* Register handler to receive the FM Radio events, including:
* - StateChangedEvent
* - FrequencyChangedEvent
*
* Called by FMRadio and FMRadioParent.
*/
virtual void AddObserver(FMRadioEventObserver* aObserver) = 0;
virtual void RemoveObserver(FMRadioEventObserver* aObserver) = 0;
// Enable/Disable FMRadio
virtual void EnableAudio(bool aAudioEnabled) = 0;
/**
* Static method to return the singleton instance. If it's in the child
* process, we will get an object of FMRadioChild.
*/
static IFMRadioService* Singleton();
};
enum FMRadioState
{
Disabled,
Disabling,
Enabling,
Enabled,
Seeking
};
class FMRadioService final : public IFMRadioService
, public hal::FMRadioObserver
, public hal::FMRadioRDSObserver
, public nsIObserver
{
friend class ReadAirplaneModeSettingTask;
friend class EnableRunnable;
friend class DisableRunnable;
friend class NotifyRunnable;
public:
static FMRadioService* Singleton();
NS_DECL_ISUPPORTS
virtual bool IsEnabled() const override;
virtual bool IsRDSEnabled() const override;
virtual double GetFrequency() const override;
virtual double GetFrequencyUpperBound() const override;
virtual double GetFrequencyLowerBound() const override;
virtual double GetChannelWidth() const override;
virtual Nullable<unsigned short> GetPi() const override;
virtual Nullable<uint8_t> GetPty() const override;
virtual bool GetPs(nsString& aPsname) override;
virtual bool GetRt(nsString& aRadiotext) override;
virtual bool GetRdsgroup(uint64_t& aRDSGroup) override;
virtual void Enable(double aFrequency,
FMRadioReplyRunnable* aReplyRunnable) override;
virtual void Disable(FMRadioReplyRunnable* aReplyRunnable) override;
virtual void SetFrequency(double aFrequency,
FMRadioReplyRunnable* aReplyRunnable) override;
virtual void Seek(mozilla::hal::FMRadioSeekDirection aDirection,
FMRadioReplyRunnable* aReplyRunnable) override;
virtual void CancelSeek(FMRadioReplyRunnable* aReplyRunnable) override;
virtual void SetRDSGroupMask(uint32_t aRDSGroupMask) override;
virtual void EnableRDS(FMRadioReplyRunnable* aReplyRunnable) override;
virtual void DisableRDS(FMRadioReplyRunnable* aReplyRunnable) override;
virtual void AddObserver(FMRadioEventObserver* aObserver) override;
virtual void RemoveObserver(FMRadioEventObserver* aObserver) override;
virtual void EnableAudio(bool aAudioEnabled) override;
/* FMRadioObserver */
void Notify(const hal::FMRadioOperationInformation& aInfo) override;
/* FMRadioRDSObserver */
void Notify(const hal::FMRadioRDSGroup& aRDSGroup) override;
void EnableFMRadio();
void DisableFMRadio();
void DispatchFMRadioEventToMainThread(enum FMRadioEventType aType);
NS_DECL_NSIOBSERVER
protected:
FMRadioService();
virtual ~FMRadioService();
private:
int32_t RoundFrequency(double aFrequencyInMHz);
void NotifyFMRadioEvent(FMRadioEventType aType);
void DoDisable();
void TransitionState(const FMRadioResponseType& aResponse, FMRadioState aState);
void SetState(FMRadioState aState);
void UpdatePowerState();
void UpdateFrequency();
private:
bool mEnabled;
int32_t mPendingFrequencyInKHz;
FMRadioState mState;
bool mHasReadAirplaneModeSetting;
bool mAirplaneModeEnabled;
bool mRDSEnabled;
uint32_t mUpperBoundInKHz;
uint32_t mLowerBoundInKHz;
uint32_t mChannelWidthInKHz;
uint32_t mPreemphasis;
nsCOMPtr<nsIThread> mTuneThread;
RefPtr<FMRadioReplyRunnable> mPendingRequest;
FMRadioEventObserverList mObserverList;
static StaticRefPtr<FMRadioService> sFMRadioService;
uint32_t mRDSGroupMask;
uint16_t mLastPI;
uint16_t mLastPTY;
Atomic<uint32_t> mPI;
Atomic<uint32_t> mPTY;
Atomic<bool> mPISet;
Atomic<bool> mPTYSet;
/* Protects mPSName, mRadiotext, and mRDSGroup */
Mutex mRDSLock;
char16_t mPSName[9];
char16_t mRadiotext[65];
uint64_t mRDSGroup;
uint8_t mPSNameState;
uint16_t mRadiotextState;
uint16_t mTempPSName[8];
uint16_t mTempRadiotext[64];
bool mRadiotextAB;
bool mRDSGroupSet;
bool mPSNameSet;
bool mRadiotextSet;
};
END_FMRADIO_NAMESPACE
#endif // mozilla_dom_fmradioservice_h__

View File

@ -1,352 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "FMRadioChild.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/FMRadioRequestChild.h"
using namespace mozilla::hal;
BEGIN_FMRADIO_NAMESPACE
StaticAutoPtr<FMRadioChild> FMRadioChild::sFMRadioChild;
FMRadioChild::FMRadioChild()
: mEnabled(false)
, mRDSEnabled(false)
, mRDSGroupSet(false)
, mPSNameSet(false)
, mRadiotextSet(false)
, mFrequency(0)
, mRDSGroup(0)
, mRDSGroupMask(0)
, mObserverList(FMRadioEventObserverList())
{
MOZ_COUNT_CTOR(FMRadioChild);
ContentChild::GetSingleton()->SendPFMRadioConstructor(this);
StatusInfo statusInfo;
SendGetStatusInfo(&statusInfo);
mEnabled = statusInfo.enabled();
mFrequency = statusInfo.frequency();
mUpperBound = statusInfo.upperBound();
mLowerBound= statusInfo.lowerBound();
mChannelWidth = statusInfo.channelWidth();
}
FMRadioChild::~FMRadioChild()
{
MOZ_COUNT_DTOR(FMRadioChild);
}
bool
FMRadioChild::IsEnabled() const
{
return mEnabled;
}
bool
FMRadioChild::IsRDSEnabled() const
{
return mRDSEnabled;
}
double
FMRadioChild::GetFrequency() const
{
return mFrequency;
}
double
FMRadioChild::GetFrequencyUpperBound() const
{
return mUpperBound;
}
double
FMRadioChild::GetFrequencyLowerBound() const
{
return mLowerBound;
}
double
FMRadioChild::GetChannelWidth() const
{
return mChannelWidth;
}
Nullable<unsigned short>
FMRadioChild::GetPi() const
{
return mPI;
}
Nullable<uint8_t>
FMRadioChild::GetPty() const
{
return mPTY;
}
bool
FMRadioChild::GetPs(nsString& aPSName)
{
if (mPSNameSet) {
aPSName = mPSName;
}
return mPSNameSet;
}
bool
FMRadioChild::GetRt(nsString& aRadiotext)
{
if (mRadiotextSet) {
aRadiotext = mRadiotext;
}
return mRadiotextSet;
}
bool
FMRadioChild::GetRdsgroup(uint64_t& aRDSGroup)
{
aRDSGroup = mRDSGroup;
return mRDSGroupSet;
}
void
FMRadioChild::Enable(double aFrequency, FMRadioReplyRunnable* aReplyRunnable)
{
SendRequest(aReplyRunnable, EnableRequestArgs(aFrequency));
}
void
FMRadioChild::Disable(FMRadioReplyRunnable* aReplyRunnable)
{
SendRequest(aReplyRunnable, DisableRequestArgs());
}
void
FMRadioChild::SetFrequency(double aFrequency,
FMRadioReplyRunnable* aReplyRunnable)
{
SendRequest(aReplyRunnable, SetFrequencyRequestArgs(aFrequency));
}
void
FMRadioChild::Seek(FMRadioSeekDirection aDirection,
FMRadioReplyRunnable* aReplyRunnable)
{
SendRequest(aReplyRunnable, SeekRequestArgs(aDirection));
}
void
FMRadioChild::CancelSeek(FMRadioReplyRunnable* aReplyRunnable)
{
SendRequest(aReplyRunnable, CancelSeekRequestArgs());
}
void
FMRadioChild::SetRDSGroupMask(uint32_t aRDSGroupMask)
{
mRDSGroupMask = aRDSGroupMask;
SendSetRDSGroupMask(aRDSGroupMask);
}
void
FMRadioChild::EnableRDS(FMRadioReplyRunnable* aReplyRunnable)
{
SendRequest(aReplyRunnable, EnableRDSArgs());
}
void
FMRadioChild::DisableRDS(FMRadioReplyRunnable* aReplyRunnable)
{
SendRequest(aReplyRunnable, DisableRDSArgs());
}
inline void
FMRadioChild::NotifyFMRadioEvent(FMRadioEventType aType)
{
mObserverList.Broadcast(aType);
}
void
FMRadioChild::AddObserver(FMRadioEventObserver* aObserver)
{
mObserverList.AddObserver(aObserver);
}
void
FMRadioChild::RemoveObserver(FMRadioEventObserver* aObserver)
{
mObserverList.RemoveObserver(aObserver);
}
void
FMRadioChild::SendRequest(FMRadioReplyRunnable* aReplyRunnable,
FMRadioRequestArgs aArgs)
{
PFMRadioRequestChild* childRequest = new FMRadioRequestChild(aReplyRunnable);
SendPFMRadioRequestConstructor(childRequest, aArgs);
}
bool
FMRadioChild::RecvNotifyFrequencyChanged(const double& aFrequency)
{
mFrequency = aFrequency;
NotifyFMRadioEvent(FrequencyChanged);
if (!mPI.IsNull()) {
mPI.SetNull();
NotifyFMRadioEvent(PIChanged);
}
if (!mPTY.IsNull()) {
mPTY.SetNull();
NotifyFMRadioEvent(PTYChanged);
}
if (mPSNameSet) {
mPSNameSet = false;
mPSName.Truncate();
NotifyFMRadioEvent(PSChanged);
}
if (mRadiotextSet) {
mRadiotextSet = false;
mRadiotext.Truncate();
NotifyFMRadioEvent(RadiotextChanged);
}
mRDSGroupSet = false;
return true;
}
bool
FMRadioChild::RecvNotifyEnabledChanged(const bool& aEnabled,
const double& aFrequency)
{
mEnabled = aEnabled;
mFrequency = aFrequency;
if (!mEnabled) {
mPI.SetNull();
mPTY.SetNull();
mPSName.Truncate();
mRadiotext.Truncate();
mRDSGroupSet = false;
mPSNameSet = false;
mRadiotextSet = false;
}
NotifyFMRadioEvent(EnabledChanged);
return true;
}
bool
FMRadioChild::RecvNotifyRDSEnabledChanged(const bool& aEnabled)
{
mRDSEnabled = aEnabled;
NotifyFMRadioEvent(RDSEnabledChanged);
return true;
}
bool
FMRadioChild::RecvNotifyPIChanged(const bool& aValid,
const uint16_t& aCode)
{
if (aValid) {
mPI.SetValue(aCode);
} else {
mPI.SetNull();
}
NotifyFMRadioEvent(PIChanged);
return true;
}
bool
FMRadioChild::RecvNotifyPTYChanged(const bool& aValid,
const uint8_t& aPTY)
{
if (aValid) {
mPTY.SetValue(aPTY);
} else {
mPTY.SetNull();
}
NotifyFMRadioEvent(PTYChanged);
return true;
}
bool
FMRadioChild::RecvNotifyPSChanged(const nsString& aPSName)
{
mPSNameSet = true;
mPSName = aPSName;
NotifyFMRadioEvent(PSChanged);
return true;
}
bool
FMRadioChild::RecvNotifyRadiotextChanged(const nsString& aRadiotext)
{
mRadiotextSet = true;
mRadiotext = aRadiotext;
NotifyFMRadioEvent(RadiotextChanged);
return true;
}
bool
FMRadioChild::RecvNotifyNewRDSGroup(const uint64_t& aGroup)
{
uint16_t grouptype = (aGroup >> 43) & 0x1F;
if (!(mRDSGroupMask & (1 << grouptype))) {
return true;
}
mRDSGroupSet = true;
mRDSGroup = aGroup;
NotifyFMRadioEvent(NewRDSGroup);
return true;
}
bool
FMRadioChild::Recv__delete__()
{
return true;
}
PFMRadioRequestChild*
FMRadioChild::AllocPFMRadioRequestChild(const FMRadioRequestArgs& aArgs)
{
MOZ_CRASH();
return nullptr;
}
bool
FMRadioChild::DeallocPFMRadioRequestChild(PFMRadioRequestChild* aActor)
{
delete aActor;
return true;
}
void
FMRadioChild::EnableAudio(bool aAudioEnabled)
{
SendEnableAudio(aAudioEnabled);
}
// static
FMRadioChild*
FMRadioChild::Singleton()
{
MOZ_ASSERT(!XRE_IsParentProcess());
MOZ_ASSERT(NS_IsMainThread());
if (!sFMRadioChild) {
sFMRadioChild = new FMRadioChild();
}
return sFMRadioChild;
}
END_FMRADIO_NAMESPACE

View File

@ -1,134 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_fmradiochild_h__
#define mozilla_dom_fmradiochild_h__
#include "FMRadioCommon.h"
#include "FMRadioService.h"
#include "mozilla/dom/PFMRadioChild.h"
#include "mozilla/StaticPtr.h"
BEGIN_FMRADIO_NAMESPACE
/**
* FMRadioChild plays two roles:
* - Kind of proxy of FMRadioService
* Redirect all the requests coming from web content to FMRadioService
* in parent through IPC channel.
* - Child Actor of PFMRadio
* IPC channel to transfer the requests.
*/
class FMRadioChild final : public IFMRadioService
, public PFMRadioChild
{
public:
static FMRadioChild* Singleton();
~FMRadioChild();
void SendRequest(FMRadioReplyRunnable* aReplyRunnable,
FMRadioRequestArgs aArgs);
/* IFMRadioService */
virtual bool IsEnabled() const override;
virtual bool IsRDSEnabled() const override;
virtual double GetFrequency() const override;
virtual double GetFrequencyUpperBound() const override;
virtual double GetFrequencyLowerBound() const override;
virtual double GetChannelWidth() const override;
virtual Nullable<unsigned short> GetPi() const override;
virtual Nullable<uint8_t> GetPty() const override;
virtual bool GetPs(nsString& aPSName) override;
virtual bool GetRt(nsString& aRadiotext) override;
virtual bool GetRdsgroup(uint64_t& aRDSGroup) override;
virtual void Enable(double aFrequency,
FMRadioReplyRunnable* aReplyRunnable) override;
virtual void Disable(FMRadioReplyRunnable* aReplyRunnable) override;
virtual void SetFrequency(double frequency,
FMRadioReplyRunnable* aReplyRunnable) override;
virtual void Seek(mozilla::hal::FMRadioSeekDirection aDirection,
FMRadioReplyRunnable* aReplyRunnable) override;
virtual void CancelSeek(FMRadioReplyRunnable* aReplyRunnable) override;
virtual void SetRDSGroupMask(uint32_t aRDSGroupMask) override;
virtual void EnableRDS(FMRadioReplyRunnable* aReplyRunnable) override;
virtual void DisableRDS(FMRadioReplyRunnable* aReplyRunnable) override;
virtual void AddObserver(FMRadioEventObserver* aObserver) override;
virtual void RemoveObserver(FMRadioEventObserver* aObserver) override;
virtual void EnableAudio(bool aAudioEnabled) override;
/* PFMRadioChild */
virtual bool
Recv__delete__() override;
virtual bool
RecvNotifyFrequencyChanged(const double& aFrequency) override;
virtual bool
RecvNotifyEnabledChanged(const bool& aEnabled,
const double& aFrequency) override;
virtual bool
RecvNotifyRDSEnabledChanged(const bool& aEnabled) override;
virtual bool
RecvNotifyPIChanged(const bool& aValid,
const uint16_t& aCode) override;
virtual bool
RecvNotifyPTYChanged(const bool& aValid,
const uint8_t& aPTY) override;
virtual bool
RecvNotifyPSChanged(const nsString& aPSName) override;
virtual bool
RecvNotifyRadiotextChanged(const nsString& aRadiotext) override;
virtual bool
RecvNotifyNewRDSGroup(const uint64_t& aGroup) override;
virtual PFMRadioRequestChild*
AllocPFMRadioRequestChild(const FMRadioRequestArgs& aArgs) override;
virtual bool
DeallocPFMRadioRequestChild(PFMRadioRequestChild* aActor) override;
private:
FMRadioChild();
void Init();
inline void NotifyFMRadioEvent(FMRadioEventType aType);
bool mEnabled;
bool mRDSEnabled;
bool mRDSGroupSet;
bool mPSNameSet;
bool mRadiotextSet;
double mFrequency;
double mUpperBound;
double mLowerBound;
double mChannelWidth;
Nullable<unsigned short> mPI;
Nullable<uint8_t> mPTY;
nsAutoString mPSName;
nsAutoString mRadiotext;
uint64_t mRDSGroup;
uint32_t mRDSGroupMask;
FMRadioEventObserverList mObserverList;
private:
static StaticAutoPtr<FMRadioChild> sFMRadioChild;
};
END_FMRADIO_NAMESPACE
#endif // mozilla_dom_fmradiochild_h__

View File

@ -1,167 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "FMRadioParent.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/DebugOnly.h"
#include "FMRadioRequestParent.h"
#include "FMRadioService.h"
BEGIN_FMRADIO_NAMESPACE
FMRadioParent::FMRadioParent()
{
MOZ_COUNT_CTOR(FMRadioParent);
IFMRadioService::Singleton()->AddObserver(this);
}
FMRadioParent::~FMRadioParent()
{
MOZ_COUNT_DTOR(FMRadioParent);
IFMRadioService::Singleton()->RemoveObserver(this);
}
void
FMRadioParent::ActorDestroy(ActorDestroyReason aWhy)
{
// Implement me! Bug 1005146
}
bool
FMRadioParent::RecvGetStatusInfo(StatusInfo* aStatusInfo)
{
aStatusInfo->enabled() = IFMRadioService::Singleton()->IsEnabled();
aStatusInfo->frequency() = IFMRadioService::Singleton()->GetFrequency();
aStatusInfo->upperBound() =
IFMRadioService::Singleton()->GetFrequencyUpperBound();
aStatusInfo->lowerBound() =
IFMRadioService::Singleton()->GetFrequencyLowerBound();
aStatusInfo->channelWidth() =
IFMRadioService::Singleton()->GetChannelWidth();
return true;
}
PFMRadioRequestParent*
FMRadioParent::AllocPFMRadioRequestParent(const FMRadioRequestArgs& aArgs)
{
RefPtr<FMRadioRequestParent> requestParent = new FMRadioRequestParent();
switch (aArgs.type()) {
case FMRadioRequestArgs::TEnableRequestArgs:
IFMRadioService::Singleton()->Enable(
aArgs.get_EnableRequestArgs().frequency(), requestParent);
break;
case FMRadioRequestArgs::TDisableRequestArgs:
IFMRadioService::Singleton()->Disable(requestParent);
break;
case FMRadioRequestArgs::TSetFrequencyRequestArgs:
IFMRadioService::Singleton()->SetFrequency(
aArgs.get_SetFrequencyRequestArgs().frequency(), requestParent);
break;
case FMRadioRequestArgs::TSeekRequestArgs:
IFMRadioService::Singleton()->Seek(
aArgs.get_SeekRequestArgs().direction(), requestParent);
break;
case FMRadioRequestArgs::TCancelSeekRequestArgs:
IFMRadioService::Singleton()->CancelSeek(requestParent);
break;
case FMRadioRequestArgs::TEnableRDSArgs:
IFMRadioService::Singleton()->EnableRDS(requestParent);
break;
case FMRadioRequestArgs::TDisableRDSArgs:
IFMRadioService::Singleton()->DisableRDS(requestParent);
break;
default:
MOZ_CRASH();
}
// Balanced in DeallocPFMRadioRequestParent
return requestParent.forget().take();
}
bool
FMRadioParent::DeallocPFMRadioRequestParent(PFMRadioRequestParent* aActor)
{
FMRadioRequestParent* parent = static_cast<FMRadioRequestParent*>(aActor);
NS_RELEASE(parent);
return true;
}
void
FMRadioParent::Notify(const FMRadioEventType& aType)
{
switch (aType) {
case FrequencyChanged:
Unused << SendNotifyFrequencyChanged(
IFMRadioService::Singleton()->GetFrequency());
break;
case EnabledChanged:
Unused << SendNotifyEnabledChanged(
IFMRadioService::Singleton()->IsEnabled(),
IFMRadioService::Singleton()->GetFrequency());
break;
case RDSEnabledChanged:
Unused << SendNotifyRDSEnabledChanged(
IFMRadioService::Singleton()->IsRDSEnabled());
break;
case PIChanged: {
Nullable<unsigned short> pi =
IFMRadioService::Singleton()->GetPi();
Unused << SendNotifyPIChanged(!pi.IsNull(),
pi.IsNull() ? 0 : pi.Value());
break;
}
case PTYChanged: {
Nullable<uint8_t> pty = IFMRadioService::Singleton()->GetPty();
Unused << SendNotifyPTYChanged(!pty.IsNull(),
pty.IsNull() ? 0 : pty.Value());
break;
}
case PSChanged: {
nsAutoString psname;
IFMRadioService::Singleton()->GetPs(psname);
Unused << SendNotifyPSChanged(psname);
break;
}
case RadiotextChanged: {
nsAutoString radiotext;
IFMRadioService::Singleton()->GetRt(radiotext);
Unused << SendNotifyRadiotextChanged(radiotext);
break;
}
case NewRDSGroup: {
uint64_t group;
DebugOnly<bool> rdsgroupset =
IFMRadioService::Singleton()->GetRdsgroup(group);
MOZ_ASSERT(rdsgroupset);
Unused << SendNotifyNewRDSGroup(group);
break;
}
default:
NS_RUNTIMEABORT("not reached");
break;
}
}
bool
FMRadioParent::RecvEnableAudio(const bool& aAudioEnabled)
{
IFMRadioService::Singleton()->EnableAudio(aAudioEnabled);
return true;
}
bool
FMRadioParent::RecvSetRDSGroupMask(const uint32_t& aRDSGroupMask)
{
IFMRadioService::Singleton()->SetRDSGroupMask(aRDSGroupMask);
return true;
}
END_FMRADIO_NAMESPACE

View File

@ -1,50 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_fmradioparent_h__
#define mozilla_dom_fmradioparent_h__
#include "FMRadioCommon.h"
#include "mozilla/dom/PFMRadioParent.h"
#include "mozilla/HalTypes.h"
BEGIN_FMRADIO_NAMESPACE
class PFMRadioRequestParent;
class FMRadioParent final : public PFMRadioParent
, public FMRadioEventObserver
{
public:
FMRadioParent();
~FMRadioParent();
virtual void
ActorDestroy(ActorDestroyReason aWhy) override;
virtual bool
RecvGetStatusInfo(StatusInfo* aStatusInfo) override;
virtual PFMRadioRequestParent*
AllocPFMRadioRequestParent(const FMRadioRequestArgs& aArgs) override;
virtual bool
DeallocPFMRadioRequestParent(PFMRadioRequestParent* aActor) override;
/* FMRadioEventObserver */
virtual void Notify(const FMRadioEventType& aType) override;
virtual bool
RecvEnableAudio(const bool& aAudioEnabled) override;
virtual bool
RecvSetRDSGroupMask(const uint32_t& aRDSGroupMask) override;
};
END_FMRADIO_NAMESPACE
#endif // mozilla_dom_fmradioparent_h__

View File

@ -1,34 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "mozilla/dom/PFMRadioRequestChild.h"
#include "FMRadioRequestChild.h"
#include "FMRadioService.h"
BEGIN_FMRADIO_NAMESPACE
FMRadioRequestChild::FMRadioRequestChild(FMRadioReplyRunnable* aReplyRunnable)
: mReplyRunnable(aReplyRunnable)
{
MOZ_COUNT_CTOR(FMRadioRequestChild);
}
FMRadioRequestChild::~FMRadioRequestChild()
{
MOZ_COUNT_DTOR(FMRadioRequestChild);
}
bool
FMRadioRequestChild::Recv__delete__(const FMRadioResponseType& aType)
{
mReplyRunnable->SetReply(aType);
NS_DispatchToMainThread(mReplyRunnable);
return true;
}
END_FMRADIO_NAMESPACE

View File

@ -1,34 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_fmradiorequestchild_h__
#define mozilla_dom_fmradiorequestchild_h__
#include "FMRadioCommon.h"
#include "mozilla/dom/PFMRadioRequestChild.h"
#include "DOMRequest.h"
BEGIN_FMRADIO_NAMESPACE
class FMRadioReplyRunnable;
class FMRadioRequestChild final : public PFMRadioRequestChild
{
public:
FMRadioRequestChild(FMRadioReplyRunnable* aReplyRunnable);
~FMRadioRequestChild();
virtual bool
Recv__delete__(const FMRadioResponseType& aResponse) override;
private:
RefPtr<FMRadioReplyRunnable> mReplyRunnable;
};
END_FMRADIO_NAMESPACE
#endif // mozilla_dom_fmradiorequestchild_h__

View File

@ -1,44 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "FMRadioRequestParent.h"
#include "FMRadioService.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/PFMRadio.h"
BEGIN_FMRADIO_NAMESPACE
FMRadioRequestParent::FMRadioRequestParent()
: mActorDestroyed(false)
{
MOZ_COUNT_CTOR(FMRadioRequestParent);
}
FMRadioRequestParent::~FMRadioRequestParent()
{
MOZ_COUNT_DTOR(FMRadioRequestParent);
}
void
FMRadioRequestParent::ActorDestroy(ActorDestroyReason aWhy)
{
mActorDestroyed = true;
}
nsresult
FMRadioRequestParent::Run()
{
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
if (!mActorDestroyed) {
Unused << Send__delete__(this, mResponseType);
}
return NS_OK;
}
END_FMRADIO_NAMESPACE

View File

@ -1,34 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_fmradiorequestparent_h__
#define mozilla_dom_fmradiorequestparent_h__
#include "FMRadioCommon.h"
#include "mozilla/dom/PFMRadioRequestParent.h"
#include "FMRadioService.h"
BEGIN_FMRADIO_NAMESPACE
class FMRadioRequestParent final : public PFMRadioRequestParent
, public FMRadioReplyRunnable
{
public:
FMRadioRequestParent();
~FMRadioRequestParent();
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
NS_IMETHOD Run();
private:
bool mActorDestroyed;
};
END_FMRADIO_NAMESPACE
#endif // mozilla_dom_fmradiorequestparent_h__

View File

@ -1,137 +0,0 @@
/* 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 protocol PContent;
include protocol PFMRadioRequest;
using mozilla::hal::FMRadioSeekDirection from "mozilla/HalTypes.h";
namespace mozilla {
namespace dom {
struct EnableRequestArgs
{
double frequency;
};
struct DisableRequestArgs
{
};
struct SetFrequencyRequestArgs
{
double frequency;
};
struct SeekRequestArgs
{
FMRadioSeekDirection direction;
};
struct CancelSeekRequestArgs
{
};
struct EnableRDSArgs
{
};
struct DisableRDSArgs
{
};
union FMRadioRequestArgs
{
EnableRequestArgs;
DisableRequestArgs;
SetFrequencyRequestArgs;
SeekRequestArgs;
CancelSeekRequestArgs;
EnableRDSArgs;
DisableRDSArgs;
};
struct StatusInfo
{
bool enabled;
double frequency;
double upperBound;
double lowerBound;
double channelWidth;
};
sync protocol PFMRadio
{
manager PContent;
manages PFMRadioRequest;
child:
/**
* Sent when the frequency is changed.
*/
async NotifyFrequencyChanged(double frequency);
/**
* Sent when the power state of FM radio HW is changed.
*/
async NotifyEnabledChanged(bool enabled, double frequency);
/**
* Sent when RDS is enabled or disabled.
*/
async NotifyRDSEnabledChanged(bool enabled);
/**
* Sent when we have a new PI code.
*/
async NotifyPIChanged(bool valid, uint16_t code);
/**
* Sent when we have a new PTY
*/
async NotifyPTYChanged(bool valid, uint8_t pty);
/**
* Sent when we have a new PS name.
*/
async NotifyPSChanged(nsString psname);
/**
* Sent when we have new radiotext.
*/
async NotifyRadiotextChanged(nsString radiotext);
/**
* Sent when a full RDS group is received.
*/
async NotifyNewRDSGroup(uint64_t data);
async __delete__();
parent:
/**
* Get the current status infomation of FM radio HW synchronously.
* Sent when the singleton object of FMRadioChild is initialized.
*/
sync GetStatusInfo() returns (StatusInfo info);
/**
* Send request to parent process to operate the FM radio HW.
*
* We don't have separate Enable/SetFrequency/etc. methods instead here,
* because we can leverage the IPC messaging mechanism to manage the mapping
* of the asynchronous request and the DOMRequest we returned to the caller
* on web content, otherwise, we have to do the mapping stuff manually which
* is more error prone.
*/
async PFMRadioRequest(FMRadioRequestArgs requestType);
/**
* Enable/Disable audio
*/
async EnableAudio(bool audioEnabled);
/**
* Set RDS group mask
*/
async SetRDSGroupMask(uint32_t groupMask);
};
} // namespace dom
} // namespace mozilla

View File

@ -1,43 +0,0 @@
/* 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 protocol PFMRadio;
namespace mozilla {
namespace dom {
struct ErrorResponse
{
nsString error;
};
struct SuccessResponse
{
};
union FMRadioResponseType
{
ErrorResponse;
SuccessResponse;
};
/**
* The protocol is used for sending asynchronous operation requests of
* FM radio HW from child to parent, and the type of the request is defined in
* FMRadioRequestArgs.
*
* When the request completed, the result, i.e. FMRadioResponseType, will be
* sent back to child from parent in the `__delete__` message.
*/
async protocol PFMRadioRequest
{
manager PFMRadio;
child:
async __delete__(FMRadioResponseType response);
};
} // namespace dom
} // namespace mozilla

View File

@ -1,31 +0,0 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
EXPORTS.mozilla.dom += [
'FMRadioChild.h',
'FMRadioParent.h',
'FMRadioRequestChild.h',
'FMRadioRequestParent.h',
]
UNIFIED_SOURCES += [
'FMRadioChild.cpp',
'FMRadioParent.cpp',
'FMRadioRequestChild.cpp',
'FMRadioRequestParent.cpp',
]
LOCAL_INCLUDES += [
'/dom/base',
]
include('/ipc/chromium/chromium-config.mozbuild')
FINAL_LIBRARY = 'xul'
LOCAL_INCLUDES += [
'/dom/fmradio',
]

View File

@ -1,34 +0,0 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
if CONFIG['MOZ_B2G_FM']:
DIRS += [
'ipc',
]
EXPORTS.mozilla.dom += [
'FMRadio.h',
'FMRadioCommon.h',
'FMRadioService.h',
]
UNIFIED_SOURCES += [
'FMRadio.cpp',
'FMRadioService.cpp',
]
FINAL_LIBRARY = 'xul'
IPDL_SOURCES += [
'ipc/PFMRadio.ipdl',
'ipc/PFMRadioRequest.ipdl',
]
LOCAL_INCLUDES += [
'../base',
'../system/gonk',
]
include('/ipc/chromium/chromium-config.mozbuild')

View File

@ -1,11 +0,0 @@
[DEFAULT]
run-if = buildapp == 'b2g'
[test_enable_disable.js]
[test_set_frequency.js]
[test_cancel_seek.js]
[test_one_seek_at_once.js]
[test_seek_up_and_down.js]
[test_bug862672.js]
[test_bug876597.js]

View File

@ -1,53 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
SpecialPowers.addPermission("fmradio", true, document);
var FMRadio = window.navigator.mozFMRadio;
function verifyInitialState() {
log("Verifying initial state.");
ok(FMRadio);
is(FMRadio.enabled, false);
enableThenDisable();
}
function enableThenDisable() {
log("Enable FM Radio and disable it immediately.");
var frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
var request = FMRadio.enable(frequency);
ok(request);
var failedToEnable = false;
request.onerror = function() {
failedToEnable = true;
};
var enableCompleted = false;
request.onsuccess = function() {
ok(!failedToEnable);
enableCompleted = true;
};
var disableReq = FMRadio.disable();
ok(disableReq);
disableReq.onsuccess = function() {
// There are two possibilities which depends on the system
// process scheduling (bug 911063 comment 0):
// - enable fails
// - enable's onsuccess fires before disable's onsucess
ok(failedToEnable || enableCompleted);
ok(!FMRadio.enabled);
finish();
};
disableReq.onerror = function() {
ok(false, "Disable request should not fail.");
};
}
verifyInitialState();

View File

@ -1,92 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
SpecialPowers.addPermission("fmradio", true, document);
SpecialPowers.addPermission("settings-read", true, document);
SpecialPowers.addPermission("settings-write", true, document);
SpecialPowers.addPermission("settings-api-read", true, document);
SpecialPowers.addPermission("settings-api-write", true, document);
var FMRadio = window.navigator.mozFMRadio;
var mozSettings = window.navigator.mozSettings;
var KEY = "airplaneMode.enabled";
function verifyInitialState() {
log("Verifying initial state.");
ok(FMRadio);
is(FMRadio.enabled, false);
ok(mozSettings);
checkAirplaneModeSettings();
}
function checkAirplaneModeSettings() {
log("Checking airplane mode settings");
let req = mozSettings.createLock().get(KEY);
req.onsuccess = function(event) {
ok(!req.result[KEY], "Airplane mode is disabled.");
enableFMRadio();
};
req.onerror = function() {
ok(false, "Error occurs when reading settings value.");
finish();
};
}
function enableFMRadio() {
log("Enable FM radio");
let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
let req = FMRadio.enable(frequency);
req.onsuccess = function() {
enableAirplaneMode();
};
req.onerror = function() {
ok(false, "Failed to enable FM radio.");
};
}
function enableAirplaneMode() {
log("Enable airplane mode");
FMRadio.ondisabled = function() {
FMRadio.ondisabled = null;
enableFMRadioWithAirplaneModeEnabled();
};
let settings = {};
settings[KEY] = true;
mozSettings.createLock().set(settings);
}
function enableFMRadioWithAirplaneModeEnabled() {
log("Enable FM radio with airplane mode enabled");
let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
let req = FMRadio.enable(frequency);
req.onerror = cleanUp();
req.onsuccess = function() {
ok(false, "FMRadio could be enabled when airplane mode is enabled.");
};
}
function cleanUp() {
let settings = {};
settings[KEY] = false;
let req = mozSettings.createLock().set(settings);
req.onsuccess = function() {
ok(!FMRadio.enabled);
finish();
};
req.onerror = function() {
ok(false, "Error occurs when setting value");
};
}
verifyInitialState();

View File

@ -1,69 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
SpecialPowers.addPermission("fmradio", true, document);
var FMRadio = window.navigator.mozFMRadio;
function verifyInitialState() {
log("Verifying initial state.");
ok(FMRadio);
is(FMRadio.enabled, false);
setUp();
}
function setUp() {
let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
FMRadio.enable(frequency);
FMRadio.onenabled = seek;
}
function seek() {
log("Seek up");
var request = FMRadio.seekUp();
ok(request);
var seekUpIsCancelled = false;
request.onerror = function() {
seekUpIsCancelled = true;
};
var seekUpCompleted = false;
request.onsuccess = function() {
ok(!seekUpIsCancelled);
seekUpCompleted = true;
};
log("Seek up");
var cancelSeekReq = FMRadio.cancelSeek();
ok(cancelSeekReq);
// There are two possibilities which depends on the system
// process scheduling (bug 911063 comment 0):
// - seekup action is canceled
// - seekup's onsuccess fires before cancelSeek's onerror
cancelSeekReq.onsuccess = function() {
ok(seekUpIsCancelled, "Seekup request failed.");
cleanUp();
};
cancelSeekReq.onerror = function() {
ok(seekUpCompleted);
cleanUp();
};
}
function cleanUp() {
FMRadio.disable();
FMRadio.ondisabled = function() {
FMRadio.ondisabled = null;
ok(!FMRadio.enabled);
finish();
};
}
verifyInitialState();

View File

@ -1,85 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
SpecialPowers.addPermission("fmradio", true, document);
var FMRadio = window.navigator.mozFMRadio;
function verifyInitialState() {
log("Verifying initial state.");
ok(FMRadio);
is(FMRadio.enabled, false);
log("Verifying attributes when disabled.");
is(FMRadio.frequency, null);
ok(FMRadio.frequencyLowerBound);
ok(FMRadio.frequencyUpperBound);
ok(FMRadio.frequencyUpperBound > FMRadio.frequencyLowerBound);
ok(FMRadio.channelWidth);
enableFMRadio();
}
function enableFMRadio() {
log("Verifying behaviors when enabled.");
var frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
var request = FMRadio.enable(frequency);
ok(request, "FMRadio.enable(r" + frequency + ") returns request");
request.onsuccess = function() {
ok(FMRadio.enabled);
ok(typeof FMRadio.frequency == "number");
ok(FMRadio.frequency > FMRadio.frequencyLowerBound);
};
request.onerror = function() {
ok(null, "Failed to enable");
};
var enabled = false;
FMRadio.onenabled = function() {
FMRadio.onenabled = null;
enabled = FMRadio.enabled;
};
FMRadio.onfrequencychange = function() {
log("Check if 'onfrequencychange' event is fired after the 'enabled' event");
FMRadio.onfrequencychange = null;
ok(enabled, "FMRadio is enabled when handling `onfrequencychange`");
disableFMRadio();
};
}
function disableFMRadio() {
log("Verify behaviors when disabled");
// There are two possibilities which depends on the system
// process scheduling (bug 911063 comment 0):
// - seek fails
// - seek's onsuccess fires before disable's onsucess
var seekRequest = FMRadio.seekUp();
var seekCompletes = false;
var failedToSeek = false;
seekRequest.onerror = function() {
ok(!seekCompletes);
failedToSeek = true;
};
seekRequest.onsuccess = function() {
ok(!failedToSeek);
seekCompletes = true;
};
FMRadio.disable();
FMRadio.ondisabled = function() {
FMRadio.ondisabled = null;
ok(seekCompletes || failedToSeek);
ok(!FMRadio.enabled);
finish();
};
}
verifyInitialState();

View File

@ -1,73 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
SpecialPowers.addPermission("fmradio", true, document);
var FMRadio = window.navigator.mozFMRadio;
function verifyInitialState() {
log("Verifying initial state.");
ok(FMRadio);
is(FMRadio.enabled, false);
setUp();
}
function setUp() {
let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
FMRadio.enable(frequency);
FMRadio.onenabled = seek;
}
function seek() {
var request = FMRadio.seekUp();
ok(request);
// There are two possibilities which depends on the system
// process scheduling (bug 911063 comment 0):
// - the second seek fails
// - both seeks are executed
request.onerror = function() {
ok(!firstSeekCompletes);
cleanUp();
};
var firstSeekCompletes = false;
request.onsuccess = function() {
firstSeekCompletes = true;
};
var seekAgainReq = FMRadio.seekUp();
ok(seekAgainReq);
seekAgainReq.onerror = function() {
log("Cancel the first seek to finish the test");
let cancelReq = FMRadio.cancelSeek();
ok(cancelReq);
// It's possible that the first seek completes when the
// cancel request is handled.
cancelReq.onerror = function() {
cleanUp();
};
};
seekAgainReq.onsuccess = function() {
ok(firstSeekCompletes);
cleanUp();
};
}
function cleanUp() {
FMRadio.disable();
FMRadio.ondisabled = function() {
FMRadio.ondisabled = null;
ok(!FMRadio.enabled);
finish();
};
}
verifyInitialState();

View File

@ -1,61 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
SpecialPowers.addPermission("fmradio", true, document);
var FMRadio = window.navigator.mozFMRadio;
function verifyInitialState() {
log("Verifying initial state.");
ok(FMRadio);
is(FMRadio.enabled, false);
setUp();
}
function setUp() {
let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
FMRadio.enable(frequency);
FMRadio.onenabled = seekUp;
}
function seekUp() {
log("Seek up");
var request = FMRadio.seekUp();
ok(request);
request.onsuccess = function() {
seekDown();
};
request.onerror = function() {
ok(false, "Seekup request should not fail.");
};
}
function seekDown() {
log("Seek down");
var request = FMRadio.seekDown();
ok(request);
request.onsuccess = function() {
cleanUp();
};
request.onerror = function() {
ok(false, "Seekdown request should not fail.");
};
}
function cleanUp() {
FMRadio.disable();
FMRadio.ondisabled = function() {
FMRadio.ondisabled = null;
ok(!FMRadio.enabled);
finish();
};
}
verifyInitialState();

View File

@ -1,87 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
SpecialPowers.addPermission("fmradio", true, document);
var FMRadio = window.navigator.mozFMRadio;
function verifyInitialState() {
log("Verifying initial state.");
ok(FMRadio);
is(FMRadio.enabled, false);
setUp();
}
function setUp() {
let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
FMRadio.enable(frequency);
FMRadio.onenabled = setFrequency;
}
function setFrequency() {
log("Set Frequency");
let frequency = FMRadio.frequency + FMRadio.channelWidth;
var request = FMRadio.setFrequency(frequency);
ok(request);
request.onsuccess = setOutOfRangeFrequency;
request.onerror = function() {
ok(false, "setFrequency request should not fail.");
};
}
function setOutOfRangeFrequency() {
log("Set Frequency that out of the range");
var request = FMRadio.setFrequency(FMRadio.frequencyUpperBound + 1);
ok(request);
request.onsuccess = function() {
ok(false, "The request of setting an out-of-range frequency should fail.");
};
request.onerror = setFrequencyWhenSeeking;
}
function setFrequencyWhenSeeking() {
log("Set frequency when seeking");
var request = FMRadio.seekUp();
ok(request);
// There are two possibilities which depends on the system
// process scheduling (bug 911063 comment 0):
// - seek fails
// - seek's onsuccess fires before setFrequency's onsucess
var failedToSeek = false;
request.onerror = function() {
failedToSeek = true;
};
var seekCompletes = false;
request.onsuccess = function() {
ok(!failedToSeek);
seekCompletes = true;
};
var frequency = FMRadio.frequencyUpperBound - FMRadio.channelWidth;
var setFreqRequest = FMRadio.setFrequency(frequency);
ok(setFreqRequest);
setFreqRequest.onsuccess = function() {
ok(failedToSeek || seekCompletes);
cleanUp();
};
}
function cleanUp() {
FMRadio.disable();
FMRadio.ondisabled = function() {
FMRadio.ondisabled = null;
ok(!FMRadio.enabled);
finish();
};
}
verifyInitialState();

View File

@ -175,7 +175,6 @@
#include "mozilla/dom/mobilemessage/SmsChild.h"
#include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h"
#include "mozilla/dom/bluetooth/PBluetoothChild.h"
#include "mozilla/dom/PFMRadioChild.h"
#include "mozilla/dom/PPresentationChild.h"
#include "mozilla/dom/PresentationIPCService.h"
#include "mozilla/ipc/InputStreamUtils.h"
@ -2078,30 +2077,6 @@ ContentChild::DeallocPBluetoothChild(PBluetoothChild* aActor)
#endif
}
PFMRadioChild*
ContentChild::AllocPFMRadioChild()
{
#ifdef MOZ_B2G_FM
NS_RUNTIMEABORT("No one should be allocating PFMRadioChild actors");
return nullptr;
#else
NS_RUNTIMEABORT("No support for FMRadio on this platform!");
return nullptr;
#endif
}
bool
ContentChild::DeallocPFMRadioChild(PFMRadioChild* aActor)
{
#ifdef MOZ_B2G_FM
delete aActor;
return true;
#else
NS_RUNTIMEABORT("No support for FMRadio on this platform!");
return false;
#endif
}
PSpeechSynthesisChild*
ContentChild::AllocPSpeechSynthesisChild()
{

View File

@ -361,10 +361,6 @@ public:
virtual bool DeallocPBluetoothChild(PBluetoothChild* aActor) override;
virtual PFMRadioChild* AllocPFMRadioChild() override;
virtual bool DeallocPFMRadioChild(PFMRadioChild* aActor) override;
virtual PPresentationChild* AllocPPresentationChild() override;
virtual bool DeallocPPresentationChild(PPresentationChild* aActor) override;

View File

@ -54,7 +54,6 @@
#include "mozilla/dom/PContentBridgeParent.h"
#include "mozilla/dom/PContentPermissionRequestParent.h"
#include "mozilla/dom/PCycleCollectWithLogsParent.h"
#include "mozilla/dom/PFMRadioParent.h"
#include "mozilla/dom/PMemoryReportRequestParent.h"
#include "mozilla/dom/ServiceWorkerRegistrar.h"
#include "mozilla/dom/bluetooth/PBluetoothParent.h"
@ -236,10 +235,6 @@ using namespace mozilla::system;
#include "mozilla/RemoteSpellCheckEngineParent.h"
#ifdef MOZ_B2G_FM
#include "mozilla/dom/FMRadioParent.h"
#endif
#include "Crypto.h"
#ifdef MOZ_WEBSPEECH
@ -3572,32 +3567,6 @@ ContentParent::RecvPBluetoothConstructor(PBluetoothParent* aActor)
#endif
}
PFMRadioParent*
ContentParent::AllocPFMRadioParent()
{
#ifdef MOZ_B2G_FM
if (!AssertAppProcessPermission(this, "fmradio")) {
return nullptr;
}
return new FMRadioParent();
#else
NS_WARNING("No support for FMRadio on this platform!");
return nullptr;
#endif
}
bool
ContentParent::DeallocPFMRadioParent(PFMRadioParent* aActor)
{
#ifdef MOZ_B2G_FM
delete aActor;
return true;
#else
NS_WARNING("No support for FMRadio on this platform!");
return false;
#endif
}
PPresentationParent*
ContentParent::AllocPPresentationParent()
{

View File

@ -869,10 +869,6 @@ private:
virtual bool RecvPBluetoothConstructor(PBluetoothParent* aActor) override;
virtual PFMRadioParent* AllocPFMRadioParent() override;
virtual bool DeallocPFMRadioParent(PFMRadioParent* aActor) override;
virtual PPresentationParent* AllocPPresentationParent() override;
virtual bool DeallocPPresentationParent(PPresentationParent* aActor) override;

View File

@ -18,7 +18,6 @@ include protocol PExternalHelperApp;
include protocol PHandlerService;
include protocol PDeviceStorageRequest;
include protocol PFileDescriptorSet;
include protocol PFMRadio;
include protocol PHal;
include protocol PHeapSnapshotTempFileHelper;
include protocol PIcc;
@ -238,40 +237,6 @@ struct DeviceStorageLocationInfo {
nsString crashes;
};
struct FMRadioRequestEnableParams
{
double frequency;
};
struct FMRadioRequestDisableParams
{
};
struct FMRadioRequestSetFrequencyParams
{
double frequency;
};
struct FMRadioRequestSeekParams
{
bool upward;
};
struct FMRadioRequestCancelSeekParams
{
};
union FMRadioRequestParams
{
FMRadioRequestEnableParams;
FMRadioRequestDisableParams;
FMRadioRequestSetFrequencyParams;
FMRadioRequestSeekParams;
FMRadioRequestCancelSeekParams;
};
union PrefValue {
nsCString;
int32_t;
@ -395,7 +360,6 @@ nested(upto inside_cpow) sync protocol PContent
manages PPSMContentDownloader;
manages PExternalHelperApp;
manages PFileDescriptorSet;
manages PFMRadio;
manages PHal;
manages PHandlerService;
manages PHeapSnapshotTempFileHelper;
@ -874,8 +838,6 @@ parent:
async PBluetooth();
async PFMRadio();
async PWebrtcGlobal();
async PPresentation();

View File

@ -130,7 +130,6 @@ LOCAL_INCLUDES += [
'/dom/devicestorage',
'/dom/events',
'/dom/filesystem',
'/dom/fmradio/ipc',
'/dom/geolocation',
'/dom/media/webspeech/synth/ipc',
'/dom/mobilemessage/ipc',

View File

@ -57,7 +57,6 @@ DIRS += [
'filehandle',
'filesystem',
'flyweb',
'fmradio',
'gamepad',
'geolocation',
'grid',

View File

@ -34,9 +34,6 @@ MOCHITEST_MANIFESTS += ['tests/mochitest.ini']
if CONFIG['MOZ_B2G_RIL']:
MOCHITEST_MANIFESTS += ['tests/mochitest-ril.ini']
if CONFIG['MOZ_B2G_FM']:
MOCHITEST_MANIFESTS += ['tests/mochitest-fm.ini']
if CONFIG['MOZ_B2G_BT']:
MOCHITEST_MANIFESTS += ['tests/mochitest-bt.ini']

View File

@ -1 +0,0 @@
[test_fmradio.html]

View File

@ -1,31 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=815105
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 815105 </title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=815105">Mozilla Bug 815105 </a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
<script type="application/javascript;version=1.8" src="file_framework.js"></script>
<script type="application/javascript;version=1.8">
var gData = [
{
perm: ["fmradio"],
needParentPerm: true,
obj: "mozFMRadio",
webidl: "FMRadio",
},
]
</script>
</pre>
</body>
</html>

View File

@ -1,176 +0,0 @@
/* 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/. */
interface FMRadio : EventTarget {
/* Indicates if the FM radio is enabled. */
readonly attribute boolean enabled;
/* Indicates if RDS reception is enabled */
readonly attribute boolean rdsEnabled;
/* Indicates if the antenna is plugged and available. */
readonly attribute boolean antennaAvailable;
/**
* Current frequency in MHz. The value will be null if the FM radio is
* disabled.
*/
readonly attribute double? frequency;
/* The upper bound of frequency in MHz. */
readonly attribute double frequencyUpperBound;
/* The lower bound of frequency in MHz. */
readonly attribute double frequencyLowerBound;
/**
* The difference in frequency between two "adjacent" channels, in MHz. That
* is, any two radio channels' frequencies differ by at least channelWidth
* MHz. Usually, the value is one of:
* - 0.05 MHz
* - 0.1 MHz
* - 0.2 MHz
*/
readonly attribute double channelWidth;
/**
* This is a mask consisting of bits corresponding to
* (1 << groupcode) that can be specified to receive
* raw RDS groups of specific group types. Note that
* groupcode corresponds to the upper 5 bits in block B.
*/
attribute unsigned long rdsGroupMask;
/**
* The Program Identification (PI) code.
* Available if RDS is enabled on both the station and on this device.
* The value is null otherwise.
*/
readonly attribute unsigned short? pi;
/**
* The Program Type (PTY) code.
* Available if RDS is enabled on both the station and on this device.
* The value is null otherwise.
*/
readonly attribute octet? pty;
/**
* The Program Service (PS) name.
* Available if RDS is enabled on the station and on this device
*/
readonly attribute DOMString? ps;
/**
* The radiotext, as provided by group 2A/2B.
* Available if RDS is enabled on the station and on this device
*/
readonly attribute DOMString? rt;
/**
* The last RDS group received.
* Available if RDS is enabled on the station and on this device
*/
readonly attribute Uint16Array? rdsgroup;
/* Fired when the FM radio is enabled. */
attribute EventHandler onenabled;
/* Fired when the FM radio is disabled. */
attribute EventHandler ondisabled;
/* Fired when the RDS is enabled. */
attribute EventHandler onrdsenabled;
/* Fired when the RDS is disabled. */
attribute EventHandler onrdsdisabled;
/**
* Fired when the antenna becomes available or unavailable, i.e., fired when
* the antennaAvailable attribute changes.
*/
attribute EventHandler onantennaavailablechange;
/* Fired when the FM radio's frequency is changed. */
attribute EventHandler onfrequencychange;
/* Fired when the PI code changes */
attribute EventHandler onpichange;
/* Fired when the PTY changes */
attribute EventHandler onptychange;
/* Fired when the PS name changes */
attribute EventHandler onpschange;
/* Fired when the radiotext changes */
attribute EventHandler onrtchange;
/* Fired when we get a new RDS group */
attribute EventHandler onnewrdsgroup;
/**
* Power the FM radio off. The disabled event will be fired if this request
* completes successfully.
*/
DOMRequest disable();
/**
* Power the FM radio on, and tune the radio to the given frequency in MHz.
* This will fail if the given frequency is out of range. The enabled event
* and frequencychange event will be fired if this request completes
* successfully.
*/
DOMRequest enable(double frequency);
/**
* Tune the FM radio to the given frequency. This will fail if the given
* frequency is out of range.
*
* Note that the FM radio may not tuned to the exact frequency given. To get
* the frequency the radio is actually tuned to, wait for the request to fire
* sucess (or wait for the frequencychange event to fire), and then read the
* frequency attribute.
*/
DOMRequest setFrequency(double frequency);
/**
* Tell the FM radio to seek up to the next channel. If the frequency is
* successfully changed, the frequencychange event will be triggered.
*
* Only one seek is allowed at once: If the radio is seeking when the seekUp
* is called, error will be fired.
*/
DOMRequest seekUp();
/**
* Tell the FM radio to seek down to the next channel. If the frequency is
* successfully changed, the frequencychange event will be triggered.
*
* Only one seek is allowed at once: If the radio is seeking when the
* seekDown is called, error will be fired.
*/
DOMRequest seekDown();
/**
* Cancel the seek action. If the radio is not currently seeking up or down,
* error will be fired.
*/
DOMRequest cancelSeek();
/**
* Enable RDS reception.
*
* If the radio is off, RDS will be enabled when the radio is turned on.
*/
DOMRequest enableRDS();
/**
* Disable RDS reception.
*
* If the radio is off, RDS will not be enabled when the radio is turned on.
*/
DOMRequest disableRDS();
};

View File

@ -327,13 +327,6 @@ partial interface Navigator {
};
#endif // MOZ_B2G_BT
#ifdef MOZ_B2G_FM
partial interface Navigator {
[Throws, ChromeOnly, UnsafeInPrerendering]
readonly attribute FMRadio mozFMRadio;
};
#endif // MOZ_B2G_FM
#ifdef MOZ_TIME_MANAGER
// nsIDOMMozNavigatorTime
partial interface Navigator {

View File

@ -768,11 +768,6 @@ else:
'InstallTrigger.webidl',
]
if CONFIG['MOZ_B2G_FM']:
WEBIDL_FILES += [
'FMRadio.webidl',
]
GENERATED_EVENTS_WEBIDL_FILES = [
'AddonEvent.webidl',
'AnimationPlaybackEvent.webidl',

View File

@ -85,11 +85,6 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
'/dom/system/gonk',
]
if CONFIG['MOZ_B2G_FM']:
LOCAL_INCLUDES += [
'/dom/fmradio',
]
if CONFIG['MOZ_B2G_BT']:
LOCAL_INCLUDES += [
'/dom/bluetooth/common',

View File

@ -970,7 +970,6 @@ case "$target" in
AC_DEFINE(NO_PW_GECOS)
if test -n "$gonkdir"; then
_PLATFORM_HAVE_RIL=1
MOZ_B2G_FM=1
MOZ_SYNTH_PICO=1
else
if test "$COMPILE_ENVIRONMENT"; then
@ -4812,14 +4811,6 @@ if test -n "$MOZ_B2G_RIL"; then
fi
AC_SUBST(MOZ_B2G_RIL)
dnl ========================================================
dnl = Enable Radio FM for B2G (Gonk usually)
dnl ========================================================
if test -n "$MOZ_B2G_FM"; then
AC_DEFINE(MOZ_B2G_FM)
fi
AC_SUBST(MOZ_B2G_FM)
dnl ========================================================
dnl = Enable Bluetooth Interface for B2G (Gonk usually)
dnl ========================================================