Bug 1825212 [wpt PR 39266] - [@scope] Propagate proximity from SubResult, a=testonly
[gecko.git] / dom / url / URL.h
blob88e72a2da03ca87eb890b907c81aa37cc929dd18
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_URL_h
8 #define mozilla_dom_URL_h
10 #include "mozilla/dom/URLSearchParams.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsIURI.h"
13 #include "nsString.h"
14 #include "nsWrapperCache.h"
16 class nsISupports;
18 namespace mozilla {
20 class ErrorResult;
22 namespace dom {
24 class Blob;
25 class MediaSource;
26 class GlobalObject;
27 template <typename T>
28 class Optional;
30 class URL final : public URLSearchParamsObserver, public nsWrapperCache {
31 public:
32 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
33 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(URL)
35 explicit URL(nsISupports* aParent, nsCOMPtr<nsIURI> aURI)
36 : mParent(aParent), mURI(std::move(aURI)) {
37 MOZ_ASSERT(mURI);
40 // WebIDL methods
41 nsISupports* GetParentObject() const { return mParent; }
43 JSObject* WrapObject(JSContext* aCx,
44 JS::Handle<JSObject*> aGivenProto) override;
46 static already_AddRefed<URL> Constructor(const GlobalObject& aGlobal,
47 const nsAString& aURL,
48 const Optional<nsAString>& aBase,
49 ErrorResult& aRv);
51 static already_AddRefed<URL> Constructor(nsISupports* aParent,
52 const nsAString& aURL,
53 const nsAString& aBase,
54 ErrorResult& aRv);
56 static already_AddRefed<URL> Constructor(nsISupports* aParent,
57 const nsAString& aURL, nsIURI* aBase,
58 ErrorResult& aRv);
60 static void CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
61 nsAString& aResult, ErrorResult& aRv);
63 static void CreateObjectURL(const GlobalObject& aGlobal, MediaSource& aSource,
64 nsAString& aResult, ErrorResult& aRv);
66 static void RevokeObjectURL(const GlobalObject& aGlobal,
67 const nsAString& aURL, ErrorResult& aRv);
69 static bool IsValidURL(const GlobalObject& aGlobal, const nsAString& aURL,
70 ErrorResult& aRv);
72 void GetHref(nsAString& aHref) const;
74 void SetHref(const nsAString& aHref, ErrorResult& aRv);
76 void GetOrigin(nsAString& aOrigin, ErrorResult& aRv) const;
78 void GetProtocol(nsAString& aProtocol) const;
80 void SetProtocol(const nsAString& aProtocol, ErrorResult& aRv);
82 void GetUsername(nsAString& aUsername) const;
84 void SetUsername(const nsAString& aUsername);
86 void GetPassword(nsAString& aPassword) const;
88 void SetPassword(const nsAString& aPassword);
90 void GetHost(nsAString& aHost) const;
92 void SetHost(const nsAString& aHost);
94 void GetHostname(nsAString& aHostname) const;
96 void SetHostname(const nsAString& aHostname);
98 void GetPort(nsAString& aPort) const;
100 void SetPort(const nsAString& aPort);
102 void GetPathname(nsAString& aPathname) const;
104 void SetPathname(const nsAString& aPathname);
106 void GetSearch(nsAString& aSearch) const;
108 void SetSearch(const nsAString& aSearch);
110 URLSearchParams* SearchParams();
112 void GetHash(nsAString& aHost) const;
114 void SetHash(const nsAString& aHash);
116 void ToJSON(nsAString& aResult) const { GetHref(aResult); }
118 // URLSearchParamsObserver
119 void URLSearchParamsUpdated(URLSearchParams* aSearchParams) override;
121 nsIURI* URI() const;
122 static already_AddRefed<URL> FromURI(GlobalObject&, nsIURI*);
124 private:
125 ~URL() = default;
127 void UpdateURLSearchParams();
129 private:
130 void SetSearchInternal(const nsAString& aSearch);
132 void CreateSearchParamsIfNeeded();
134 nsCOMPtr<nsISupports> mParent;
135 RefPtr<URLSearchParams> mSearchParams;
136 nsCOMPtr<nsIURI> mURI;
139 bool IsChromeURI(nsIURI* aURI);
141 } // namespace dom
142 } // namespace mozilla
144 #endif /* mozilla_dom_URL_h */