tor-browser

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

ProtocolHandlerInfo.h (2239B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_net_ProtocolHandlerInfo_h
      8 #define mozilla_net_ProtocolHandlerInfo_h
      9 
     10 #include "mozilla/Variant.h"
     11 #include "nsProxyRelease.h"
     12 #include "nsIProtocolHandler.h"
     13 
     14 namespace mozilla {
     15 namespace xpcom {
     16 struct StaticProtocolHandler;
     17 }
     18 
     19 namespace net {
     20 
     21 struct RuntimeProtocolHandler {
     22  nsMainThreadPtrHandle<nsIProtocolHandler> mHandler;
     23  uint32_t mProtocolFlags;
     24  int32_t mDefaultPort;
     25 };
     26 
     27 // Information about a specific protocol handler.
     28 class ProtocolHandlerInfo {
     29 public:
     30  explicit ProtocolHandlerInfo(const xpcom::StaticProtocolHandler& aStatic)
     31      : mInner(AsVariant(&aStatic)) {}
     32  explicit ProtocolHandlerInfo(RuntimeProtocolHandler aDynamic)
     33      : mInner(AsVariant(std::move(aDynamic))) {}
     34 
     35  // Returns the statically known protocol-specific flags.
     36  // See `nsIProtocolHandler` for valid values.
     37  uint32_t StaticProtocolFlags() const;
     38 
     39  // The port that this protocol normally uses.
     40  // If a port does not make sense for the protocol (e.g., "about:") then -1
     41  // will be returned.
     42  int32_t DefaultPort() const;
     43 
     44  // If true, `DynamicProtocolFlags()` may return a different value than
     45  // `StaticProtocolFlags()` for flags in `DYNAMIC_URI_FLAGS`, due to a
     46  // `nsIProtocolHandlerWithDynamicFlags` implementation.
     47  bool HasDynamicFlags() const;
     48 
     49  // Like `StaticProtocolFlags()` but also checks
     50  // `nsIProtocolHandlerWithDynamicFlags` for uri-specific flags.
     51  //
     52  // NOTE: Only safe to call from the main thread.
     53  nsresult DynamicProtocolFlags(nsIURI* aURI, uint32_t* aFlags) const
     54      MOZ_REQUIRES(sMainThreadCapability);
     55 
     56  // Get the main-thread-only nsIProtocolHandler instance.
     57  already_AddRefed<nsIProtocolHandler> Handler() const
     58      MOZ_REQUIRES(sMainThreadCapability);
     59 
     60 private:
     61  Variant<const xpcom::StaticProtocolHandler*, RuntimeProtocolHandler> mInner;
     62 };
     63 
     64 }  // namespace net
     65 }  // namespace mozilla
     66 
     67 #endif  // mozilla_net_ProtocolHandlerInfo_h