media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.h

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
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef peerconnectionctx_h___h__
michael@0 6 #define peerconnectionctx_h___h__
michael@0 7
michael@0 8 #include <string>
michael@0 9
michael@0 10 #include "mozilla/Attributes.h"
michael@0 11 #include "CallControlManager.h"
michael@0 12 #include "CC_Device.h"
michael@0 13 #include "CC_DeviceInfo.h"
michael@0 14 #include "CC_Call.h"
michael@0 15 #include "CC_CallInfo.h"
michael@0 16 #include "CC_Line.h"
michael@0 17 #include "CC_LineInfo.h"
michael@0 18 #include "CC_Observer.h"
michael@0 19 #include "CC_FeatureInfo.h"
michael@0 20 #include "cpr_stdlib.h"
michael@0 21
michael@0 22 #include "StaticPtr.h"
michael@0 23 #include "PeerConnectionImpl.h"
michael@0 24
michael@0 25 namespace mozilla {
michael@0 26 class PeerConnectionCtxShutdown;
michael@0 27
michael@0 28 namespace dom {
michael@0 29 class WebrtcGlobalInformation;
michael@0 30 }
michael@0 31
michael@0 32 // Unit-test helper, because cc_media_constraints_t is hard to forward-declare
michael@0 33
michael@0 34 class MediaConstraintsExternal {
michael@0 35 public:
michael@0 36 MediaConstraintsExternal();
michael@0 37 MediaConstraintsExternal(const dom::MediaConstraintsInternal &aOther);
michael@0 38 cc_media_constraints_t* build() const;
michael@0 39 protected:
michael@0 40 cc_media_constraints_t mConstraints;
michael@0 41 };
michael@0 42 }
michael@0 43
michael@0 44 namespace sipcc {
michael@0 45
michael@0 46 class OnCallEventArgs {
michael@0 47 public:
michael@0 48 OnCallEventArgs(ccapi_call_event_e aCallEvent, CSF::CC_CallInfoPtr aInfo)
michael@0 49 : mCallEvent(aCallEvent), mInfo(aInfo) {}
michael@0 50
michael@0 51 ccapi_call_event_e mCallEvent;
michael@0 52 CSF::CC_CallInfoPtr mInfo;
michael@0 53 };
michael@0 54
michael@0 55 // A class to hold some of the singleton objects we need:
michael@0 56 // * The global PeerConnectionImpl table and its associated lock.
michael@0 57 // * Currently SIPCC only allows a single stack instance to exist in a process
michael@0 58 // at once. This class implements a singleton object that wraps that.
michael@0 59 // * The observer class that demuxes events onto individual PCs.
michael@0 60 class PeerConnectionCtx : public CSF::CC_Observer {
michael@0 61 public:
michael@0 62 static nsresult InitializeGlobal(nsIThread *mainThread, nsIEventTarget *stsThread);
michael@0 63 static PeerConnectionCtx* GetInstance();
michael@0 64 static bool isActive();
michael@0 65 static void Destroy();
michael@0 66
michael@0 67 // Implementations of CC_Observer methods
michael@0 68 virtual void onDeviceEvent(ccapi_device_event_e deviceEvent, CSF::CC_DevicePtr device, CSF::CC_DeviceInfoPtr info);
michael@0 69 virtual void onFeatureEvent(ccapi_device_event_e deviceEvent, CSF::CC_DevicePtr device, CSF::CC_FeatureInfoPtr feature_info) {}
michael@0 70 virtual void onLineEvent(ccapi_line_event_e lineEvent, CSF::CC_LinePtr line, CSF::CC_LineInfoPtr info) {}
michael@0 71 virtual void onCallEvent(ccapi_call_event_e callEvent, CSF::CC_CallPtr call, CSF::CC_CallInfoPtr info);
michael@0 72
michael@0 73 // Create a SIPCC Call
michael@0 74 CSF::CC_CallPtr createCall();
michael@0 75
michael@0 76 mozilla::dom::PCImplSipccState sipcc_state() { return mSipccState; }
michael@0 77
michael@0 78 // Make these classes friend so that they can access mPeerconnections.
michael@0 79 friend class PeerConnectionImpl;
michael@0 80 friend class PeerConnectionWrapper;
michael@0 81 friend class mozilla::dom::WebrtcGlobalInformation;
michael@0 82
michael@0 83 private:
michael@0 84 // We could make these available only via accessors but it's too much trouble.
michael@0 85 std::map<const std::string, PeerConnectionImpl *> mPeerConnections;
michael@0 86
michael@0 87 PeerConnectionCtx() : mSipccState(mozilla::dom::PCImplSipccState::Idle),
michael@0 88 mCCM(nullptr), mDevice(nullptr) {}
michael@0 89 // This is a singleton, so don't copy construct it, etc.
michael@0 90 PeerConnectionCtx(const PeerConnectionCtx& other) MOZ_DELETE;
michael@0 91 void operator=(const PeerConnectionCtx& other) MOZ_DELETE;
michael@0 92 virtual ~PeerConnectionCtx() {};
michael@0 93
michael@0 94 nsresult Initialize();
michael@0 95 nsresult Cleanup();
michael@0 96
michael@0 97 void ChangeSipccState(mozilla::dom::PCImplSipccState aState) {
michael@0 98 mSipccState = aState;
michael@0 99 }
michael@0 100
michael@0 101 // Telemetry Peer conection counter
michael@0 102 int mConnectionCounter;
michael@0 103
michael@0 104 // SIPCC objects
michael@0 105 mozilla::dom::PCImplSipccState mSipccState; // TODO(ekr@rtfm.com): refactor this out? What does it do?
michael@0 106 CSF::CallControlManagerPtr mCCM;
michael@0 107 CSF::CC_DevicePtr mDevice;
michael@0 108
michael@0 109 static PeerConnectionCtx *gInstance;
michael@0 110 public:
michael@0 111 static nsIThread *gMainThread;
michael@0 112 static mozilla::StaticRefPtr<mozilla::PeerConnectionCtxShutdown> gPeerConnectionCtxShutdown;
michael@0 113 };
michael@0 114
michael@0 115 } // namespace sipcc
michael@0 116
michael@0 117 #endif

mercurial