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 nsSimpleURI* StartClone(RefHandlingEnum refHandlingMode,
41                                   const nsACString& newRef) override;
42   NS_IMETHOD Mutate(nsIURIMutator** _retval) override;
43   NS_IMETHOD_(void) Serialize(ipc::URIParams& aParams) override;
44 
45   // nsISerializable overrides
46   NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
47   NS_IMETHOD Write(nsIObjectOutputStream* aStream) override;
48 
49  protected:
50   nsCOMPtr<nsIURI> mInnerURI;
51 
52   nsresult SetPathQueryRef(const nsACString& aPathQueryRef) override;
53   nsresult SetQuery(const nsACString& aQuery) override;
54   nsresult SetRef(const nsACString& aRef) override;
55   bool Deserialize(const mozilla::ipc::URIParams&);
56   nsresult ReadPrivate(nsIObjectInputStream* stream);
57 
58  public:
59   class Mutator final : public nsIURIMutator,
60                         public BaseURIMutator<nsSimpleNestedURI>,
61                         public nsISerializable,
62                         public nsINestedURIMutator {
63     NS_DECL_ISUPPORTS
64     NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
65 
66     explicit Mutator() = default;
67 
68    private:
69     virtual ~Mutator() = default;
70 
Deserialize(const mozilla::ipc::URIParams & aParams)71     [[nodiscard]] NS_IMETHOD Deserialize(
72         const mozilla::ipc::URIParams& aParams) override {
73       return InitFromIPCParams(aParams);
74     }
75 
76     NS_IMETHOD
Write(nsIObjectOutputStream * aOutputStream)77     Write(nsIObjectOutputStream* aOutputStream) override {
78       return NS_ERROR_NOT_IMPLEMENTED;
79     }
80 
Read(nsIObjectInputStream * aStream)81     [[nodiscard]] NS_IMETHOD Read(nsIObjectInputStream* aStream) override {
82       return InitFromInputStream(aStream);
83     }
84 
Finalize(nsIURI ** aURI)85     [[nodiscard]] NS_IMETHOD Finalize(nsIURI** aURI) override {
86       mURI.forget(aURI);
87       return NS_OK;
88     }
89 
SetSpec(const nsACString & aSpec,nsIURIMutator ** aMutator)90     [[nodiscard]] NS_IMETHOD SetSpec(const nsACString& aSpec,
91                                      nsIURIMutator** aMutator) override {
92       if (aMutator) {
93         NS_ADDREF(*aMutator = this);
94       }
95       return InitFromSpec(aSpec);
96     }
97 
Init(nsIURI * innerURI)98     [[nodiscard]] NS_IMETHOD Init(nsIURI* innerURI) override {
99       mURI = new nsSimpleNestedURI(innerURI);
100       return NS_OK;
101     }
102 
103     friend class nsSimpleNestedURI;
104   };
105 
106   friend BaseURIMutator<nsSimpleNestedURI>;
107 };
108 
109 }  // namespace net
110 }  // namespace mozilla
111 
112 #endif /* nsSimpleNestedURI_h__ */
113