diff options
author | Pale Moon <git-repo@palemoon.org> | 2017-05-02 18:58:12 +0200 |
---|---|---|
committer | Pale Moon <git-repo@palemoon.org> | 2017-05-02 18:58:12 +0200 |
commit | 2ad5a8ef93079a9484ce7ada16a9b17c533380d6 (patch) | |
tree | 094983a2a5da0a69df01a5ab778ad9e6a8b41d92 /browser | |
parent | 5331ef918d11ba4373f48e835fa553ff29bb56ba (diff) | |
download | palemoon-gre-2ad5a8ef93079a9484ce7ada16a9b17c533380d6.tar.gz |
Implement browser startup autorecovery module.
Diffstat (limited to 'browser')
-rw-r--r-- | browser/base/content/autorecovery.js | 48 | ||||
-rw-r--r-- | browser/base/content/autorecovery.xul | 12 | ||||
-rw-r--r-- | browser/base/content/browser.xul | 2 | ||||
-rw-r--r-- | browser/base/jar.mn | 2 |
4 files changed, 64 insertions, 0 deletions
diff --git a/browser/base/content/autorecovery.js b/browser/base/content/autorecovery.js new file mode 100644 index 000000000..f0a1da8f1 --- /dev/null +++ b/browser/base/content/autorecovery.js @@ -0,0 +1,48 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Auto-recovery module. + * This module aims to catch fatal browser initialization errors and either + * automatically correct likely causes from them, or automatically restarting + * the browser in safe mode. This is hooked into the browser's "onload" + * event because it can be assumed that at that point, everything must + * have been properly initialized already. + */ + +let Cc = Components.classes; +let Ci = Components.interfaces; +let Cu = Components.utils; + +// Services = object with smart getters for common XPCOM services +Cu.import("resource://gre/modules/Services.jsm"); + +var browser_autoRecovery = +{ + onLoad: function() { + if (typeof gBrowser === "undefined") { + // gBrowser should always be defined at this point, but if it is not, then most likely + // it is due to an incompatible or outdated language pack being installed and selected. + // In this case, we reset "general.useragent.locale" to try to recover browser startup. + if (Services.prefs.prefHasUserValue("general.useragent.locale")) { + // Restart automatically in en-US. + Services.prefs.clearUserPref("general.useragent.locale"); + a=Ci.nsIAppStartup,Cc["@mozilla.org/toolkit/app-startup;1"].getService(a).quit(a.eRestart | a.eAttemptQuit); + } else if (!Services.appinfo.inSafeMode) { + // gBrowser isn't defined, and we're not using a custom locale. Most likely + // a user-installed add-on causes issues here, so we restart in Safe Mode. + Services.prompt.alert(null, "Error", + "The Browser didn't start properly!\n"+ + "This is usually caused by an add-on or misconfiguration.\n"+ + "Restarting in Safe Mode..."); + a=Ci.nsIAppStartup,Cc["@mozilla.org/toolkit/app-startup;1"].getService(a).restartInSafeMode(a.eRestart | a.eAttemptQuit); + } + // Something else caused this issue and we're already in Safe Mode, so we return + // without doing anything else, and let normal error handling take place. + } + // Remove our listener, since we don't want this to fire on every load. + window.removeEventListener("load", browser_autoRecovery.onLoad, false); + } +}; + +window.addEventListener("load", browser_autoRecovery.onLoad, false); diff --git a/browser/base/content/autorecovery.xul b/browser/base/content/autorecovery.xul new file mode 100644 index 000000000..866bdf288 --- /dev/null +++ b/browser/base/content/autorecovery.xul @@ -0,0 +1,12 @@ +<?xml version="1.0"?> + +<overlay + id="autorecovery" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + +<script type="application/x-javascript" src="chrome://browser/content/autorecovery.js"/> + +<!-- This is an empty overlay to allow separation of the script into its + own context (needed for locale issues preventing browser start) --> + +</overlay> diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index 1bdbee831..f83010023 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -25,6 +25,8 @@ <?xul-overlay href="chrome://browser/content/padlock.xul"?> # Improve bookmark menu dragging <?xul-overlay href="chrome://browser/content/browser-menudragging.xul"?> +# Automatic browser recovery +<?xul-overlay href="chrome://browser/content/autorecovery.xul"?> # All DTD information is stored in a separate file so that it can be shared by diff --git a/browser/base/jar.mn b/browser/base/jar.mn index 26a63ed1c..49d83da4a 100644 --- a/browser/base/jar.mn +++ b/browser/base/jar.mn @@ -45,6 +45,8 @@ browser.jar: content/browser/abouthome/restore-large@2x.png (content/abouthome/restore-large@2x.png) content/browser/aboutRobots-icon.png (content/aboutRobots-icon.png) content/browser/aboutRobots-widget-left.png (content/aboutRobots-widget-left.png) + content/browser/autorecovery.js (content/autorecovery.js) + content/browser/autorecovery.xul (content/autorecovery.xul) * content/browser/browser.css (content/browser.css) content/browser/browser-menudragging.xul (content/browser-menudragging.xul) content/browser/browser-menudragging.js (content/browser-menudragging.js) |