tor-browser

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

nsSimpleNestedURI.h (3280B)


      1 /* -*- Mode: C++; tab-width: 4; 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 /**
      7 * URI class to be used for cases when a simple URI actually resolves to some
      8 * other sort of URI, with the latter being what's loaded when the load
      9 * happens.
     10 */
     11 
     12 #ifndef nsSimpleNestedURI_h__
     13 #define nsSimpleNestedURI_h__
     14 
     15 #include "nsCOMPtr.h"
     16 #include "nsSimpleURI.h"
     17 #include "nsINestedURI.h"
     18 #include "nsIURIMutator.h"
     19 
     20 namespace mozilla {
     21 namespace net {
     22 
     23 class nsSimpleNestedURI : public nsSimpleURI, public nsINestedURI {
     24 protected:
     25  nsSimpleNestedURI() = default;
     26  explicit nsSimpleNestedURI(nsIURI* innerURI);
     27 
     28  ~nsSimpleNestedURI() = default;
     29 
     30 public:
     31  NS_DECL_ISUPPORTS_INHERITED
     32  NS_DECL_NSINESTEDURI
     33 
     34  // Overrides for various methods nsSimpleURI implements follow.
     35 
     36  // nsSimpleURI overrides
     37  virtual nsresult EqualsInternal(nsIURI* other,
     38                                  RefHandlingEnum refHandlingMode,
     39                                  bool* result) override;
     40  virtual already_AddRefed<nsSimpleURI> StartClone() override;
     41  NS_IMETHOD Mutate(nsIURIMutator** _retval) override;
     42  NS_IMETHOD_(void) Serialize(ipc::URIParams& aParams) override;
     43 
     44  // nsISerializable overrides
     45  NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
     46  NS_IMETHOD Write(nsIObjectOutputStream* aStream) override;
     47 
     48 protected:
     49  nsCOMPtr<nsIURI> mInnerURI;
     50 
     51  nsresult SetPathQueryRef(const nsACString& aPathQueryRef) override;
     52  nsresult SetQuery(const nsACString& aQuery) override;
     53  nsresult SetRef(const nsACString& aRef) override;
     54  bool Deserialize(const mozilla::ipc::URIParams&);
     55  nsresult ReadPrivate(nsIObjectInputStream* stream);
     56 
     57 public:
     58  class Mutator final : public nsIURIMutator,
     59                        public BaseURIMutator<nsSimpleNestedURI>,
     60                        public nsISerializable,
     61                        public nsINestedURIMutator {
     62    NS_DECL_ISUPPORTS
     63    NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
     64 
     65    explicit Mutator() = default;
     66 
     67   private:
     68    virtual ~Mutator() = default;
     69 
     70    [[nodiscard]] NS_IMETHOD Deserialize(
     71        const mozilla::ipc::URIParams& aParams) override {
     72      return InitFromIPCParams(aParams);
     73    }
     74 
     75    NS_IMETHOD
     76    Write(nsIObjectOutputStream* aOutputStream) override {
     77      return NS_ERROR_NOT_IMPLEMENTED;
     78    }
     79 
     80    [[nodiscard]] NS_IMETHOD Read(nsIObjectInputStream* aStream) override {
     81      return InitFromInputStream(aStream);
     82    }
     83 
     84    [[nodiscard]] NS_IMETHOD Finalize(nsIURI** aURI) override {
     85      mURI.forget(aURI);
     86      return NS_OK;
     87    }
     88 
     89    [[nodiscard]] NS_IMETHOD SetSpec(const nsACString& aSpec,
     90                                     nsIURIMutator** aMutator) override {
     91      if (aMutator) {
     92        NS_ADDREF(*aMutator = this);
     93      }
     94      return InitFromSpec(aSpec);
     95    }
     96 
     97    [[nodiscard]] NS_IMETHOD Init(nsIURI* innerURI) override {
     98      mURI = new nsSimpleNestedURI(innerURI);
     99      return NS_OK;
    100    }
    101 
    102    friend class nsSimpleNestedURI;
    103  };
    104 
    105  friend BaseURIMutator<nsSimpleNestedURI>;
    106 };
    107 
    108 }  // namespace net
    109 }  // namespace mozilla
    110 
    111 #endif /* nsSimpleNestedURI_h__ */