Bug 1761938 - Part 2: Give each web extension content script global its own module loader r=smaug,yulia
This gives the DOM module loader a kind and records content script module loaders in an array on the script loader. Differential Revision: https://phabricator.services.mozilla.com/D142829
This commit is contained in:
@@ -167,7 +167,8 @@ NS_IMPL_CYCLE_COLLECTION(ScriptLoader, mNonAsyncExternalScriptInsertedRequests,
|
||||
mOffThreadCompilingRequests, mDeferRequests,
|
||||
mXSLTRequests, mParserBlockingRequest,
|
||||
mBytecodeEncodingQueue, mPreloads,
|
||||
mPendingChildLoaders, mModuleLoader)
|
||||
mPendingChildLoaders, mModuleLoader,
|
||||
mWebExtModuleLoaders)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(ScriptLoader)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(ScriptLoader)
|
||||
@@ -187,7 +188,7 @@ ScriptLoader::ScriptLoader(Document* aDocument)
|
||||
mLoadEventFired(false),
|
||||
mGiveUpEncoding(false),
|
||||
mReporter(new ConsoleReportCollector()),
|
||||
mModuleLoader(new ModuleLoader(this)) {
|
||||
mModuleLoader(new ModuleLoader(this, ModuleLoader::Normal)) {
|
||||
LOG(("ScriptLoader::ScriptLoader %p", this));
|
||||
|
||||
mSpeculativeOMTParsingEnabled = StaticPrefs::
|
||||
@@ -250,6 +251,13 @@ ScriptLoader::~ScriptLoader() {
|
||||
mModuleLoader = nullptr;
|
||||
}
|
||||
|
||||
void ScriptLoader::RegisterContentScriptModuleLoader(ModuleLoader* aLoader) {
|
||||
MOZ_ASSERT(aLoader);
|
||||
MOZ_ASSERT(aLoader->GetScriptLoader() == this);
|
||||
|
||||
mWebExtModuleLoaders.AppendElement(aLoader);
|
||||
}
|
||||
|
||||
// Collect telemtry data about the cache information, and the kind of source
|
||||
// which are being loaded, and where it is being loaded from.
|
||||
static void CollectScriptTelemetry(ScriptLoadRequest* aRequest) {
|
||||
@@ -2539,12 +2547,25 @@ bool ScriptLoader::HasPendingRequests() {
|
||||
return mParserBlockingRequest || !mXSLTRequests.isEmpty() ||
|
||||
!mLoadedAsyncRequests.isEmpty() ||
|
||||
!mNonAsyncExternalScriptInsertedRequests.isEmpty() ||
|
||||
!mDeferRequests.isEmpty() ||
|
||||
mModuleLoader->HasPendingDynamicImports() ||
|
||||
!mDeferRequests.isEmpty() || HasPendingDynamicImports() ||
|
||||
!mPendingChildLoaders.IsEmpty();
|
||||
// mOffThreadCompilingRequests are already being processed.
|
||||
}
|
||||
|
||||
bool ScriptLoader::HasPendingDynamicImports() const {
|
||||
if (mModuleLoader->HasPendingDynamicImports()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (ModuleLoader* loader : mWebExtModuleLoaders) {
|
||||
if (loader->HasPendingDynamicImports()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScriptLoader::ProcessPendingRequestsAsync() {
|
||||
if (HasPendingRequests()) {
|
||||
nsCOMPtr<nsIRunnable> task =
|
||||
@@ -3335,6 +3356,10 @@ void ScriptLoader::ParsingComplete(bool aTerminated) {
|
||||
|
||||
mModuleLoader->CancelAndClearDynamicImports();
|
||||
|
||||
for (ModuleLoader* loader : mWebExtModuleLoaders) {
|
||||
loader->CancelAndClearDynamicImports();
|
||||
}
|
||||
|
||||
if (mParserBlockingRequest) {
|
||||
mParserBlockingRequest->Cancel();
|
||||
mParserBlockingRequest = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user