Bug 1665252 - remove allowpaymentrequest attribute from HTMLIFrameElement r=dom-worke...
[gecko.git] / dom / base / Location.h
blobc6e7ae4ef5f6f85434bfd9b905f0c7efd1fb6acc
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"
17 #include "nsString.h"
18 #include "nsWrapperCache.h"
20 class nsIDocShell;
21 class nsIURI;
22 class nsDocShellLoadState;
24 namespace mozilla {
25 namespace dom {
27 //*****************************************************************************
28 // Location: Script "location" object
29 //*****************************************************************************
31 class Location final : public nsISupports,
32 public LocationBase,
33 public nsWrapperCache {
34 public:
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)
42 // WebIDL API:
43 void Assign(const nsAString& aUrl, nsIPrincipal& aSubjectPrincipal,
44 ErrorResult& aError);
46 void Reload(bool aForceget, nsIPrincipal& aSubjectPrincipal,
47 ErrorResult& aError) {
48 if (!CallerSubsumes(&aSubjectPrincipal)) {
49 aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
50 return;
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);
60 return;
63 aError = GetHref(aHref);
66 void GetOrigin(nsAString& aOrigin, nsIPrincipal& aSubjectPrincipal,
67 ErrorResult& aError);
69 void GetProtocol(nsAString& aProtocol, nsIPrincipal& aSubjectPrincipal,
70 ErrorResult& aError);
72 void SetProtocol(const nsAString& aProtocol, nsIPrincipal& aSubjectPrincipal,
73 ErrorResult& aError);
75 void GetHost(nsAString& aHost, nsIPrincipal& aSubjectPrincipal,
76 ErrorResult& aError);
78 void SetHost(const nsAString& aHost, nsIPrincipal& aSubjectPrincipal,
79 ErrorResult& aError);
81 void GetHostname(nsAString& aHostname, nsIPrincipal& aSubjectPrincipal,
82 ErrorResult& aError);
84 void SetHostname(const nsAString& aHostname, nsIPrincipal& aSubjectPrincipal,
85 ErrorResult& aError);
87 void GetPort(nsAString& aPort, nsIPrincipal& aSubjectPrincipal,
88 ErrorResult& aError);
90 void SetPort(const nsAString& aPort, nsIPrincipal& aSubjectPrincipal,
91 ErrorResult& aError);
93 void GetPathname(nsAString& aPathname, nsIPrincipal& aSubjectPrincipal,
94 ErrorResult& aError);
96 void SetPathname(const nsAString& aPathname, nsIPrincipal& aSubjectPrincipal,
97 ErrorResult& aError);
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);
124 protected:
125 virtual ~Location();
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;
144 } // namespace dom
145 } // namespace mozilla
147 #endif // mozilla_dom_Location_h