Bug 624150 - Generalize about:rights code into an about: redirector. r=Standard8
authorSiddharth Agarwal <sid.bugzilla@gmail.com>
Tue, 11 Jan 2011 01:16:43 +0530
changeset 6928 62d072900e475e089bc9c941dc8cde6f747edfe1
parent 6927 3015fb52fbe9b07d21e697da98e7ed70a4506a01
child 6929 57a01a6867f86889d3130ca976c1920ef840b9ae
push idunknown
push userunknown
push dateunknown
reviewersStandard8
bugs624150
Bug 624150 - Generalize about:rights code into an about: redirector. r=Standard8
mail/components/Makefile.in
mail/components/aboutRedirector.js
mail/components/aboutRights.js
mail/components/mailComponents.manifest
mail/installer/package-manifest.in
mail/installer/removed-files.in
--- a/mail/components/Makefile.in
+++ b/mail/components/Makefile.in
@@ -54,17 +54,17 @@ ifdef MOZ_SAFE_BROWSING
 DIRS += phishing 
 endif
 
 DIRS += build
 
 EXTRA_COMPONENTS = \
 	nsMailDefaultHandler.js \
 	mailContentHandler.js \
-	aboutRights.js \
+	aboutRedirector.js \
 	mailComponents.manifest \
 	$(NULL)
 
 EXTRA_JS_MODULES = \
   appIdleManager.js \
   $(NULL)
 
 
rename from mail/components/aboutRights.js
rename to mail/components/aboutRedirector.js
--- a/mail/components/aboutRights.js
+++ b/mail/components/aboutRedirector.js
@@ -16,16 +16,17 @@
  * The Initial Developer of the Original Code is Mozilla Foundation.
  * Portions created by the Initial Developer are Copyright (C) 2008
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Ryan Flint <rflint@mozilla.com>
  *   Justin Dolske <dolske@mozilla.com>
  *   Mark Banner <bugzilla@standard8.plus.com>
+ *   Siddharth Agarwal <sid.bugzilla@gmail.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -34,39 +35,60 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
 
