Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 2; 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
#ifndef nsSimpleURI_h__
7
#define nsSimpleURI_h__
8
9
#include "mozilla/MemoryReporting.h"
10
#include "nsIURI.h"
11
#include "nsISerializable.h"
12
#include "nsString.h"
13
#include "nsIClassInfo.h"
14
#include "nsISizeOf.h"
15
#include "nsIURIMutator.h"
16
17
namespace mozilla {
18
namespace net {
19
20
#define NS_THIS_SIMPLEURI_IMPLEMENTATION_CID \
21
{ /* 0b9bb0c2-fee6-470b-b9b9-9fd9462b5e19 */ \
22
0x0b9bb0c2, 0xfee6, 0x470b, { \
23
0xb9, 0xb9, 0x9f, 0xd9, 0x46, 0x2b, 0x5e, 0x19 \
24
} \
25
}
26
27
class nsSimpleURI : public nsIURI,
28
public nsISerializable,
29
public nsIClassInfo,
30
public nsISizeOf {
31
protected:
32
nsSimpleURI();
33
virtual ~nsSimpleURI() = default;
34
35
public:
36
NS_DECL_THREADSAFE_ISUPPORTS
37
NS_DECL_NSIURI
38
NS_DECL_NSISERIALIZABLE
39
NS_DECL_NSICLASSINFO
40
41
static already_AddRefed<nsSimpleURI> From(nsIURI* aURI);
42
43
// nsSimpleURI methods:
44
45
bool Equals(nsSimpleURI* aOther) { return EqualsInternal(aOther, eHonorRef); }
46
47
// nsISizeOf
48
// Among the sub-classes that inherit (directly or indirectly) from
49
// nsSimpleURI, measurement of the following members may be added later if
50
// DMD finds it is worthwhile:
51
// - nsJSURI: mBaseURI
52
// - nsSimpleNestedURI: mInnerURI
53
// - nsBlobURI: mPrincipal
54
virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
55
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
56
57
protected:
58
// enum used in a few places to specify how .ref attribute should be handled
59
enum RefHandlingEnum { eIgnoreRef, eHonorRef, eReplaceRef };
60
61
virtual nsresult Clone(nsIURI** aURI);
62
virtual nsresult SetSpecInternal(const nsACString& input);
63
virtual nsresult SetScheme(const nsACString& input);
64
virtual nsresult SetUserPass(const nsACString& input);
65
nsresult SetUsername(const nsACString& input);
66
virtual nsresult SetPassword(const nsACString& input);
67
virtual nsresult SetHostPort(const nsACString& aValue);
68
virtual nsresult SetHost(const nsACString& input);
69
virtual nsresult SetPort(int32_t port);
70
virtual nsresult SetPathQueryRef(const nsACString& input);
71
virtual nsresult SetRef(const nsACString& input);
72
virtual nsresult SetFilePath(const nsACString& input);
73
virtual nsresult SetQuery(const nsACString& input);
74
virtual nsresult SetQueryWithEncoding(const nsACString& input,
75
const Encoding* encoding);
76
nsresult ReadPrivate(nsIObjectInputStream* stream);
77
78
// Helper to share code between Equals methods.
79
virtual nsresult EqualsInternal(nsIURI* other,
80
RefHandlingEnum refHandlingMode,
81
bool* result);
82
83
// Helper to be used by inherited classes who want to test
84
// equality given an assumed nsSimpleURI. This must NOT check
85
// the passed-in other for QI to our CID.
86
bool EqualsInternal(nsSimpleURI* otherUri, RefHandlingEnum refHandlingMode);
87
88
// Used by StartClone (and versions of StartClone in subclasses) to
89
// handle the ref in the right way for clones.
90
void SetRefOnClone(nsSimpleURI* url, RefHandlingEnum refHandlingMode,
91
const nsACString& newRef);
92
93
// NOTE: This takes the refHandlingMode as an argument because
94
// nsSimpleNestedURI's specialized version needs to know how to clone
95
// its inner URI.
96
virtual nsSimpleURI* StartClone(RefHandlingEnum refHandlingMode,
97
const nsACString& newRef);
98
99
// Helper to share code between Clone methods.
100
virtual nsresult CloneInternal(RefHandlingEnum refHandlingMode,
101
const nsACString& newRef, nsIURI** clone);
102
103
nsresult SetPathQueryRefEscaped(const nsACString& aPath, bool aNeedsEscape);
104
105
bool Deserialize(const mozilla::ipc::URIParams&);
106
107
nsCString mScheme;
108
nsCString mPath; // NOTE: mPath does not include ref, as an optimization
109
nsCString mRef; // so that URIs with different refs can share string data.
110
nsCString
111
mQuery; // so that URLs with different querys can share string data.
112
bool mMutable;
113
bool mIsRefValid; // To distinguish between empty-ref and no-ref.
114
bool mIsQueryValid; // To distinguish between empty-query and no-query.
115
116
public:
117
class Mutator final : public nsIURIMutator,
118
public BaseURIMutator<nsSimpleURI>,
119
public nsISerializable {
120
NS_DECL_ISUPPORTS
121
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
122
NS_DEFINE_NSIMUTATOR_COMMON
123
124
NS_IMETHOD
125
Write(nsIObjectOutputStream* aOutputStream) override {
126
return NS_ERROR_NOT_IMPLEMENTED;
127
}
128
129
MOZ_MUST_USE NS_IMETHOD Read(nsIObjectInputStream* aStream) override {
130
return InitFromInputStream(aStream);
131
}
132
133
explicit Mutator() = default;
134
135
private:
136
virtual ~Mutator() = default;
137
138
friend class nsSimpleURI;
139
};
140
141
friend BaseURIMutator<nsSimpleURI>;
142
};
143
144
} // namespace net
145
} // namespace mozilla
146
147
#endif // nsSimpleURI_h__