Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "FMRadioParent.h"
7 #include "mozilla/unused.h"
8 #include "mozilla/dom/ContentParent.h"
9 #include "FMRadioRequestParent.h"
10 #include "FMRadioService.h"
12 BEGIN_FMRADIO_NAMESPACE
14 FMRadioParent::FMRadioParent()
15 {
16 MOZ_COUNT_CTOR(FMRadioParent);
18 IFMRadioService::Singleton()->AddObserver(this);
19 }
21 FMRadioParent::~FMRadioParent()
22 {
23 MOZ_COUNT_DTOR(FMRadioParent);
25 IFMRadioService::Singleton()->RemoveObserver(this);
26 }
28 bool
29 FMRadioParent::RecvGetStatusInfo(StatusInfo* aStatusInfo)
30 {
31 aStatusInfo->enabled() = IFMRadioService::Singleton()->IsEnabled();
32 aStatusInfo->frequency() = IFMRadioService::Singleton()->GetFrequency();
33 aStatusInfo->upperBound() =
34 IFMRadioService::Singleton()->GetFrequencyUpperBound();
35 aStatusInfo->lowerBound() =
36 IFMRadioService::Singleton()->GetFrequencyLowerBound();
37 aStatusInfo->channelWidth() =
38 IFMRadioService::Singleton()->GetChannelWidth();
39 return true;
40 }
42 PFMRadioRequestParent*
43 FMRadioParent::AllocPFMRadioRequestParent(const FMRadioRequestArgs& aArgs)
44 {
45 nsRefPtr<FMRadioRequestParent> requestParent = new FMRadioRequestParent();
47 switch (aArgs.type()) {
48 case FMRadioRequestArgs::TEnableRequestArgs:
49 IFMRadioService::Singleton()->Enable(
50 aArgs.get_EnableRequestArgs().frequency(), requestParent);
51 break;
52 case FMRadioRequestArgs::TDisableRequestArgs:
53 IFMRadioService::Singleton()->Disable(requestParent);
54 break;
55 case FMRadioRequestArgs::TSetFrequencyRequestArgs:
56 IFMRadioService::Singleton()->SetFrequency(
57 aArgs.get_SetFrequencyRequestArgs().frequency(), requestParent);
58 break;
59 case FMRadioRequestArgs::TSeekRequestArgs:
60 IFMRadioService::Singleton()->Seek(
61 aArgs.get_SeekRequestArgs().direction(), requestParent);
62 break;
63 case FMRadioRequestArgs::TCancelSeekRequestArgs:
64 IFMRadioService::Singleton()->CancelSeek(requestParent);
65 break;
66 default:
67 MOZ_CRASH();
68 }
70 // Balanced in DeallocPFMRadioRequestParent
71 return requestParent.forget().take();
72 }
74 bool
75 FMRadioParent::DeallocPFMRadioRequestParent(PFMRadioRequestParent* aActor)
76 {
77 FMRadioRequestParent* parent = static_cast<FMRadioRequestParent*>(aActor);
78 NS_RELEASE(parent);
79 return true;
80 }
82 void
83 FMRadioParent::Notify(const FMRadioEventType& aType)
84 {
85 switch (aType) {
86 case FrequencyChanged:
87 unused << SendNotifyFrequencyChanged(
88 IFMRadioService::Singleton()->GetFrequency());
89 break;
90 case EnabledChanged:
91 unused << SendNotifyEnabledChanged(
92 IFMRadioService::Singleton()->IsEnabled(),
93 IFMRadioService::Singleton()->GetFrequency());
94 break;
95 default:
96 NS_RUNTIMEABORT("not reached");
97 break;
98 }
99 }
101 bool
102 FMRadioParent::RecvEnableAudio(const bool& aAudioEnabled)
103 {
104 IFMRadioService::Singleton()->EnableAudio(aAudioEnabled);
105 return true;
106 }
108 END_FMRADIO_NAMESPACE