tor-browser

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

TRRServiceBase.h (3487B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef TRRServiceBase_h_
      7 #define TRRServiceBase_h_
      8 
      9 #include "mozilla/Atomics.h"
     10 #include "mozilla/DataMutex.h"
     11 #include "mozilla/net/rust_helper.h"
     12 #include "nsString.h"
     13 #include "nsIDNSService.h"
     14 #include "nsIProtocolProxyService2.h"
     15 
     16 class nsICancelable;
     17 class nsIProxyInfo;
     18 
     19 namespace mozilla {
     20 namespace net {
     21 
     22 class nsHttpConnectionInfo;
     23 
     24 static const char kRolloutURIPref[] = "doh-rollout.uri";
     25 static const char kRolloutModePref[] = "doh-rollout.mode";
     26 
     27 class TRRServiceBase : public nsIProxyConfigChangedCallback {
     28 public:
     29  NS_DECL_THREADSAFE_ISUPPORTS
     30 
     31  TRRServiceBase();
     32  nsIDNSService::ResolverMode Mode() { return mMode; }
     33  virtual void GetURI(nsACString& result) = 0;
     34  already_AddRefed<nsHttpConnectionInfo> TRRConnectionInfo();
     35  // Called to initialize the connection info. Once the connection info is
     36  // created first time, mTRRConnectionInfoInited will be set to true.
     37  // When aForceReinit is true, we always create the conncetion info again.
     38  virtual void InitTRRConnectionInfo(bool aForceReinit = false);
     39  bool TRRConnectionInfoInited() const { return mTRRConnectionInfoInited; }
     40 
     41 protected:
     42  virtual ~TRRServiceBase();
     43 
     44  virtual bool MaybeSetPrivateURI(const nsACString& aURI) = 0;
     45  void ProcessURITemplate(nsACString& aURI);
     46  // Checks the network.trr.uri or the doh-rollout.uri prefs and sets the URI
     47  // in order of preference:
     48  // 1. The value of network.trr.uri if it is not the default one, meaning
     49  //    is was set by an explicit user action
     50  // 2. The value of doh-rollout.uri if it exists
     51  //    this is set by the rollout addon
     52  // 3. The default value of network.trr.uri
     53  void CheckURIPrefs();
     54 
     55  void OnTRRModeChange();
     56  void OnTRRURIChange();
     57 
     58  void DoReadEtcHostsFile(ParsingCallback aCallback);
     59  virtual void ReadEtcHostsFile() = 0;
     60  // Called to create a connection info that will be used by TRRServiceChannel.
     61  // Note that when this function is called, mDefaultTRRConnectionInfo will be
     62  // set to null to invalidate the connection info.
     63  // When the connection info is created, SetDefaultTRRConnectionInfo() is
     64  // called to set the result to mDefaultTRRConnectionInfo.
     65  // Note that this method does nothing when mTRRConnectionInfoInited is false.
     66  // We want to starting updating the connection info after it's create first
     67  // time.
     68  void AsyncCreateTRRConnectionInfo(const nsACString& aURI);
     69  void AsyncCreateTRRConnectionInfoInternal(const nsACString& aURI);
     70  virtual void SetDefaultTRRConnectionInfo(nsHttpConnectionInfo* aConnInfo);
     71  void RegisterProxyChangeListener();
     72  void UnregisterProxyChangeListener();
     73 
     74  nsCString mPrivateURI;  // protected by mMutex
     75  // Pref caches should only be used on the main thread.
     76  nsCString mURIPref;
     77  nsCString mRolloutURIPref;
     78  nsCString mDefaultURIPref;
     79  nsCString mOHTTPURIPref;
     80 
     81  Atomic<nsIDNSService::ResolverMode, Relaxed> mMode{
     82      nsIDNSService::MODE_NATIVEONLY};
     83  Atomic<bool, Relaxed> mURISetByDetection{false};
     84  Atomic<bool, Relaxed> mTRRConnectionInfoInited{false};
     85  DataMutex<RefPtr<nsHttpConnectionInfo>> mDefaultTRRConnectionInfo;
     86  bool mNativeHTTPSQueryEnabled{false};
     87 };
     88 
     89 }  // namespace net
     90 }  // namespace mozilla
     91 
     92 #endif  // TRRServiceBase_h_