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 nsACString
& aURL
,
48 const Optional
<nsACString
>& aBase
,
51 static already_AddRefed
<URL
> Constructor(nsISupports
* aParent
,
52 const nsACString
& aURL
,
53 const nsACString
& aBase
,
56 static already_AddRefed
<URL
> Constructor(nsISupports
* aParent
,
57 const nsACString
& aURL
,
58 nsIURI
* aBase
, ErrorResult
& aRv
);
60 static void CreateObjectURL(const GlobalObject
& aGlobal
, Blob
& aBlob
,
61 nsACString
& aResult
, ErrorResult
& aRv
);
63 static void CreateObjectURL(const GlobalObject
& aGlobal
, MediaSource
& aSource
,
64 nsACString
& aResult
, ErrorResult
& aRv
);
66 static void RevokeObjectURL(const GlobalObject
& aGlobal
,
67 const nsACString
& aURL
, ErrorResult
& aRv
);
69 static bool IsValidObjectURL(const GlobalObject
& aGlobal
,
70 const nsACString
& aURL
, ErrorResult
& aRv
);
72 static already_AddRefed
<URL
> Parse(const GlobalObject
& aGlobal
,
73 const nsACString
& aURL
,
74 const Optional
<nsACString
>& aBase
);
76 static bool CanParse(const GlobalObject
& aGlobal
, const nsACString
& aURL
,
77 const Optional
<nsACString
>& aBase
);
79 void GetHref(nsACString
& aHref
) const;
80 void SetHref(const nsACString
& aHref
, ErrorResult
& aRv
);
82 void GetOrigin(nsACString
& aOrigin
) const;
84 void GetProtocol(nsACString
& aProtocol
) const;
85 void SetProtocol(const nsACString
& aProtocol
);
87 void GetUsername(nsACString
& aUsername
) const;
88 void SetUsername(const nsACString
& aUsername
);
90 void GetPassword(nsACString
& aPassword
) const;
91 void SetPassword(const nsACString
& aPassword
);
93 void GetHost(nsACString
& aHost
) const;
94 void SetHost(const nsACString
& aHost
);
96 void GetHostname(nsACString
& aHostname
) const;
97 void SetHostname(const nsACString
& aHostname
);
99 void GetPort(nsACString
& aPort
) const;
100 void SetPort(const nsACString
& aPort
);
102 void GetPathname(nsACString
& aPathname
) const;
103 void SetPathname(const nsACString
& aPathname
);
105 void GetSearch(nsACString
& aSearch
) const;
106 void SetSearch(const nsACString
& aSearch
);
108 URLSearchParams
* SearchParams();
110 void GetHash(nsACString
& aHash
) const;
111 void SetHash(const nsACString
& aHash
);
113 void ToJSON(nsACString
& aResult
) const { GetHref(aResult
); }
115 // URLSearchParamsObserver
116 void URLSearchParamsUpdated(URLSearchParams
* aSearchParams
) override
;
119 static already_AddRefed
<URL
> FromURI(GlobalObject
&, nsIURI
*);
124 static already_AddRefed
<nsIURI
> ParseURI(const nsACString
& aURL
,
125 const Optional
<nsACString
>& aBase
);
127 void UpdateURLSearchParams();
130 void SetSearchInternal(const nsACString
& 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 */