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_SCRIPT_HOLDER_CLASS(URL
)
35 explicit URL(nsISupports
* aParent
) : mParent(aParent
) {}
38 nsISupports
* GetParentObject() const { return mParent
; }
40 JSObject
* WrapObject(JSContext
* aCx
,
41 JS::Handle
<JSObject
*> aGivenProto
) override
;
43 static already_AddRefed
<URL
> Constructor(const GlobalObject
& aGlobal
,
44 const nsAString
& aURL
,
45 const Optional
<nsAString
>& aBase
,
48 static already_AddRefed
<URL
> Constructor(nsISupports
* aParent
,
49 const nsAString
& aURL
,
50 const nsAString
& aBase
,
53 static already_AddRefed
<URL
> Constructor(nsISupports
* aParent
,
54 const nsAString
& aURL
, nsIURI
* aBase
,
57 static void CreateObjectURL(const GlobalObject
& aGlobal
, Blob
& aBlob
,
58 nsAString
& aResult
, ErrorResult
& aRv
);
60 static void CreateObjectURL(const GlobalObject
& aGlobal
, MediaSource
& aSource
,
61 nsAString
& aResult
, ErrorResult
& aRv
);
63 static void RevokeObjectURL(const GlobalObject
& aGlobal
,
64 const nsAString
& aURL
, ErrorResult
& aRv
);
66 static bool IsValidURL(const GlobalObject
& aGlobal
, const nsAString
& aURL
,
69 void GetHref(nsAString
& aHref
) const;
71 void SetHref(const nsAString
& aHref
, ErrorResult
& aRv
);
73 void GetOrigin(nsAString
& aOrigin
, ErrorResult
& aRv
) const;
75 void GetProtocol(nsAString
& aProtocol
) const;
77 void SetProtocol(const nsAString
& aProtocol
, ErrorResult
& aRv
);
79 void GetUsername(nsAString
& aUsername
) const;
81 void SetUsername(const nsAString
& aUsername
);
83 void GetPassword(nsAString
& aPassword
) const;
85 void SetPassword(const nsAString
& aPassword
);
87 void GetHost(nsAString
& aHost
) const;
89 void SetHost(const nsAString
& aHost
);
91 void GetHostname(nsAString
& aHostname
) const;
93 void SetHostname(const nsAString
& aHostname
);
95 void GetPort(nsAString
& aPort
) const;
97 void SetPort(const nsAString
& aPort
);
99 void GetPathname(nsAString
& aPathname
) const;
101 void SetPathname(const nsAString
& aPathname
);
103 void GetSearch(nsAString
& aSearch
) const;
105 void SetSearch(const nsAString
& aSearch
);
107 URLSearchParams
* SearchParams();
109 void GetHash(nsAString
& aHost
) const;
111 void SetHash(const nsAString
& aHash
);
113 void ToJSON(nsAString
& aResult
) const { GetHref(aResult
); }
115 // URLSearchParamsObserver
116 void URLSearchParamsUpdated(URLSearchParams
* aSearchParams
) override
;
121 void SetURI(already_AddRefed
<nsIURI
> aURI
);
123 nsIURI
* GetURI() const;
125 void UpdateURLSearchParams();
128 void SetSearchInternal(const nsAString
& aSearch
);
130 void CreateSearchParamsIfNeeded();
132 nsCOMPtr
<nsISupports
> mParent
;
133 RefPtr
<URLSearchParams
> mSearchParams
;
134 nsCOMPtr
<nsIURI
> mURI
;
137 bool IsChromeURI(nsIURI
* aURI
);
140 } // namespace mozilla
142 #endif /* mozilla_dom_URL_h */