1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 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/. */
7 #ifndef mozilla_dom_Location_h
8 #define mozilla_dom_Location_h
10 #include "js/TypeDecls.h"
11 #include "mozilla/ErrorResult.h"
12 #include "mozilla/dom/BrowsingContext.h"
13 #include "mozilla/dom/LocationBase.h"
14 #include "nsCycleCollectionParticipant.h"
15 #include "nsIWeakReferenceUtils.h"
16 #include "nsPIDOMWindow.h"
18 #include "nsWrapperCache.h"
22 class nsDocShellLoadState
;
27 //*****************************************************************************
28 // Location: Script "location" object
29 //*****************************************************************************
31 class Location final
: public nsISupports
,
33 public nsWrapperCache
{
35 typedef BrowsingContext::LocationProxy RemoteProxy
;
37 Location(nsPIDOMWindowInner
* aWindow
, BrowsingContext
* aBrowsingContext
);
39 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
40 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Location
)
43 void Assign(const nsAString
& aUrl
, nsIPrincipal
& aSubjectPrincipal
,
46 void Reload(bool aForceget
, nsIPrincipal
& aSubjectPrincipal
,
47 ErrorResult
& aError
) {
48 if (!CallerSubsumes(&aSubjectPrincipal
)) {
49 aError
.Throw(NS_ERROR_DOM_SECURITY_ERR
);
53 Reload(aForceget
, aError
);
56 void GetHref(nsAString
& aHref
, nsIPrincipal
& aSubjectPrincipal
,
57 ErrorResult
& aError
) {
58 if (!CallerSubsumes(&aSubjectPrincipal
)) {
59 aError
.Throw(NS_ERROR_DOM_SECURITY_ERR
);
63 aError
= GetHref(aHref
);
66 void GetOrigin(nsAString
& aOrigin
, nsIPrincipal
& aSubjectPrincipal
,
69 void GetProtocol(nsAString
& aProtocol
, nsIPrincipal
& aSubjectPrincipal
,
72 void SetProtocol(const nsAString
& aProtocol
, nsIPrincipal
& aSubjectPrincipal
,
75 void GetHost(nsAString
& aHost
, nsIPrincipal
& aSubjectPrincipal
,
78 void SetHost(const nsAString
& aHost
, nsIPrincipal
& aSubjectPrincipal
,
81 void GetHostname(nsAString
& aHostname
, nsIPrincipal
& aSubjectPrincipal
,
84 void SetHostname(const nsAString
& aHostname
, nsIPrincipal
& aSubjectPrincipal
,
87 void GetPort(nsAString
& aPort
, nsIPrincipal
& aSubjectPrincipal
,
90 void SetPort(const nsAString
& aPort
, nsIPrincipal
& aSubjectPrincipal
,
93 void GetPathname(nsAString
& aPathname
, nsIPrincipal
& aSubjectPrincipal
,
96 void SetPathname(const nsAString
& aPathname
, nsIPrincipal
& aSubjectPrincipal
,
99 void GetSearch(nsAString
& aSeach
, nsIPrincipal
& aSubjectPrincipal
,
100 ErrorResult
& aError
);
102 void SetSearch(const nsAString
& aSeach
, nsIPrincipal
& aSubjectPrincipal
,
103 ErrorResult
& aError
);
105 void GetHash(nsAString
& aHash
, nsIPrincipal
& aSubjectPrincipal
,
106 ErrorResult
& aError
);
108 void SetHash(const nsAString
& aHash
, nsIPrincipal
& aSubjectPrincipal
,
109 ErrorResult
& aError
);
111 nsPIDOMWindowInner
* GetParentObject() const { return mInnerWindow
; }
113 virtual JSObject
* WrapObject(JSContext
* aCx
,
114 JS::Handle
<JSObject
*> aGivenProto
) override
;
116 // Non WebIDL methods:
118 nsresult
GetHref(nsAString
& aHref
);
120 nsresult
ToString(nsAString
& aString
) { return GetHref(aString
); }
122 void Reload(bool aForceget
, ErrorResult
& aRv
);
127 BrowsingContext
* GetBrowsingContext() override
;
128 already_AddRefed
<nsIDocShell
> GetDocShell() override
;
130 // In the case of jar: uris, we sometimes want the place the jar was
131 // fetched from as the URI instead of the jar: uri itself. Pass in
132 // true for aGetInnermostURI when that's the case.
133 // Note, this method can return NS_OK with a null value for aURL. This happens
134 // if the docShell is null.
135 nsresult
GetURI(nsIURI
** aURL
, bool aGetInnermostURI
= false);
137 bool CallerSubsumes(nsIPrincipal
* aSubjectPrincipal
);
139 nsString mCachedHash
;
140 nsCOMPtr
<nsPIDOMWindowInner
> mInnerWindow
;
141 uint64_t mBrowsingContextId
= 0;
145 } // namespace mozilla
147 #endif // mozilla_dom_Location_h