-function AboutRights() {}
-AboutRights.prototype = {
-  classDescription: "about:rights",
+function AboutRedirector() {}
+AboutRedirector.prototype = {
+  classDescription: "Mail about: Redirector",
   classID: Components.ID("{8cc51368-6aa0-43e8-b762-bde9b9fd828c}"),
   QueryInterface: XPCOMUtils.generateQI([Ci.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.
+  _redirMap: {
+    "rights": {url: "chrome://messenger/content/aboutRights.xhtml",
+               flags: (Ci.nsIAboutModule.ALLOW_SCRIPT |
+                       Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT)},
+  },
+
+  /**
+   * Gets the module name from the given URI.
+   */
+  _getModuleName: function AboutRedirector__getModuleName(aURI) {
+    // Strip out the first ? or #, and anything following it
+    let name = (/[^?#]+/.exec(aURI.path))[0];
+    return name.toLowerCase();
+  },
+
   getURIFlags: function(aURI) {
-    return (Ci.nsIAboutModule.ALLOW_SCRIPT |
-            Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT);
+    let name = this._getModuleName(aURI);
+    if (!(name in this._redirMap))
+      throw Components.results.NS_ERROR_ILLEGAL_VALUE;
+    return this._redirMap[name].flags;
   },
 
   newChannel: function(aURI) {
-    var ios = Cc["@mozilla.org/network/io-service;1"].
-              getService(Ci.nsIIOService);
+    let name = this._getModuleName(aURI);
+    if (!(name in this._redirMap))
+      throw Components.results.NS_ERROR_ILLEGAL_VALUE;
 
-    var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].
-                 getService(Ci.nsIScriptSecurityManager);
+    let channel = Services.io.newChannel(this._redirMap[name].url, null, null);
+    channel.originalURI = aURI;
 
-    var channel = ios.newChannel("chrome://messenger/content/aboutRights.xhtml",
-                                 null, null);
-    var principal = secMan.getCodebasePrincipal(aURI);
-
-    channel.originalURI = aURI;
-    channel.owner = principal;
+    if (this._redirMap[name].flags & Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT) {
+      let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"]
+                     .getService(Ci.nsIScriptSecurityManager);
+      let principal = secMan.getCodebasePrincipal(aURI);
+      channel.owner = principal;
+    }
 
     return channel;
   }
 };
 
-const NSGetFactory = XPCOMUtils.generateNSGetFactory([AboutRights]);
+const NSGetFactory = XPCOMUtils.generateNSGetFactory([AboutRedirector]);
--- a/mail/components/mailComponents.manifest
+++ b/mail/components/mailComponents.manifest
@@ -1,9 +1,9 @@
-component {8cc51368-6aa0-43e8-b762-bde9b9fd828c} aboutRights.js
+component {8cc51368-6aa0-43e8-b762-bde9b9fd828c} aboutRedirector.js
 contract @mozilla.org/network/protocol/about;1?what=rights {8cc51368-6aa0-43e8-b762-bde9b9fd828c}
 
 component {44346520-c5d2-44e5-a1ec-034e04d7fac4} nsMailDefaultHandler.js
 contract @mozilla.org/mail/clh;1 {44346520-c5d2-44e5-a1ec-034e04d7fac4}
 category command-line-handler x-default @mozilla.org/mail/clh;1
 category command-line-validator b-default @mozilla.org/mail/clh;1
 
 component {1c73f03a-b817-4640-b984-18c3478a9ae3} mailContentHandler.js
--- a/mail/installer/package-manifest.in
+++ b/mail/installer/package-manifest.in
@@ -108,17 +108,17 @@
 @BINPATH@/defaults/messenger/mailViews.dat
 @BINPATH@/defaults/profile/localstore.rdf
 @BINPATH@/defaults/profile/prefs.js
 @BINPATH@/defaults/profile/mimeTypes.rdf
 
 @BINPATH@/isp/*
 
 @BINPATH@/components/components.manifest
-@BINPATH@/components/aboutRights.js
+@BINPATH@/components/aboutRedirector.js
 @BINPATH@/components/activity.xpt
 @BINPATH@/components/activityComponents.manifest
 @BINPATH@/components/addrbook.xpt
 @BINPATH@/components/fts3tok.xpt
 ; interfaces.manifest doesn't get packaged because it is dynamically
 ; re-created at packaging time when linking the xpts that will actually
 ; go into the package, so the test related interfaces aren't included.
 @BINPATH@/components/mime.xpt
--- a/mail/installer/removed-files.in
+++ b/mail/installer/removed-files.in
@@ -46,16 +46,17 @@ components/compreg.dat
 components/components.list
 components/history.xpt
 components/jsconsole.xpt
 components/layout.xpt
 components/mailnews.xpt
 components/mozgnome.xpt
 components/@DLL_PREFIX@myspell@DLL_SUFFIX@
 components/necko_data.xpt
+components/aboutRights.js
 components/nsAddonRepository.js
 components/nsBackgroundUpdateService.js
 components/nsCloseAllWindows.js
 components/nsComposerCmdLineHandler.js
 components/nsDownloadProgressListener.js
 components/nsExtensionManager.js
 components/nsInterfaceInfoToIDL.js
 components/nsLDAPPrefsService.js
@@ -317,16 +318,23 @@ regxpcom.exe
 @DLL_PREFIX@zlib@DLL_SUFFIX@
 #ifdef XP_WIN
   js3250.dll
 #endif
 # ****************************************************************************
 # * End generic removals section.                                            *
 # ****************************************************************************
 
+# ****************************************************************************
+# * Remove the files that were included in the omnijar at the time of the    *
+# * switch to omnijar. If a file is removed from the build later, it should  *
+# * be moved up to the generic removals section, but new files need not be   *
+# * added to this section.                                                   *
+# ****************************************************************************
+
 #ifdef MOZ_OMNIJAR
   chrome/@AB_CD@.jar
   chrome/@AB_CD@.manifest
   chrome/classic.jar
   chrome/classic.manifest
   chrome/comm.jar
   chrome/comm.manifest
   chrome/gloda.jar
@@ -336,17 +344,16 @@ regxpcom.exe
   chrome/messenger.manifest
   chrome/newsblog.jar
   chrome/newsblog.manifest
   chrome/nonlocalized.manifest
   chrome/pippki.jar
   chrome/pippki.manifest
   chrome/toolkit.jar
   chrome/toolkit.manifest
-  components/aboutRights.js
   components/addonManager.js
   components/amContentHandler.js
   components/amWebInstallListener.js
   components/components.manifest
   components/ConsoleAPI.js
   components/contentAreaDropListener.js
   components/contentSecurityPolicy.js
   components/crypto-SDR.js