1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=80: */
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/. */
10 #include "nsIDOMLocation.h"
12 #include "nsIWeakReferenceUtils.h"
13 #include "nsWrapperCache.h"
14 #include "nsCycleCollectionParticipant.h"
15 #include "js/TypeDecls.h"
16 #include "mozilla/ErrorResult.h"
17 #include "mozilla/dom/URLSearchParams.h"
18 #include "nsPIDOMWindow.h"
22 class nsIDocShellLoadInfo
;
24 //*****************************************************************************
25 // nsLocation: Script "location" object
26 //*****************************************************************************
28 class nsLocation MOZ_FINAL
: public nsIDOMLocation
29 , public nsWrapperCache
30 , public mozilla::dom::URLSearchParamsObserver
32 typedef mozilla::ErrorResult ErrorResult
;
35 nsLocation(nsPIDOMWindow
* aWindow
, nsIDocShell
*aDocShell
);
37 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
38 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsLocation
,
41 void SetDocShell(nsIDocShell
*aDocShell
);
42 nsIDocShell
*GetDocShell();
45 NS_DECL_NSIDOMLOCATION
48 void Assign(const nsAString
& aUrl
, ErrorResult
& aError
)
50 aError
= Assign(aUrl
);
52 void Replace(const nsAString
& aUrl
, ErrorResult
& aError
)
54 aError
= Replace(aUrl
);
56 void Reload(bool aForceget
, ErrorResult
& aError
)
58 aError
= Reload(aForceget
);
60 void GetHref(nsAString
& aHref
, ErrorResult
& aError
)
62 aError
= GetHref(aHref
);
64 void SetHref(const nsAString
& aHref
, ErrorResult
& aError
)
66 aError
= SetHref(aHref
);
68 void GetOrigin(nsAString
& aOrigin
, ErrorResult
& aError
)
70 aError
= GetOrigin(aOrigin
);
72 void GetProtocol(nsAString
& aProtocol
, ErrorResult
& aError
)
74 aError
= GetProtocol(aProtocol
);
76 void SetProtocol(const nsAString
& aProtocol
, ErrorResult
& aError
)
78 aError
= SetProtocol(aProtocol
);
80 void GetUsername(nsAString
& aUsername
, ErrorResult
& aError
);
81 void SetUsername(const nsAString
& aUsername
, ErrorResult
& aError
);
82 void GetPassword(nsAString
& aPassword
, ErrorResult
& aError
);
83 void SetPassword(const nsAString
& aPassword
, ErrorResult
& aError
);
84 void GetHost(nsAString
& aHost
, ErrorResult
& aError
)
86 aError
= GetHost(aHost
);
88 void SetHost(const nsAString
& aHost
, ErrorResult
& aError
)
90 aError
= SetHost(aHost
);
92 void GetHostname(nsAString
& aHostname
, ErrorResult
& aError
)
94 aError
= GetHostname(aHostname
);
96 void SetHostname(const nsAString
& aHostname
, ErrorResult
& aError
)
98 aError
= SetHostname(aHostname
);
100 void GetPort(nsAString
& aPort
, ErrorResult
& aError
)
102 aError
= GetPort(aPort
);
104 void SetPort(const nsAString
& aPort
, ErrorResult
& aError
)
106 aError
= SetPort(aPort
);
108 void GetPathname(nsAString
& aPathname
, ErrorResult
& aError
)
110 aError
= GetPathname(aPathname
);
112 void SetPathname(const nsAString
& aPathname
, ErrorResult
& aError
)
114 aError
= SetPathname(aPathname
);
116 void GetSearch(nsAString
& aSeach
, ErrorResult
& aError
)
118 aError
= GetSearch(aSeach
);
120 void SetSearch(const nsAString
& aSeach
, ErrorResult
& aError
)
122 aError
= SetSearch(aSeach
);
125 mozilla::dom::URLSearchParams
* SearchParams();
127 void SetSearchParams(mozilla::dom::URLSearchParams
& aSearchParams
);
129 void GetHash(nsAString
& aHash
, ErrorResult
& aError
)
131 aError
= GetHash(aHash
);
133 void SetHash(const nsAString
& aHash
, ErrorResult
& aError
)
135 aError
= SetHash(aHash
);
137 void Stringify(nsAString
& aRetval
, ErrorResult
& aError
)
139 GetHref(aRetval
, aError
);
141 nsPIDOMWindow
* GetParentObject() const
145 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
147 // URLSearchParamsObserver
148 void URLSearchParamsUpdated(mozilla::dom::URLSearchParams
* aSearchParams
) MOZ_OVERRIDE
;
151 virtual ~nsLocation();
153 nsresult
SetSearchInternal(const nsAString
& aSearch
);
154 void UpdateURLSearchParams();
155 void RemoveURLSearchParams();
157 mozilla::dom::URLSearchParams
* GetDocShellSearchParams();
159 // In the case of jar: uris, we sometimes want the place the jar was
160 // fetched from as the URI instead of the jar: uri itself. Pass in
161 // true for aGetInnermostURI when that's the case.
162 nsresult
GetURI(nsIURI
** aURL
, bool aGetInnermostURI
= false);
163 nsresult
GetWritableURI(nsIURI
** aURL
);
164 nsresult
SetURI(nsIURI
* aURL
, bool aReplace
= false);
165 nsresult
SetHrefWithBase(const nsAString
& aHref
, nsIURI
* aBase
,
167 nsresult
SetHrefWithContext(JSContext
* cx
, const nsAString
& aHref
,
170 nsresult
GetSourceBaseURL(JSContext
* cx
, nsIURI
** sourceURL
);
171 nsresult
CheckURL(nsIURI
*url
, nsIDocShellLoadInfo
** aLoadInfo
);
172 bool CallerSubsumes();
174 nsString mCachedHash
;
175 nsCOMPtr
<nsPIDOMWindow
> mInnerWindow
;
176 nsRefPtr
<mozilla::dom::URLSearchParams
> mSearchParams
;
180 #endif // nsLocation_h__