Permalink
Browse files

Merge pull request #7402 from benfrancis/browser-crashed-tab

Bug 821406 - [B2G browser] Opening a link from news.google.com in a new ...
  • Loading branch information...
2 parents 76aa31d + 1de20fd commit 1883fe5128520b5eda9469360a305ac8acb203ac @daleharvey daleharvey committed Jan 9, 2013
Showing with 53 additions and 44 deletions.
  1. +1 −0 .gitignore
  2. +5 −0 apps/browser/js/authentication_dialog.js
  3. +41 −43 apps/browser/js/browser.js
  4. +6 −1 apps/browser/js/modal_dialog.js
View
@@ -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
@@ -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];
}
};
View
@@ -212,7 +212,7 @@ var Browser = {
},
handleTryReloading: function browser_handleTryReloading() {
- this.navigate(this.currentTab.url);
+ this.reviveCrashedTab(this.currentTab);
},
handleCloseTab: function browser_handleCloseTab() {
@@ -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':
@@ -493,37 +487,33 @@ 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;
+ this.hideCrashScreen();
},
handleWindowOpen: function browser_handleWindowOpen(evt) {
@@ -562,10 +552,6 @@ var Browser = {
},
navigate: function browser_navigate(url) {
- if (this.currentTab.crashed) {
- this.currentTab.crashed = false;
- this.hideCrashScreen();
- }
this.hideStartscreen();
this.showPageScreen();
this.currentTab.title = null;
@@ -601,30 +587,37 @@ var Browser = {
e.preventDefault();
}
- if (this.currentTab.crashed && this.urlButtonMode == this.REFRESH) {
+ if (this.urlButtonMode == this.REFRESH && this.currentTab.crashed) {
this.setUrlBar(this.currentTab.url);
- this.navigate(this.currentTab.url);
+ this.reviveCrashedTab(this.currentTab);
return;
}
- if (this.urlButtonMode == this.REFRESH) {
+ if (this.urlButtonMode == this.REFRESH && !this.currentTab.crashed) {
this.currentTab.dom.reload(true);
return;
}
- if (this.urlButtonMode == this.STOP) {
+ if (this.urlButtonMode == this.STOP && !this.currentTab.crashed) {
this.currentTab.dom.stop();
return;
}
var url = this.getUrlFromInput(this.urlInput.value);
- if (url !== this.currentTab.url && !this.currentTab.crashed) {
+ if (url !== this.currentTab.url) {
this.setUrlBar(url);
this.currentTab.url = url;
}
- this.navigate(url);
+
this.urlInput.blur();
+
+ if (this.currentTab.crashed) {
+ this.reviveCrashedTab(this.currentTab);
+ return;
+ }
+
+ this.navigate(url);
},
goBack: function browser_goBack() {
@@ -1131,6 +1124,9 @@ var Browser = {
},
setTabVisibility: function(tab, visible) {
+ if (!tab.dom)
+ return;
+
if (ModalDialog.originHasEvent(tab.id)) {
if (visible) {
ModalDialog.show(tab.id);
@@ -1146,18 +1142,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';
},
@@ -1215,8 +1210,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);
@@ -1256,9 +1254,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);
@@ -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();
}
@@ -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 1883fe5

Please sign in to comment.