Bug 1833152 - Make about:third-party wait until module processing is ready before displaying modules r=chutten

This prevents the problem where restarting Firefox with an about:third-party tab active would show that no modules were loaded.

Differential Revision: https://phabricator.services.mozilla.com/D181515
This commit is contained in:
Greg Stoll 2023-06-20 20:15:24 +00:00
Родитель afb505be6b
Коммит 831432948a
3 изменённых файлов: 31 добавлений и 0 удалений

Просмотреть файл

@ -52,6 +52,21 @@ function moduleCompareForDisplay(a, b) {
async function fetchData() {
let data = null;
try {
// Wait until the module load events are ready (bug 1833152)
const sleep = delayInMs =>
new Promise(resolve => setTimeout(resolve, delayInMs));
let loadEventsReady = Services.telemetry.areUntrustedModuleLoadEventsReady;
let numberOfAttempts = 0;
// Just to make sure we don't infinite loop here. (this is normally quite
// quick) If we do hit this limit, the page will return an empty list of
// modules.
const MAX_ATTEMPTS = 30;
while (!loadEventsReady && numberOfAttempts < MAX_ATTEMPTS) {
await sleep(1000);
numberOfAttempts++;
loadEventsReady = Services.telemetry.areUntrustedModuleLoadEventsReady;
}
data = await Services.telemetry.getUntrustedModuleLoadEvents(
Services.telemetry.INCLUDE_OLD_LOADEVENTS |
Services.telemetry.KEEP_LOADEVENTS_NEW |

Просмотреть файл

@ -663,6 +663,16 @@ TelemetryImpl::GetUntrustedModuleLoadEvents(uint32_t aFlags, JSContext* cx,
#endif
}
NS_IMETHODIMP
TelemetryImpl::GetAreUntrustedModuleLoadEventsReady(bool* ret) {
#if defined(XP_WIN)
*ret = DllServices::Get()->IsReadyForBackgroundProcessing();
return NS_OK;
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
#if defined(MOZ_GECKO_PROFILER)
class GetLoadedModulesResultRunnable final : public Runnable {
nsMainThreadPtrHandle<Promise> mPromise;

Просмотреть файл

@ -240,6 +240,12 @@ interface nsITelemetry : nsISupports
[implicit_jscontext]
Promise getUntrustedModuleLoadEvents([optional] in unsigned long aFlags);
/*
* Whether the untrusted module load events are ready for processing.
* Calling getUntrustedModuleLoadEvents() before this attribute is true
* will result in an empty array. */
readonly attribute boolean areUntrustedModuleLoadEventsReady;
/*
* Asynchronously get an array of the modules loaded in the process.
*