From 1d79f1c3115b83f6bb2422c14913ac0f1e2e6530 Mon Sep 17 00:00:00 2001 From: Szabolcs Hubai Date: Fri, 4 Apr 2014 00:24:48 -0700 Subject: [PATCH] Bug 985742 - Construct the [[Prototype]] chain given to FUEL Application instances without using mutable __proto__. r=mak --- browser/fuel/src/fuelApplication.js | 99 +++++++++++++++++++---------- 1 file changed, 66 insertions(+), 33 deletions(-) diff --git a/browser/fuel/src/fuelApplication.js b/browser/fuel/src/fuelApplication.js index 225b1b52993c..7c354a847530 100644 --- a/browser/fuel/src/fuelApplication.js +++ b/browser/fuel/src/fuelApplication.js @@ -4,8 +4,9 @@ const Ci = Components.interfaces; const Cc = Components.classes; +const Cu = Components.utils; -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); const APPLICATION_CID = Components.ID("fe74cf80-aa2d-11db-abbd-0800200c9a66"); const APPLICATION_CONTRACTID = "@mozilla.org/fuel/application;1"; @@ -729,6 +730,8 @@ var ApplicationFactory = { }; +#include ../../../toolkit/components/exthelper/extApplication.js + //================================================= // Application constructor function Application() { @@ -737,60 +740,90 @@ function Application() { //================================================= // Application implementation -Application.prototype = { +function ApplicationPrototype() { // for nsIClassInfo + XPCOMUtils - classID: APPLICATION_CID, + this.classID = APPLICATION_CID; // redefine the default factory for XPCOMUtils - _xpcom_factory: ApplicationFactory, + this._xpcom_factory = ApplicationFactory; // for nsISupports - QueryInterface: XPCOMUtils.generateQI([Ci.fuelIApplication, Ci.extIApplication, - Ci.nsIObserver, Ci.nsISupportsWeakReference]), + this.QueryInterface = XPCOMUtils.generateQI([ + Ci.fuelIApplication, + Ci.extIApplication, + Ci.nsIObserver, + Ci.nsISupportsWeakReference + ]); // for nsIClassInfo - classInfo: XPCOMUtils.generateCI({classID: APPLICATION_CID, - contractID: APPLICATION_CONTRACTID, - interfaces: [Ci.fuelIApplication, - Ci.extIApplication, - Ci.nsIObserver], - flags: Ci.nsIClassInfo.SINGLETON}), + this.classInfo = XPCOMUtils.generateCI({ + classID: APPLICATION_CID, + contractID: APPLICATION_CONTRACTID, + interfaces: [ + Ci.fuelIApplication, + Ci.extIApplication, + Ci.nsIObserver + ], + flags: Ci.nsIClassInfo.SINGLETON + }); // for nsIObserver - observe: function app_observe(aSubject, aTopic, aData) { + this.observe = function (aSubject, aTopic, aData) { // Call the extApplication version of this function first - this.__proto__.__proto__.observe.call(this, aSubject, aTopic, aData); + var superPrototype = Object.getPrototypeOf(Object.getPrototypeOf(this)); + superPrototype.observe.call(this, aSubject, aTopic, aData); if (aTopic == "xpcom-shutdown") { this._obs.removeObserver(this, "xpcom-shutdown"); Utilities.free(); } - }, + }; - get bookmarks() { - let bookmarks = new BookmarkRoots(); - this.__defineGetter__("bookmarks", function() bookmarks); - return this.bookmarks; - }, + Object.defineProperty(this, "bookmarks", { + get: function bookmarks () { + let bookmarks = new BookmarkRoots(); + Object.defineProperty(this, "bookmarks", { value: bookmarks }); + return this.bookmarks; + }, + enumerable: true, + configurable: true + }); - get windows() { - var win = []; - var browserEnum = Utilities.windowMediator.getEnumerator("navigator:browser"); + Object.defineProperty(this, "windows", { + get: function windows() { + var win = []; + var browserEnum = Utilities.windowMediator.getEnumerator("navigator:browser"); - while (browserEnum.hasMoreElements()) - win.push(getWindow(browserEnum.getNext())); + while (browserEnum.hasMoreElements()) + win.push(getWindow(browserEnum.getNext())); - return win; - }, + return win; + }, + enumerable: true, + configurable: true + }); + + Object.defineProperty(this, "activeWindow", { + get: function () { + let { RecentWindow } = Cu.import("resource:///modules/RecentWindow.jsm", {}); + + Object.defineProperty(this, "activeWindow", { + get: () => RecentWindow.getMostRecentBrowserWindow(), + enumerable: true, + configurable: true + }); + + return this.activeWindow; + }, + enumerable: true, + configurable: true + }); - get activeWindow() { - return getWindow(Utilities.windowMediator.getMostRecentWindow("navigator:browser")); - } }; -#include ../../../toolkit/components/exthelper/extApplication.js - // set the proto, defined in extApplication.js -Application.prototype.__proto__ = extApplication.prototype; +ApplicationPrototype.prototype = extApplication.prototype; + +Application.prototype = new ApplicationPrototype(); this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Application]);