Bug 985042 - DataStore.jsm removes its inner-window-destroyed observer. r=ehsan

This commit is contained in:
Andrea Marchesini 2014-03-19 06:03:11 -07:00
parent b6ea0644a4
commit caeca6d43d

View File

@ -68,7 +68,8 @@ this.DataStore.prototype = {
classDescription: "DataStore XPCOM Component",
classID: Components.ID("{db5c9602-030f-4bff-a3de-881a8de370f2}"),
contractID: "@mozilla.org/dom/datastore;1",
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupports]),
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupports,
Components.interfaces.nsIObserver]),
callbacks: [],
@ -92,16 +93,7 @@ this.DataStore.prototype = {
this._db = new DataStoreDB();
this._db.init(aOwner, aName);
let self = this;
Services.obs.addObserver(function(aSubject, aTopic, aData) {
let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
if (wId == self._innerWindowID) {
cpmm.removeMessageListener("DataStore:Changed:Return:OK", self);
cpmm.sendAsyncMessage("DataStore:UnregisterForMessages");
self._shuttingdown = true;
self._db.close();
}
}, "inner-window-destroyed", false);
Services.obs.addObserver(this, "inner-window-destroyed", false);
let util = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
@ -112,6 +104,18 @@ this.DataStore.prototype = {
{ store: this._name, owner: this._owner });
},
observe: function(aSubject, aTopic, aData) {
let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
if (wId == this._innerWindowID) {
Services.obs.removeObserver(this, "inner-window-destroyed");
cpmm.removeMessageListener("DataStore:Changed:Return:OK", this);
cpmm.sendAsyncMessage("DataStore:UnregisterForMessages");
this._shuttingdown = true;
this._db.close();
}
},
newDBPromise: function(aTxnType, aFunction) {
let self = this;
return new this._window.Promise(function(aResolve, aReject) {