Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / Location.h
blob338366e81bc4928c5128ee62da402e7da39728cc
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"
16 #include "nsString.h"
17 #include "nsWrapperCache.h"
19 class nsIDocShell;
20 class nsIPrincipal;
21 class nsIURI;
22 class nsPIDOMWindowInner;
24 namespace mozilla::dom {
26 //*****************************************************************************
27 // Location: Script "location" object
28 //*****************************************************************************
30 class Location final : public nsISupports,
31 public LocationBase,
32 public nsWrapperCache,
33 public LinkedListElement<Location> {
34 public:
35 typedef BrowsingContext::LocationProxy RemoteProxy;
37 explicit Location(nsPIDOMWindowInner* aWindow);
39 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
40 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Location)
42 // WebIDL API:
43 void Assign(const nsAString& aUrl, nsIPrincipal& aSubjectPrincipal,
44 ErrorResult& aError);
46 void Reload(bool aForceget, nsIPrincipal& aSubjectPrincipal,
47 ErrorResult& aError);
49 void GetHref(nsAString& aHref, nsIPrincipal& aSubjectPrincipal,
50 ErrorResult& aError) {
51 if (!CallerSubsumes(&aSubjectPrincipal)) {
52 aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
53 return;
56 aError = GetHref(aHref);
59 void GetOrigin(nsAString& aOrigin, nsIPrincipal& aSubjectPrincipal,
60 ErrorResult& aError);
62 void GetProtocol(nsAString& aProtocol, nsIPrincipal& aSubjectPrincipal,
63 ErrorResult& aError);
65 void SetProtocol(const nsAString& aProtocol, nsIPrincipal& aSubjectPrincipal,
66 ErrorResult& aError);
68 void GetHost(nsAString& aHost, nsIPrincipal& aSubjectPrincipal,
69 ErrorResult& aError);
71 void SetHost(const nsAString& aHost, nsIPrincipal& aSubjectPrincipal,
72 ErrorResult& aError);
74 void GetHostname(nsAString& aHostname, nsIPrincipal& aSubjectPrincipal,
75 ErrorResult& aError);
77 void SetHostname(const nsAString& aHostname, nsIPrincipal& aSubjectPrincipal,
78 ErrorResult& aError);
80 void GetPort(nsAString& aPort, nsIPrincipal& aSubjectPrincipal,
81 ErrorResult& aError);
83 void SetPort(const nsAString& aPort, nsIPrincipal& aSubjectPrincipal,
84 ErrorResult& aError);
86 void GetPathname(nsAString& aPathname, nsIPrincipal& aSubjectPrincipal,
87 ErrorResult& aError);
89 void SetPathname(const nsAString& aPathname, nsIPrincipal& aSubjectPrincipal,
90 ErrorResult& aError);
92 void GetSearch(nsAString& aSeach, nsIPrincipal& aSubjectPrincipal,
93 ErrorResult& aError);
95 void SetSearch(const nsAString& aSeach, nsIPrincipal& aSubjectPrincipal,
96 ErrorResult& aError);
98 void GetHash(nsAString& aHash, nsIPrincipal& aSubjectPrincipal,
99 ErrorResult& aError);
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();
117 protected:
118 virtual ~Location();
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