Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "SpeechSynthesisParent.h" |
michael@0 | 6 | #include "nsSynthVoiceRegistry.h" |
michael@0 | 7 | |
michael@0 | 8 | namespace mozilla { |
michael@0 | 9 | namespace dom { |
michael@0 | 10 | |
michael@0 | 11 | SpeechSynthesisParent::SpeechSynthesisParent() |
michael@0 | 12 | { |
michael@0 | 13 | MOZ_COUNT_CTOR(SpeechSynthesisParent); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | SpeechSynthesisParent::~SpeechSynthesisParent() |
michael@0 | 17 | { |
michael@0 | 18 | MOZ_COUNT_DTOR(SpeechSynthesisParent); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | bool |
michael@0 | 22 | SpeechSynthesisParent::RecvReadVoiceList(InfallibleTArray<RemoteVoice>* aVoices, |
michael@0 | 23 | InfallibleTArray<nsString>* aDefaults) |
michael@0 | 24 | { |
michael@0 | 25 | nsSynthVoiceRegistry::GetInstance()->SendVoices(aVoices, aDefaults); |
michael@0 | 26 | return true; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | PSpeechSynthesisRequestParent* |
michael@0 | 30 | SpeechSynthesisParent::AllocPSpeechSynthesisRequestParent(const nsString& aText, |
michael@0 | 31 | const nsString& aLang, |
michael@0 | 32 | const nsString& aUri, |
michael@0 | 33 | const float& aVolume, |
michael@0 | 34 | const float& aRate, |
michael@0 | 35 | const float& aPitch) |
michael@0 | 36 | { |
michael@0 | 37 | nsRefPtr<SpeechTaskParent> task = new SpeechTaskParent(aVolume, aText); |
michael@0 | 38 | SpeechSynthesisRequestParent* actor = new SpeechSynthesisRequestParent(task); |
michael@0 | 39 | return actor; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | bool |
michael@0 | 43 | SpeechSynthesisParent::DeallocPSpeechSynthesisRequestParent(PSpeechSynthesisRequestParent* aActor) |
michael@0 | 44 | { |
michael@0 | 45 | delete aActor; |
michael@0 | 46 | return true; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | bool |
michael@0 | 50 | SpeechSynthesisParent::RecvPSpeechSynthesisRequestConstructor(PSpeechSynthesisRequestParent* aActor, |
michael@0 | 51 | const nsString& aText, |
michael@0 | 52 | const nsString& aLang, |
michael@0 | 53 | const nsString& aUri, |
michael@0 | 54 | const float& aVolume, |
michael@0 | 55 | const float& aRate, |
michael@0 | 56 | const float& aPitch) |
michael@0 | 57 | { |
michael@0 | 58 | MOZ_ASSERT(aActor); |
michael@0 | 59 | SpeechSynthesisRequestParent* actor = |
michael@0 | 60 | static_cast<SpeechSynthesisRequestParent*>(aActor); |
michael@0 | 61 | nsSynthVoiceRegistry::GetInstance()->Speak(aText, aLang, aUri, aRate, |
michael@0 | 62 | aPitch, actor->mTask); |
michael@0 | 63 | return true; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | // SpeechSynthesisRequestParent |
michael@0 | 67 | |
michael@0 | 68 | SpeechSynthesisRequestParent::SpeechSynthesisRequestParent(SpeechTaskParent* aTask) |
michael@0 | 69 | : mTask(aTask) |
michael@0 | 70 | { |
michael@0 | 71 | mTask->mActor = this; |
michael@0 | 72 | MOZ_COUNT_CTOR(SpeechSynthesisRequestParent); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | SpeechSynthesisRequestParent::~SpeechSynthesisRequestParent() |
michael@0 | 76 | { |
michael@0 | 77 | if (mTask && mTask->mActor) { |
michael@0 | 78 | mTask->mActor = nullptr; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | MOZ_COUNT_DTOR(SpeechSynthesisRequestParent); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | bool |
michael@0 | 85 | SpeechSynthesisRequestParent::RecvPause() |
michael@0 | 86 | { |
michael@0 | 87 | MOZ_ASSERT(mTask); |
michael@0 | 88 | mTask->Pause(); |
michael@0 | 89 | return true; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | bool |
michael@0 | 93 | SpeechSynthesisRequestParent::RecvResume() |
michael@0 | 94 | { |
michael@0 | 95 | MOZ_ASSERT(mTask); |
michael@0 | 96 | mTask->Resume(); |
michael@0 | 97 | return true; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | bool |
michael@0 | 101 | SpeechSynthesisRequestParent::RecvCancel() |
michael@0 | 102 | { |
michael@0 | 103 | MOZ_ASSERT(mTask); |
michael@0 | 104 | mTask->Cancel(); |
michael@0 | 105 | return true; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | // SpeechTaskParent |
michael@0 | 109 | |
michael@0 | 110 | nsresult |
michael@0 | 111 | SpeechTaskParent::DispatchStartImpl() |
michael@0 | 112 | { |
michael@0 | 113 | MOZ_ASSERT(mActor); |
michael@0 | 114 | NS_ENSURE_TRUE(mActor->SendOnStart(), NS_ERROR_FAILURE); |
michael@0 | 115 | |
michael@0 | 116 | return NS_OK; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | nsresult |
michael@0 | 120 | SpeechTaskParent::DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex) |
michael@0 | 121 | { |
michael@0 | 122 | MOZ_ASSERT(mActor); |
michael@0 | 123 | SpeechSynthesisRequestParent* actor = mActor; |
michael@0 | 124 | mActor = nullptr; |
michael@0 | 125 | NS_ENSURE_TRUE(actor->Send__delete__(actor, false, aElapsedTime, aCharIndex), |
michael@0 | 126 | NS_ERROR_FAILURE); |
michael@0 | 127 | |
michael@0 | 128 | return NS_OK; |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | nsresult |
michael@0 | 132 | SpeechTaskParent::DispatchPauseImpl(float aElapsedTime, uint32_t aCharIndex) |
michael@0 | 133 | { |
michael@0 | 134 | MOZ_ASSERT(mActor); |
michael@0 | 135 | NS_ENSURE_TRUE(mActor->SendOnPause(aElapsedTime, aCharIndex), NS_ERROR_FAILURE); |
michael@0 | 136 | |
michael@0 | 137 | return NS_OK; |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | nsresult |
michael@0 | 141 | SpeechTaskParent::DispatchResumeImpl(float aElapsedTime, uint32_t aCharIndex) |
michael@0 | 142 | { |
michael@0 | 143 | MOZ_ASSERT(mActor); |
michael@0 | 144 | NS_ENSURE_TRUE(mActor->SendOnResume(aElapsedTime, aCharIndex), NS_ERROR_FAILURE); |
michael@0 | 145 | |
michael@0 | 146 | return NS_OK; |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | nsresult |
michael@0 | 150 | SpeechTaskParent::DispatchErrorImpl(float aElapsedTime, uint32_t aCharIndex) |
michael@0 | 151 | { |
michael@0 | 152 | MOZ_ASSERT(mActor); |
michael@0 | 153 | SpeechSynthesisRequestParent* actor = mActor; |
michael@0 | 154 | mActor = nullptr; |
michael@0 | 155 | NS_ENSURE_TRUE(actor->Send__delete__(actor, true, aElapsedTime, aCharIndex), |
michael@0 | 156 | NS_ERROR_FAILURE); |
michael@0 | 157 | |
michael@0 | 158 | return NS_OK; |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | nsresult |
michael@0 | 162 | SpeechTaskParent::DispatchBoundaryImpl(const nsAString& aName, |
michael@0 | 163 | float aElapsedTime, uint32_t aCharIndex) |
michael@0 | 164 | { |
michael@0 | 165 | MOZ_ASSERT(mActor); |
michael@0 | 166 | NS_ENSURE_TRUE(mActor->SendOnBoundary(nsString(aName), aElapsedTime, aCharIndex), |
michael@0 | 167 | NS_ERROR_FAILURE); |
michael@0 | 168 | |
michael@0 | 169 | return NS_OK; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | nsresult |
michael@0 | 173 | SpeechTaskParent::DispatchMarkImpl(const nsAString& aName, |
michael@0 | 174 | float aElapsedTime, uint32_t aCharIndex) |
michael@0 | 175 | { |
michael@0 | 176 | MOZ_ASSERT(mActor); |
michael@0 | 177 | NS_ENSURE_TRUE(mActor->SendOnMark(nsString(aName), aElapsedTime, aCharIndex), |
michael@0 | 178 | NS_ERROR_FAILURE); |
michael@0 | 179 | |
michael@0 | 180 | return NS_OK; |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | } // namespace dom |
michael@0 | 184 | } // namespace mozilla |