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 { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
7 import { RemotePageChild } from "resource://gre/actors/RemotePageChild.sys.mjs";
11 XPCOMUtils.defineLazyServiceGetter(
13 "@mozilla.org/network/serialization-helper;1",
14 "nsISerializationHelper"
17 export class AboutHttpsOnlyErrorChild extends RemotePageChild {
21 // If you add a new function, remember to add it to RemotePageAccessManager.sys.mjs
22 // to allow content-privileged about:httpsonlyerror to use it.
23 const exportableFunctions = [
24 "RPMTryPingSecureWWWLink",
25 "RPMOpenSecureWWWLink",
27 this.exportFunctions(exportableFunctions);
30 RPMTryPingSecureWWWLink() {
31 // try if the page can be reached with www prefix
32 // if so send message to the parent to send message to the error page to display
33 // suggestion button for www
35 const httpsOnlySuggestionPref = Services.prefs.getBoolPref(
36 "dom.security.https_only_mode_error_page_user_suggestions"
39 // only check if pref is true otherwise return
40 if (!httpsOnlySuggestionPref) {
44 // get the host url without the path with www in front
45 const wwwURL = "https://www." + this.contentWindow.location.host;
51 if (data.status === 200) {
52 this.contentWindow.dispatchEvent(
53 new this.contentWindow.CustomEvent("pingSecureWWWLinkSuccess")
58 dump("No secure www suggestion possible for " + wwwURL);
62 RPMOpenSecureWWWLink() {
63 // if user wants to visit suggested secure www page: visit page with www prefix and delete errorpage from history
64 const context = this.manager.browsingContext;
65 const docShell = context.docShell;
66 const httpChannel = docShell.failedChannel.QueryInterface(
69 const webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
70 const triggeringPrincipal =
71 docShell.failedChannel.loadInfo.triggeringPrincipal;
72 const oldURI = httpChannel.URI;
73 const newWWWURI = oldURI
75 .setHost("www." + oldURI.host)
78 webNav.loadURI(newWWWURI, {
80 loadFlags: Ci.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY,