Skip to content

Commit

Permalink
Bug 1599846 - Enable Background WebExtension scripts in FxR on PC r=z…
Browse files Browse the repository at this point in the history
…ombie

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
  • Loading branch information
thomasmo committed Nov 30, 2019
1 parent 0e75050 commit 2892149
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions browser/fxr/content/fxrui.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ function setupBrowser() {
);

FullScreen.init();

// Send this notification to start and allow background scripts for
// WebExtensions, since this FxR UI doesn't participate in typical
// startup activities
Services.obs.notifyObservers(window, "extensions-late-startup");
}
}

Expand Down
2 changes: 1 addition & 1 deletion gfx/vr/VRShMem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ bool VRShMem::JoinShMem() {
msg.AppendPrintf("VRService OpenMutex error \"%lu\".", GetLastError());
NS_WARNING(msg.get());
# endif
MOZ_ASSERT(false);
return false;
}
MOZ_ASSERT(GetLastError() == 0);
}
Expand Down
5 changes: 5 additions & 0 deletions gfx/vr/nsFxrCommandLineHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "nsString.h"
#include "nsArray.h"
#include "nsCOMPtr.h"
#include "mozilla/StaticPrefs_extensions.h"

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

MOZ_ASSERT(mozilla::StaticPrefs::extensions_webextensions_remote(),
"Remote extensions are the only supported configuration on "
"desktop platforms");

aCmdLine->SetPreventDefault(true);

nsCOMPtr<nsIWindowWatcher> wwatch =
Expand Down
12 changes: 8 additions & 4 deletions toolkit/components/extensions/ExtensionParent.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -2079,15 +2079,19 @@ var ExtensionParent = {

// browserPaintedPromise and browserStartupPromise are promises that
// resolve after the first browser window is painted and after browser
// windows have been restored, respectively.
// windows have been restored, respectively. Alternatively,
// browserStartupPromise also resolves from the extensions-late-startup
// notification sent by Firefox Reality on desktop platforms, because it
// doesn't support SessionStore.
// _resetStartupPromises should only be called from outside this file in tests.
ExtensionParent._resetStartupPromises = () => {
ExtensionParent.browserPaintedPromise = promiseObserved(
"browser-delayed-startup-finished"
).then(() => {});
ExtensionParent.browserStartupPromise = promiseObserved(
"sessionstore-windows-restored"
).then(() => {});
ExtensionParent.browserStartupPromise = Promise.race([
promiseObserved("sessionstore-windows-restored"),
promiseObserved("extensions-late-startup"),
]).then(() => {});
};
ExtensionParent._resetStartupPromises();

Expand Down

0 comments on commit 2892149

Please sign in to comment.