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