9999999-port1881745-CONTRIB-about-redirector-jscomp2esmodule.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. # HG changeset patch
  2. # User Matt A. Tobin <email@mattatobin.com>
  3. # Date 1659988365 0
  4. Bug 9999999 - Port bug 1881745 to the suite.
  5. Bug 1881745 - Convert all registered components to ESM.
  6. Update suite AboutRedirector and change about: to about:version
  7. diff --git a/suite/base/content/utilityOverlay.js b/suite/base/content/utilityOverlay.js
  8. --- a/suite/base/content/utilityOverlay.js
  9. +++ b/suite/base/content/utilityOverlay.js
  10. @@ -593,17 +593,17 @@ function isRestricted( url )
  11. } catch (e) {
  12. return false;
  13. }
  14. }
  15. function goAbout(aProtocol)
  16. {
  17. var target;
  18. - var url = "about:" + (aProtocol || "");
  19. + var url = "about:version" + (aProtocol || "");
  20. var defaultAboutState = Services.prefs.getIntPref("browser.link.open_external");
  21. switch (defaultAboutState) {
  22. case Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW:
  23. target = "window";
  24. break;
  25. case Ci.nsIBrowserDOMWindow.OPEN_CURRENTWINDOW:
  26. target = "current";
  27. diff --git a/suite/components/AboutRedirector.sys.mjs b/suite/components/AboutRedirector.sys.mjs
  28. new file mode 100644
  29. --- /dev/null
  30. +++ b/suite/components/AboutRedirector.sys.mjs
  31. @@ -0,0 +1,121 @@
  32. +/* This Source Code Form is subject to the terms of the Mozilla Public
  33. + * License, v. 2.0. If a copy of the MPL was not distributed with this
  34. + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  35. +
  36. +export function AboutRedirector() {}
  37. +
  38. +AboutRedirector.prototype = {
  39. + QueryInterface: ChromeUtils.generateQI(["nsIAboutModule"]),
  40. +
  41. + // Each entry in the map has the key as the part after the "about:" and the
  42. + // value as a record with url and flags entries. Note that each addition here
  43. + // should be coupled with a corresponding addition in components.conf.
  44. + _redirMap: {
  45. + version: {
  46. + url: "chrome://communicator/content/about.xhtml",
  47. + flags:
  48. + Ci.nsIAboutModule.ALLOW_SCRIPT,
  49. + },
  50. + blocked: {
  51. + url: "chrome://communicator/content/blockedSite.xhtml",
  52. + flags:
  53. + Ci.nsIAboutModule.ALLOW_SCRIPT |
  54. + Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT,
  55. + },
  56. + data: {
  57. + url: "chrome://communicator/content/dataman/dataman.xhtml",
  58. + flags:
  59. + Ci.nsIAboutModule.ALLOW_SCRIPT,
  60. + },
  61. + feeds: {
  62. + url: "chrome://communicator/content/feeds/subscribe.xhtml",
  63. + flags:
  64. + Ci.nsIAboutModule.ALLOW_SCRIPT |
  65. + Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT,
  66. + },
  67. + life: {
  68. + url: "chrome://communicator/content/aboutLife.xhtml",
  69. + flags:
  70. + Ci.nsIAboutModule.ALLOW_SCRIPT |
  71. + Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT,
  72. + },
  73. + newserror: {
  74. + url: "chrome://messenger/content/newsError.xhtml",
  75. + flags:
  76. + Ci.nsIAboutModule.ALLOW_SCRIPT,
  77. + },
  78. + privatebrowsing: {
  79. + url: "chrome://communicator/content/aboutPrivateBrowsing.xhtml",
  80. + flags:
  81. + Ci.nsIAboutModule.ALLOW_SCRIPT,
  82. + },
  83. + rights: {
  84. + url: "chrome://branding/content/aboutRights.xhtml",
  85. + flags:
  86. + Ci.nsIAboutModule.ALLOW_SCRIPT |
  87. + Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT,
  88. + },
  89. + sessionrestore: {
  90. + url: "chrome://communicator/content/aboutSessionRestore.xhtml",
  91. + flags:
  92. + Ci.nsIAboutModule.ALLOW_SCRIPT,
  93. + },
  94. + profiling: {
  95. + url: "chrome://devtools/content/performance-new/aboutprofiling/index.xhtml",
  96. + flags:
  97. + Ci.nsIAboutModule.ALLOW_SCRIPT | Ci.nsIAboutModule.IS_SECURE_CHROME_UI,
  98. + },
  99. + },
  100. +
  101. + /**
  102. + * Gets the module name from the given URI.
  103. + */
  104. + _getModuleName(aURI) {
  105. + // Strip out the first ? or #, and anything following it
  106. + const name = /[^?#]+/.exec(aURI.pathQueryRef)[0];
  107. + return name.toLowerCase();
  108. + },
  109. +
  110. + getURIFlags(aURI) {
  111. + const name = this._getModuleName(aURI);
  112. + if (!(name in this._redirMap)) {
  113. + throw Components.Exception(`no about:${name}`, Cr.NS_ERROR_ILLEGAL_VALUE);
  114. + }
  115. + return this._redirMap[name].flags;
  116. + },
  117. +
  118. + newChannel(aURI, aLoadInfo) {
  119. + const name = this._getModuleName(aURI);
  120. + if (!(name in this._redirMap)) {
  121. + throw Components.Exception(`no about:${name}`, Cr.NS_ERROR_ILLEGAL_VALUE);
  122. + }
  123. +
  124. + const newURI = Services.io.newURI(this._redirMap[name].url);
  125. + const channel = Services.io.newChannelFromURIWithLoadInfo(
  126. + newURI,
  127. + aLoadInfo
  128. + );
  129. + channel.originalURI = aURI;
  130. +
  131. + if (
  132. + this._redirMap[name].flags &
  133. + Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT
  134. + ) {
  135. + const principal = Services.scriptSecurityManager.createContentPrincipal(
  136. + aURI,
  137. + {}
  138. + );
  139. + channel.owner = principal;
  140. + }
  141. +
  142. + return channel;
  143. + },
  144. +
  145. + getChromeURI(aURI) {
  146. + const name = this._getModuleName(aURI);
  147. + if (!(name in this._redirMap)) {
  148. + throw Components.Exception(`no about:${name}`, Cr.NS_ERROR_ILLEGAL_VALUE);
  149. + }
  150. + return Services.io.newURI(this._redirMap[name].url);
  151. + },
  152. +};
  153. diff --git a/suite/components/SuiteComponents.manifest b/suite/components/SuiteComponents.manifest
  154. --- a/suite/components/SuiteComponents.manifest
  155. +++ b/suite/components/SuiteComponents.manifest
  156. @@ -1,18 +1,7 @@
  157. -component {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f} nsAbout.js
  158. -contract @mozilla.org/network/protocol/about;1?what= {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
  159. -contract @mozilla.org/network/protocol/about;1?what=blocked {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
  160. -contract @mozilla.org/network/protocol/about;1?what=certerror {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
  161. -contract @mozilla.org/network/protocol/about;1?what=data {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
  162. -contract @mozilla.org/network/protocol/about;1?what=feeds {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
  163. -contract @mozilla.org/network/protocol/about;1?what=life {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
  164. -contract @mozilla.org/network/protocol/about;1?what=newserror {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
  165. -contract @mozilla.org/network/protocol/about;1?what=privatebrowsing {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
  166. -contract @mozilla.org/network/protocol/about;1?what=rights {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
  167. -contract @mozilla.org/network/protocol/about;1?what=sessionrestore {d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}
  168. component {22042bdb-56e4-47c6-8b12-fdfa859c05a9} nsGopherProtocolStubHandler.js
  169. contract @mozilla.org/network/protocol;1?name=gopher {22042bdb-56e4-47c6-8b12-fdfa859c05a9}
  170. component {bbbbe845-5a1b-40ee-813c-f84b8faaa07c} nsSuiteGlue.js
  171. contract @mozilla.org/suite/suiteglue;1 {bbbbe845-5a1b-40ee-813c-f84b8faaa07c}
  172. category app-startup nsSuiteGlue service,@mozilla.org/suite/suiteglue;1
  173. component {9d4c845d-3f09-402a-b66d-50f291d7d50f} nsSuiteGlue.js
  174. contract @mozilla.org/content-permission/prompt;1 {9d4c845d-3f09-402a-b66d-50f291d7d50f}
  175. diff --git a/suite/components/components.conf b/suite/components/components.conf
  176. new file mode 100644
  177. --- /dev/null
  178. +++ b/suite/components/components.conf
  179. @@ -0,0 +1,25 @@
  180. +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
  181. +# vim: set filetype=python:
  182. +# This Source Code Form is subject to the terms of the Mozilla Public
  183. +# License, v. 2.0. If a copy of the MPL was not distributed with this
  184. +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
  185. +
  186. +Classes = [
  187. + {
  188. + 'cid': '{d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}',
  189. + 'contract_ids': [
  190. + '@mozilla.org/network/protocol/about;1?what=version',
  191. + '@mozilla.org/network/protocol/about;1?what=blocked',
  192. + '@mozilla.org/network/protocol/about;1?what=certerror',
  193. + '@mozilla.org/network/protocol/about;1?what=data',
  194. + '@mozilla.org/network/protocol/about;1?what=feeds',
  195. + '@mozilla.org/network/protocol/about;1?what=life',
  196. + '@mozilla.org/network/protocol/about;1?what=newserror',
  197. + '@mozilla.org/network/protocol/about;1?what=privatebrowsing',
  198. + '@mozilla.org/network/protocol/about;1?what=rights',
  199. + '@mozilla.org/network/protocol/about;1?what=sessionrestore',
  200. + ],
  201. + 'esModule': 'resource://gre/modules/AboutRedirector.sys.mjs',
  202. + 'constructor': 'AboutRedirector',
  203. + },
  204. +]
  205. diff --git a/suite/components/moz.build b/suite/components/moz.build
  206. --- a/suite/components/moz.build
  207. +++ b/suite/components/moz.build
  208. @@ -41,13 +41,20 @@ MOCHITEST_CHROME_MANIFESTS += [
  209. XPIDL_SOURCES += [
  210. "nsISuiteGlue.idl",
  211. ]
  212. XPIDL_MODULE = "suite-components"
  213. EXTRA_COMPONENTS += [
  214. - "nsAbout.js",
  215. "nsGopherProtocolStubHandler.js",
  216. "nsSuiteGlue.js",
  217. "SuiteComponents.manifest",
  218. ]
  219. +
  220. +EXTRA_JS_MODULES += [
  221. + "AboutRedirector.sys.mjs",
  222. +]
  223. +
  224. +XPCOM_MANIFESTS += [
  225. + 'components.conf',
  226. +]
  227. \ No newline at end of file
  228. diff --git a/suite/components/nsAbout.js b/suite/components/nsAbout.js
  229. deleted file mode 100644
  230. --- a/suite/components/nsAbout.js
  231. +++ /dev/null
  232. @@ -1,75 +0,0 @@
  233. -/* This Source Code Form is subject to the terms of the Mozilla Public
  234. - * License, v. 2.0. If a copy of the MPL was not distributed with this
  235. - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  236. -
  237. -var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
  238. -
  239. -const SCRIPT = Ci.nsIAboutModule.ALLOW_SCRIPT;
  240. -const UNTRUSTED = Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT;
  241. -const HIDE = Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT;
  242. -const INDEXEDDB = Ci.nsIAboutModule.ENABLE_INDEXED_DB;
  243. -
  244. -function About() { }
  245. -About.prototype = {
  246. - Flags: SCRIPT,
  247. - URI: "chrome://communicator/content/about.xhtml",
  248. - blockedFlags: SCRIPT | UNTRUSTED | HIDE,
  249. - blockedURI: "chrome://communicator/content/blockedSite.xhtml",
  250. - certerrorFlags: SCRIPT | UNTRUSTED | HIDE,
  251. - certerrorURI: "chrome://communicator/content/certError.xhtml",
  252. - dataFlags: SCRIPT,
  253. - dataURI: "chrome://communicator/content/dataman/dataman.xul",
  254. - feedsFlags: SCRIPT | UNTRUSTED | HIDE,
  255. - feedsURI: "chrome://communicator/content/feeds/subscribe.xhtml",
  256. - lifeFlags: SCRIPT | UNTRUSTED | HIDE,
  257. - lifeURI: "chrome://communicator/content/aboutLife.xhtml",
  258. - newserrorFlags: SCRIPT | HIDE,
  259. - newserrorURI: "chrome://messenger/content/newsError.xhtml",
  260. - privatebrowsingFlags: SCRIPT,
  261. - privatebrowsingURI: "chrome://communicator/content/aboutPrivateBrowsing.xul",
  262. - rightsFlags: SCRIPT | UNTRUSTED,
  263. - rightsURI: "chrome://branding/content/aboutRights.xhtml",
  264. - sessionrestoreFlags: SCRIPT | HIDE,
  265. - sessionrestoreURI: "chrome://communicator/content/aboutSessionRestore.xhtml",
  266. - // synctabsFlags: SCRIPT,
  267. - // synctabsURI: "chrome://communicator/content/aboutSyncTabs.xul",
  268. -
  269. - classID: Components.ID("{d54f2c89-8fd6-4eeb-a7a4-51d4dcdf460f}"),
  270. - QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
  271. -
  272. - getModule: function(aURI) {
  273. - return aURI.pathQueryRef.replace(/-|\W.*$/g, "").toLowerCase();
  274. - },
  275. -
  276. - getURIFlags: function(aURI) {
  277. - return this[this.getModule(aURI) + "Flags"];
  278. - },
  279. -
  280. - newChannel: function(aURI, aLoadInfo) {
  281. - let module = this.getModule(aURI);
  282. - let newURI = Services.io.newURI(this[module + "URI"]);
  283. -
  284. - // We want a happy family which is always providing a loadInfo object.
  285. - if (!aLoadInfo) {
  286. - // Write out an error so that we have a stack and can fix the caller.
  287. - Cu.reportError('aLoadInfo was not provided in nsAbout.newChannel!');
  288. - }
  289. -
  290. - let channel = aLoadInfo ?
  291. - Services.io.newChannelFromURIWithLoadInfo(newURI, aLoadInfo) :
  292. - Services.io.newChannelFromURI(newURI, null,
  293. - Services.scriptSecurityManager.getSystemPrincipal(),
  294. - null,
  295. - Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
  296. - Ci.nsIContentPolicy.TYPE_OTHER);
  297. -
  298. - channel.originalURI = aURI;
  299. - if (this[module + "Flags"] & UNTRUSTED) {
  300. - let principal = Services.scriptSecurityManager.createCodebasePrincipal(aURI, {});
  301. - channel.owner = principal;
  302. - }
  303. - return channel;
  304. - },
  305. -};
  306. -
  307. -var NSGetFactory = XPCOMUtils.generateNSGetFactory([About]);
  308. diff --git a/suite/installer/package-manifest.in b/suite/installer/package-manifest.in
  309. --- a/suite/installer/package-manifest.in
  310. +++ b/suite/installer/package-manifest.in
  311. @@ -157,17 +157,16 @@
  312. @RESPATH@/components/SuiteFeeds.manifest
  313. @RESPATH@/components/SuiteSidebar.manifest
  314. ; JavaScript components
  315. @RESPATH@/components/cryptoComponents.manifest
  316. @RESPATH@/components/FeedConverter.js
  317. @RESPATH@/components/FeedWriter.js
  318. @RESPATH@/components/jsconsole-clhandler.js
  319. @RESPATH@/components/jsconsole-clhandler.manifest
  320. -@RESPATH@/components/nsAbout.js
  321. @RESPATH@/components/nsBrowserContentHandler.js
  322. @RESPATH@/components/nsComposerCmdLineHandler.js
  323. @RESPATH@/components/nsComposerCmdLineHandler.manifest
  324. @RESPATH@/components/nsGopherProtocolStubHandler.js
  325. @RESPATH@/components/nsPlacesAutoComplete.js
  326. @RESPATH@/components/nsPlacesAutoComplete.manifest
  327. @RESPATH@/components/nsSessionStartup.js
  328. @RESPATH@/components/nsSessionStartup.manifest