Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsJSProtocolHandler.h
Line
Count
Source (jump to first uncovered line)
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
#include "nsINestedURI.h"
18
19
#define NS_JSPROTOCOLHANDLER_CID                     \
20
{ /* bfc310d2-38a0-11d3-8cd3-0060b0fc14a3 */         \
21
    0xbfc310d2,                                      \
22
    0x38a0,                                          \
23
    0x11d3,                                          \
24
    {0x8c, 0xd3, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
25
}
26
27
#define NS_JSURI_CID                                 \
28
{ /* 58f089ee-512a-42d2-a935-d0c874128930 */         \
29
    0x58f089ee,                                      \
30
    0x512a,                                          \
31
    0x42d2,                                          \
32
    {0xa9, 0x35, 0xd0, 0xc8, 0x74, 0x12, 0x89, 0x30} \
33
}
34
35
#define NS_JSURIMUTATOR_CID                          \
36
{ /* 574ce83e-fe9f-4095-b85c-7909abbf7c37 */         \
37
    0x574ce83e,                                      \
38
    0xfe9f,                                          \
39
    0x4095,                                          \
40
    {0xb8, 0x5c, 0x79, 0x09, 0xab, 0xbf, 0x7c, 0x37} \
41
}
42
43
#define NS_JSPROTOCOLHANDLER_CONTRACTID \
44
    NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "javascript"
45
46
47
class nsJSProtocolHandler : public nsIProtocolHandler
48
{
49
public:
50
    NS_DECL_ISUPPORTS
51
52
    // nsIProtocolHandler methods:
53
    NS_DECL_NSIPROTOCOLHANDLER
54
55
    // nsJSProtocolHandler methods:
56
    nsJSProtocolHandler();
57
58
    static nsresult
59
    Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
60
61
    nsresult Init();
62
63
protected:
64
    virtual ~nsJSProtocolHandler();
65
66
    nsresult EnsureUTF8Spec(const nsCString& aSpec, const char *aCharset,
67
                            nsACString &aUTF8Spec);
68
69
    nsCOMPtr<nsITextToSubURI>  mTextToSubURI;
70
};
71
72
class nsJSURI final
73
    : public mozilla::net::nsSimpleURI
74
{
75
public:
76
    using mozilla::net::nsSimpleURI::Read;
77
    using mozilla::net::nsSimpleURI::Write;
78
79
    nsIURI* GetBaseURI() const
80
    {
81
        return mBaseURI;
82
    }
83
84
    NS_DECL_ISUPPORTS_INHERITED
85
86
    // nsIURI overrides
87
    virtual mozilla::net::nsSimpleURI* StartClone(RefHandlingEnum refHandlingMode,
88
                                                  const nsACString& newRef) override;
89
    NS_IMETHOD Mutate(nsIURIMutator * *_retval) override;
90
91
    // nsISerializable overrides
92
    NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
93
    NS_IMETHOD Write(nsIObjectOutputStream* aStream) override;
94
95
    // nsIIPCSerializableURI overrides
96
    NS_DECL_NSIIPCSERIALIZABLEURI
97
98
    // Override the nsIClassInfo method GetClassIDNoAlloc to make sure our
99
    // nsISerializable impl works right.
100
    NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) override;
101
    //NS_IMETHOD QueryInterface( const nsIID& aIID, void** aInstancePtr ) override;
102
103
protected:
104
0
    nsJSURI() {}
105
    explicit nsJSURI(nsIURI* aBaseURI) : mBaseURI(aBaseURI) {}
106
107
    virtual ~nsJSURI() {}
108
109
    virtual nsresult EqualsInternal(nsIURI* other,
110
                                    RefHandlingEnum refHandlingMode,
111
                                    bool* result) override;
112
    bool Deserialize(const mozilla::ipc::URIParams&);
113
    nsresult ReadPrivate(nsIObjectInputStream *aStream);
114
115
private:
116
    nsCOMPtr<nsIURI> mBaseURI;
117
118
public:
119
    class Mutator final
120
        : public nsIURIMutator
121
        , public BaseURIMutator<nsJSURI>
122
        , public nsISerializable
123
        , public nsIJSURIMutator
124
    {
125
        NS_DECL_ISUPPORTS
126
        NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
127
        NS_DEFINE_NSIMUTATOR_COMMON
128
129
        NS_IMETHOD
130
        Write(nsIObjectOutputStream *aOutputStream) override
131
        {
132
            return NS_ERROR_NOT_IMPLEMENTED;
133
        }
134
135
        MOZ_MUST_USE NS_IMETHOD
136
        Read(nsIObjectInputStream* aStream) override
137
        {
138
            return InitFromInputStream(aStream);
139
        }
140
141
        MOZ_MUST_USE NS_IMETHOD
142
        SetBase(nsIURI* aBaseURI) override
143
        {
144
            mURI = new nsJSURI(aBaseURI);
145
            return NS_OK;
146
        }
147
148
1.79k
        explicit Mutator() { }
149
    private:
150
        virtual ~Mutator() { }
151
152
        friend class nsJSURI;
153
    };
154
155
    friend BaseURIMutator<nsJSURI>;
156
};
157
158
#endif /* nsJSProtocolHandler_h___ */