Skip to content

Commit

Permalink
browser(firefox): wait for search and addon manager initialization (#…
Browse files Browse the repository at this point in the history
…4081)

It looks like terminating browser when search service or addon manager is
not fully initialized results in a broken shutdown sequence. As of
today, this results in multiple errors in the browser STDERR. In future,
this might also result in browser stalling instead of terminating.

This starts awaiting search and addon manager termination.

References #3995
  • Loading branch information
aslushnikov authored Oct 7, 2020
1 parent 3b42328 commit 6beef55
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions browser_patches/firefox/BUILD_NUMBER
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1185
Changed: lushnikov@chromium.org Wed Oct 7 08:45:05 PDT 2020
1186
Changed: lushnikov@chromium.org Wed Oct 7 09:26:45 PDT 2020
33 changes: 33 additions & 0 deletions browser_patches/firefox/juggler/protocol/BrowserHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

"use strict";

const {AddonManager} = ChromeUtils.import("resource://gre/modules/AddonManager.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const {TargetRegistry} = ChromeUtils.import("chrome://juggler/content/TargetRegistry.js");
const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
Expand Down Expand Up @@ -45,6 +46,18 @@ class BrowserHandler {

for (const target of this._targetRegistry.targets())
this._onTargetCreated(target);

// Wait to complete initialization of addon manager and search
// service before returning from this method. Failing to do so will result
// in a broken shutdown sequence and multiple errors in browser STDERR log.
//
// NOTE: we have to put this here instead of in the `Browser.close` handler
// since browser shutdown can be initiated when the last tab is closed, e.g.
// with persistent context.
await Promise.all([
waitForAddonManager(),
waitForSearchService(),
]);
}

async ['Browser.createBrowserContext']({removeOnDetach}) {
Expand Down Expand Up @@ -243,6 +256,26 @@ class BrowserHandler {
}
}

async function waitForSearchService() {
const searchService = Components.classes["@mozilla.org/browser/search-service;1"].getService(Components.interfaces.nsISearchService);
await searchService.init();
}

async function waitForAddonManager() {
if (AddonManager.isReady)
return;
await new Promise(resolve => {
let listener = {
onStartup() {
AddonManager.removeManagerListener(listener);
resolve();
},
onShutdown() { },
};
AddonManager.addManagerListener(listener);
});
}

function nullToUndefined(value) {
return value === null ? undefined : value;
}
Expand Down

0 comments on commit 6beef55

Please sign in to comment.