content/media/webaudio/PeriodicWave.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.

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 "PeriodicWave.h"
michael@0 8 #include "AudioContext.h"
michael@0 9 #include "mozilla/dom/PeriodicWaveBinding.h"
michael@0 10
michael@0 11 namespace mozilla {
michael@0 12 namespace dom {
michael@0 13
michael@0 14 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(PeriodicWave, mContext)
michael@0 15
michael@0 16 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(PeriodicWave, AddRef)
michael@0 17 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(PeriodicWave, Release)
michael@0 18
michael@0 19 PeriodicWave::PeriodicWave(AudioContext* aContext,
michael@0 20 const float* aRealData,
michael@0 21 const float* aImagData,
michael@0 22 const uint32_t aLength,
michael@0 23 ErrorResult& aRv)
michael@0 24 : mContext(aContext)
michael@0 25 {
michael@0 26 MOZ_ASSERT(aContext);
michael@0 27 SetIsDOMBinding();
michael@0 28
michael@0 29 // Caller should have checked this and thrown.
michael@0 30 MOZ_ASSERT(aLength > 0);
michael@0 31 MOZ_ASSERT(aLength <= 4096);
michael@0 32 mLength = aLength;
michael@0 33
michael@0 34 // Copy coefficient data. The two arrays share an allocation.
michael@0 35 mCoefficients = new ThreadSharedFloatArrayBufferList(2);
michael@0 36 float* buffer = static_cast<float*>(malloc(aLength*sizeof(float)*2));
michael@0 37 if (buffer == nullptr) {
michael@0 38 aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
michael@0 39 return;
michael@0 40 }
michael@0 41 PodCopy(buffer, aRealData, aLength);
michael@0 42 mCoefficients->SetData(0, buffer, buffer);
michael@0 43 PodCopy(buffer+aLength, aImagData, aLength);
michael@0 44 mCoefficients->SetData(1, nullptr, buffer+aLength);
michael@0 45 }
michael@0 46
michael@0 47 size_t
michael@0 48 PeriodicWave::SizeOfExcludingThisIfNotShared(MallocSizeOf aMallocSizeOf) const
michael@0 49 {
michael@0 50 // Not owned:
michael@0 51 // - mContext
michael@0 52 size_t amount = 0;
michael@0 53 if (!mCoefficients->IsShared()) {
michael@0 54 amount += mCoefficients->SizeOfIncludingThis(aMallocSizeOf);
michael@0 55 }
michael@0 56
michael@0 57 return amount;
michael@0 58 }
michael@0 59
michael@0 60 JSObject*
michael@0 61 PeriodicWave::WrapObject(JSContext* aCx)
michael@0 62 {
michael@0 63 return PeriodicWaveBinding::Wrap(aCx, this);
michael@0 64 }
michael@0 65
michael@0 66 } // namespace dom
michael@0 67 } // namespace mozilla
michael@0 68

mercurial