1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  * vim: sw=2 ts=2 sts=2 expandtab
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
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 /**
8  * This wraps nsSimpleURI so that all calls to it are done on the main thread.
9  */
10 
11 #ifndef mozilla_NullPrincipalURI_h
12 #define mozilla_NullPrincipalURI_h
13 
14 #include "nsIURI.h"
15 #include "nsISizeOf.h"
16 #include "nsString.h"
17 #include "mozilla/Attributes.h"
18 #include "mozilla/MemoryReporting.h"
19 #include "NullPrincipal.h"
20 #include "nsID.h"
21 #include "nsIURIMutator.h"
22 
23 // {51fcd543-3b52-41f7-b91b-6b54102236e6}
24 #define NS_NULLPRINCIPALURI_IMPLEMENTATION_CID       \
25   {                                                  \
26     0x51fcd543, 0x3b52, 0x41f7, {                    \
27       0xb9, 0x1b, 0x6b, 0x54, 0x10, 0x22, 0x36, 0xe6 \
28     }                                                \
29   }
30 
31 namespace mozilla {
32 
33 class Encoding;
34 
35 class NullPrincipalURI final : public nsIURI, public nsISizeOf {
36  public:
37   NS_DECL_THREADSAFE_ISUPPORTS
38   NS_DECL_NSIURI
39 
40   NullPrincipalURI();
41 
42   // nsISizeOf
43   virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
44   virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
45 
46  private:
47   NullPrincipalURI(const NullPrincipalURI& aOther);
48   void operator=(const NullPrincipalURI& aOther) = delete;
49 
~NullPrincipalURI()50   ~NullPrincipalURI() {}
51 
52   nsAutoCStringN<NSID_LENGTH> mPath;
53 
54   nsresult Clone(nsIURI** aURI);
55   nsresult SetSpecInternal(const nsACString& input);
56   nsresult SetScheme(const nsACString& input);
57   nsresult SetUserPass(const nsACString& input);
58   nsresult SetUsername(const nsACString& input);
59   nsresult SetPassword(const nsACString& input);
60   nsresult SetHostPort(const nsACString& aValue);
61   nsresult SetHost(const nsACString& input);
62   nsresult SetPort(int32_t port);
63   nsresult SetPathQueryRef(const nsACString& input);
64   nsresult SetRef(const nsACString& input);
65   nsresult SetFilePath(const nsACString& input);
66   nsresult SetQuery(const nsACString& input);
67   nsresult SetQueryWithEncoding(const nsACString& input,
68                                 const Encoding* encoding);
69   bool Deserialize(const mozilla::ipc::URIParams&);
70 
71  public:
72   class Mutator final : public nsIURIMutator,
73                         public BaseURIMutator<NullPrincipalURI> {
74     NS_DECL_ISUPPORTS
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)75     NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
76 
77     NS_IMETHOD Deserialize(const mozilla::ipc::URIParams& aParams) override {
78       return InitFromIPCParams(aParams);
79     }
80 
Finalize(nsIURI ** aURI)81     NS_IMETHOD Finalize(nsIURI** aURI) override {
82       mURI.forget(aURI);
83       return NS_OK;
84     }
85 
SetSpec(const nsACString & aSpec,nsIURIMutator ** aMutator)86     NS_IMETHOD SetSpec(const nsACString& aSpec,
87                        nsIURIMutator** aMutator) override {
88       if (aMutator) {
89         nsCOMPtr<nsIURIMutator> mutator = this;
90         mutator.forget(aMutator);
91       }
92       return NS_ERROR_NOT_IMPLEMENTED;
93     }
94 
Mutator()95     explicit Mutator() {}
96 
97    private:
~Mutator()98     virtual ~Mutator() {}
99 
100     friend class NullPrincipalURI;
101   };
102 
103   friend class BaseURIMutator<NullPrincipalURI>;
104 };
105 
106 }  // namespace mozilla
107 
108 #endif  // mozilla_NullPrincipalURI_h
109