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"
16 #include "nsWrapperCache.h"
21 class nsPIDOMWindowInner
;
26 //*****************************************************************************
27 // Location: Script "location" object
28 //*****************************************************************************
30 class Location final
: public nsISupports
,
32 public nsWrapperCache
{
34 typedef BrowsingContext::LocationProxy RemoteProxy
;
36 Location(nsPIDOMWindowInner
* aWindow
, BrowsingContext
* aBrowsingContext
);
38 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
39 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Location
)
42 void Assign(const nsAString
& aUrl
, nsIPrincipal
& aSubjectPrincipal
,
45 void Reload(bool aForceget
, nsIPrincipal
& aSubjectPrincipal
,
46 ErrorResult
& aError
) {
47 if (!CallerSubsumes(&aSubjectPrincipal
)) {
48 aError
.Throw(NS_ERROR_DOM_SECURITY_ERR
);
52 Reload(aForceget
, aError
);
55 void GetHref(nsAString
& aHref
, nsIPrincipal
& aSubjectPrincipal
,
56 ErrorResult
& aError
) {
57 if (!CallerSubsumes(&aSubjectPrincipal
)) {
58 aError
.Throw(NS_ERROR_DOM_SECURITY_ERR
);
62 aError
= GetHref(aHref
);
65 void GetOrigin(nsAString
& aOrigin
, nsIPrincipal
& aSubjectPrincipal
,
68 void GetProtocol(nsAString
& aProtocol
, nsIPrincipal
& aSubjectPrincipal
,
71 void SetProtocol(const nsAString
& aProtocol
, nsIPrincipal
& aSubjectPrincipal
,
74 void GetHost(nsAString
& aHost
, nsIPrincipal
& aSubjectPrincipal
,
77 void SetHost(const nsAString
& aHost
, nsIPrincipal
& aSubjectPrincipal
,
80 void GetHostname(nsAString
& aHostname
, nsIPrincipal
& aSubjectPrincipal
,
83 void SetHostname(const nsAString
& aHostname
, nsIPrincipal
& aSubjectPrincipal
,
86 void GetPort(nsAString
& aPort
, nsIPrincipal
& aSubjectPrincipal
,
89 void SetPort(const nsAString
& aPort
, nsIPrincipal
& aSubjectPrincipal
,
92 void GetPathname(nsAString
& aPathname
, nsIPrincipal
& aSubjectPrincipal
,
95 void SetPathname(const nsAString
& aPathname
, nsIPrincipal
& aSubjectPrincipal
,
98 void GetSearch(nsAString
& aSeach
, nsIPrincipal
& aSubjectPrincipal
,
101 void SetSearch(const nsAString
& aSeach
, nsIPrincipal
& aSubjectPrincipal
,
102 ErrorResult
& aError
);
104 void GetHash(nsAString
& aHash
, nsIPrincipal
& aSubjectPrincipal
,
105 ErrorResult
& aError
);
107 void SetHash(const nsAString
& aHash
, nsIPrincipal
& aSubjectPrincipal
,
108 ErrorResult
& aError
);
110 nsPIDOMWindowInner
* GetParentObject() const { return mInnerWindow
; }
112 virtual JSObject
* WrapObject(JSContext
* aCx
,
113 JS::Handle
<JSObject
*> aGivenProto
) override
;
115 // Non WebIDL methods:
117 nsresult
GetHref(nsAString
& aHref
);
119 nsresult
ToString(nsAString
& aString
) { return GetHref(aString
); }
121 void Reload(bool aForceget
, ErrorResult
& aRv
);
126 BrowsingContext
* GetBrowsingContext() override
;
127 already_AddRefed
<nsIDocShell
> GetDocShell() override
;
129 // In the case of jar: uris, we sometimes want the place the jar was
130 // fetched from as the URI instead of the jar: uri itself. Pass in
131 // true for aGetInnermostURI when that's the case.
132 // Note, this method can return NS_OK with a null value for aURL. This happens
133 // if the docShell is null.
134 nsresult
GetURI(nsIURI
** aURL
, bool aGetInnermostURI
= false);
136 bool CallerSubsumes(nsIPrincipal
* aSubjectPrincipal
);
138 nsString mCachedHash
;
139 nsCOMPtr
<nsPIDOMWindowInner
> mInnerWindow
;
140 uint64_t mBrowsingContextId
= 0;
144 } // namespace mozilla
146 #endif // mozilla_dom_Location_h