Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit e6655d9

Browse files
committed
Bug 1599846 - Enable Background WebExtension scripts in FxR on PC r=zombie
This change allows for background scripts from WebExtensions to run in the FxR on PC chrome window. In this scenario, the promise ExtensionParent.browserStartupPromise is never fulfilled because it depends on the notification sessionstore-windows-restored, which doesn't occur because the FxR window does not participate in SessionStore. To address this issue, browserStartupPromise is now a race between the original notification and a new one, extensions-late-startup, which is fired from fxrui.js. Differential Revision: https://phabricator.services.mozilla.com/D55058 --HG-- extra : moz-landing-system : lando
1 parent cdef02e commit e6655d9

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

browser/fxr/content/fxrui.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ function setupBrowser() {
136136
);
137137

138138
FullScreen.init();
139+
140+
// Send this notification to start and allow background scripts for
141+
// WebExtensions, since this FxR UI doesn't participate in typical
142+
// startup activities
143+
Services.obs.notifyObservers(window, "extensions-late-startup");
139144
}
140145
}
141146

gfx/vr/VRShMem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ bool VRShMem::JoinShMem() {
317317
msg.AppendPrintf("VRService OpenMutex error \"%lu\".", GetLastError());
318318
NS_WARNING(msg.get());
319319
# endif
320-
MOZ_ASSERT(false);
320+
return false;
321321
}
322322
MOZ_ASSERT(GetLastError() == 0);
323323
}

gfx/vr/nsFxrCommandLineHandler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "nsString.h"
2222
#include "nsArray.h"
2323
#include "nsCOMPtr.h"
24+
#include "mozilla/StaticPrefs_extensions.h"
2425

2526
#include "windows.h"
2627
#include "WinUtils.h"
@@ -69,6 +70,10 @@ nsFxrCommandLineHandler::Handle(nsICommandLine* aCmdLine) {
6970
MOZ_CRASH("--fxr not supported without e10s");
7071
}
7172

73+
MOZ_ASSERT(mozilla::StaticPrefs::extensions_webextensions_remote(),
74+
"Remote extensions are the only supported configuration on "
75+
"desktop platforms");
76+
7277
aCmdLine->SetPreventDefault(true);
7378

7479
nsCOMPtr<nsIWindowWatcher> wwatch =

toolkit/components/extensions/ExtensionParent.jsm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,15 +2079,19 @@ var ExtensionParent = {
20792079

20802080
// browserPaintedPromise and browserStartupPromise are promises that
20812081
// resolve after the first browser window is painted and after browser
2082-
// windows have been restored, respectively.
2082+
// windows have been restored, respectively. Alternatively,
2083+
// browserStartupPromise also resolves from the extensions-late-startup
2084+
// notification sent by Firefox Reality on desktop platforms, because it
2085+
// doesn't support SessionStore.
20832086
// _resetStartupPromises should only be called from outside this file in tests.
20842087
ExtensionParent._resetStartupPromises = () => {
20852088
ExtensionParent.browserPaintedPromise = promiseObserved(
20862089
"browser-delayed-startup-finished"
20872090
).then(() => {});
2088-
ExtensionParent.browserStartupPromise = promiseObserved(
2089-
"sessionstore-windows-restored"
2090-
).then(() => {});
2091+
ExtensionParent.browserStartupPromise = Promise.race([
2092+
promiseObserved("sessionstore-windows-restored"),
2093+
promiseObserved("extensions-late-startup"),
2094+
]).then(() => {});
20912095
};
20922096
ExtensionParent._resetStartupPromises();
20932097

0 commit comments

Comments
 (0)