/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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/. */
using UntrustedModulesIpcPromise =
MozPromise<Maybe<UntrustedModulesData>, ipc::ResponseRejectReason, true>;
using MultiGetUntrustedModulesPromise =
MozPromise<bool/*aIgnored*/, nsresult, true>;
class MOZ_HEAP_CLASS MultiGetUntrustedModulesData final { public: /** * @param aFlags [in] Combinations of the flags defined under nsITelemetry. * (See "Flags for getUntrustedModuleLoadEvents" * in nsITelemetry.idl)
*/ explicit MultiGetUntrustedModulesData(uint32_t aFlags)
: mFlags(aFlags),
mBackupSvc(UntrustedModulesBackupService::Get()),
mPromise(new MultiGetUntrustedModulesPromise::Private(__func__)),
mNumPending(0) {}
if (aResult.isSome()) {
mBackupSvc->Backup(std::move(aResult.ref()));
}
OnCompletion();
}
private: // Combinations of the flags defined under nsITelemetry. // (See "Flags for getUntrustedModuleLoadEvents" in nsITelemetry.idl)
uint32_t mFlags;
nsresult rv; if (mFlags & nsITelemetry::INCLUDE_OLD_LOADEVENTS) { // When INCLUDE_OLD_LOADEVENTS is set, we need to return instances // from both "Staging" and "Settled" backup. if (mFlags & nsITelemetry::KEEP_LOADEVENTS_NEW) { // When INCLUDE_OLD_LOADEVENTS and KEEP_LOADEVENTS_NEW are set, we need to // return a JS object consisting of all instances from both "Staging" and // "Settled" backups, keeping instances in those backups as is. if (mFlags & nsITelemetry::EXCLUDE_STACKINFO_FROM_LOADEVENTS) { // Without the stack info, we can add multiple UntrustedModulesData to // the serializer directly.
rv = serializer.Add(mBackupSvc->Staging()); if (NS_WARN_IF(NS_FAILED(rv))) {
aPromise->MaybeReject(rv); return;
}
rv = serializer.Add(mBackupSvc->Settled()); if (NS_WARN_IF(NS_FAILED(rv))) {
aPromise->MaybeReject(rv); return;
}
} else { // Currently we don't have a method to merge UntrustedModulesData into // a serialized JS object because merging CombinedStack will be tricky. // Thus we return an error on this flag combination.
aPromise->MaybeReject(NS_ERROR_INVALID_ARG); return;
}
} else { // When KEEP_LOADEVENTS_NEW is not set, we can move data from "Staging" // to "Settled" first, then add "Settled" to the serializer.
mBackupSvc->SettleAllStagingData();
rv = serializer.Add(settledRef); if (NS_WARN_IF(NS_FAILED(rv))) {
aPromise->MaybeReject(rv); return;
}
}
} else { // When INCLUDE_OLD_LOADEVENTS is not set, we serialize only the "Staging" // into a JS object. const UntrustedModulesBackupData& stagingRef = mBackupSvc->Staging();
if (stagingRef.IsEmpty()) {
aPromise->MaybeReject(NS_ERROR_NOT_AVAILABLE); return;
}
rv = serializer.Add(stagingRef); if (NS_WARN_IF(NS_FAILED(rv))) {
aPromise->MaybeReject(rv); return;
}
// When KEEP_LOADEVENTS_NEW is not set, we move all "Staging" instances // to the "Settled". if (!(mFlags & nsITelemetry::KEEP_LOADEVENTS_NEW)) {
mBackupSvc->SettleAllStagingData();
}
}
#ifdefined(XP_WIN)
RefPtr<DllServices> dllSvc(DllServices::Get());
nt::SharedSection* sharedSection = dllSvc->GetSharedSection(); if (sharedSection) { auto dynamicBlocklist = sharedSection->GetDynamicBlocklist();
nsTArray<nsDependentSubstring> blockedModules; for (constauto& blockedEntry : dynamicBlocklist) { if (!blockedEntry.IsValidDynamicBlocklistEntry()) { break;
}
blockedModules.AppendElement(
nsDependentSubstring(blockedEntry.mName.Buffer,
blockedEntry.mName.Length / sizeof(wchar_t)));
}
rv = serializer.AddBlockedModules(blockedModules); if (NS_WARN_IF(NS_FAILED(rv))) {
aPromise->MaybeReject(rv); return;
}
} #endif
nsresult GetUntrustedModuleLoadEvents(uint32_t aFlags, JSContext* cx,
dom::Promise** aPromise) { // Create a promise using global context.
nsIGlobalObject* global = xpc::CurrentNativeGlobal(cx); if (NS_WARN_IF(!global)) { return NS_ERROR_FAILURE;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.