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"
14 #include "nsWrapperCache.h"
30 class URL final
: public URLSearchParamsObserver
, public nsWrapperCache
{
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
)) {
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
,
51 static already_AddRefed
<URL
> Constructor(nsISupports
* aParent
,
52 const nsAString
& aURL
,
53 const nsAString
& aBase
,
56 static already_AddRefed
<URL
> Constructor(nsISupports
* aParent
,
57 const nsAString
& aURL
, nsIURI
* aBase
,
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
,
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
;
122 static already_AddRefed
<URL
> FromURI(GlobalObject
&, nsIURI
*);
127 void UpdateURLSearchParams();
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
);
142 } // namespace mozilla
144 #endif /* mozilla_dom_URL_h */