Bug 1860712 [wpt PR 42705] - Port popover test to WPT and adjust for close requests...
[gecko.git] / dom / url / URL.h
blob7c2563d095bf27ea354143d267ebfe6e30b08a51
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 IsValidObjectURL(const GlobalObject& aGlobal,
70 const nsAString& aURL, ErrorResult& aRv);
72 static bool CanParse(const GlobalObject& aGlobal, const nsAString& aURL,
73 const Optional<nsAString>& aBase);
75 void GetHref(nsAString& aHref) const;
77 void SetHref(const nsAString& aHref, ErrorResult& aRv);
79 void GetOrigin(nsAString& aOrigin) const;
81 void GetProtocol(nsAString& aProtocol) const;
83 void SetProtocol(const nsAString& aProtocol);
85 void GetUsername(nsAString& aUsername) const;
87 void SetUsername(const nsAString& aUsername);
89 void GetPassword(nsAString& aPassword) const;
91 void SetPassword(const nsAString& aPassword);
93 void GetHost(nsAString& aHost) const;
95 void SetHost(const nsAString& aHost);
97 void GetHostname(nsAString& aHostname) const;
99 void SetHostname(const nsAString& aHostname);
101 void GetPort(nsAString& aPort) const;
103 void SetPort(const nsAString& aPort);
105 void GetPathname(nsAString& aPathname) const;
107 void SetPathname(const nsAString& aPathname);
109 void GetSearch(nsAString& aSearch) const;
111 void SetSearch(const nsAString& aSearch);
113 URLSearchParams* SearchParams();
115 void GetHash(nsAString& aHost) const;
117 void SetHash(const nsAString& aHash);
119 void ToJSON(nsAString& aResult) const { GetHref(aResult); }
121 // URLSearchParamsObserver
122 void URLSearchParamsUpdated(URLSearchParams* aSearchParams) override;
124 nsIURI* URI() const;
125 static already_AddRefed<URL> FromURI(GlobalObject&, nsIURI*);
127 private:
128 ~URL() = default;
130 void UpdateURLSearchParams();
132 private:
133 void SetSearchInternal(const nsAString& aSearch);
135 void CreateSearchParamsIfNeeded();
137 nsCOMPtr<nsISupports> mParent;
138 RefPtr<URLSearchParams> mSearchParams;
139 nsCOMPtr<nsIURI> mURI;
142 bool IsChromeURI(nsIURI* aURI);
144 } // namespace dom
145 } // namespace mozilla
147 #endif /* mozilla_dom_URL_h */