From 368212c1c0a265aa04722ef8ec7aa8d8b37a3f55 Mon Sep 17 00:00:00 2001 From: Panos Astithas Date: Thu, 5 Nov 2015 17:15:54 +0200 Subject: [PATCH] Make 'Go Back' button work even when there is nothing to go back to (bug 1221084); r=paolo --- .../aboutcerterror/aboutCertError.xhtml | 12 +----- browser/base/content/browser.js | 43 ++++++++++++++----- .../test/general/browser_aboutCertError.js | 8 ++++ .../manager/ssl/nsISecurityUITelemetry.idl | 4 +- 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/browser/base/content/aboutcerterror/aboutCertError.xhtml b/browser/base/content/aboutcerterror/aboutCertError.xhtml index 30cbe090e195..262b170d51e6 100644 --- a/browser/base/content/aboutcerterror/aboutCertError.xhtml +++ b/browser/base/content/aboutcerterror/aboutCertError.xhtml @@ -51,16 +51,6 @@ return decodeURIComponent(matches[1]); } - function goBack(buttonEl) - { - if (history.length > 1) { - history.back(); - } else { - location.href = "about:home"; - } - buttonEl.disabled = true; - } - function toggleVisibility(id) { var node = document.getElementById(id); @@ -213,7 +203,7 @@
- +
diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 5c7822ea72a7..2b18f82f13ef 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2982,20 +2982,14 @@ var BrowserOnClick = { } break; - case "getMeOutOfHereButton": + case "returnButton": if (isTopFrame) { secHistogram.add(Ci.nsISecurityUITelemetry.WARNING_BAD_CERT_TOP_GET_ME_OUT_OF_HERE); } - getMeOutOfHere(); + goBackFromErrorPage(); break; - case "technicalContent": - if (isTopFrame) { - secHistogram.add(Ci.nsISecurityUITelemetry.WARNING_BAD_CERT_TOP_TECHNICAL_DETAILS); - } - break; - - case "expertContent": + case "advancedButton": if (isTopFrame) { secHistogram.add(Ci.nsISecurityUITelemetry.WARNING_BAD_CERT_TOP_UNDERSTAND_RISKS); } @@ -3134,6 +3128,35 @@ var BrowserOnClick = { * when their own homepage is infected, we can get them somewhere safe. */ function getMeOutOfHere() { + gBrowser.loadURI(getDefaultHomePage()); +} + +/** + * Re-direct the browser to the previous page or a known-safe page if no + * previous page is found in history. This function is used when the user + * browses to a secure page with certificate issues and is presented with + * about:certerror. The "Go Back" button should take the user to the previous + * or a default start page so that even when their own homepage is on a server + * that has certificate errors, we can get them somewhere safe. + */ +function goBackFromErrorPage() { + const ss = Cc["@mozilla.org/browser/sessionstore;1"]. + getService(Ci.nsISessionStore); + let state = JSON.parse(ss.getTabState(gBrowser.selectedTab)); + if (state.index == 1) { + // If the unsafe page is the first or the only one in history, go to the + // start page. + gBrowser.loadURI(getDefaultHomePage()); + } else { + BrowserBack(); + } +} + +/** + * Return the default start page for the cases when the user's own homepage is + * infected, so we can get them somewhere safe. + */ +function getDefaultHomePage() { // Get the start page from the *default* pref branch, not the user's var prefs = Services.prefs.getDefaultBranch(null); var url = BROWSER_NEW_TAB_URL; @@ -3146,7 +3169,7 @@ function getMeOutOfHere() { } catch(e) { Components.utils.reportError("Couldn't get homepage pref: " + e); } - gBrowser.loadURI(url); + return url; } function BrowserFullScreen() diff --git a/browser/base/content/test/general/browser_aboutCertError.js b/browser/base/content/test/general/browser_aboutCertError.js index 875db2eea1ca..f3b6482a4280 100644 --- a/browser/base/content/test/general/browser_aboutCertError.js +++ b/browser/base/content/test/general/browser_aboutCertError.js @@ -7,6 +7,8 @@ const GOOD_PAGE = "https://example.com/"; const BAD_CERT = "https://expired.example.com/"; const BAD_STS_CERT = "https://badchain.include-subdomains.pinning.example.com:443"; +const {TabStateFlusher} = Cu.import("resource:///modules/sessionstore/TabStateFlusher.jsm", {}); +const ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore); add_task(function* checkReturnToAboutHome() { info("Loading a bad cert page directly and making sure 'return to previous page' goes to about:home"); @@ -24,6 +26,12 @@ add_task(function* checkReturnToAboutHome() { is(browser.webNavigation.canGoBack, false, "!webNavigation.canGoBack"); is(browser.webNavigation.canGoForward, false, "!webNavigation.canGoForward"); + // Populate the shistory entries manually, since it happens asynchronously + // and the following tests will be too soon otherwise. + yield TabStateFlusher.flush(browser); + let {entries} = JSON.parse(ss.getTabState(tab)); + is(entries.length, 1, "there is one shistory entry"); + info("Clicking the go back button on about:certerror"); let pageshowPromise = promiseWaitForEvent(browser, "pageshow"); yield ContentTask.spawn(browser, null, function* () { diff --git a/security/manager/ssl/nsISecurityUITelemetry.idl b/security/manager/ssl/nsISecurityUITelemetry.idl index c4b81d3f985c..bfaa81223cd4 100644 --- a/security/manager/ssl/nsISecurityUITelemetry.idl +++ b/security/manager/ssl/nsISecurityUITelemetry.idl @@ -6,7 +6,7 @@ #include "nsISupports.idl" -[scriptable, uuid(56e190a0-2802-4fc4-b09f-bcda357035c3)] +[scriptable, uuid(5d1acf82-223a-46fb-a8f3-a1b16e2ceb04)] interface nsISecurityUITelemetry : nsISupports { @@ -130,7 +130,7 @@ const uint32_t WARNING_BAD_CERT_TOP_CLICK_VIEW_CERT = 71; const uint32_t WARNING_BAD_CERT_TOP_DONT_REMEMBER_EXCEPTION = 72; const uint32_t WARNING_BAD_CERT_TOP_GET_ME_OUT_OF_HERE = 73; const uint32_t WARNING_BAD_CERT_TOP_UNDERSTAND_RISKS = 74; -const uint32_t WARNING_BAD_CERT_TOP_TECHNICAL_DETAILS = 75; +// removed WARNING_BAD_CERT_TOP_TECHNICAL_DETAILS = 75; const uint32_t WARNING_BAD_CERT_TOP_ADD_EXCEPTION_BASE = 76; const uint32_t WARNING_BAD_CERT_TOP_ADD_EXCEPTION_FLAG_UNTRUSTED = 1;