Skip to content

Commit

Permalink
Bug 821406 - [B2G browser] Opening a link from news.google.com in a n…
Browse files Browse the repository at this point in the history
…ew tab while news.google.com is still loading can permanently freeze the phone
  • Loading branch information
benfrancis committed Jan 8, 2013
1 parent 2e33b9e commit 5fd6c3d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,6 +14,7 @@ manifest.appcache
/apps/sms/js/blacklist.json
/test_apps/test-agent/test/config.json
/apps/dialer/contacts
/apps/browser/js/init.json

/apps/*/test/unit/_sandbox.html
/apps/*/test/unit/_proxy.html
Expand Down
5 changes: 5 additions & 0 deletions apps/browser/js/authentication_dialog.js
Expand Up @@ -126,5 +126,10 @@ var AuthenticationDialog = {

originHasEvent: function(origin) {
return origin in this.currentEvents;
},

clear: function ad_clear(origin) {
if (this.currentEvents[origin])
delete this.currentEvents[origin];
}
};
60 changes: 27 additions & 33 deletions apps/browser/js/browser.js
Expand Up @@ -212,7 +212,7 @@ var Browser = {
},

handleTryReloading: function browser_handleTryReloading() {
this.navigate(this.currentTab.url);
this.reviveCrashedTab(this.currentTab);
},

handleCloseTab: function browser_handleCloseTab() {
Expand Down Expand Up @@ -412,14 +412,8 @@ var Browser = {
break;

case 'mozbrowsererror':
if (evt.detail.type === 'fatal') {
// A background crash usually means killed to save memory
if (document.mozHidden) {
this.handleKilledTab(tab);
} else {
this.handleCrashedTab(tab);
}
}
if (evt.detail.type === 'fatal')
this.handleCrashedTab(tab);
break;

case 'mozbrowserscroll':
Expand Down Expand Up @@ -493,37 +487,32 @@ var Browser = {
},

handleCrashedTab: function browser_handleCrashedTab(tab) {
if (tab.id === this.currentTab.id) {
// No need to show the crash screen for background tabs,
// they will be revived when selected
if (tab.id === this.currentTab.id && !document.mozHidden) {
this.showCrashScreen();
}

tab.loading = false;
tab.crashed = true;
ModalDialog.clear(tab.id);
AuthenticationDialog.clear(tab.id);
this.frames.removeChild(tab.dom);
delete tab.dom;
delete tab.screenshot;
tab.loading = false;
this.createTab(null, null, tab);
this.refreshButtons();
},

handleKilledTab: function browser_handleKilledTab(tab) {
tab.killed = true;
this.frames.removeChild(tab.dom);
delete tab.dom;
tab.loading = false;
},

handleVisibilityChange: function browser_handleVisibilityChange() {
if (!document.mozHidden && this.currentTab.killed)
this.reviveKilledTab(this.currentTab);
if (!document.mozHidden && this.currentTab.crashed)
this.reviveCrashedTab(this.currentTab);
},

reviveKilledTab: function browser_reviveKilledTab(tab) {
reviveCrashedTab: function browser_reviveCrashedTab(tab) {
this.createTab(null, null, tab);
this.setTabVisibility(tab, true);
this.refreshButtons();
this.navigate(tab.url);
tab.killed = false;
tab.crashed = false;
},

handleWindowOpen: function browser_handleWindowOpen(evt) {
Expand Down Expand Up @@ -1130,6 +1119,9 @@ var Browser = {
},

setTabVisibility: function(tab, visible) {
if (!tab.dom)
return;

if (ModalDialog.originHasEvent(tab.id)) {
if (visible) {
ModalDialog.show(tab.id);
Expand All @@ -1145,18 +1137,17 @@ var Browser = {
AuthenticationDialog.hide();
}
}

// We put loading tabs off screen as we want to screenshot
// them when loaded
if (tab.loading && !visible) {
tab.dom.style.top = '-999px';
return;
}
if (tab.dom.setVisible) {

if (tab.dom.setVisible)
tab.dom.setVisible(visible);
}
if (tab.crashed) {
this.showCrashScreen();
}

tab.dom.style.display = visible ? 'block' : 'none';
tab.dom.style.top = '0px';
},
Expand Down Expand Up @@ -1214,8 +1205,11 @@ var Browser = {

deleteTab: function browser_deleteTab(id) {
var tabIds = Object.keys(this.tabs);
this.tabs[id].dom.parentNode.removeChild(this.tabs[id].dom);
if (this.tabs[id].dom)
this.tabs[id].dom.parentNode.removeChild(this.tabs[id].dom);
delete this.tabs[id];
ModalDialog.clear(id);
AuthenticationDialog.clear(id);
if (this.currentTab && this.currentTab.id === id) {
// The tab to be selected when the current one is deleted
var newTab = tabIds.indexOf(id);
Expand Down Expand Up @@ -1255,9 +1249,9 @@ var Browser = {

selectTab: function browser_selectTab(id) {
this.currentTab = this.tabs[id];
// If the tab was killed, bring it back to life
if (this.currentTab.killed)
this.reviveKilledTab(this.currentTab);
// If the tab crashed, bring it back to life
if (this.currentTab.crashed)
this.reviveCrashedTab(this.currentTab);
// We may have picked a currently loading background tab
// that was positioned off screen
this.setUrlBar(this.currentTab.title);
Expand Down
7 changes: 6 additions & 1 deletion apps/browser/js/modal_dialog.js
Expand Up @@ -70,7 +70,7 @@ var ModalDialog = {
break;

case 'click':
if (evt.currentTarget.nodeName == "BUTTON" ||
if (evt.currentTarget.nodeName == 'BUTTON' ||
evt.currentTarget == elements.customPromptButtons) {
evt.preventDefault();
}
Expand Down Expand Up @@ -242,5 +242,10 @@ var ModalDialog = {

originHasEvent: function(origin) {
return origin in this.currentEvents;
},

clear: function ad_clear(origin) {
if (this.currentEvents[origin])
delete this.currentEvents[origin];
}
};

0 comments on commit 5fd6c3d

Please sign in to comment.