tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Connection.h (2351B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      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/. */
      6 
      7 #ifndef mozilla_dom_network_Connection_h
      8 #define mozilla_dom_network_Connection_h
      9 
     10 #include "mozilla/DOMEventTargetHelper.h"
     11 #include "mozilla/dom/NetworkInformationBinding.h"
     12 #include "nsCycleCollectionParticipant.h"
     13 
     14 namespace mozilla {
     15 
     16 namespace hal {
     17 class NetworkInformation;
     18 }  // namespace hal
     19 
     20 namespace dom {
     21 
     22 class WorkerPrivate;
     23 
     24 namespace network {
     25 
     26 class Connection : public DOMEventTargetHelper {
     27 public:
     28  NS_DECL_ISUPPORTS_INHERITED
     29 
     30  static Connection* CreateForWindow(nsPIDOMWindowInner* aWindow,
     31                                     bool aShouldResistFingerprinting);
     32 
     33  static already_AddRefed<Connection> CreateForWorker(
     34      WorkerPrivate* aWorkerPrivate, ErrorResult& aRv);
     35 
     36  void Shutdown();
     37 
     38  // WebIDL
     39 
     40  virtual JSObject* WrapObject(JSContext* aCx,
     41                               JS::Handle<JSObject*> aGivenProto) override;
     42 
     43  ConnectionType Type() const {
     44    return mShouldResistFingerprinting
     45               ? static_cast<ConnectionType>(ConnectionType::Unknown)
     46               : mType;
     47  }
     48 
     49  bool GetIsWifi() const {
     50    NS_ASSERT_OWNINGTHREAD(Connection);
     51 
     52    return mIsWifi;
     53  }
     54  uint32_t GetDhcpGateway() const {
     55    NS_ASSERT_OWNINGTHREAD(Connection);
     56 
     57    return mDHCPGateway;
     58  }
     59 
     60  IMPL_EVENT_HANDLER(typechange)
     61 
     62 protected:
     63  Connection(nsPIDOMWindowInner* aWindow, bool aShouldResistFingerprinting);
     64  virtual ~Connection();
     65 
     66  void Update(ConnectionType aType, bool aIsWifi, uint32_t aDHCPGateway,
     67              bool aNotify);
     68 
     69  virtual void ShutdownInternal() = 0;
     70 
     71 private:
     72  /**
     73   * If ResistFingerprinting is enabled or disabled.
     74   */
     75  bool mShouldResistFingerprinting;
     76 
     77  /**
     78   * The type of current connection.
     79   */
     80  ConnectionType mType;
     81 
     82  /**
     83   * If the connection is WIFI
     84   */
     85  bool mIsWifi;
     86 
     87  /**
     88   * DHCP Gateway information for IPV4, in network byte order. 0 if unassigned.
     89   */
     90  uint32_t mDHCPGateway;
     91 
     92  bool mBeenShutDown;
     93 };
     94 
     95 }  // namespace network
     96 }  // namespace dom
     97 }  // namespace mozilla
     98 
     99 #endif  // mozilla_dom_network_Connection_h