Bug 1467695: Wait for async disable operations to finish when calling addonChanged listeners. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Fri, 08 Jun 2018 13:02:43 -0700
changeset 805959 fb3eb98b3f98f69892c3bc1472cf63ba753b76ba
parent 805618 5b08fd277ce5f750fbec6aaa239f3c7c9806e22a
push id112826
push usermaglione.k@gmail.com
push dateFri, 08 Jun 2018 20:03:08 +0000
reviewersaswan
bugs1467695
milestone62.0a1
Bug 1467695: Wait for async disable operations to finish when calling addonChanged listeners. r?aswan MozReview-Commit-ID: 1vsevE8IgYU
toolkit/mozapps/extensions/AddonManager.jsm
toolkit/mozapps/extensions/internal/XPIDatabase.jsm
--- a/toolkit/mozapps/extensions/AddonManager.jsm
+++ b/toolkit/mozapps/extensions/AddonManager.jsm
@@ -1499,17 +1499,17 @@ var AddonManagerInternal = {
    * @param  aID
    *         The ID of the enabled add-on
    * @param  aType
    *         The type of the enabled add-on
    * @param  aPendingRestart
    *         A boolean indicating if the change will only take place the next
    *         time the application is restarted
    */
-  notifyAddonChanged(aID, aType, aPendingRestart) {
+  async notifyAddonChanged(aID, aType, aPendingRestart) {
     if (!gStarted)
       throw Components.Exception("AddonManager is not initialized",
                                  Cr.NS_ERROR_NOT_INITIALIZED);
 
     if (aID && typeof aID != "string")
       throw Components.Exception("aID must be a string or null",
                                  Cr.NS_ERROR_INVALID_ARG);
 
@@ -1527,17 +1527,20 @@ var AddonManagerInternal = {
     // be unaccessible during XPIProvider startup. Thankfully, these are the
     // only two uses of this API, and we know it's safe to use this API with
     // both providers; so we have this hack to allow bypassing the normal
     // safetey guard.
     // The notifyAddonChanged/addonChanged API will be unneeded and therefore
     // removed by bug 520124, so this is a temporary quick'n'dirty hack.
     let providers = [...this.providers, ...this.pendingProviders];
     for (let provider of providers) {
-      callProvider(provider, "addonChanged", null, aID, aType, aPendingRestart);
+      let result = callProvider(provider, "addonChanged", null, aID, aType, aPendingRestart);
+      if (result) {
+        await result;
+      }
     }
   },
 
   /**
    * Notifies all providers they need to update the appDisabled property for
    * their add-ons in response to an application change such as a blocklist
    * update.
    */
--- a/toolkit/mozapps/extensions/internal/XPIDatabase.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIDatabase.jsm
@@ -1597,25 +1597,25 @@ this.XPIDatabase = {
    * Called when a new add-on has been enabled when only one add-on of that type
    * can be enabled.
    *
    * @param {string} aId
    *        The ID of the newly enabled add-on
    * @param {string} aType
    *        The type of the newly enabled add-on
    */
-  addonChanged(aId, aType) {
+  async addonChanged(aId, aType) {
     // We only care about themes in this provider
     if (!isTheme(aType))
       return;
 
     let addons = this.getAddonsByType("webextension-theme");
     for (let theme of addons) {
       if (theme.visible && theme.id != aId)
-        this.updateAddonDisabledState(theme, true, undefined, true);
+        await this.updateAddonDisabledState(theme, true, undefined, true);
     }
 
     if (!aId && (!LightweightThemeManager.currentTheme ||
                  LightweightThemeManager.currentTheme !== DEFAULT_THEME_ID)) {
       let theme = LightweightThemeManager.getUsedTheme(DEFAULT_THEME_ID);
       // This can only ever be null in tests.
       // This can all go away once lightweight themes are gone.
       if (theme) {