2017-10-27 01:08:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-06-17 21:12:23 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_ChromeUtils__
|
|
|
|
#define mozilla_dom_ChromeUtils__
|
|
|
|
|
|
|
|
#include "mozilla/AlreadyAddRefed.h"
|
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
|
|
|
#include "mozilla/dom/ChromeUtilsBinding.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
2020-04-04 17:48:35 +03:00
|
|
|
#include "nsDOMNavigationTiming.h" // for DOMHighResTimeStamp
|
2020-03-20 12:11:32 +03:00
|
|
|
#include "nsIContentChild.h"
|
2015-06-17 21:12:23 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace devtools {
|
|
|
|
class HeapSnapshot;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace devtools
|
2015-06-17 21:12:23 +03:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2016-03-22 22:09:04 +03:00
|
|
|
class ArrayBufferViewOrArrayBuffer;
|
2018-08-29 05:00:00 +03:00
|
|
|
class BrowsingContext;
|
2017-09-24 08:12:32 +03:00
|
|
|
class IdleRequestCallback;
|
|
|
|
struct IdleRequestOptions;
|
2020-03-05 22:43:50 +03:00
|
|
|
struct MediaMetadataInit;
|
2018-04-23 06:32:11 +03:00
|
|
|
class MozQueryInterface;
|
2017-03-17 05:10:40 +03:00
|
|
|
class PrecompiledScript;
|
|
|
|
class Promise;
|
2019-01-03 19:45:42 +03:00
|
|
|
struct WindowActorOptions;
|
2016-03-22 22:09:04 +03:00
|
|
|
|
2017-11-08 08:25:33 +03:00
|
|
|
class ChromeUtils {
|
2017-03-24 20:34:44 +03:00
|
|
|
private:
|
|
|
|
// Implemented in devtools/shared/heapsnapshot/HeapSnapshot.cpp
|
|
|
|
static void SaveHeapSnapshotShared(GlobalObject& global,
|
|
|
|
const HeapSnapshotBoundaries& boundaries,
|
|
|
|
nsAString& filePath, nsAString& snapshotId,
|
|
|
|
ErrorResult& rv);
|
|
|
|
|
2015-06-17 21:12:23 +03:00
|
|
|
public:
|
2019-11-22 01:12:20 +03:00
|
|
|
// Implemented in devtools/shared/heapsnapshot/HeapSnapshot.cpp
|
|
|
|
static uint64_t GetObjectNodeId(GlobalObject& global, JS::HandleObject aVal);
|
|
|
|
|
2015-09-21 20:07:31 +03:00
|
|
|
// Implemented in devtools/shared/heapsnapshot/HeapSnapshot.cpp
|
2015-06-17 21:12:23 +03:00
|
|
|
static void SaveHeapSnapshot(GlobalObject& global,
|
|
|
|
const HeapSnapshotBoundaries& boundaries,
|
2015-09-15 08:56:46 +03:00
|
|
|
nsAString& filePath, ErrorResult& rv);
|
2015-06-17 21:12:23 +03:00
|
|
|
|
2017-03-24 20:34:44 +03:00
|
|
|
// Implemented in devtools/shared/heapsnapshot/HeapSnapshot.cpp
|
|
|
|
static void SaveHeapSnapshotGetId(GlobalObject& global,
|
|
|
|
const HeapSnapshotBoundaries& boundaries,
|
|
|
|
nsAString& snapshotId, ErrorResult& rv);
|
|
|
|
|
2015-09-21 20:07:31 +03:00
|
|
|
// Implemented in devtools/shared/heapsnapshot/HeapSnapshot.cpp
|
2015-06-17 21:12:23 +03:00
|
|
|
static already_AddRefed<devtools::HeapSnapshot> ReadHeapSnapshot(
|
|
|
|
GlobalObject& global, const nsAString& filePath, ErrorResult& rv);
|
2015-11-11 14:55:00 +03:00
|
|
|
|
|
|
|
static void NondeterministicGetWeakMapKeys(
|
|
|
|
GlobalObject& aGlobal, JS::Handle<JS::Value> aMap,
|
|
|
|
JS::MutableHandle<JS::Value> aRetval, ErrorResult& aRv);
|
2015-11-16 17:50:00 +03:00
|
|
|
|
|
|
|
static void NondeterministicGetWeakSetKeys(
|
|
|
|
GlobalObject& aGlobal, JS::Handle<JS::Value> aSet,
|
|
|
|
JS::MutableHandle<JS::Value> aRetval, ErrorResult& aRv);
|
2016-03-22 22:09:04 +03:00
|
|
|
|
|
|
|
static void Base64URLEncode(GlobalObject& aGlobal,
|
|
|
|
const ArrayBufferViewOrArrayBuffer& aSource,
|
|
|
|
const Base64URLEncodeOptions& aOptions,
|
|
|
|
nsACString& aResult, ErrorResult& aRv);
|
|
|
|
|
|
|
|
static void Base64URLDecode(GlobalObject& aGlobal, const nsACString& aString,
|
|
|
|
const Base64URLDecodeOptions& aOptions,
|
|
|
|
JS::MutableHandle<JSObject*> aRetval,
|
|
|
|
ErrorResult& aRv);
|
2015-06-17 21:12:23 +03:00
|
|
|
|
2019-01-03 18:43:06 +03:00
|
|
|
static void ReleaseAssert(GlobalObject& aGlobal, bool aCondition,
|
|
|
|
const nsAString& aMessage);
|
|
|
|
|
2020-04-04 17:48:35 +03:00
|
|
|
static void AddProfilerMarker(GlobalObject& aGlobal, const nsACString& aName,
|
|
|
|
const Optional<DOMHighResTimeStamp>& aStartTime,
|
|
|
|
const Optional<nsACString>& text);
|
|
|
|
|
2016-02-25 18:41:13 +03:00
|
|
|
static void OriginAttributesToSuffix(
|
2015-06-24 23:34:54 +03:00
|
|
|
GlobalObject& aGlobal, const dom::OriginAttributesDictionary& aAttrs,
|
|
|
|
nsCString& aSuffix);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-09 21:36:35 +03:00
|
|
|
static bool OriginAttributesMatchPattern(
|
|
|
|
dom::GlobalObject& aGlobal, const dom::OriginAttributesDictionary& aAttrs,
|
|
|
|
const dom::OriginAttributesPatternDictionary& aPattern);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-02-29 14:26:00 +03:00
|
|
|
static void CreateOriginAttributesFromOrigin(
|
|
|
|
dom::GlobalObject& aGlobal, const nsAString& aOrigin,
|
|
|
|
dom::OriginAttributesDictionary& aAttrs, ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-04-04 13:20:00 +03:00
|
|
|
static void FillNonDefaultOriginAttributes(
|
2016-02-29 14:26:00 +03:00
|
|
|
dom::GlobalObject& aGlobal, const dom::OriginAttributesDictionary& aAttrs,
|
|
|
|
dom::OriginAttributesDictionary& aNewAttrs);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-02-25 18:41:13 +03:00
|
|
|
static bool IsOriginAttributesEqual(
|
|
|
|
dom::GlobalObject& aGlobal, const dom::OriginAttributesDictionary& aA,
|
|
|
|
const dom::OriginAttributesDictionary& aB);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-11-17 16:52:16 +03:00
|
|
|
static bool IsOriginAttributesEqual(
|
|
|
|
const dom::OriginAttributesDictionary& aA,
|
|
|
|
const dom::OriginAttributesDictionary& aB);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-01-18 15:17:19 +03:00
|
|
|
static bool IsOriginAttributesEqualIgnoringFPD(
|
|
|
|
const dom::OriginAttributesDictionary& aA,
|
2017-03-07 07:04:50 +03:00
|
|
|
const dom::OriginAttributesDictionary& aB) {
|
2019-05-03 20:13:17 +03:00
|
|
|
return aA.mInIsolatedMozBrowser == aB.mInIsolatedMozBrowser &&
|
2017-03-07 07:04:50 +03:00
|
|
|
aA.mUserContextId == aB.mUserContextId &&
|
|
|
|
aA.mPrivateBrowsingId == aB.mPrivateBrowsingId;
|
|
|
|
}
|
2017-03-17 05:10:40 +03:00
|
|
|
|
|
|
|
// Implemented in js/xpconnect/loader/ChromeScriptLoader.cpp
|
|
|
|
static already_AddRefed<Promise> CompileScript(
|
|
|
|
GlobalObject& aGlobal, const nsAString& aUrl,
|
|
|
|
const dom::CompileScriptOptionsDictionary& aOptions, ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-07-18 07:02:28 +03:00
|
|
|
static MozQueryInterface* GenerateQI(const GlobalObject& global,
|
|
|
|
const Sequence<JS::Value>& interfaces,
|
2018-04-23 06:32:11 +03:00
|
|
|
ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-18 21:10:10 +03:00
|
|
|
static void WaiveXrays(GlobalObject& aGlobal, JS::HandleValue aVal,
|
|
|
|
JS::MutableHandleValue aRetval, ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-18 21:10:10 +03:00
|
|
|
static void UnwaiveXrays(GlobalObject& aGlobal, JS::HandleValue aVal,
|
|
|
|
JS::MutableHandleValue aRetval, ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-18 21:10:10 +03:00
|
|
|
static void GetClassName(GlobalObject& aGlobal, JS::HandleObject aObj,
|
|
|
|
bool aUnwrap, nsAString& aRetval);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-24 23:33:40 +03:00
|
|
|
static void ShallowClone(GlobalObject& aGlobal, JS::HandleObject aObj,
|
|
|
|
JS::HandleObject aTarget,
|
|
|
|
JS::MutableHandleObject aRetval, ErrorResult& aRv);
|
2017-09-24 08:12:32 +03:00
|
|
|
|
|
|
|
static void IdleDispatch(const GlobalObject& global,
|
|
|
|
IdleRequestCallback& callback,
|
|
|
|
const IdleRequestOptions& options, ErrorResult& aRv);
|
2017-11-16 12:48:45 +03:00
|
|
|
|
|
|
|
static void GetRecentJSDevError(GlobalObject& aGlobal,
|
|
|
|
JS::MutableHandleValue aRetval,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
static void ClearRecentJSDevError(GlobalObject& aGlobal);
|
2017-12-16 08:30:25 +03:00
|
|
|
|
2018-07-05 17:32:03 +03:00
|
|
|
static already_AddRefed<Promise> RequestPerformanceMetrics(
|
|
|
|
GlobalObject& aGlobal, ErrorResult& aRv);
|
2018-03-20 22:07:41 +03:00
|
|
|
|
2019-05-21 22:01:31 +03:00
|
|
|
static void SetPerfStatsCollectionMask(GlobalObject& aGlobal, uint64_t aMask);
|
|
|
|
|
|
|
|
static already_AddRefed<Promise> CollectPerfStats(GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2019-02-23 21:07:59 +03:00
|
|
|
static already_AddRefed<Promise> RequestProcInfo(GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2017-12-16 08:30:25 +03:00
|
|
|
static void Import(const GlobalObject& aGlobal, const nsAString& aResourceURI,
|
|
|
|
const Optional<JS::Handle<JSObject*>>& aTargetObj,
|
|
|
|
JS::MutableHandle<JSObject*> aRetval, ErrorResult& aRv);
|
2018-01-18 06:20:16 +03:00
|
|
|
|
|
|
|
static void DefineModuleGetter(const GlobalObject& global,
|
|
|
|
JS::Handle<JSObject*> target,
|
|
|
|
const nsAString& id,
|
|
|
|
const nsAString& resourceURI,
|
|
|
|
ErrorResult& aRv);
|
Bug 1441333: Part 1 - Add helper to retrieve closest stack frame with a given principal. r=bz
Most WebExtension APIs are async, and have fairly complicated error reporting
semantics. As a result, when we report an error, the current JS stack has very
little to do with the JS caller that triggered the error, which makes it
difficult to diagnose.
In order to improve the situation, we need to store the location of the caller
at the start of an async operation, so we can tie the error to some marginally
useful location. We don't have a reasonable way to do that now other than
proactively creating an error object when the API is called, or creating a
promise with a full async stack, both of which are too expensive.
This helper instead returns a single SavedStack frame with a given principal,
which should be considerably cheaper, and likely good enough to give a
starting point for debugging cryptic errors.
MozReview-Commit-ID: BTxhpZK9Fdz
--HG--
extra : rebase_source : 7f2c66b1dc18d4ce4c47bef2e3b9d5d3ade929aa
2017-11-12 04:39:16 +03:00
|
|
|
|
|
|
|
static void GetCallerLocation(const GlobalObject& global,
|
|
|
|
nsIPrincipal* principal,
|
|
|
|
JS::MutableHandle<JSObject*> aRetval);
|
2018-03-02 01:00:00 +03:00
|
|
|
|
|
|
|
static void CreateError(const GlobalObject& global, const nsAString& message,
|
|
|
|
JS::Handle<JSObject*> stack,
|
|
|
|
JS::MutableHandle<JSObject*> aRetVal,
|
|
|
|
ErrorResult& aRv);
|
2018-06-26 11:43:16 +03:00
|
|
|
|
2018-07-06 14:43:08 +03:00
|
|
|
static already_AddRefed<Promise> RequestIOActivity(GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aRv);
|
2018-08-29 05:00:00 +03:00
|
|
|
|
2018-12-01 23:26:10 +03:00
|
|
|
static bool HasReportingHeaderForOrigin(GlobalObject& global,
|
|
|
|
const nsAString& aOrigin,
|
|
|
|
ErrorResult& aRv);
|
2019-01-04 18:16:59 +03:00
|
|
|
|
|
|
|
static PopupBlockerState GetPopupControlState(GlobalObject& aGlobal);
|
|
|
|
|
|
|
|
static bool IsPopupTokenUnused(GlobalObject& aGlobal);
|
2019-01-04 19:38:34 +03:00
|
|
|
|
2019-01-24 22:05:03 +03:00
|
|
|
static double LastExternalProtocolIframeAllowed(GlobalObject& aGlobal);
|
|
|
|
|
2019-01-30 14:19:35 +03:00
|
|
|
static void ResetLastExternalProtocolIframeAllowed(GlobalObject& aGlobal);
|
|
|
|
|
2019-01-03 19:45:42 +03:00
|
|
|
static void RegisterWindowActor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aName,
|
|
|
|
const WindowActorOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
2019-01-30 15:43:34 +03:00
|
|
|
|
2019-02-06 23:50:42 +03:00
|
|
|
static void UnregisterWindowActor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aName);
|
|
|
|
|
2019-01-30 15:43:34 +03:00
|
|
|
static bool IsClassifierBlockingErrorCode(GlobalObject& aGlobal,
|
|
|
|
uint32_t aError);
|
2019-08-15 22:28:16 +03:00
|
|
|
|
|
|
|
static void PrivateNoteIntentionalCrash(const GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aError);
|
2019-12-21 03:10:13 +03:00
|
|
|
|
|
|
|
static void GenerateMediaControlKeysTestEvent(
|
|
|
|
const GlobalObject& aGlobal, MediaControlKeysTestEvent aEvent);
|
2020-03-05 22:43:50 +03:00
|
|
|
|
2020-03-20 12:11:32 +03:00
|
|
|
static nsIContentChild* GetContentChild(const GlobalObject&);
|
|
|
|
|
2020-03-05 22:43:50 +03:00
|
|
|
// This function would only be used for testing.
|
|
|
|
static void GetCurrentActiveMediaMetadata(const GlobalObject& aGlobal,
|
|
|
|
MediaMetadataInit& aMetadata);
|
2020-03-17 04:01:31 +03:00
|
|
|
|
|
|
|
// This function would only be used for testing.
|
|
|
|
static MediaSessionPlaybackTestState GetCurrentMediaSessionPlaybackState(
|
|
|
|
GlobalObject& aGlobal);
|
2015-06-17 21:12:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_ChromeUtils__
|