Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/protocol/about/nsAboutProtocolHandler.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 nsAboutProtocolHandler_h___
7
#define nsAboutProtocolHandler_h___
8
9
#include "nsIProtocolHandler.h"
10
#include "nsSimpleNestedURI.h"
11
#include "nsWeakReference.h"
12
#include "mozilla/Attributes.h"
13
#include "nsIURIMutator.h"
14
15
class nsIURI;
16
17
namespace mozilla {
18
namespace net {
19
20
class nsAboutProtocolHandler : public nsIProtocolHandlerWithDynamicFlags
21
                             , public nsIProtocolHandler
22
                             , public nsSupportsWeakReference
23
{
24
public:
25
    NS_DECL_ISUPPORTS
26
27
    // nsIProtocolHandler methods:
28
    NS_DECL_NSIPROTOCOLHANDLER
29
    NS_DECL_NSIPROTOCOLHANDLERWITHDYNAMICFLAGS
30
31
    // nsAboutProtocolHandler methods:
32
1
    nsAboutProtocolHandler() = default;
33
34
private:
35
0
    virtual ~nsAboutProtocolHandler() = default;
36
};
37
38
class nsSafeAboutProtocolHandler final : public nsIProtocolHandler
39
                                       , public nsSupportsWeakReference
40
{
41
public:
42
    NS_DECL_ISUPPORTS
43
44
    // nsIProtocolHandler methods:
45
    NS_DECL_NSIPROTOCOLHANDLER
46
47
    // nsSafeAboutProtocolHandler methods:
48
0
    nsSafeAboutProtocolHandler() = default;
49
50
private:
51
0
    ~nsSafeAboutProtocolHandler() = default;
52
};
53
54
55
// Class to allow us to propagate the base URI to about:blank correctly
56
class nsNestedAboutURI final
57
    : public nsSimpleNestedURI
58
{
59
private:
60
    nsNestedAboutURI(nsIURI* aInnerURI, nsIURI* aBaseURI)
61
        : nsSimpleNestedURI(aInnerURI)
62
        , mBaseURI(aBaseURI)
63
0
    {}
64
0
    nsNestedAboutURI() : nsSimpleNestedURI() {}
65
0
    virtual ~nsNestedAboutURI() = default;
66
67
public:
68
    // Override QI so we can QI to our CID as needed
69
    NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
70
71
    // Override StartClone(), the nsISerializable methods, and
72
    // GetClassIDNoAlloc; this last is needed to make our nsISerializable impl
73
    // work right.
74
    virtual nsSimpleURI* StartClone(RefHandlingEnum aRefHandlingMode,
75
                                    const nsACString& newRef) override;
76
    NS_IMETHOD Mutate(nsIURIMutator * *_retval) override;
77
78
    NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
79
    NS_IMETHOD Write(nsIObjectOutputStream* aStream) override;
80
    NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) override;
81
82
0
    nsIURI* GetBaseURI() const {
83
0
        return mBaseURI;
84
0
    }
85
86
protected:
87
    nsCOMPtr<nsIURI> mBaseURI;
88
    nsresult ReadPrivate(nsIObjectInputStream *stream);
89
90
public:
91
    class Mutator final
92
        : public nsIURIMutator
93
        , public BaseURIMutator<nsNestedAboutURI>
94
        , public nsISerializable
95
        , public nsINestedAboutURIMutator
96
    {
97
        NS_DECL_ISUPPORTS
98
        NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
99
100
0
        explicit Mutator() = default;
101
    private:
102
0
        virtual ~Mutator() = default;
103
104
        MOZ_MUST_USE NS_IMETHOD
105
        Deserialize(const mozilla::ipc::URIParams& aParams) override
106
0
        {
107
0
            return InitFromIPCParams(aParams);
108
0
        }
109
110
        NS_IMETHOD
111
        Write(nsIObjectOutputStream *aOutputStream) override
112
0
        {
113
0
            return NS_ERROR_NOT_IMPLEMENTED;
114
0
        }
115
116
        MOZ_MUST_USE NS_IMETHOD
117
        Read(nsIObjectInputStream* aStream) override
118
0
        {
119
0
            return InitFromInputStream(aStream);
120
0
        }
121
122
        MOZ_MUST_USE NS_IMETHOD
123
        Finalize(nsIURI** aURI) override
124
0
        {
125
0
            mURI->mMutable = false;
126
0
            mURI.forget(aURI);
127
0
            return NS_OK;
128
0
        }
129
130
        MOZ_MUST_USE NS_IMETHOD
131
        SetSpec(const nsACString& aSpec, nsIURIMutator** aMutator) override
132
0
        {
133
0
            if (aMutator) {
134
0
                NS_ADDREF(*aMutator = this);
135
0
            }
136
0
            return InitFromSpec(aSpec);
137
0
        }
138
139
        MOZ_MUST_USE NS_IMETHOD
140
        InitWithBase(nsIURI* aInnerURI, nsIURI* aBaseURI) override
141
0
        {
142
0
            mURI = new nsNestedAboutURI(aInnerURI, aBaseURI);
143
0
            return NS_OK;
144
0
        }
145
146
        void ResetMutable()
147
0
        {
148
0
            if (mURI) {
149
0
                mURI->mMutable = true;
150
0
            }
151
0
        }
152
153
        friend class nsNestedAboutURI;
154
    };
155
156
    friend BaseURIMutator<nsNestedAboutURI>;
157
};
158
159
} // namespace net
160
} // namespace mozilla
161
162
#endif /* nsAboutProtocolHandler_h___ */