Bug 1388078 - Form Autofill: Delay adding the AOM upgrade listener until the XPI DB is loaded. r=rhelmer
MozReview-Commit-ID: CPeAOrWhEVu
--- a/browser/extensions/formautofill/bootstrap.js
+++ b/browser/extensions/formautofill/bootstrap.js
@@ -9,16 +9,18 @@
const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
const STYLESHEET_URI = "chrome://formautofill/content/formautofill.css";
const CACHED_STYLESHEETS = new WeakMap();
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "AddonManagerPrivate",
+ "resource://gre/modules/AddonManager.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "FormAutofillParent",
"resource://formautofill/FormAutofillParent.jsm");
function insertStyleSheet(domWindow, url) {
let doc = domWindow.document;
let styleSheetAttr = `href="${url}" type="text/css"`;
let styleSheet = doc.createProcessingInstruction("xml-stylesheet", styleSheetAttr);
@@ -36,27 +38,39 @@ function onMaybeOpenPopup(evt) {
if (CACHED_STYLESHEETS.has(domWindow)) {
// This window already has autofill stylesheets.
return;
}
insertStyleSheet(domWindow, STYLESHEET_URI);
}
+function addUpgradeListener(instanceID) {
+ AddonManager.addUpgradeListener(instanceID, upgrade => {
+ // don't install the upgrade by doing nothing here.
+ // The upgrade will be installed upon next restart.
+ });
+}
+
function startup(data) {
if (Services.prefs.getStringPref("extensions.formautofill.available") != "on") {
Services.prefs.clearUserPref("dom.forms.autocomplete.formautofill");
return;
}
if (data.hasOwnProperty("instanceID") && data.instanceID) {
- AddonManager.addUpgradeListener(data.instanceID, (upgrade) => {
- // don't install the upgrade by doing nothing here.
- // The upgrade will be installed upon next restart.
- });
+ if (AddonManagerPrivate.isDBLoaded()) {
+ addUpgradeListener(data.instanceID);
+ } else {
+ // Wait for the extension database to be loaded so we don't cause its init.
+ Services.obs.addObserver(function xpiDatabaseLoaded() {
+ Services.obs.removeObserver(xpiDatabaseLoaded, "xpi-database-loaded");
+ addUpgradeListener(data.instanceID);
+ }, "xpi-database-loaded");
+ }
} else {
throw Error("no instanceID passed to bootstrap startup");
}
// This pref is used for web contents to detect the autocomplete feature.
// When it's true, "element.autocomplete" will return tokens we currently
// support -- otherwise it'll return an empty string.
Services.prefs.setBoolPref("dom.forms.autocomplete.formautofill", true);