media/webrtc/signaling/src/peerconnection/MediaStreamList.cpp

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "CSFLog.h"
michael@0 6 #include "base/basictypes.h"
michael@0 7 #include "MediaStreamList.h"
michael@0 8 #ifdef MOZILLA_INTERNAL_API
michael@0 9 #include "mozilla/dom/MediaStreamListBinding.h"
michael@0 10 #endif
michael@0 11 #include "nsIScriptGlobalObject.h"
michael@0 12 #include "PeerConnectionImpl.h"
michael@0 13 #include "PeerConnectionMedia.h"
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16 namespace dom {
michael@0 17
michael@0 18 MediaStreamList::MediaStreamList(sipcc::PeerConnectionImpl* peerConnection,
michael@0 19 StreamType type)
michael@0 20 : mPeerConnection(peerConnection),
michael@0 21 mType(type)
michael@0 22 {
michael@0 23 SetIsDOMBinding();
michael@0 24 }
michael@0 25
michael@0 26 MediaStreamList::~MediaStreamList()
michael@0 27 {
michael@0 28 }
michael@0 29
michael@0 30 #ifdef MOZILLA_INTERNAL_API
michael@0 31 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(MediaStreamList)
michael@0 32 #else
michael@0 33 NS_IMPL_CYCLE_COLLECTION_CLASS(MediaStreamList)
michael@0 34 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MediaStreamList)
michael@0 35 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
michael@0 36 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(MediaStreamList)
michael@0 37 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
michael@0 38 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(MediaStreamList)
michael@0 39 NS_IMPL_CYCLE_COLLECTION_TRACE_END
michael@0 40 #endif
michael@0 41
michael@0 42 NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaStreamList)
michael@0 43 NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaStreamList)
michael@0 44 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaStreamList)
michael@0 45 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
michael@0 46 NS_INTERFACE_MAP_ENTRY(nsISupports)
michael@0 47 NS_INTERFACE_MAP_END
michael@0 48
michael@0 49 JSObject*
michael@0 50 MediaStreamList::WrapObject(JSContext* cx)
michael@0 51 {
michael@0 52 #ifdef MOZILLA_INTERNAL_API
michael@0 53 return MediaStreamListBinding::Wrap(cx, this);
michael@0 54 #else
michael@0 55 return nullptr;
michael@0 56 #endif
michael@0 57 }
michael@0 58
michael@0 59 nsISupports*
michael@0 60 MediaStreamList::GetParentObject()
michael@0 61 {
michael@0 62 return mPeerConnection->GetWindow();
michael@0 63 }
michael@0 64
michael@0 65 template<class T>
michael@0 66 static DOMMediaStream*
michael@0 67 GetStreamFromInfo(T* info, bool& found)
michael@0 68 {
michael@0 69 if (!info) {
michael@0 70 found = false;
michael@0 71 return nullptr;
michael@0 72 }
michael@0 73
michael@0 74 found = true;
michael@0 75 return info->GetMediaStream();
michael@0 76 }
michael@0 77
michael@0 78 DOMMediaStream*
michael@0 79 MediaStreamList::IndexedGetter(uint32_t index, bool& found)
michael@0 80 {
michael@0 81 if (!mPeerConnection->media()) { // PeerConnection closed
michael@0 82 found = false;
michael@0 83 return nullptr;
michael@0 84 }
michael@0 85 if (mType == Local) {
michael@0 86 return GetStreamFromInfo(mPeerConnection->media()->
michael@0 87 GetLocalStream(index), found);
michael@0 88 }
michael@0 89
michael@0 90 return GetStreamFromInfo(mPeerConnection->media()->
michael@0 91 GetRemoteStream(index), found);
michael@0 92 }
michael@0 93
michael@0 94 uint32_t
michael@0 95 MediaStreamList::Length()
michael@0 96 {
michael@0 97 if (!mPeerConnection->media()) { // PeerConnection closed
michael@0 98 return 0;
michael@0 99 }
michael@0 100 return mType == Local ? mPeerConnection->media()->LocalStreamsLength() :
michael@0 101 mPeerConnection->media()->RemoteStreamsLength();
michael@0 102 }
michael@0 103
michael@0 104 } // namespace dom
michael@0 105 } // namespace mozilla

mercurial