Bug 985742 - Construct the [[Prototype]] chain given to FUEL Application instances without using mutable __proto__. r=mak

This commit is contained in:
Szabolcs Hubai 2014-04-04 00:24:48 -07:00
Родитель ac9d6d88f2
Коммит 1d79f1c311
1 изменённых файлов: 66 добавлений и 33 удалений

Просмотреть файл

@ -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]);