Bug 1389784: Recover gracefully when we fail to create a tab browser. r=mystor

There are some cases where we fail to create a tab's browser due to the sanity
checks in _createBrowser(). While in theory those should never fail, in
practice they seem to. And when they do, they leave the browser in an
inconsistent state.

This change should both prevent the worst effects of these failures, and also
give use better error reporting so that we can properly debug them.

MozReview-Commit-ID: EZjKN9URw5X

--HG--
extra : rebase_source : 100b36b89b1c09087230f5e5cb4d6822e18e6daf
extra : amend_source : d054df358bf346ec0a340c4e7d6b0a99f3ceb646
This commit is contained in:
Kris Maglione 2017-10-03 12:56:24 -07:00
Родитель e147b24667
Коммит 4f1cf2c5d1
1 изменённых файлов: 90 добавлений и 77 удалений

Просмотреть файл

@ -2697,88 +2697,101 @@
this.tabContainer.appendChild(t);
// If this new tab is owned by another, assert that relationship
if (aOwner)
t.owner = aOwner;
var position = this.tabs.length - 1;
t._tPos = position;
this.tabContainer._setPositionalAttributes();
this.tabContainer.updateVisibility();
// If we don't have a preferred remote type, and we have a remote
// opener, use the opener's remote type.
if (!aPreferredRemoteType && aOpenerBrowser) {
aPreferredRemoteType = aOpenerBrowser.remoteType;
}
// If URI is about:blank and we don't have a preferred remote type,
// then we need to use the referrer, if we have one, to get the
// correct remote type for the new tab.
if (uriIsAboutBlank && !aPreferredRemoteType && aReferrerURI) {
aPreferredRemoteType =
E10SUtils.getRemoteTypeForURI(aReferrerURI.spec,
gMultiProcessBrowser);
}
let remoteType =
aForceNotRemote ? E10SUtils.NOT_REMOTE
: E10SUtils.getRemoteTypeForURI(aURI, gMultiProcessBrowser,
aPreferredRemoteType);
let b;
let usingPreloadedContent = false;
let b;
// If we open a new tab with the newtab URL in the default
// userContext, check if there is a preloaded browser ready.
// Private windows are not included because both the label and the
// icon for the tab would be set incorrectly (see bug 1195981).
if (aURI == BROWSER_NEW_TAB_URL &&
!aUserContextId &&
!PrivateBrowsingUtils.isWindowPrivate(window)) {
b = this._getPreloadedBrowser();
if (b) {
usingPreloadedContent = true;
try {
// If this new tab is owned by another, assert that relationship
if (aOwner)
t.owner = aOwner;
var position = this.tabs.length - 1;
t._tPos = position;
this.tabContainer._setPositionalAttributes();
this.tabContainer.updateVisibility();
// If we don't have a preferred remote type, and we have a remote
// opener, use the opener's remote type.
if (!aPreferredRemoteType && aOpenerBrowser) {
aPreferredRemoteType = aOpenerBrowser.remoteType;
}
}
if (!b) {
// No preloaded browser found, create one.
b = this._createBrowser({ remoteType,
uriIsAboutBlank,
userContextId: aUserContextId,
sameProcessAsFrameLoader: aSameProcessAsFrameLoader,
openerWindow: aOpener,
isPrerendered: aIsPrerendered,
nextTabParentId: aNextTabParentId,
name: aName });
}
t.linkedBrowser = b;
if (aFocusUrlBar) {
b._urlbarFocused = true;
}
this._tabForBrowser.set(b, t);
t.permanentKey = b.permanentKey;
t._browserParams = { uriIsAboutBlank,
remoteType,
usingPreloadedContent };
// If the caller opts in, create a lazy browser.
if (aCreateLazyBrowser) {
this._createLazyBrowser(t);
if (lazyBrowserURI) {
// Lazy browser must be explicitly registered so tab will appear as
// a switch-to-tab candidate in autocomplete.
this._unifiedComplete.registerOpenPage(lazyBrowserURI, aUserContextId);
b.registeredOpenURI = lazyBrowserURI;
// If URI is about:blank and we don't have a preferred remote type,
// then we need to use the referrer, if we have one, to get the
// correct remote type for the new tab.
if (uriIsAboutBlank && !aPreferredRemoteType && aReferrerURI) {
aPreferredRemoteType =
E10SUtils.getRemoteTypeForURI(aReferrerURI.spec,
gMultiProcessBrowser);
}
} else {
this._insertBrowser(t, true);
let remoteType =
aForceNotRemote ? E10SUtils.NOT_REMOTE
: E10SUtils.getRemoteTypeForURI(aURI, gMultiProcessBrowser,
aPreferredRemoteType);
// If we open a new tab with the newtab URL in the default
// userContext, check if there is a preloaded browser ready.
// Private windows are not included because both the label and the
// icon for the tab would be set incorrectly (see bug 1195981).
if (aURI == BROWSER_NEW_TAB_URL &&
!aUserContextId &&
!PrivateBrowsingUtils.isWindowPrivate(window)) {
b = this._getPreloadedBrowser();
if (b) {
usingPreloadedContent = true;
}
}
if (!b) {
// No preloaded browser found, create one.
b = this._createBrowser({ remoteType,
uriIsAboutBlank,
userContextId: aUserContextId,
sameProcessAsFrameLoader: aSameProcessAsFrameLoader,
openerWindow: aOpener,
isPrerendered: aIsPrerendered,
nextTabParentId: aNextTabParentId,
name: aName });
}
t.linkedBrowser = b;
if (aFocusUrlBar) {
b._urlbarFocused = true;
}
this._tabForBrowser.set(b, t);
t.permanentKey = b.permanentKey;
t._browserParams = { uriIsAboutBlank,
remoteType,
usingPreloadedContent };
// If the caller opts in, create a lazy browser.
if (aCreateLazyBrowser) {
this._createLazyBrowser(t);
if (lazyBrowserURI) {
// Lazy browser must be explicitly registered so tab will appear as
// a switch-to-tab candidate in autocomplete.
this._unifiedComplete.registerOpenPage(lazyBrowserURI, aUserContextId);
b.registeredOpenURI = lazyBrowserURI;
}
} else {
this._insertBrowser(t, true);
}
} catch (e) {
Cu.reportError("Failed to create tab");
Cu.reportError(e);
t.remove();
if (t.linkedBrowser) {
this._tabFilters.delete(t);
this._tabListeners.delete(t);
let notificationbox = this.getNotificationBox(t.linkedBrowser);
notificationbox.remove();
}
throw e;
}
// Dispatch a new tab notification. We do this once we're