Bug 1401691 - Accept windowId parameter for browser.theme.reset(). r=jaws draft
authorTim Nguyen <ntim.bugs@gmail.com>
Fri, 29 Sep 2017 16:47:48 +0100
changeset 672670 4d04c56c114937cfa1032661470f125570476840
parent 671329 f2b5c9dd4f592de658126269d1488b88c3dd7d7a
child 733877 abbcb0e2cc9677bf17c377d2d70033f626f113ee
push id82328
push userbmo:ntim.bugs@gmail.com
push dateFri, 29 Sep 2017 15:48:15 +0000
reviewersjaws
bugs1401691
milestone58.0a1
Bug 1401691 - Accept windowId parameter for browser.theme.reset(). r=jaws MozReview-Commit-ID: G6XGeHAI5uF
toolkit/components/extensions/ext-theme.js
toolkit/components/extensions/schemas/theme.json
--- a/toolkit/components/extensions/ext-theme.js
+++ b/toolkit/components/extensions/ext-theme.js
@@ -237,28 +237,33 @@ class Theme {
           break;
         }
       }
     }
   }
 
   /**
    * Unloads the currently applied theme.
+   * @param {Object} targetWindow The window the theme should be unloaded from
    */
-  unload() {
+  unload(targetWindow) {
     let lwtStyles = {
       headerURL: "",
       accentcolor: "",
       additionalBackgrounds: "",
       backgroundsAlignment: "",
       backgroundsTiling: "",
       textcolor: "",
       icons: {},
     };
 
+    if (targetWindow) {
+      lwtStyles.window = getWinUtils(targetWindow).outerWindowID;
+    }
+
     for (let icon of ICONS) {
       lwtStyles.icons[`--${icon}--icon`] = "";
     }
     LightweightThemeManager.fallbackThemeData = null;
     Services.obs.notifyObservers(null,
       "lightweight-theme-styling-update",
       JSON.stringify(lwtStyles));
   }
@@ -308,25 +313,30 @@ this.theme = class extends ExtensionAPI 
           }
 
           let browserWindow;
           if (windowId !== null) {
             browserWindow = windowTracker.getWindow(windowId, context);
           }
           this.theme.load(details, browserWindow);
         },
-        reset: () => {
+        reset: (windowId) => {
           if (!gThemesEnabled) {
             // Return early if themes are disabled.
             return;
           }
 
           if (!this.theme) {
             // If no theme has been initialized, nothing to do.
             return;
           }
 
-          this.theme.unload();
+          let browserWindow;
+          if (windowId !== null) {
+            browserWindow = windowTracker.getWindow(windowId, context);
+          }
+
+          this.theme.unload(browserWindow);
         },
       },
     };
   }
 };
--- a/toolkit/components/extensions/schemas/theme.json
+++ b/toolkit/components/extensions/schemas/theme.json
@@ -477,13 +477,20 @@
           }
         ]
       },
       {
         "name": "reset",
         "type": "function",
         "async": true,
         "description": "Removes the updates made to the theme.",
-        "parameters": []
+        "parameters": [
+          {
+            "type": "integer",
+            "name": "windowId",
+            "optional": true,
+            "description": "The id of the window to reset. No id resets all windows."
+          }
+        ]
       }
     ]
   }
 ]