Skip to content

Commit

Permalink
Merge pull request mozilla#765 from ochameau/bug/833783
Browse files Browse the repository at this point in the history
Fix Bug 833783: Fix leaks in tabs and windows when closing a top-level chrome window. r=@erikvold(cherry picked from commit b06eb5b)
  • Loading branch information
erikvold authored and Wes Kocher committed Feb 11, 2013
1 parent 22cda4b commit b439ee9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
39 changes: 28 additions & 11 deletions lib/sdk/tabs/tab-firefox.js
Expand Up @@ -58,6 +58,8 @@ const TabTrait = Trait.compose(EventEmitter, {
destroy: function destroy() {
this._removeAllListeners();
this._browser.removeEventListener(EVENTS.ready.dom, this._onReady, true);
this._tab = null;
TABS.splice(TABS.indexOf(this), 1);
},

/**
Expand Down Expand Up @@ -98,35 +100,35 @@ const TabTrait = Trait.compose(EventEmitter, {
/**
* Unique id for the tab, actually maps to tab.linkedPanel but with some munging.
*/
get id() getTabId(this._tab),
get id() this._tab ? getTabId(this._tab) : undefined,

/**
* The title of the page currently loaded in the tab.
* Changing this property changes an actual title.
* @type {String}
*/
get title() getTabTitle(this._tab),
set title(title) setTabTitle(this._tab, title),
get title() this._tab ? getTabTitle(this._tab) : undefined,
set title(title) this._tab && setTabTitle(this._tab, title),

/**
* Returns the MIME type that the document loaded in the tab is being
* rendered as.
* @type {String}
*/
get contentType() getTabContentType(this._tab),
get contentType() this._tab ? getTabContentType(this._tab) : undefined,

/**
* Location of the page currently loaded in this tab.
* Changing this property will loads page under under the specified location.
* @type {String}
*/
get url() getTabURL(this._tab),
set url(url) setTabURL(this._tab, url),
get url() this._tab ? getTabURL(this._tab) : undefined,
set url(url) this._tab && setTabURL(this._tab, url),
/**
* URI of the favicon for the page currently loaded in this tab.
* @type {String}
*/
get favicon() getFaviconURIForLocation(this.url),
get favicon() this._tab ? getFaviconURIForLocation(this.url) : undefined,
/**
* The CSS style for the tab
*/
Expand All @@ -137,23 +139,30 @@ const TabTrait = Trait.compose(EventEmitter, {
* @type {Number}
*/
get index()
this._window.gBrowser.getBrowserIndexForDocument(this._contentDocument),
set index(value) this._window.gBrowser.moveTabTo(this._tab, value),
this._tab ?
this._window.gBrowser.getBrowserIndexForDocument(this._contentDocument) :
undefined,
set index(value)
this._tab && this._window.gBrowser.moveTabTo(this._tab, value),
/**
* Thumbnail data URI of the page currently loaded in this tab.
* @type {String}
*/
getThumbnail: function getThumbnail()
getThumbnailURIForWindow(this._contentWindow),
this._tab ? getThumbnailURIForWindow(this._contentWindow) : undefined,
/**
* Whether or not tab is pinned (Is an app-tab).
* @type {Boolean}
*/
get isPinned() this._tab.pinned,
get isPinned() this._tab ? this._tab.pinned : undefined,
pin: function pin() {
if (!this._tab)
return;
this._window.gBrowser.pinTab(this._tab);
},
unpin: function unpin() {
if (!this._tab)
return;
this._window.gBrowser.unpinTab(this._tab);
},

Expand All @@ -162,6 +171,8 @@ const TabTrait = Trait.compose(EventEmitter, {
* @type {Worker}
*/
attach: function attach(options) {
if (!this._tab)
return;
// BUG 792946 https://bugzilla.mozilla.org/show_bug.cgi?id=792946
// TODO: fix this circular dependency
let { Worker } = require('./worker');
Expand All @@ -175,12 +186,16 @@ const TabTrait = Trait.compose(EventEmitter, {
* we would like to return instance before firing a 'TabActivated' event.
*/
activate: defer(function activate() {
if (!this._tab)
return;
activateTab(this._tab);
}),
/**
* Close the tab
*/
close: function close(callback) {
if (!this._tab)
return;
if (callback)
this.once(EVENTS.close.name, callback);
this._window.gBrowser.removeTab(this._tab);
Expand All @@ -189,6 +204,8 @@ const TabTrait = Trait.compose(EventEmitter, {
* Reload the tab
*/
reload: function reload() {
if (!this._tab)
return;
this._window.gBrowser.reloadTab(this._tab);
}
});
Expand Down
3 changes: 3 additions & 0 deletions lib/sdk/windows/loader.js
Expand Up @@ -86,6 +86,9 @@ const WindowLoader = Trait.compose({
this._onLoad(window)
}
}
else {
this.__window = null;
}
}
},
__window: null,
Expand Down
18 changes: 18 additions & 0 deletions test/test-tab.js
Expand Up @@ -109,6 +109,24 @@ function step3(assert, done) {
});
}

exports["test behavior on close"] = function(assert, done) {

tabs.open({
url: "about:mozilla",
onReady: function(tab) {
assert.equal(tab.url, "about:mozilla", "Tab has the expected url");
assert.equal(tab.index, 1, "Tab has the expected index");
tab.close(function () {
assert.equal(tab.url, undefined,
"After being closed, tab attributes are undefined (url)");
assert.equal(tab.index, undefined,
"After being closed, tab attributes are undefined (index)");
done();
});
}
});
};

if (require("sdk/system/xul-app").is("Fennec")) {
module.exports = {
"test Unsupported Test": function UnsupportedTest (assert) {
Expand Down

0 comments on commit b439ee9

Please sign in to comment.