content/media/webspeech/synth/SpeechSynthesisUtterance.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

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

mercurial