Browse Source

AboutRedirector

Bill Gianopoulos 1 month ago
parent
commit
933d59e72b

+ 332 - 0
comm-central/patches/TOP-CONTRIB-about-redirector-jscomp2esmodule.patch

@@ -0,0 +1,332 @@
+# HG changeset patch
+# User Matt A. Tobin <email@mattatobin.com>
+# Date 1659988365 0
+9999999 - Update suite AboutRedirector and change about: to about:version
+
+diff --git a/suite/base/content/utilityOverlay.js b/suite/base/content/utilityOverlay.js
+--- a/suite/base/content/utilityOverlay.js
++++ b/suite/base/content/utilityOverlay.js
+@@ -593,17 +593,17 @@ function isRestricted( url )
+   } catch (e) {
+     return false;
+   }
+ }
+ 
+ function goAbout(aProtocol)
+ {
+   var target;
+-  var url = "about:" + (aProtocol || "");
++  var url = "about:version" + (aProtocol || "");
+   var defaultAboutState = Services.prefs.getIntPref("browser.link.open_external");
+ 
+   switch (defaultAboutState) {
+   case Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW:
+     target = "window";
+     break;
+   case Ci.nsIBrowserDOMWindow.OPEN_CURRENTWINDOW:
+     target = "current";
+diff --git a/suite/components/AboutRedirector.sys.mjs b/suite/components/AboutRedirector.sys.mjs
+new file mode 100644
+--- /dev/null
++++ b/suite/components/AboutRedirector.sys.mjs
+@@ -0,0 +1,121 @@
++/* 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/. */
++
++export function AboutRedirector() {}
++
++AboutRedirector.prototype = {
++  QueryInterface: ChromeUtils.generateQI(["nsIAboutModule"]),
++
++  // Each entry in the map has the key as the part after the "about:" and the
++  // value as a record with url and flags entries. Note that each addition here
++  // should be coupled with a corresponding addition in components.conf.
++  _redirMap: {
++    version: {
++      url: "chrome://communicator/content/about.xhtml",
++      flags:
++        Ci.nsIAboutModule.ALLOW_SCRIPT,
++    },
++    blocked: {
++      url: "chrome://communicator/content/blockedSite.xhtml",
++      flags:
++        Ci.nsIAboutModule.ALLOW_SCRIPT |
++        Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT,
++    },
++    data: {
++      url: "chrome://communicator/content/dataman/dataman.xhtml",
++      flags:
++        Ci.nsIAboutModule.ALLOW_SCRIPT,
++    },
++    feeds: {
++      url: "chrome://communicator/content/feeds/subscribe.xhtml",
++      flags:
++        Ci.nsIAboutModule.ALLOW_SCRIPT |
++        Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT,
++    },
++    life: {
++      url: "chrome://communicator/content/aboutLife.xhtml",
++      flags:
++        Ci.nsIAboutModule.ALLOW_SCRIPT |
++        Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT,
++    },
++    newserror: {
++      url: "chrome://messenger/content/newsError.xhtml",
++      flags:
++        Ci.nsIAboutModule.ALLOW_SCRIPT,
++    },
++    privatebrowsing: {
++      url: "chrome://communicator/content/aboutPrivateBrowsing.xhtml",
++      flags:
++        Ci.nsIAboutModule.ALLOW_SCRIPT,
++    },
++    rights: {
++      url: "chrome://branding/content/aboutRights.xhtml",
++      flags:
++        Ci.nsIAboutModule.ALLOW_SCRIPT |
++        Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT,
++    },
++    sessionrestore: {
++      url: "chrome://communicator/content/aboutSessionRestore.xhtml",
++      flags:
++        Ci.nsIAboutModule.ALLOW_SCRIPT,
++    },
++    profiling: {
++      url: "chrome://devtools/content/performance-new/aboutprofiling/index.xhtml",
++      flags:
++        Ci.nsIAboutModule.ALLOW_SCRIPT | Ci.nsIAboutModule.IS_SECURE_CHROME_UI,
++    },
++  },
++
++ /**
++   * Gets the module name from the given URI.
++   */
++  _getModuleName(aURI) {
++    // Strip out the first ? or #, and anything following it
++    const name = /[^?#]+/.exec(aURI.pathQueryRef)[0];
++    return name.toLowerCase();
++  },
++
++  getURIFlags(aURI) {
++    const name = this._getModuleName(aURI);
++    if (!(name in this._redirMap)) {
++      throw Components.Exception(`no about:${name}`, Cr.NS_ERROR_ILLEGAL_VALUE);
++    }
++    return this._redirMap[name].flags;
++  },
++
++  newChannel(aURI, aLoadInfo) {
++    const name = this._getModuleName(aURI);
++    if (!(name in this._redirMap)) {
++      throw Components.Exception(`no about:${name}`, Cr.NS_ERROR_ILLEGAL_VALUE);
++    }
++
++    const newURI = Services.io.newURI(this._redirMap[name].url);
++    const channel = Services.io.newChannelFromURIWithLoadInfo(
++      newURI,
++      aLoadInfo
++    );
++    channel.originalURI = aURI;
++
++    if (
++      this._redirMap[name].flags &
++      Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT
++    ) {
++      const principal = Services.scriptSecurityManager.createContentPrincipal(
++        aURI,
++        {}
++      );
++      channel.owner = principal;
++    }
++
++    return channel;
++  },
++
++  getChromeURI(aURI) {
++    const name = this._getModuleName(aURI);
++    if (!(name in this._redirMap)) {
++      throw Components.Exception(`no about:${name}`, Cr.NS_ERROR_ILLEGAL_VALUE);
++    }
++    return Services.io.newURI(this._redirMap[name].url);
++  },
++};
+diff --git a/suite/components/SuiteComponents.manifest b/suite/components/SuiteComponents.manifest
+--- a/suite/components/SuiteComponents.manifest
++++ b/suite/components/SuiteComponents.manifest
+@@ -1,18 +1,7 @@
+-component {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f} nsAbout.js
+-contract @mozilla.org/network/protocol/about;1?what= {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
+-contract @mozilla.org/network/protocol/about;1?what=blocked {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
+-contract @mozilla.org/network/protocol/about;1?what=certerror {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
+-contract @mozilla.org/network/protocol/about;1?what=data {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
+-contract @mozilla.org/network/protocol/about;1?what=feeds {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
+-contract @mozilla.org/network/protocol/about;1?what=life {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
+-contract @mozilla.org/network/protocol/about;1?what=newserror {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
+-contract @mozilla.org/network/protocol/about;1?what=privatebrowsing {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
+-contract @mozilla.org/network/protocol/about;1?what=rights {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
+-contract @mozilla.org/network/protocol/about;1?what=sessionrestore {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
+ component {22042bdb-56e4-47c6-8b12-fdfa859c05a9} nsGopherProtocolStubHandler.js
+ contract @mozilla.org/network/protocol;1?name=gopher {22042bdb-56e4-47c6-8b12-fdfa859c05a9}
+ component {bbbbe845-5a1b-40ee-813c-f84b8faaa07c} nsSuiteGlue.js
+ contract @mozilla.org/suite/suiteglue;1 {bbbbe845-5a1b-40ee-813c-f84b8faaa07c}
+ category app-startup nsSuiteGlue service,@mozilla.org/suite/suiteglue;1
+ component {9d4c845d-3f09-402a-b66d-50f291d7d50f} nsSuiteGlue.js
+ contract @mozilla.org/content-permission/prompt;1 {9d4c845d-3f09-402a-b66d-50f291d7d50f}
+diff --git a/suite/components/components.conf b/suite/components/components.conf
+new file mode 100644
+--- /dev/null
++++ b/suite/components/components.conf
+@@ -0,0 +1,25 @@
++# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
++# vim: set filetype=python:
++# 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/.
++
++Classes = [
++  {
++    'cid': '{d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}',
++    'contract_ids': [
++      '@mozilla.org/network/protocol/about;1?what=version',
++      '@mozilla.org/network/protocol/about;1?what=blocked',
++      '@mozilla.org/network/protocol/about;1?what=certerror',
++      '@mozilla.org/network/protocol/about;1?what=data',
++      '@mozilla.org/network/protocol/about;1?what=feeds',
++      '@mozilla.org/network/protocol/about;1?what=life',
++      '@mozilla.org/network/protocol/about;1?what=newserror',
++      '@mozilla.org/network/protocol/about;1?what=privatebrowsing',
++      '@mozilla.org/network/protocol/about;1?what=rights',
++      '@mozilla.org/network/protocol/about;1?what=sessionrestore',
++    ],
++    'esModule': 'resource://gre/modules/AboutRedirector.sys.mjs',
++    'constructor': 'AboutRedirector',
++  },
++]
+diff --git a/suite/components/moz.build b/suite/components/moz.build
+--- a/suite/components/moz.build
++++ b/suite/components/moz.build
+@@ -41,13 +41,20 @@ MOCHITEST_CHROME_MANIFESTS += [
+ 
+ XPIDL_SOURCES += [
+     "nsISuiteGlue.idl",
+ ]
+ 
+ XPIDL_MODULE = "suite-components"
+ 
+ EXTRA_COMPONENTS += [
+-    "nsAbout.js",
+     "nsGopherProtocolStubHandler.js",
+     "nsSuiteGlue.js",
+     "SuiteComponents.manifest",
+ ]
++
++EXTRA_JS_MODULES += [
++    "AboutRedirector.sys.mjs",
++]
++
++XPCOM_MANIFESTS += [
++    'components.conf',
++]
+\ No newline at end of file
+diff --git a/suite/components/nsAbout.js b/suite/components/nsAbout.js
+deleted file mode 100644
+--- a/suite/components/nsAbout.js
++++ /dev/null
+@@ -1,75 +0,0 @@
+-/* 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/. */
+-
+-var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+-
+-const SCRIPT = Ci.nsIAboutModule.ALLOW_SCRIPT;
+-const UNTRUSTED = Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT;
+-const HIDE = Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT;
+-const INDEXEDDB = Ci.nsIAboutModule.ENABLE_INDEXED_DB;
+-
+-function About() { }
+-About.prototype = {
+-  Flags: SCRIPT,
+-  URI: "chrome://communicator/content/about.xhtml",
+-  blockedFlags: SCRIPT | UNTRUSTED | HIDE,
+-  blockedURI: "chrome://communicator/content/blockedSite.xhtml",
+-  certerrorFlags: SCRIPT | UNTRUSTED | HIDE,
+-  certerrorURI: "chrome://communicator/content/certError.xhtml",
+-  dataFlags: SCRIPT,
+-  dataURI: "chrome://communicator/content/dataman/dataman.xhtml",
+-  feedsFlags: SCRIPT | UNTRUSTED | HIDE,
+-  feedsURI: "chrome://communicator/content/feeds/subscribe.xhtml",
+-  lifeFlags: SCRIPT | UNTRUSTED | HIDE,
+-  lifeURI: "chrome://communicator/content/aboutLife.xhtml",
+-  newserrorFlags: SCRIPT | HIDE,
+-  newserrorURI: "chrome://messenger/content/newsError.xhtml",
+-  privatebrowsingFlags: SCRIPT,
+-  privatebrowsingURI: "chrome://communicator/content/aboutPrivateBrowsing.xhtml",
+-  rightsFlags: SCRIPT | UNTRUSTED,
+-  rightsURI: "chrome://branding/content/aboutRights.xhtml",
+-  sessionrestoreFlags: SCRIPT | HIDE,
+-  sessionrestoreURI: "chrome://communicator/content/aboutSessionRestore.xhtml",
+-  // synctabsFlags: SCRIPT,
+-  // synctabsURI: "chrome://communicator/content/aboutSyncTabs.xhtml",
+-
+-  classID: Components.ID("{d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}"),
+-  QueryInterface: ChromeUtils.generateQI([Ci.nsIAboutModule]),
+-
+-  getModule: function(aURI) {
+-    return aURI.pathQueryRef.replace(/-|\W.*$/g, "").toLowerCase();
+-  },
+-
+-  getURIFlags: function(aURI) {
+-    return this[this.getModule(aURI) + "Flags"];
+-  },
+-
+-  newChannel: function(aURI, aLoadInfo) {
+-    let module = this.getModule(aURI);
+-    let newURI = Services.io.newURI(this[module + "URI"]);
+-
+-    // We want a happy family which is always providing a loadInfo object.
+-    if (!aLoadInfo) {
+-      // Write out an error so that we have a stack and can fix the caller.
+-      Cu.reportError('aLoadInfo was not provided in nsAbout.newChannel!');
+-    }
+-
+-    let channel = aLoadInfo ?
+-                  Services.io.newChannelFromURIWithLoadInfo(newURI, aLoadInfo) :
+-                  Services.io.newChannelFromURI(newURI, null,
+-                                                Services.scriptSecurityManager.getSystemPrincipal(),
+-                                                null,
+-                                                Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
+-                                                Ci.nsIContentPolicy.TYPE_OTHER);
+-
+-    channel.originalURI = aURI;
+-    if (this[module + "Flags"] & UNTRUSTED) {
+-      let principal = Services.scriptSecurityManager.createCodebasePrincipal(aURI, {});
+-      channel.owner = principal;
+-    }
+-    return channel;
+-  },
+-};
+-
+-var NSGetFactory = XPCOMUtils.generateNSGetFactory([About]);
+diff --git a/suite/installer/package-manifest.in b/suite/installer/package-manifest.in
+--- a/suite/installer/package-manifest.in
++++ b/suite/installer/package-manifest.in
+@@ -157,17 +157,16 @@
+ @RESPATH@/components/SuiteFeeds.manifest
+ @RESPATH@/components/SuiteSidebar.manifest
+ ; JavaScript components
+ @RESPATH@/components/cryptoComponents.manifest
+ @RESPATH@/components/FeedConverter.js
+ @RESPATH@/components/FeedWriter.js
+ @RESPATH@/components/jsconsole-clhandler.js
+ @RESPATH@/components/jsconsole-clhandler.manifest
+-@RESPATH@/components/nsAbout.js
+ @RESPATH@/components/nsBrowserContentHandler.js
+ @RESPATH@/components/nsComposerCmdLineHandler.js
+ @RESPATH@/components/nsComposerCmdLineHandler.manifest
+ @RESPATH@/components/nsGopherProtocolStubHandler.js
+ @RESPATH@/components/nsPlacesAutoComplete.js
+ @RESPATH@/components/nsPlacesAutoComplete.manifest
+ @RESPATH@/components/nsSessionStartup.js
+ @RESPATH@/components/nsSessionStartup.manifest

+ 1 - 0
comm-central/patches/series

@@ -4,6 +4,7 @@
 9999999-port1903050-suite-bustage.patch
 9999999-port1860654-suite-bustage.patch
 9999999-port1908725-suite-bustage.patch
+TOP-CONTRIB-about-redirector-jscomp2esmodule.patch
 TOP-1642188-remove-nsDOMIEvent-cc.patch
 TOP-1614671-port1456035-4-and-5-61a1-cc.patch
 TOP-1611647-1-rename-xul-suite.patch