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 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "nsCOMPtr.h" |
michael@0 | 8 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 9 | #include "nsGkAtoms.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "GeneratedEvents.h" |
michael@0 | 12 | #include "nsIDOMSpeechSynthesisEvent.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "mozilla/dom/SpeechSynthesisUtteranceBinding.h" |
michael@0 | 15 | #include "SpeechSynthesisUtterance.h" |
michael@0 | 16 | #include "SpeechSynthesisVoice.h" |
michael@0 | 17 | |
michael@0 | 18 | namespace mozilla { |
michael@0 | 19 | namespace dom { |
michael@0 | 20 | |
michael@0 | 21 | NS_IMPL_CYCLE_COLLECTION_INHERITED(SpeechSynthesisUtterance, |
michael@0 | 22 | DOMEventTargetHelper, mVoice); |
michael@0 | 23 | |
michael@0 | 24 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SpeechSynthesisUtterance) |
michael@0 | 25 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
michael@0 | 26 | NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) |
michael@0 | 27 | |
michael@0 | 28 | NS_IMPL_ADDREF_INHERITED(SpeechSynthesisUtterance, DOMEventTargetHelper) |
michael@0 | 29 | NS_IMPL_RELEASE_INHERITED(SpeechSynthesisUtterance, DOMEventTargetHelper) |
michael@0 | 30 | |
michael@0 | 31 | SpeechSynthesisUtterance::SpeechSynthesisUtterance(nsPIDOMWindow* aOwnerWindow, |
michael@0 | 32 | const nsAString& text) |
michael@0 | 33 | : DOMEventTargetHelper(aOwnerWindow) |
michael@0 | 34 | , mText(text) |
michael@0 | 35 | , mVolume(1) |
michael@0 | 36 | , mRate(1) |
michael@0 | 37 | , mPitch(1) |
michael@0 | 38 | , mState(STATE_NONE) |
michael@0 | 39 | , mPaused(false) |
michael@0 | 40 | { |
michael@0 | 41 | SetIsDOMBinding(); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | SpeechSynthesisUtterance::~SpeechSynthesisUtterance() {} |
michael@0 | 45 | |
michael@0 | 46 | JSObject* |
michael@0 | 47 | SpeechSynthesisUtterance::WrapObject(JSContext* aCx) |
michael@0 | 48 | { |
michael@0 | 49 | return SpeechSynthesisUtteranceBinding::Wrap(aCx, this); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | nsISupports* |
michael@0 | 53 | SpeechSynthesisUtterance::GetParentObject() const |
michael@0 | 54 | { |
michael@0 | 55 | return GetOwner(); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | already_AddRefed<SpeechSynthesisUtterance> |
michael@0 | 59 | SpeechSynthesisUtterance::Constructor(GlobalObject& aGlobal, |
michael@0 | 60 | ErrorResult& aRv) |
michael@0 | 61 | { |
michael@0 | 62 | return Constructor(aGlobal, NS_LITERAL_STRING(""), aRv); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | already_AddRefed<SpeechSynthesisUtterance> |
michael@0 | 66 | SpeechSynthesisUtterance::Constructor(GlobalObject& aGlobal, |
michael@0 | 67 | const nsAString& aText, |
michael@0 | 68 | ErrorResult& aRv) |
michael@0 | 69 | { |
michael@0 | 70 | nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.GetAsSupports()); |
michael@0 | 71 | |
michael@0 | 72 | if (!win) { |
michael@0 | 73 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | MOZ_ASSERT(win->IsInnerWindow()); |
michael@0 | 77 | nsRefPtr<SpeechSynthesisUtterance> object = |
michael@0 | 78 | new SpeechSynthesisUtterance(win, aText); |
michael@0 | 79 | return object.forget(); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | void |
michael@0 | 83 | SpeechSynthesisUtterance::GetText(nsString& aResult) const |
michael@0 | 84 | { |
michael@0 | 85 | aResult = mText; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | void |
michael@0 | 89 | SpeechSynthesisUtterance::SetText(const nsAString& aText) |
michael@0 | 90 | { |
michael@0 | 91 | mText = aText; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | void |
michael@0 | 95 | SpeechSynthesisUtterance::GetLang(nsString& aResult) const |
michael@0 | 96 | { |
michael@0 | 97 | aResult = mLang; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | void |
michael@0 | 101 | SpeechSynthesisUtterance::SetLang(const nsAString& aLang) |
michael@0 | 102 | { |
michael@0 | 103 | mLang = aLang; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | SpeechSynthesisVoice* |
michael@0 | 107 | SpeechSynthesisUtterance::GetVoice() const |
michael@0 | 108 | { |
michael@0 | 109 | return mVoice; |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | void |
michael@0 | 113 | SpeechSynthesisUtterance::SetVoice(SpeechSynthesisVoice* aVoice) |
michael@0 | 114 | { |
michael@0 | 115 | mVoice = aVoice; |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | float |
michael@0 | 119 | SpeechSynthesisUtterance::Volume() const |
michael@0 | 120 | { |
michael@0 | 121 | return mVolume; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | void |
michael@0 | 125 | SpeechSynthesisUtterance::SetVolume(float aVolume) |
michael@0 | 126 | { |
michael@0 | 127 | mVolume = aVolume; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | float |
michael@0 | 131 | SpeechSynthesisUtterance::Rate() const |
michael@0 | 132 | { |
michael@0 | 133 | return mRate; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | void |
michael@0 | 137 | SpeechSynthesisUtterance::SetRate(float aRate) |
michael@0 | 138 | { |
michael@0 | 139 | mRate = aRate; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | float |
michael@0 | 143 | SpeechSynthesisUtterance::Pitch() const |
michael@0 | 144 | { |
michael@0 | 145 | return mPitch; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | void |
michael@0 | 149 | SpeechSynthesisUtterance::SetPitch(float aPitch) |
michael@0 | 150 | { |
michael@0 | 151 | mPitch = aPitch; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | void |
michael@0 | 155 | SpeechSynthesisUtterance::DispatchSpeechSynthesisEvent(const nsAString& aEventType, |
michael@0 | 156 | uint32_t aCharIndex, |
michael@0 | 157 | float aElapsedTime, |
michael@0 | 158 | const nsAString& aName) |
michael@0 | 159 | { |
michael@0 | 160 | nsCOMPtr<nsIDOMEvent> domEvent; |
michael@0 | 161 | NS_NewDOMSpeechSynthesisEvent(getter_AddRefs(domEvent), nullptr, nullptr, nullptr); |
michael@0 | 162 | |
michael@0 | 163 | nsCOMPtr<nsIDOMSpeechSynthesisEvent> ssEvent = do_QueryInterface(domEvent); |
michael@0 | 164 | ssEvent->InitSpeechSynthesisEvent(aEventType, false, false, |
michael@0 | 165 | aCharIndex, aElapsedTime, aName); |
michael@0 | 166 | |
michael@0 | 167 | DispatchTrustedEvent(domEvent); |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | } // namespace dom |
michael@0 | 171 | } // namespace mozilla |