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.

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

mercurial