Bug 1319567 fix window id so it is never zero, r?kmag draft
authorShane Caraveo <scaraveo@mozilla.com>
Tue, 22 Nov 2016 17:35:37 -0800
changeset 442677 6201544e0acc4749d1928fc1ed2f251abe9a8fea
parent 442558 5f53728a080b2f7f8795c62e5c30bc449eff5ed5
child 537863 09a8150e728c2000b5e69d8f31fab5d60e271e69
push id36781
push usermixedpuppy@gmail.com
push dateWed, 23 Nov 2016 01:37:04 +0000
reviewerskmag
bugs1319567
milestone53.0a1
Bug 1319567 fix window id so it is never zero, r?kmag MozReview-Commit-ID: 30u1o1BOAvv
browser/components/extensions/ext-utils.js
--- a/browser/components/extensions/ext-utils.js
+++ b/browser/components/extensions/ext-utils.js
@@ -919,19 +919,16 @@ TabManager.for = function(extension) {
 /* eslint-disable mozilla/balanced-listeners */
 extensions.on("shutdown", (type, extension) => {
   tabManagers.delete(extension);
 });
 /* eslint-enable mozilla/balanced-listeners */
 
 // Manages mapping between XUL windows and extension window IDs.
 global.WindowManager = {
-  _windows: new WeakMap(),
-  _nextId: 0,
-
   // Note: These must match the values in windows.json.
   WINDOW_ID_NONE: -1,
   WINDOW_ID_CURRENT: -2,
 
   get topWindow() {
     return Services.wm.getMostRecentWindow("navigator:browser");
   },
 
@@ -960,22 +957,21 @@ global.WindowManager = {
     if (options.width !== null || options.height !== null) {
       let width = options.width !== null ? options.width : window.outerWidth;
       let height = options.height !== null ? options.height : window.outerHeight;
       window.resizeTo(width, height);
     }
   },
 
   getId(window) {
-    if (this._windows.has(window)) {
-      return this._windows.get(window);
+    if (!window.QueryInterface) {
+      return null;
     }
-    let id = this._nextId++;
-    this._windows.set(window, id);
-    return id;
+    return window.QueryInterface(Ci.nsIInterfaceRequestor)
+                 .getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
   },
 
   getWindow(id, context) {
     if (id == this.WINDOW_ID_CURRENT) {
       return currentWindow(context);
     }
 
     for (let window of WindowListManager.browserWindows(true)) {