Merge mozilla-central to autoland. CLOSED TREE
[gecko.git] / toolkit / actors / AboutHttpsOnlyErrorParent.sys.mjs
blob3d4ed65daa5fb2a3755abbeb9f6cec01cd477fc5
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { HomePage } from "resource:///modules/HomePage.sys.mjs";
6 import { PrivateBrowsingUtils } from "resource://gre/modules/PrivateBrowsingUtils.sys.mjs";
8 export class AboutHttpsOnlyErrorParent extends JSWindowActorParent {
9   get browser() {
10     return this.browsingContext.top.embedderElement;
11   }
13   receiveMessage(aMessage) {
14     switch (aMessage.name) {
15       case "goBack":
16         this.goBackFromErrorPage(this.browser);
17         break;
18     }
19   }
21   goBackFromErrorPage(aBrowser) {
22     if (!aBrowser.canGoBack) {
23       // If the unsafe page is the first or the only one in history, go to the
24       // start page.
25       aBrowser.fixupAndLoadURIString(
26         this.getDefaultHomePage(aBrowser.ownerGlobal),
27         {
28           triggeringPrincipal:
29             Services.scriptSecurityManager.getSystemPrincipal(),
30         }
31       );
32     } else {
33       aBrowser.goBack();
34     }
35   }
37   getDefaultHomePage(win) {
38     if (PrivateBrowsingUtils.isWindowPrivate(win)) {
39       return win.BROWSER_NEW_TAB_URL || "about:blank";
40     }
41     let url = HomePage.getDefault();
42     // If url is a pipe-delimited set of pages, just take the first one.
43     if (url.includes("|")) {
44       url = url.split("|")[0];
45     }
46     return url;
47   }