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_ChromeUtils__
8 #define mozilla_dom_ChromeUtils__
10 #include "mozilla/AlreadyAddRefed.h"
11 #include "mozilla/dom/BindingDeclarations.h"
12 #include "mozilla/dom/ChromeUtilsBinding.h"
13 #include "mozilla/dom/Exceptions.h"
14 #include "mozilla/dom/Record.h"
15 #include "nsDOMNavigationTiming.h" // for DOMHighResTimeStamp
16 #include "nsIDOMProcessChild.h"
17 #include "nsIDOMProcessParent.h"
25 } // namespace devtools
29 class ArrayBufferViewOrArrayBuffer
;
30 class BrowsingContext
;
32 class IdleRequestCallback
;
33 struct IdleRequestOptions
;
34 struct MediaMetadataInit
;
35 class MozQueryInterface
;
36 class PrecompiledScript
;
38 struct ProcessActorOptions
;
39 struct WindowActorOptions
;
43 // Implemented in devtools/shared/heapsnapshot/HeapSnapshot.cpp
44 static void SaveHeapSnapshotShared(GlobalObject
& global
,
45 const HeapSnapshotBoundaries
& boundaries
,
46 nsAString
& filePath
, nsAString
& snapshotId
,
50 // Implemented in devtools/shared/heapsnapshot/HeapSnapshot.cpp
51 static uint64_t GetObjectNodeId(GlobalObject
& global
,
52 JS::Handle
<JSObject
*> aVal
);
54 // Implemented in devtools/shared/heapsnapshot/HeapSnapshot.cpp
55 static void SaveHeapSnapshot(GlobalObject
& global
,
56 const HeapSnapshotBoundaries
& boundaries
,
57 nsAString
& filePath
, ErrorResult
& rv
);
59 // Implemented in devtools/shared/heapsnapshot/HeapSnapshot.cpp
60 static void SaveHeapSnapshotGetId(GlobalObject
& global
,
61 const HeapSnapshotBoundaries
& boundaries
,
62 nsAString
& snapshotId
, ErrorResult
& rv
);
64 // Implemented in devtools/shared/heapsnapshot/HeapSnapshot.cpp
65 static already_AddRefed
<devtools::HeapSnapshot
> ReadHeapSnapshot(
66 GlobalObject
& global
, const nsAString
& filePath
, ErrorResult
& rv
);
68 static bool IsDevToolsOpened();
69 static bool IsDevToolsOpened(GlobalObject
& aGlobal
);
70 static void NotifyDevToolsOpened(GlobalObject
& aGlobal
);
71 static void NotifyDevToolsClosed(GlobalObject
& aGlobal
);
73 static void NondeterministicGetWeakMapKeys(
74 GlobalObject
& aGlobal
, JS::Handle
<JS::Value
> aMap
,
75 JS::MutableHandle
<JS::Value
> aRetval
, ErrorResult
& aRv
);
77 static void NondeterministicGetWeakSetKeys(
78 GlobalObject
& aGlobal
, JS::Handle
<JS::Value
> aSet
,
79 JS::MutableHandle
<JS::Value
> aRetval
, ErrorResult
& aRv
);
81 static void Base64URLEncode(GlobalObject
& aGlobal
,
82 const ArrayBufferViewOrArrayBuffer
& aSource
,
83 const Base64URLEncodeOptions
& aOptions
,
84 nsACString
& aResult
, ErrorResult
& aRv
);
86 static void Base64URLDecode(GlobalObject
& aGlobal
, const nsACString
& aString
,
87 const Base64URLDecodeOptions
& aOptions
,
88 JS::MutableHandle
<JSObject
*> aRetval
,
91 static void ReleaseAssert(GlobalObject
& aGlobal
, bool aCondition
,
92 const nsAString
& aMessage
);
94 static void AddProfilerMarker(GlobalObject
& aGlobal
, const nsACString
& aName
,
95 const ProfilerMarkerOptionsOrDouble
& aOptions
,
96 const Optional
<nsACString
>& text
);
98 static void GetXPCOMErrorName(GlobalObject
& aGlobal
, uint32_t aErrorCode
,
101 static void OriginAttributesToSuffix(
102 GlobalObject
& aGlobal
, const dom::OriginAttributesDictionary
& aAttrs
,
105 static bool OriginAttributesMatchPattern(
106 dom::GlobalObject
& aGlobal
, const dom::OriginAttributesDictionary
& aAttrs
,
107 const dom::OriginAttributesPatternDictionary
& aPattern
);
109 static void CreateOriginAttributesFromOrigin(
110 dom::GlobalObject
& aGlobal
, const nsAString
& aOrigin
,
111 dom::OriginAttributesDictionary
& aAttrs
, ErrorResult
& aRv
);
113 static void CreateOriginAttributesFromOriginSuffix(
114 dom::GlobalObject
& aGlobal
, const nsAString
& aSuffix
,
115 dom::OriginAttributesDictionary
& aAttrs
, ErrorResult
& aRv
);
117 static void FillNonDefaultOriginAttributes(
118 dom::GlobalObject
& aGlobal
, const dom::OriginAttributesDictionary
& aAttrs
,
119 dom::OriginAttributesDictionary
& aNewAttrs
);
121 static bool IsOriginAttributesEqual(
122 dom::GlobalObject
& aGlobal
, const dom::OriginAttributesDictionary
& aA
,
123 const dom::OriginAttributesDictionary
& aB
);
125 static bool IsOriginAttributesEqual(
126 const dom::OriginAttributesDictionary
& aA
,
127 const dom::OriginAttributesDictionary
& aB
);
129 static bool IsOriginAttributesEqualIgnoringFPD(
130 const dom::OriginAttributesDictionary
& aA
,
131 const dom::OriginAttributesDictionary
& aB
) {
132 return aA
.mInIsolatedMozBrowser
== aB
.mInIsolatedMozBrowser
&&
133 aA
.mUserContextId
== aB
.mUserContextId
&&
134 aA
.mPrivateBrowsingId
== aB
.mPrivateBrowsingId
;
137 static void GetBaseDomainFromPartitionKey(dom::GlobalObject
& aGlobal
,
138 const nsAString
& aPartitionKey
,
139 nsAString
& aBaseDomain
,
142 static void GetPartitionKeyFromURL(dom::GlobalObject
& aGlobal
,
143 const nsAString
& aURL
,
144 nsAString
& aPartitionKey
,
147 // Implemented in js/xpconnect/loader/ChromeScriptLoader.cpp
148 static already_AddRefed
<Promise
> CompileScript(
149 GlobalObject
& aGlobal
, const nsAString
& aUrl
,
150 const dom::CompileScriptOptionsDictionary
& aOptions
, ErrorResult
& aRv
);
152 static MozQueryInterface
* GenerateQI(const GlobalObject
& global
,
153 const Sequence
<JS::Value
>& interfaces
);
155 static void WaiveXrays(GlobalObject
& aGlobal
, JS::Handle
<JS::Value
> aVal
,
156 JS::MutableHandle
<JS::Value
> aRetval
,
159 static void UnwaiveXrays(GlobalObject
& aGlobal
, JS::Handle
<JS::Value
> aVal
,
160 JS::MutableHandle
<JS::Value
> aRetval
,
163 static void GetClassName(GlobalObject
& aGlobal
, JS::Handle
<JSObject
*> aObj
,
164 bool aUnwrap
, nsAString
& aRetval
);
166 static bool IsDOMObject(GlobalObject
& aGlobal
, JS::Handle
<JSObject
*> aObj
,
169 static void ShallowClone(GlobalObject
& aGlobal
, JS::Handle
<JSObject
*> aObj
,
170 JS::Handle
<JSObject
*> aTarget
,
171 JS::MutableHandle
<JSObject
*> aRetval
,
174 static void IdleDispatch(const GlobalObject
& global
,
175 IdleRequestCallback
& callback
,
176 const IdleRequestOptions
& options
, ErrorResult
& aRv
);
178 static void GetRecentJSDevError(GlobalObject
& aGlobal
,
179 JS::MutableHandle
<JS::Value
> aRetval
,
182 static void ClearRecentJSDevError(GlobalObject
& aGlobal
);
184 static void ClearStyleSheetCacheByPrincipal(GlobalObject
&,
185 nsIPrincipal
* aForPrincipal
);
187 static void ClearStyleSheetCacheByBaseDomain(GlobalObject
& aGlobal
,
188 const nsACString
& aBaseDomain
);
190 static void ClearStyleSheetCache(GlobalObject
& aGlobal
);
192 static void SetPerfStatsCollectionMask(GlobalObject
& aGlobal
, uint64_t aMask
);
194 static already_AddRefed
<Promise
> CollectPerfStats(GlobalObject
& aGlobal
,
197 static already_AddRefed
<Promise
> RequestProcInfo(GlobalObject
& aGlobal
,
200 static bool VsyncEnabled(GlobalObject
& aGlobal
);
202 static void Import(const GlobalObject
& aGlobal
,
203 const nsACString
& aResourceURI
,
204 const Optional
<JS::Handle
<JSObject
*>>& aTargetObj
,
205 JS::MutableHandle
<JSObject
*> aRetval
, ErrorResult
& aRv
);
207 static void ImportESModule(const GlobalObject
& aGlobal
,
208 const nsAString
& aResourceURI
,
209 const ImportESModuleOptionsDictionary
& aOptions
,
210 JS::MutableHandle
<JSObject
*> aRetval
,
213 static void DefineLazyGetter(const GlobalObject
& aGlobal
,
214 JS::Handle
<JSObject
*> aTarget
,
215 JS::Handle
<JS::Value
> aName
,
216 JS::Handle
<JSObject
*> aLambda
, ErrorResult
& aRv
);
218 static void DefineModuleGetter(const GlobalObject
& global
,
219 JS::Handle
<JSObject
*> target
,
221 const nsAString
& resourceURI
,
224 static void DefineESModuleGetters(const GlobalObject
& global
,
225 JS::Handle
<JSObject
*> target
,
226 JS::Handle
<JSObject
*> modules
,
230 static void GetLibcConstants(const GlobalObject
&, LibcConstants
& aConsts
);
233 static void GetCallerLocation(const GlobalObject
& global
,
234 nsIPrincipal
* principal
,
235 JS::MutableHandle
<JSObject
*> aRetval
);
237 static void CreateError(const GlobalObject
& global
, const nsAString
& message
,
238 JS::Handle
<JSObject
*> stack
,
239 JS::MutableHandle
<JSObject
*> aRetVal
,
242 static already_AddRefed
<Promise
> RequestIOActivity(GlobalObject
& aGlobal
,
245 static bool HasReportingHeaderForOrigin(GlobalObject
& global
,
246 const nsAString
& aOrigin
,
249 static PopupBlockerState
GetPopupControlState(GlobalObject
& aGlobal
);
251 static double LastExternalProtocolIframeAllowed(GlobalObject
& aGlobal
);
253 static void ResetLastExternalProtocolIframeAllowed(GlobalObject
& aGlobal
);
255 static void EndWheelTransaction(GlobalObject
& aGlobal
);
257 static void RegisterWindowActor(const GlobalObject
& aGlobal
,
258 const nsACString
& aName
,
259 const WindowActorOptions
& aOptions
,
262 static void UnregisterWindowActor(const GlobalObject
& aGlobal
,
263 const nsACString
& aName
);
265 static void RegisterProcessActor(const GlobalObject
& aGlobal
,
266 const nsACString
& aName
,
267 const ProcessActorOptions
& aOptions
,
270 static void UnregisterProcessActor(const GlobalObject
& aGlobal
,
271 const nsACString
& aName
);
273 static bool IsClassifierBlockingErrorCode(GlobalObject
& aGlobal
,
276 static void PrivateNoteIntentionalCrash(const GlobalObject
& aGlobal
,
277 ErrorResult
& aError
);
279 static nsIDOMProcessChild
* GetDomProcessChild(const GlobalObject
&);
281 static void GetAllDOMProcesses(
282 GlobalObject
& aGlobal
, nsTArray
<RefPtr
<nsIDOMProcessParent
>>& aParents
,
285 static void ConsumeInteractionData(
286 GlobalObject
& aGlobal
, Record
<nsString
, InteractionData
>& aInteractions
,
289 static already_AddRefed
<Promise
> CollectScrollingData(GlobalObject
& aGlobal
,
292 static void GetFormAutofillConfidences(
293 GlobalObject
& aGlobal
, const Sequence
<OwningNonNull
<Element
>>& aElements
,
294 nsTArray
<FormAutofillConfidences
>& aResults
, ErrorResult
& aRv
);
296 static bool IsDarkBackground(GlobalObject
&, Element
&);
298 static double DateNow(GlobalObject
&);
300 static void EnsureJSOracleStarted(GlobalObject
&);
302 static unsigned AliveUtilityProcesses(const GlobalObject
&);
304 static void GetAllPossibleUtilityActorNames(GlobalObject
& aGlobal
,
305 nsTArray
<nsCString
>& aNames
);
307 static bool ShouldResistFingerprinting(GlobalObject
& aGlobal
,
308 JSRFPTarget aTarget
);
311 // Number of DevTools session debugging the current process
312 static std::atomic
<uint32_t> sDevToolsOpenedCount
;
316 } // namespace mozilla
318 #endif // mozilla_dom_ChromeUtils__