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/LinkedList.h"
13 #include "mozilla/dom/BrowsingContext.h"
14 #include "mozilla/dom/LocationBase.h"
15 #include "nsCycleCollectionParticipant.h"
17 #include "nsWrapperCache.h"
22 class nsPIDOMWindowInner
;
24 namespace mozilla::dom
{
26 //*****************************************************************************
27 // Location: Script "location" object
28 //*****************************************************************************
30 class Location final
: public nsISupports
,
32 public nsWrapperCache
,
33 public LinkedListElement
<Location
> {
35 typedef BrowsingContext::LocationProxy RemoteProxy
;
37 explicit Location(nsPIDOMWindowInner
* aWindow
);
39 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
40 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Location
)
43 void Assign(const nsAString
& aUrl
, nsIPrincipal
& aSubjectPrincipal
,
46 void Reload(bool aForceget
, nsIPrincipal
& aSubjectPrincipal
,
49 void GetHref(nsAString
& aHref
, nsIPrincipal
& aSubjectPrincipal
,
50 ErrorResult
& aError
) {
51 if (!CallerSubsumes(&aSubjectPrincipal
)) {
52 aError
.Throw(NS_ERROR_DOM_SECURITY_ERR
);
56 aError
= GetHref(aHref
);
59 void GetOrigin(nsAString
& aOrigin
, nsIPrincipal
& aSubjectPrincipal
,
62 void GetProtocol(nsAString
& aProtocol
, nsIPrincipal
& aSubjectPrincipal
,
65 void SetProtocol(const nsAString
& aProtocol
, nsIPrincipal
& aSubjectPrincipal
,
68 void GetHost(nsAString
& aHost
, nsIPrincipal
& aSubjectPrincipal
,
71 void SetHost(const nsAString
& aHost
, nsIPrincipal
& aSubjectPrincipal
,
74 void GetHostname(nsAString
& aHostname
, nsIPrincipal
& aSubjectPrincipal
,
77 void SetHostname(const nsAString
& aHostname
, nsIPrincipal
& aSubjectPrincipal
,
80 void GetPort(nsAString
& aPort
, nsIPrincipal
& aSubjectPrincipal
,
83 void SetPort(const nsAString
& aPort
, nsIPrincipal
& aSubjectPrincipal
,
86 void GetPathname(nsAString
& aPathname
, nsIPrincipal
& aSubjectPrincipal
,
89 void SetPathname(const nsAString
& aPathname
, nsIPrincipal
& aSubjectPrincipal
,
92 void GetSearch(nsAString
& aSeach
, nsIPrincipal
& aSubjectPrincipal
,
95 void SetSearch(const nsAString
& aSeach
, nsIPrincipal
& aSubjectPrincipal
,
98 void GetHash(nsAString
& aHash
, nsIPrincipal
& aSubjectPrincipal
,
101 void SetHash(const nsAString
& aHash
, nsIPrincipal
& aSubjectPrincipal
,
102 ErrorResult
& aError
);
104 nsPIDOMWindowInner
* GetParentObject() const { return mInnerWindow
; }
106 virtual JSObject
* WrapObject(JSContext
* aCx
,
107 JS::Handle
<JSObject
*> aGivenProto
) override
;
109 // Non WebIDL methods:
111 nsresult
GetHref(nsAString
& aHref
);
113 nsresult
ToString(nsAString
& aString
) { return GetHref(aString
); }
115 void ClearCachedValues();
120 BrowsingContext
* GetBrowsingContext() override
;
121 nsIDocShell
* GetDocShell() override
;
123 // In the case of jar: uris, we sometimes want the place the jar was
124 // fetched from as the URI instead of the jar: uri itself. Pass in
125 // true for aGetInnermostURI when that's the case.
126 // Note, this method can return NS_OK with a null value for aURL. This happens
127 // if the docShell is null.
128 nsresult
GetURI(nsIURI
** aURL
, bool aGetInnermostURI
= false);
130 bool CallerSubsumes(nsIPrincipal
* aSubjectPrincipal
);
132 nsString mCachedHash
;
133 nsCOMPtr
<nsPIDOMWindowInner
> mInnerWindow
;
136 } // namespace mozilla::dom
138 #endif // mozilla_dom_Location_h