Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #30153 from alivedise/bugzilla/1166591/leak-browse…
Browse files Browse the repository at this point in the history
…r-iframe

Bug 1166591 - Drop browser element ref when app is suspended
  • Loading branch information
alivedise committed May 22, 2015
2 parents 6fa6da1 + 829aed8 commit 4421961
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions apps/system/js/app_statusbar.js
Expand Up @@ -10,6 +10,8 @@
this._fetchAllElements();
this._touchForwarder = new TouchForwarder();
this._touchForwarder.destination = this.app.browser.element;
this.app.element.addEventListener('_suspended', this);
this.app.element.addEventListener('_resumed', this);
};

AppStatusbar.prototype = Object.create(BaseUI.prototype);
Expand All @@ -31,6 +33,17 @@
this.titleBar = this.containerElement.querySelector('.titlebar');
};

AppStatusbar.prototype.handleEvent = function(evt) {
switch (evt.type) {
case '_resumed':
this._touchForwarder.destination = this.app.browser.element;
break;
case '_suspended':
this._touchForwarder.destination = null;
break;
}
};

AppStatusbar.prototype.handleStatusbarTouch = function(evt, barHeight) {
this.app.debug('preprocessing touch event...', evt.type);
var touch;
Expand Down
16 changes: 16 additions & 0 deletions apps/system/test/unit/app_statusbar_test.js
Expand Up @@ -27,6 +27,22 @@ suite('system/AppStatusbar', function() {
subject.titleBar = document.createElement('div');
});

suite('Reset destination if browser is destroyed', function() {
test('Suspend', function() {
app.element.dispatchEvent(new CustomEvent('_suspended'));
assert.isNull(subject._touchForwarder.destination);
});

test('Resume', function() {
var newBrowserElement = document.createElement('iframe');
app.browser = {
element: newBrowserElement
};
app.element.dispatchEvent(new CustomEvent('_resumed'));
assert.deepEqual(subject._touchForwarder.destination, newBrowserElement);
});
});

suite('fullscreen mode >', function() {
function forgeTouchEvent(type, x, y) {
var touch = document.createTouch(window, null, 42, x, y,
Expand Down
3 changes: 3 additions & 0 deletions apps/system/test/unit/mock_app_window.js
Expand Up @@ -58,6 +58,9 @@
element: this._iframe
};
},
set browser(browser) {
this._iframe = browser.element;
},
get frame() {
return this.element;
},
Expand Down

0 comments on commit 4421961

Please sign in to comment.