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 "MediaStreamAudioSourceNode.h" |
michael@0 | 8 | #include "mozilla/dom/MediaStreamAudioSourceNodeBinding.h" |
michael@0 | 9 | #include "AudioNodeEngine.h" |
michael@0 | 10 | #include "AudioNodeExternalInputStream.h" |
michael@0 | 11 | #include "DOMMediaStream.h" |
michael@0 | 12 | |
michael@0 | 13 | namespace mozilla { |
michael@0 | 14 | namespace dom { |
michael@0 | 15 | |
michael@0 | 16 | NS_IMPL_CYCLE_COLLECTION_CLASS(MediaStreamAudioSourceNode) |
michael@0 | 17 | |
michael@0 | 18 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MediaStreamAudioSourceNode) |
michael@0 | 19 | NS_IMPL_CYCLE_COLLECTION_UNLINK(mInputStream) |
michael@0 | 20 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(AudioNode) |
michael@0 | 21 | |
michael@0 | 22 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MediaStreamAudioSourceNode, AudioNode) |
michael@0 | 23 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInputStream) |
michael@0 | 24 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
michael@0 | 25 | |
michael@0 | 26 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MediaStreamAudioSourceNode) |
michael@0 | 27 | NS_INTERFACE_MAP_END_INHERITING(AudioNode) |
michael@0 | 28 | |
michael@0 | 29 | NS_IMPL_ADDREF_INHERITED(MediaStreamAudioSourceNode, AudioNode) |
michael@0 | 30 | NS_IMPL_RELEASE_INHERITED(MediaStreamAudioSourceNode, AudioNode) |
michael@0 | 31 | |
michael@0 | 32 | MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AudioContext* aContext, |
michael@0 | 33 | DOMMediaStream* aMediaStream) |
michael@0 | 34 | : AudioNode(aContext, |
michael@0 | 35 | 2, |
michael@0 | 36 | ChannelCountMode::Max, |
michael@0 | 37 | ChannelInterpretation::Speakers), |
michael@0 | 38 | mInputStream(aMediaStream) |
michael@0 | 39 | { |
michael@0 | 40 | AudioNodeEngine* engine = new AudioNodeEngine(this); |
michael@0 | 41 | mStream = aContext->Graph()->CreateAudioNodeExternalInputStream(engine); |
michael@0 | 42 | ProcessedMediaStream* outputStream = static_cast<ProcessedMediaStream*>(mStream.get()); |
michael@0 | 43 | mInputPort = outputStream->AllocateInputPort(aMediaStream->GetStream(), |
michael@0 | 44 | MediaInputPort::FLAG_BLOCK_INPUT); |
michael@0 | 45 | mInputStream->AddConsumerToKeepAlive(this); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | MediaStreamAudioSourceNode::~MediaStreamAudioSourceNode() |
michael@0 | 49 | { |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | size_t |
michael@0 | 53 | MediaStreamAudioSourceNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const |
michael@0 | 54 | { |
michael@0 | 55 | // Future: |
michael@0 | 56 | // - mInputStream |
michael@0 | 57 | size_t amount = AudioNode::SizeOfExcludingThis(aMallocSizeOf); |
michael@0 | 58 | amount += mInputPort->SizeOfIncludingThis(aMallocSizeOf); |
michael@0 | 59 | return amount; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | size_t |
michael@0 | 63 | MediaStreamAudioSourceNode::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const |
michael@0 | 64 | { |
michael@0 | 65 | return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | void |
michael@0 | 69 | MediaStreamAudioSourceNode::DestroyMediaStream() |
michael@0 | 70 | { |
michael@0 | 71 | if (mInputPort) { |
michael@0 | 72 | mInputPort->Destroy(); |
michael@0 | 73 | mInputPort = nullptr; |
michael@0 | 74 | } |
michael@0 | 75 | AudioNode::DestroyMediaStream(); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | JSObject* |
michael@0 | 79 | MediaStreamAudioSourceNode::WrapObject(JSContext* aCx) |
michael@0 | 80 | { |
michael@0 | 81 | return MediaStreamAudioSourceNodeBinding::Wrap(aCx, this); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | } |
michael@0 | 85 | } |
michael@0 | 86 |