home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2006 February / maximum-cd-2006-02.iso / Software / Apps / firefox_setup_1.5.exe / browser.xpi / bin / components / nsBrowserContentHandler.js < prev    next >
Encoding:
Text File  |  2005-11-11  |  22.0 KB  |  678 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is the Mozilla Firefox browser.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Benjamin Smedberg <benjamin@smedbergs.us>
  18.  *
  19.  * Portions created by the Initial Developer are Copyright (C) 2004
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. const nsISupports            = Components.interfaces.nsISupports;
  39.  
  40. const nsIBrowserDOMWindow    = Components.interfaces.nsIBrowserDOMWindow;
  41. const nsIBrowserHandler      = Components.interfaces.nsIBrowserHandler;
  42. const nsIBrowserHistory      = Components.interfaces.nsIBrowserHistory;
  43. const nsIChannel             = Components.interfaces.nsIChannel;
  44. const nsICommandLine         = Components.interfaces.nsICommandLine;
  45. const nsICommandLineHandler  = Components.interfaces.nsICommandLineHandler;
  46. const nsIContentHandler      = Components.interfaces.nsIContentHandler;
  47. const nsIDocShellTreeItem    = Components.interfaces.nsIDocShellTreeItem;
  48. const nsIDOMChromeWindow     = Components.interfaces.nsIDOMChromeWindow;
  49. const nsIDOMWindow           = Components.interfaces.nsIDOMWindow;
  50. const nsIFactory             = Components.interfaces.nsIFactory;
  51. const nsIFileURL             = Components.interfaces.nsIFileURL;
  52. const nsIHttpProtocolHandler = Components.interfaces.nsIHttpProtocolHandler;
  53. const nsIInterfaceRequestor  = Components.interfaces.nsIInterfaceRequestor;
  54. const nsIPrefBranch          = Components.interfaces.nsIPrefBranch;
  55. const nsIPrefLocalizedString = Components.interfaces.nsIPrefLocalizedString;
  56. const nsISupportsString      = Components.interfaces.nsISupportsString;
  57. const nsIURIFixup            = Components.interfaces.nsIURIFixup;
  58. const nsIWebNavigation       = Components.interfaces.nsIWebNavigation;
  59. const nsIWindowMediator      = Components.interfaces.nsIWindowMediator;
  60. const nsIWindowWatcher       = Components.interfaces.nsIWindowWatcher;
  61. const nsICategoryManager     = Components.interfaces.nsICategoryManager;
  62. const nsIWebNavigationInfo   = Components.interfaces.nsIWebNavigationInfo;
  63.  
  64. const NS_BINDING_ABORTED = 0x80020006;
  65. const NS_ERROR_WONT_HANDLE_CONTENT = 0x805d0001;
  66. const NS_ERROR_ABORT = Components.results.NS_ERROR_ABORT;
  67.  
  68. function shouldLoadURI(aURI) {
  69.   if (aURI && !aURI.schemeIs("chrome"))
  70.     return true;
  71.  
  72.   dump("*** Preventing external load of chrome: URI into browser window\n");
  73.   dump("    Use -chrome <uri> instead\n");
  74.   return false;
  75. }
  76.  
  77. function resolveURIInternal(aCmdLine, aArgument) {
  78.   var uri = aCmdLine.resolveURI(aArgument);
  79.  
  80.   if (!(uri instanceof nsIFileURL)) {
  81.     return uri;
  82.   }
  83.  
  84.   try {
  85.     if (uri.file.exists())
  86.       return uri;
  87.   }
  88.   catch (e) {
  89.     Components.utils.reportError(e);
  90.   }
  91.  
  92.   // We have interpreted the argument as a relative file URI, but the file
  93.   // doesn't exist. Try URI fixup heuristics: see bug 290782.
  94.  
  95.   try {
  96.     var urifixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
  97.                              .getService(nsIURIFixup);
  98.  
  99.     uri = urifixup.createFixupURI(aArgument, 0);
  100.   }
  101.   catch (e) {
  102.     Components.utils.reportError(e);
  103.   }
  104.  
  105.   return uri;
  106. }
  107.  
  108. function needHomepageOverride(prefb) {
  109.   var savedmstone;
  110.   try {
  111.     savedmstone = prefb.getCharPref("browser.startup.homepage_override.mstone");
  112.   }
  113.   catch (e) {
  114.   }
  115.  
  116.   if (savedmstone == "ignore")
  117.     return false;
  118.  
  119.   var mstone = Components.classes["@mozilla.org/network/protocol;1?name=http"]
  120.                          .getService(nsIHttpProtocolHandler).misc;
  121.  
  122.   if (mstone == savedmstone)
  123.     return false;
  124.  
  125.   prefb.setCharPref("browser.startup.homepage_override.mstone", mstone);
  126.   return true;
  127. }
  128.  
  129. function openWindow(parent, url, target, features, args) {
  130.   var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  131.                          .getService(nsIWindowWatcher);
  132.  
  133.   var argstring;
  134.   if (args) {
  135.     argstring = Components.classes["@mozilla.org/supports-string;1"]
  136.                             .createInstance(nsISupportsString);
  137.     argstring.data = args;
  138.   }
  139.   return wwatch.openWindow(parent, url, target, features, argstring);
  140. }
  141.  
  142. function openPreferences() {
  143.   var features = "chrome,titlebar,toolbar,centerscreen,dialog=no";
  144.   var url = "chrome://browser/content/preferences/preferences.xul";
  145.  
  146.   var win = getMostRecentWindow("Browser:Preferences");
  147.   if (win) {
  148.     win.focus();
  149.   } else {
  150.     openWindow(null, url, "_blank", features);
  151.   }
  152. }
  153.  
  154. function getMostRecentWindow(aType) {
  155.   var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  156.                      .getService(nsIWindowMediator);
  157.   return wm.getMostRecentWindow(aType);
  158. }
  159.  
  160. //@line 165 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8/WINNT_5.2_Depend/mozilla/browser/components/nsBrowserContentHandler.js"
  161.  
  162. // this returns the most recent non-popup browser window
  163. function getMostRecentBrowserWindow() {
  164.   var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  165.                      .getService(Components.interfaces.nsIWindowMediator);
  166.  
  167. //@line 185 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8/WINNT_5.2_Depend/mozilla/browser/components/nsBrowserContentHandler.js"
  168.   var windowList = wm.getZOrderDOMWindowEnumerator("navigator:browser", true);
  169.   if (!windowList.hasMoreElements())
  170.     return null;
  171.  
  172.   var win = windowList.getNext();
  173.   while (!win.toolbar.visible) {
  174.     if (!windowList.hasMoreElements()) 
  175.       return null;
  176.  
  177.     win = windowList.getNext();
  178.   }
  179. //@line 197 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8/WINNT_5.2_Depend/mozilla/browser/components/nsBrowserContentHandler.js"
  180.  
  181.   return win;
  182. }
  183.  
  184. var nsBrowserContentHandler = {
  185.   /* helper functions */
  186.  
  187.   mChromeURL : null,
  188.  
  189.   get chromeURL() {
  190.     if (this.mChromeURL) {
  191.       return this.mChromeURL;
  192.     }
  193.  
  194.     var prefb = Components.classes["@mozilla.org/preferences-service;1"]
  195.                           .getService(nsIPrefBranch);
  196.     this.mChromeURL = prefb.getCharPref("browser.chromeURL");
  197.  
  198.     return this.mChromeURL;
  199.   },
  200.  
  201.   /* nsISupports */
  202.   QueryInterface : function bch_QI(iid) {
  203.     if (!iid.equals(nsISupports) &&
  204.         !iid.equals(nsICommandLineHandler) &&
  205.         !iid.equals(nsIBrowserHandler) &&
  206.         !iid.equals(nsIContentHandler) &&
  207.         !iid.equals(nsIFactory))
  208.       throw Components.errors.NS_ERROR_NO_INTERFACE;
  209.  
  210.     return this;
  211.   },
  212.  
  213.   /* nsICommandLineHandler */
  214.   handle : function bch_handle(cmdLine) {
  215.     if (cmdLine.handleFlag("browser", false)) {
  216.       openWindow(null, this.chromeURL, "_blank",
  217.                  "chrome,dialog=no,all" + this.getFeatures(cmdLine),
  218.                  this.defaultArgs);
  219.       cmdLine.preventDefault = true;
  220.     }
  221.  
  222.     try {
  223.       var remoteCommand = cmdLine.handleFlagWithParam("remote", true);
  224.     }
  225.     catch (e) {
  226.       throw NS_ERROR_ABORT;
  227.     }
  228.  
  229.     if (remoteCommand != null) {
  230.       try {
  231.         var a = /^\s*(\w+)\(([^\)]*)\)\s*$/.exec(remoteCommand);
  232.         var remoteVerb = a[1].toLowerCase();
  233.         var remoteParams = a[2].split(",");
  234.  
  235.         switch (remoteVerb) {
  236.         case "openurl":
  237.         case "openfile":
  238.           // openURL(<url>)
  239.           // openURL(<url>,new-window)
  240.           // openURL(<url>,new-tab)
  241.  
  242.           var uri = resolveURIInternal(cmdLine, remoteParams[0]);
  243.  
  244.           var location = nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW;
  245.           if (/new-window/.test(remoteParams[1]))
  246.             location = nsIBrowserDOMWindow.OPEN_NEWWINDOW;
  247.           else if (/new-tab/.test(remoteParams[1]))
  248.             location = nsIBrowserDOMWindow.OPEN_NEWTAB;
  249.  
  250.           handURIToExistingBrowser(uri, location);
  251.           break;
  252.  
  253.         case "xfedocommand":
  254.           // xfeDoCommand(openBrowser)
  255.           if (remoteParams[0].toLowerCase() != "openbrowser")
  256.             throw NS_ERROR_ABORT;
  257.  
  258.           openWindow(null, this.chromeURL, "_blank",
  259.                      "chrome,dialog=no,all" + this.getFeatures(cmdLine),
  260.                      this.defaultArgs);
  261.           break;
  262.  
  263.         default:
  264.           // Somebody sent us a remote command we don't know how to process:
  265.           // just abort.
  266.           throw NS_ERROR_ABORT;
  267.         }
  268.  
  269.         cmdLine.preventDefault = true;
  270.       }
  271.       catch (e) {
  272.         // If we had a -remote flag but failed to process it, throw
  273.         // NS_ERROR_ABORT so that the xremote code knows to return a failure
  274.         // back to the handling code.
  275.         throw NS_ERROR_ABORT;
  276.       }
  277.     }
  278.  
  279.     var uriparam;
  280.     try {
  281.       while ((uriparam = cmdLine.handleFlagWithParam("new-window", false))) {
  282.         var uri = resolveURIInternal(cmdLine, uriparam);
  283.         if (!shouldLoadURI(uri))
  284.           continue;
  285.         openWindow(null, this.chromeURL, "_blank",
  286.                    "chrome,dialog=no,all" + this.getFeatures(cmdLine),
  287.                    uri.spec);
  288.         cmdLine.preventDefault = true;
  289.       }
  290.     }
  291.     catch (e) {
  292.       Components.utils.reportError(e);
  293.     }
  294.  
  295.     try {
  296.       while ((uriparam = cmdLine.handleFlagWithParam("new-tab", false))) {
  297.         var uri = resolveURIInternal(cmdLine, uriparam);
  298.         handURIToExistingBrowser(uri, nsIBrowserDOMWindow.OPEN_NEWTAB);
  299.         cmdLine.preventDefault = true;
  300.       }
  301.     }
  302.     catch (e) {
  303.       Components.utils.reportError(e);
  304.     }
  305.  
  306.     var chromeParam = cmdLine.handleFlagWithParam("chrome", false);
  307.     if (chromeParam) {
  308.  
  309.       // Handle the old preference dialog URL separately (bug 285416)
  310.       if (chromeParam == "chrome://browser/content/pref/pref.xul") {
  311.         openPreferences();
  312.       } else {
  313.         var features = "chrome,dialog=no,all" + this.getFeatures(cmdLine);
  314.         openWindow(null, chromeParam, "_blank", features, "");
  315.       }
  316.  
  317.       cmdLine.preventDefault = true;
  318.     }
  319.     if (cmdLine.handleFlag("preferences", false)) {
  320.       openPreferences();
  321.       cmdLine.preventDefault = true;
  322.     }
  323.   },
  324.  
  325.   helpInfo : "  -browser            Open a browser window.\n",
  326.  
  327.   /* nsIBrowserHandler */
  328.  
  329.   get defaultArgs() {
  330.     var prefb = Components.classes["@mozilla.org/preferences-service;1"]
  331.                           .getService(nsIPrefBranch);
  332.  
  333.     if (needHomepageOverride(prefb)) {
  334.       try {
  335.         return prefb.getComplexValue("startup.homepage_override_url",
  336.                                      nsIPrefLocalizedString).data;
  337.       }
  338.       catch (e) {
  339.       }
  340.     }
  341.  
  342.     try {
  343.       var choice = prefb.getIntPref("browser.startup.page");
  344.       if (choice == 1)
  345.         return this.startPage;
  346.  
  347.       if (choice == 2)
  348.         return Components.classes["@mozilla.org/browser/global-history;2"]
  349.                          .getService(nsIBrowserHistory).lastPageVisited;
  350.     }
  351.     catch (e) {
  352.     }
  353.  
  354.     return "about:blank";
  355.   },
  356.  
  357.   get startPage() {
  358.     var prefb = Components.classes["@mozilla.org/preferences-service;1"]
  359.                           .getService(nsIPrefBranch);
  360.  
  361.     var uri = prefb.getComplexValue("browser.startup.homepage",
  362.                                     nsIPrefLocalizedString).data;
  363.  
  364.     if (!uri) {
  365.       prefb.clearUserPref("browser.startup.homepage");
  366.       uri = prefb.getComplexValue("browser.startup.homepage",
  367.                                   nsIPrefLocalizedString).data;
  368.     }
  369.                                 
  370.     var count;
  371.     try {
  372.       count = prefb.getIntPref("browser.startup.homepage.count");
  373.     }
  374.     catch (e) {
  375.       return uri;
  376.     }
  377.  
  378.     for (var i = 1; i < count; ++i) {
  379.       try {
  380.         var page = prefb.getComplexValue("browser.startup.homepage." + i,
  381.                                          nsIPrefLocalizedString).data;
  382.         uri += "\n" + page;
  383.       }
  384.       catch (e) {
  385.       }
  386.     }
  387.  
  388.     return uri;
  389.   },
  390.  
  391.   mFeatures : null,
  392.  
  393.   getFeatures : function bch_features(cmdLine) {
  394.     if (this.mFeatures === null) {
  395.       this.mFeatures = "";
  396.  
  397.       try {
  398.         var width = cmdLine.handleFlagWithParam("width", false);
  399.         var height = cmdLine.handleFlagWithParam("height", false);
  400.  
  401.         if (width)
  402.           this.mFeatures += ",width=" + width;
  403.         if (height)
  404.           this.mFeatures += ",height=" + height;
  405.       }
  406.       catch (e) {
  407.       }
  408.     }
  409.  
  410.     return this.mFeatures;
  411.   },
  412.  
  413.   /* nsIContentHandler */
  414.  
  415.   handleContent : function bch_handleContent(contentType, context, request) {
  416.     try {
  417.       var webNavInfo = Components.classes["@mozilla.org/webnavigation-info;1"]
  418.                                  .getService(nsIWebNavigationInfo);
  419.       if (!webNavInfo.isTypeSupported(contentType, null)) {
  420.         throw NS_ERROR_WONT_HANDLE_CONTENT;
  421.       }
  422.     } catch (e) {
  423.       throw NS_ERROR_WONT_HANDLE_CONTENT;
  424.     }
  425.  
  426.     var parentWin;
  427.     try {
  428.       parentWin = context.getInterface(nsIDOMWindow);
  429.     }
  430.     catch (e) {
  431.     }
  432.  
  433.     request.QueryInterface(nsIChannel);
  434.     
  435.     openWindow(parentWin, request.URI, "_blank", null, null);
  436.     request.cancel(NS_BINDING_ABORTED);
  437.   },
  438.  
  439.   /* nsIFactory */
  440.   createInstance: function bch_CI(outer, iid) {
  441.     if (outer != null)
  442.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  443.  
  444.     return this.QueryInterface(iid);
  445.   },
  446.     
  447.   lockFactory : function bch_lock(lock) {
  448.     /* no-op */
  449.   }
  450. };
  451.  
  452. const bch_contractID = "@mozilla.org/browser/clh;1";
  453. const bch_CID = Components.ID("{5d0ce354-df01-421a-83fb-7ead0990c24e}");
  454. const CONTRACTID_PREFIX = "@mozilla.org/uriloader/content-handler;1?type=";
  455.  
  456. function handURIToExistingBrowser(uri, location)
  457. {
  458.   if (!shouldLoadURI(uri))
  459.     return;
  460.  
  461.   var navWin = getMostRecentBrowserWindow();
  462.   if (!navWin) {
  463.     // if we couldn't load it in an existing window, open a new one
  464.     openWindow(null, nsBrowserContentHandler.chromeURL, "_blank",
  465.                "chrome,dialog=no,all" + nsBrowserContentHandler.getFeatures(cmdLine),
  466.                uri.spec);
  467.     return;
  468.   }
  469.  
  470.   var navNav = navWin.QueryInterface(nsIInterfaceRequestor)
  471.                      .getInterface(nsIWebNavigation);
  472.   var rootItem = navNav.QueryInterface(nsIDocShellTreeItem).rootTreeItem;
  473.   var rootWin = rootItem.QueryInterface(nsIInterfaceRequestor)
  474.                         .getInterface(nsIDOMWindow);
  475.   var bwin = rootWin.QueryInterface(nsIDOMChromeWindow).browserDOMWindow;
  476.   bwin.openURI(uri, null, location,
  477.                nsIBrowserDOMWindow.OPEN_EXTERNAL);
  478. }
  479.  
  480.  
  481. var nsDefaultCommandLineHandler = {
  482.   /* nsISupports */
  483.   QueryInterface : function dch_QI(iid) {
  484.     if (!iid.equals(nsISupports) &&
  485.         !iid.equals(nsICommandLineHandler) &&
  486.         !iid.equals(nsIFactory))
  487.       throw Components.errors.NS_ERROR_NO_INTERFACE;
  488.  
  489.     return this;
  490.   },
  491.  
  492.   /* nsICommandLineHandler */
  493.   handle : function dch_handle(cmdLine) {
  494.     var urilist = [];
  495.  
  496.     try {
  497.       var ar;
  498.       while ((ar = cmdLine.handleFlagWithParam("url", false))) {
  499.         urilist.push(resolveURIInternal(cmdLine, ar));
  500.       }
  501.     }
  502.     catch (e) {
  503.       Components.utils.reportError(e);
  504.     }
  505.  
  506.     var count = cmdLine.length;
  507.  
  508.     for (var i = 0; i < count; ++i) {
  509.       var curarg = cmdLine.getArgument(i);
  510.       if (curarg.match(/^-/)) {
  511.         Components.utils.reportError("Warning: unrecognized command line flag " + curarg + "\n");
  512.         // To emulate the pre-nsICommandLine behavior, we ignore
  513.         // the argument after an unrecognized flag.
  514.         ++i;
  515.       } else {
  516.         try {
  517.           urilist.push(resolveURIInternal(cmdLine, curarg));
  518.         }
  519.         catch (e) {
  520.           Components.utils.reportError("Error opening URI '" + curarg + "' from the command line: " + e + "\n");
  521.         }
  522.       }
  523.     }
  524.  
  525.     if (urilist.length) {
  526.       if (cmdLine.state != nsICommandLine.STATE_INITIAL_LAUNCH &&
  527.           urilist.length == 1) {
  528.         // Try to find an existing window and load our URI into the
  529.         // current tab, new tab, or new window as prefs determine.
  530.         try {
  531.           handURIToExistingBrowser(urilist[0], nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW);
  532.           return;
  533.         }
  534.         catch (e) {
  535.         }
  536.       }
  537.  
  538.       var speclist = [];
  539.       for (var uri in urilist) {
  540.         if (shouldLoadURI(urilist[uri]))
  541.           speclist.push(urilist[uri].spec);
  542.       }
  543.  
  544.       if (speclist.length) {
  545.         openWindow(null, nsBrowserContentHandler.chromeURL, "_blank",
  546.                    "chrome,dialog=no,all" + nsBrowserContentHandler.getFeatures(cmdLine),
  547.                    speclist.join("|"));
  548.       }
  549.  
  550.     }
  551.     else if (!cmdLine.preventDefault) {
  552.       openWindow(null, nsBrowserContentHandler.chromeURL, "_blank",
  553.                  "chrome,dialog=no,all" + nsBrowserContentHandler.getFeatures(cmdLine),
  554.                  nsBrowserContentHandler.defaultArgs);
  555.     }
  556.   },
  557.  
  558.   // XXX localize me... how?
  559.   helpInfo : "Usage: firefox [-flags] [<url>]\n",
  560.  
  561.   /* nsIFactory */
  562.   createInstance: function dch_CI(outer, iid) {
  563.     if (outer != null)
  564.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  565.  
  566.     return this.QueryInterface(iid);
  567.   },
  568.     
  569.   lockFactory : function dch_lock(lock) {
  570.     /* no-op */
  571.   }
  572. };
  573.  
  574. const dch_contractID = "@mozilla.org/browser/final-clh;1";
  575. const dch_CID = Components.ID("{47cd0651-b1be-4a0f-b5c4-10e5a573ef71}");
  576.  
  577. var Module = {
  578.   /* nsISupports */
  579.   QueryInterface: function mod_QI(iid) {
  580.     if (iid.equals(Components.interfaces.nsIModule) ||
  581.         iid.equals(Components.interfaces.nsISupports))
  582.       return this;
  583.  
  584.     throw Components.results.NS_ERROR_NO_INTERFACE;
  585.   },
  586.  
  587.   /* nsIModule */
  588.   getClassObject: function mod_getco(compMgr, cid, iid) {
  589.     if (cid.equals(bch_CID))
  590.       return nsBrowserContentHandler.QueryInterface(iid);
  591.  
  592.     if (cid.equals(dch_CID))
  593.       return nsDefaultCommandLineHandler.QueryInterface(iid);
  594.  
  595.     throw Components.results.NS_ERROR_NO_INTERFACE;
  596.   },
  597.     
  598.   registerSelf: function mod_regself(compMgr, fileSpec, location, type) {
  599.     var compReg =
  600.       compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar );
  601.  
  602.     compReg.registerFactoryLocation( bch_CID,
  603.                                      "nsBrowserContentHandler",
  604.                                      bch_contractID,
  605.                                      fileSpec,
  606.                                      location,
  607.                                      type );
  608.     compReg.registerFactoryLocation( dch_CID,
  609.                                      "nsDefaultCommandLineHandler",
  610.                                      dch_contractID,
  611.                                      fileSpec,
  612.                                      location,
  613.                                      type );
  614.  
  615.     function registerType(contentType) {
  616.       compReg.registerFactoryLocation( bch_CID,
  617.                        "Browser Cmdline Handler",
  618.                        CONTRACTID_PREFIX + contentType,
  619.                        fileSpec,
  620.                        location,
  621.                        type );
  622.     }
  623.  
  624.     registerType("text/html");
  625.     registerType("application/vnd.mozilla.xul+xml");
  626. //@line 644 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8/WINNT_5.2_Depend/mozilla/browser/components/nsBrowserContentHandler.js"
  627.     registerType("image/svg+xml");
  628. //@line 646 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8/WINNT_5.2_Depend/mozilla/browser/components/nsBrowserContentHandler.js"
  629.     registerType("text/rdf");
  630.     registerType("text/xml");
  631.     registerType("application/xhtml+xml");
  632.     registerType("text/css");
  633.     registerType("text/plain");
  634.     registerType("image/gif");
  635.     registerType("image/jpeg");
  636.     registerType("image/jpg");
  637.     registerType("image/png");
  638.     registerType("image/bmp");
  639.     registerType("image/x-icon");
  640.     registerType("image/vnd.microsoft.icon");
  641.     registerType("image/x-xbitmap");
  642.     registerType("application/http-index-format");
  643.  
  644.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  645.                            .getService(nsICategoryManager);
  646.  
  647.     catMan.addCategoryEntry("command-line-handler",
  648.                             "m-browser",
  649.                             bch_contractID, true, true);
  650.     catMan.addCategoryEntry("command-line-handler",
  651.                             "x-default",
  652.                             dch_contractID, true, true);
  653.   },
  654.     
  655.   unregisterSelf : function mod_unregself(compMgr, location, type) {
  656.     var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
  657.     compReg.unregisterFactoryLocation(bch_CID, location);
  658.     compReg.unregisterFactoryLocation(dch_CID, location);
  659.  
  660.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  661.                            .getService(nsICategoryManager);
  662.  
  663.     catMan.deleteCategoryEntry("command-line-handler",
  664.                                "m-browser", true);
  665.     catMan.deleteCategoryEntry("command-line-handler",
  666.                                "x-default", true);
  667.   },
  668.  
  669.   canUnload: function(compMgr) {
  670.     return true;
  671.   }
  672. };
  673.  
  674. // NSGetModule: Return the nsIModule object.
  675. function NSGetModule(compMgr, fileSpec) {
  676.   return Module;
  677. }
  678.