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"
|
|
|
|
|
|
|
|
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;
|
2017-09-24 08:12:32 +03:00
|
|
|
class IdleRequestCallback;
|
|
|
|
struct IdleRequestOptions;
|
2017-03-17 05:10:40 +03:00
|
|
|
class PrecompiledScript;
|
|
|
|
class Promise;
|
2016-03-22 22:09:04 +03:00
|
|
|
|
2017-11-08 08:25:33 +03:00
|
|
|
class ChromeUtils
|
2015-06-17 21:12:23 +03:00
|
|
|
{
|
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:
|
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,
|
2015-06-17 21:12:23 +03:00
|
|
|
ErrorResult& rv);
|
|
|
|
|
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
|
|
|
|
2015-06-24 23:34:54 +03:00
|
|
|
static void
|
2016-02-25 18:41:13 +03:00
|
|
|
OriginAttributesToSuffix(GlobalObject& aGlobal,
|
2015-06-24 23:34:54 +03:00
|
|
|
const dom::OriginAttributesDictionary& aAttrs,
|
|
|
|
nsCString& aSuffix);
|
2015-07-09 21:36:35 +03:00
|
|
|
|
|
|
|
static bool
|
|
|
|
OriginAttributesMatchPattern(dom::GlobalObject& aGlobal,
|
|
|
|
const dom::OriginAttributesDictionary& aAttrs,
|
|
|
|
const dom::OriginAttributesPatternDictionary& aPattern);
|
2016-01-06 13:08:30 +03:00
|
|
|
|
2016-02-29 14:26:00 +03:00
|
|
|
static void
|
|
|
|
CreateOriginAttributesFromOrigin(dom::GlobalObject& aGlobal,
|
|
|
|
const nsAString& aOrigin,
|
|
|
|
dom::OriginAttributesDictionary& aAttrs,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
static void
|
2016-04-04 13:20:00 +03:00
|
|
|
FillNonDefaultOriginAttributes(dom::GlobalObject& aGlobal,
|
2016-02-29 14:26:00 +03:00
|
|
|
const dom::OriginAttributesDictionary& aAttrs,
|
|
|
|
dom::OriginAttributesDictionary& aNewAttrs);
|
2016-02-25 18:41:13 +03:00
|
|
|
|
|
|
|
static bool
|
|
|
|
IsOriginAttributesEqual(dom::GlobalObject& aGlobal,
|
|
|
|
const dom::OriginAttributesDictionary& aA,
|
|
|
|
const dom::OriginAttributesDictionary& aB);
|
2016-06-07 20:59:22 +03:00
|
|
|
|
2016-11-17 16:52:16 +03:00
|
|
|
static bool
|
|
|
|
IsOriginAttributesEqual(const dom::OriginAttributesDictionary& aA,
|
|
|
|
const dom::OriginAttributesDictionary& aB);
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return aA.mAppId == aB.mAppId &&
|
|
|
|
aA.mInIsolatedMozBrowser == aB.mInIsolatedMozBrowser &&
|
|
|
|
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);
|
2017-08-18 21:10:10 +03:00
|
|
|
|
|
|
|
static void WaiveXrays(GlobalObject& aGlobal,
|
|
|
|
JS::HandleValue aVal,
|
|
|
|
JS::MutableHandleValue aRetval,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
static void UnwaiveXrays(GlobalObject& aGlobal,
|
|
|
|
JS::HandleValue aVal,
|
|
|
|
JS::MutableHandleValue aRetval,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
static void GetClassName(GlobalObject& aGlobal,
|
|
|
|
JS::HandleObject aObj,
|
|
|
|
bool aUnwrap,
|
|
|
|
nsAString& aRetval);
|
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-03-20 22:07:41 +03:00
|
|
|
#ifndef RELEASE_OR_BETA
|
|
|
|
static void RequestPerformanceMetrics(GlobalObject& aGlobal);
|
|
|
|
#endif
|
|
|
|
|
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);
|
2015-06-17 21:12:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_ChromeUtils__
|