Bug 1845134 - Part 4: Update existing ui-icons to use the latest source from acorn...
[gecko.git] / netwerk / base / ProtocolHandlerInfo.h
blob337dbddcfc8b9eb6579504ae945bf483bca395d3
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/. */
7 #ifndef mozilla_net_ProtocolHandlerInfo_h
8 #define mozilla_net_ProtocolHandlerInfo_h
10 #include "mozilla/Variant.h"
11 #include "nsProxyRelease.h"
12 #include "nsIProtocolHandler.h"
14 namespace mozilla {
15 namespace xpcom {
16 struct StaticProtocolHandler;
19 namespace net {
21 struct RuntimeProtocolHandler {
22 nsMainThreadPtrHandle<nsIProtocolHandler> mHandler;
23 uint32_t mProtocolFlags;
24 int32_t mDefaultPort;
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))) {}
35 // Returns the statically known protocol-specific flags.
36 // See `nsIProtocolHandler` for valid values.
37 uint32_t StaticProtocolFlags() const;
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;
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;
49 // Like `StaticProtocolFlags()` but also checks
50 // `nsIProtocolHandlerWithDynamicFlags` for uri-specific flags.
52 // NOTE: Only safe to call from the main thread.
53 nsresult DynamicProtocolFlags(nsIURI* aURI, uint32_t* aFlags) const
54 MOZ_REQUIRES(sMainThreadCapability);
56 // Get the main-thread-only nsIProtocolHandler instance.
57 already_AddRefed<nsIProtocolHandler> Handler() const
58 MOZ_REQUIRES(sMainThreadCapability);
60 private:
61 Variant<const xpcom::StaticProtocolHandler*, RuntimeProtocolHandler> mInner;
64 } // namespace net
65 } // namespace mozilla
67 #endif // mozilla_net_ProtocolHandlerInfo_h