1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef nsJSProtocolHandler_h___
7 #define nsJSProtocolHandler_h___
8 
9 #include "mozilla/Attributes.h"
10 #include "nsIProtocolHandler.h"
11 #include "nsITextToSubURI.h"
12 #include "nsIURI.h"
13 #include "nsIMutable.h"
14 #include "nsISerializable.h"
15 #include "nsIClassInfo.h"
16 #include "nsSimpleURI.h"
17 
18 #define NS_JSPROTOCOLHANDLER_CID                     \
19 { /* bfc310d2-38a0-11d3-8cd3-0060b0fc14a3 */         \
20     0xbfc310d2,                                      \
21     0x38a0,                                          \
22     0x11d3,                                          \
23     {0x8c, 0xd3, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
24 }
25 
26 #define NS_JSURI_CID                                 \
27 { /* 58f089ee-512a-42d2-a935-d0c874128930 */         \
28     0x58f089ee,                                      \
29     0x512a,                                          \
30     0x42d2,                                          \
31     {0xa9, 0x35, 0xd0, 0xc8, 0x74, 0x12, 0x89, 0x30} \
32 }
33 
34 #define NS_JSPROTOCOLHANDLER_CONTRACTID \
35     NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "javascript"
36 
37 
38 class nsJSProtocolHandler : public nsIProtocolHandler
39 {
40 public:
41     NS_DECL_ISUPPORTS
42 
43     // nsIProtocolHandler methods:
44     NS_DECL_NSIPROTOCOLHANDLER
45 
46     // nsJSProtocolHandler methods:
47     nsJSProtocolHandler();
48 
49     static nsresult
50     Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
51 
52     nsresult Init();
53 
54 protected:
55     virtual ~nsJSProtocolHandler();
56 
57     nsresult EnsureUTF8Spec(const nsAFlatCString &aSpec, const char *aCharset,
58                             nsACString &aUTF8Spec);
59 
60     nsCOMPtr<nsITextToSubURI>  mTextToSubURI;
61 };
62 
63 
64 class nsJSURI : public mozilla::net::nsSimpleURI
65 {
66 public:
67     using mozilla::net::nsSimpleURI::Read;
68     using mozilla::net::nsSimpleURI::Write;
69 
nsJSURI()70     nsJSURI() {}
71 
nsJSURI(nsIURI * aBaseURI)72     explicit nsJSURI(nsIURI* aBaseURI) : mBaseURI(aBaseURI) {}
73 
GetBaseURI()74     nsIURI* GetBaseURI() const
75     {
76         return mBaseURI;
77     }
78 
79     NS_DECL_ISUPPORTS_INHERITED
80 
81     // nsIURI overrides
82     virtual mozilla::net::nsSimpleURI* StartClone(RefHandlingEnum refHandlingMode,
83                                                   const nsACString& newRef) override;
84 
85     // nsISerializable overrides
86     NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
87     NS_IMETHOD Write(nsIObjectOutputStream* aStream) override;
88 
89     // nsIIPCSerializableURI overrides
90     NS_DECL_NSIIPCSERIALIZABLEURI
91 
92     // Override the nsIClassInfo method GetClassIDNoAlloc to make sure our
93     // nsISerializable impl works right.
94     NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) override;
95     //NS_IMETHOD QueryInterface( const nsIID& aIID, void** aInstancePtr );
96 
97 protected:
~nsJSURI()98     virtual ~nsJSURI() {}
99 
100     virtual nsresult EqualsInternal(nsIURI* other,
101                                     RefHandlingEnum refHandlingMode,
102                                     bool* result) override;
103 private:
104     nsCOMPtr<nsIURI> mBaseURI;
105 };
106 
107 #endif /* nsJSProtocolHandler_h___ */
108