home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / firefox / components / nsBrowserContentHandler.js < prev    next >
Encoding:
Text File  |  2006-08-18  |  23.4 KB  |  729 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. const nsIBrowserSearchService = Components.interfaces.nsIBrowserSearchService;
  64.  
  65. const NS_BINDING_ABORTED = 0x804b0002;
  66. const NS_ERROR_WONT_HANDLE_CONTENT = 0x805d0001;
  67. const NS_ERROR_ABORT = Components.results.NS_ERROR_ABORT;
  68.  
  69. function shouldLoadURI(aURI) {
  70.   if (aURI && !aURI.schemeIs("chrome"))
  71.     return true;
  72.  
  73.   dump("*** Preventing external load of chrome: URI into browser window\n");
  74.   dump("    Use -chrome <uri> instead\n");
  75.   return false;
  76. }
  77.  
  78. function resolveURIInternal(aCmdLine, aArgument) {
  79.   var uri = aCmdLine.resolveURI(aArgument);
  80.  
  81.   if (!(uri instanceof nsIFileURL)) {
  82.     return uri;
  83.   }
  84.  
  85.   try {
  86.     if (uri.file.exists())
  87.       return uri;
  88.   }
  89.   catch (e) {
  90.     Components.utils.reportError(e);
  91.   }
  92.  
  93.   // We have interpreted the argument as a relative file URI, but the file
  94.   // doesn't exist. Try URI fixup heuristics: see bug 290782.
  95.  
  96.   try {
  97.     var urifixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
  98.                              .getService(nsIURIFixup);
  99.  
  100.     uri = urifixup.createFixupURI(aArgument, 0);
  101.   }
  102.   catch (e) {
  103.     Components.utils.reportError(e);
  104.   }
  105.  
  106.   return uri;
  107. }
  108.  
  109. function needHomepageOverride(prefb) {
  110.   var savedmstone;
  111.   try {
  112.     savedmstone = prefb.getCharPref("browser.startup.homepage_override.mstone");
  113.   }
  114.   catch (e) {
  115.   }
  116.  
  117.   if (savedmstone == "ignore")
  118.     return false;
  119.  
  120.   var mstone = Components.classes["@mozilla.org/network/protocol;1?name=http"]
  121.                          .getService(nsIHttpProtocolHandler).misc;
  122.  
  123.   if (mstone == savedmstone)
  124.     return false;
  125.  
  126.   prefb.setCharPref("browser.startup.homepage_override.mstone", mstone);
  127.   return true;
  128. }
  129.  
  130. function openWindow(parent, url, target, features, args) {
  131.   var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  132.                          .getService(nsIWindowWatcher);
  133.  
  134.   var argstring;
  135.   if (args) {
  136.     argstring = Components.classes["@mozilla.org/supports-string;1"]
  137.                             .createInstance(nsISupportsString);
  138.     argstring.data = args;
  139.   }
  140.   return wwatch.openWindow(parent, url, target, features, argstring);
  141. }
  142.  
  143. function openPreferences() {
  144.   var features = "chrome,titlebar,toolbar,centerscreen,dialog=no";
  145.   var url = "chrome://browser/content/preferences/preferences.xul";
  146.  
  147.   var win = getMostRecentWindow("Browser:Preferences");
  148.   if (win) {
  149.     win.focus();
  150.   } else {
  151.     openWindow(null, url, "_blank", features);
  152.   }
  153. }
  154.  
  155. function getMostRecentWindow(aType) {
  156.   var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  157.                      .getService(nsIWindowMediator);
  158.   return wm.getMostRecentWindow(aType);
  159. }
  160.  
  161. //@line 166 "/build/buildd/firefox-1.99+2.0b1+dfsg/browser/components/nsBrowserContentHandler.js"
  162.  
  163. // this returns the most recent non-popup browser window
  164. function getMostRecentBrowserWindow() {
  165.   var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  166.                      .getService(Components.interfaces.nsIWindowMediator);
  167.  
  168. //@line 173 "/build/buildd/firefox-1.99+2.0b1+dfsg/browser/components/nsBrowserContentHandler.js"
  169.   var win = wm.getMostRecentWindow("navigator:browser", true);
  170.  
  171.   // if we're lucky, this isn't a popup, and we can just return this
  172.   if (win && !win.toolbar.visible) {
  173.     var windowList = wm.getEnumerator("navigator:browser", true);
  174.     // this is oldest to newest, so this gets a bit ugly
  175.     while (windowList.hasMoreElements()) {
  176.       var nextWin = windowList.getNext();
  177.       if (nextWin.toolbar.visible)
  178.         win = nextWin;
  179.     }
  180.   }
  181. //@line 198 "/build/buildd/firefox-1.99+2.0b1+dfsg/browser/components/nsBrowserContentHandler.js"
  182.  
  183.   return win;
  184. }
  185.  
  186. function doSearch(searchTerm, cmdLine) {
  187.   var ss = Components.classes["@mozilla.org/browser/search-service;1"]
  188.                      .getService(nsIBrowserSearchService);
  189.  
  190.   var submission = ss.defaultEngine.getSubmission(searchTerm);
  191.  
  192.   // fill our nsISupportsArray with uri-as-wstring, null, null, postData
  193.   var sa = Components.classes["@mozilla.org/supports-array;1"]
  194.                      .createInstance(Components.interfaces.nsISupportsArray);
  195.  
  196.   var wuri = Components.classes["@mozilla.org/supports-string;1"]
  197.                        .createInstance(Components.interfaces.nsISupportsString);
  198.   wuri.data = submission.uri.spec;
  199.  
  200.   sa.AppendElement(wuri);
  201.   sa.AppendElement(null);
  202.   sa.AppendElement(null);
  203.   sa.AppendElement(submission.postData);
  204.  
  205.   // XXXbsmedberg: use handURIToExistingBrowser to obey tabbed-browsing
  206.   // preferences, but need nsIBrowserDOMWindow extensions
  207.  
  208.   var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  209.                          .getService(nsIWindowWatcher);
  210.  
  211.   return wwatch.openWindow(null, nsBrowserContentHandler.chromeURL,
  212.                            "_blank",
  213.                            "chrome,dialog=no,all" +
  214.                              nsBrowserContentHandler.getFeatures(cmdLine),
  215.                            sa);
  216. }
  217.  
  218. var nsBrowserContentHandler = {
  219.   /* helper functions */
  220.  
  221.   mChromeURL : null,
  222.  
  223.   get chromeURL() {
  224.     if (this.mChromeURL) {
  225.       return this.mChromeURL;
  226.     }
  227.  
  228.     var prefb = Components.classes["@mozilla.org/preferences-service;1"]
  229.                           .getService(nsIPrefBranch);
  230.     this.mChromeURL = prefb.getCharPref("browser.chromeURL");
  231.  
  232.     return this.mChromeURL;
  233.   },
  234.  
  235.   /* nsISupports */
  236.   QueryInterface : function bch_QI(iid) {
  237.     if (!iid.equals(nsISupports) &&
  238.         !iid.equals(nsICommandLineHandler) &&
  239.         !iid.equals(nsIBrowserHandler) &&
  240.         !iid.equals(nsIContentHandler) &&
  241.         !iid.equals(nsIFactory))
  242.       throw Components.errors.NS_ERROR_NO_INTERFACE;
  243.  
  244.     return this;
  245.   },
  246.  
  247.   /* nsICommandLineHandler */
  248.   handle : function bch_handle(cmdLine) {
  249.     if (cmdLine.handleFlag("browser", false)) {
  250.       openWindow(null, this.chromeURL, "_blank",
  251.                  "chrome,dialog=no,all" + this.getFeatures(cmdLine),
  252.                  this.defaultArgs);
  253.       cmdLine.preventDefault = true;
  254.     }
  255.  
  256.     try {
  257.       var remoteCommand = cmdLine.handleFlagWithParam("remote", true);
  258.     }
  259.     catch (e) {
  260.       throw NS_ERROR_ABORT;
  261.     }
  262.  
  263.     if (remoteCommand != null) {
  264.       try {
  265.         var a = /^\s*(\w+)\(([^\)]*)\)\s*$/.exec(remoteCommand);
  266.         var remoteVerb = a[1].toLowerCase();
  267.         var remoteParams = [];
  268.         var sepIndex = a[2].lastIndexOf(",");
  269.         if (sepIndex == -1)
  270.           remoteParams[0] = a[2];
  271.         else {
  272.           remoteParams[0] = a[2].substring(0, sepIndex);
  273.           remoteParams[1] = a[2].substring(sepIndex + 1);
  274.         }
  275.  
  276.         switch (remoteVerb) {
  277.         case "openurl":
  278.         case "openfile":
  279.           // openURL(<url>)
  280.           // openURL(<url>,new-window)
  281.           // openURL(<url>,new-tab)
  282.  
  283.           var uri = resolveURIInternal(cmdLine, remoteParams[0]);
  284.  
  285.           var location = nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW;
  286.           if (/new-window/.test(remoteParams[1]))
  287.             location = nsIBrowserDOMWindow.OPEN_NEWWINDOW;
  288.           else if (/new-tab/.test(remoteParams[1]))
  289.             location = nsIBrowserDOMWindow.OPEN_NEWTAB;
  290.  
  291.           handURIToExistingBrowser(uri, location);
  292.           break;
  293.  
  294.         case "xfedocommand":
  295.           // xfeDoCommand(openBrowser)
  296.           if (remoteParams[0].toLowerCase() != "openbrowser")
  297.             throw NS_ERROR_ABORT;
  298.  
  299.           openWindow(null, this.chromeURL, "_blank",
  300.                      "chrome,dialog=no,all" + this.getFeatures(cmdLine),
  301.                      this.defaultArgs);
  302.           break;
  303.  
  304.         default:
  305.           // Somebody sent us a remote command we don't know how to process:
  306.           // just abort.
  307.           throw NS_ERROR_ABORT;
  308.         }
  309.  
  310.         cmdLine.preventDefault = true;
  311.       }
  312.       catch (e) {
  313.         // If we had a -remote flag but failed to process it, throw
  314.         // NS_ERROR_ABORT so that the xremote code knows to return a failure
  315.         // back to the handling code.
  316.         throw NS_ERROR_ABORT;
  317.       }
  318.     }
  319.  
  320.     var uriparam;
  321.     try {
  322.       while ((uriparam = cmdLine.handleFlagWithParam("new-window", false))) {
  323.         var uri = resolveURIInternal(cmdLine, uriparam);
  324.         if (!shouldLoadURI(uri))
  325.           continue;
  326.         openWindow(null, this.chromeURL, "_blank",
  327.                    "chrome,dialog=no,all" + this.getFeatures(cmdLine),
  328.                    uri.spec);
  329.         cmdLine.preventDefault = true;
  330.       }
  331.     }
  332.     catch (e) {
  333.       Components.utils.reportError(e);
  334.     }
  335.  
  336.     try {
  337.       while ((uriparam = cmdLine.handleFlagWithParam("new-tab", false))) {
  338.         var uri = resolveURIInternal(cmdLine, uriparam);
  339.         handURIToExistingBrowser(uri, nsIBrowserDOMWindow.OPEN_NEWTAB);
  340.         cmdLine.preventDefault = true;
  341.       }
  342.     }
  343.     catch (e) {
  344.       Components.utils.reportError(e);
  345.     }
  346.  
  347.     var chromeParam = cmdLine.handleFlagWithParam("chrome", false);
  348.     if (chromeParam) {
  349.  
  350.       // Handle the old preference dialog URL separately (bug 285416)
  351.       if (chromeParam == "chrome://browser/content/pref/pref.xul") {
  352.         openPreferences();
  353.       } else {
  354.         var features = "chrome,dialog=no,all" + this.getFeatures(cmdLine);
  355.         openWindow(null, chromeParam, "_blank", features, "");
  356.       }
  357.  
  358.       cmdLine.preventDefault = true;
  359.     }
  360.     if (cmdLine.handleFlag("preferences", false)) {
  361.       openPreferences();
  362.       cmdLine.preventDefault = true;
  363.     }
  364.     if (cmdLine.handleFlag("silent", false))
  365.       cmdLine.preventDefault = true;
  366.  
  367.     var searchParam = cmdLine.handleFlagWithParam("search", false);
  368.     if (searchParam) {
  369.       doSearch(searchParam, cmdLine);
  370.       cmdLine.preventDefault = true;
  371.     }
  372.  
  373. //@line 402 "/build/buildd/firefox-1.99+2.0b1+dfsg/browser/components/nsBrowserContentHandler.js"
  374.   },
  375.  
  376.   helpInfo : "  -browser            Open a browser window.\n",
  377.  
  378.   /* nsIBrowserHandler */
  379.  
  380.   get defaultArgs() {
  381.     var prefb = Components.classes["@mozilla.org/preferences-service;1"]
  382.                           .getService(nsIPrefBranch);
  383.  
  384.     if (needHomepageOverride(prefb)) {
  385.       try {
  386.         return prefb.getComplexValue("startup.homepage_override_url",
  387.                                      nsIPrefLocalizedString).data;
  388.       }
  389.       catch (e) {
  390.       }
  391.     }
  392.  
  393.     try {
  394.       var choice = prefb.getIntPref("browser.startup.page");
  395.       if (choice == 1)
  396.         return this.startPage;
  397.  
  398.       if (choice == 2)
  399.         return Components.classes["@mozilla.org/browser/global-history;2"]
  400.                          .getService(nsIBrowserHistory).lastPageVisited;
  401.     }
  402.     catch (e) {
  403.     }
  404.  
  405.     return "about:blank";
  406.   },
  407.  
  408.   get startPage() {
  409.     var prefb = Components.classes["@mozilla.org/preferences-service;1"]
  410.                           .getService(nsIPrefBranch);
  411.  
  412.     var uri = prefb.getComplexValue("browser.startup.homepage",
  413.                                     nsIPrefLocalizedString).data;
  414.  
  415.     if (!uri) {
  416.       prefb.clearUserPref("browser.startup.homepage");
  417.       uri = prefb.getComplexValue("browser.startup.homepage",
  418.                                   nsIPrefLocalizedString).data;
  419.     }
  420.                                 
  421.     var count;
  422.     try {
  423.       count = prefb.getIntPref("browser.startup.homepage.count");
  424.     }
  425.     catch (e) {
  426.       return uri;
  427.     }
  428.  
  429.     for (var i = 1; i < count; ++i) {
  430.       try {
  431.         var page = prefb.getComplexValue("browser.startup.homepage." + i,
  432.                                          nsIPrefLocalizedString).data;
  433.         uri += "\n" + page;
  434.       }
  435.       catch (e) {
  436.       }
  437.     }
  438.  
  439.     return uri;
  440.   },
  441.  
  442.   mFeatures : null,
  443.  
  444.   getFeatures : function bch_features(cmdLine) {
  445.     if (this.mFeatures === null) {
  446.       this.mFeatures = "";
  447.  
  448.       try {
  449.         var width = cmdLine.handleFlagWithParam("width", false);
  450.         var height = cmdLine.handleFlagWithParam("height", false);
  451.  
  452.         if (width)
  453.           this.mFeatures += ",width=" + width;
  454.         if (height)
  455.           this.mFeatures += ",height=" + height;
  456.       }
  457.       catch (e) {
  458.       }
  459.     }
  460.  
  461.     return this.mFeatures;
  462.   },
  463.  
  464.   /* nsIContentHandler */
  465.  
  466.   handleContent : function bch_handleContent(contentType, context, request) {
  467.     try {
  468.       var webNavInfo = Components.classes["@mozilla.org/webnavigation-info;1"]
  469.                                  .getService(nsIWebNavigationInfo);
  470.       if (!webNavInfo.isTypeSupported(contentType, null)) {
  471.         throw NS_ERROR_WONT_HANDLE_CONTENT;
  472.       }
  473.     } catch (e) {
  474.       throw NS_ERROR_WONT_HANDLE_CONTENT;
  475.     }
  476.  
  477.     var parentWin;
  478.     try {
  479.       parentWin = context.getInterface(nsIDOMWindow);
  480.     }
  481.     catch (e) {
  482.     }
  483.  
  484.     request.QueryInterface(nsIChannel);
  485.     
  486.     openWindow(parentWin, request.URI, "_blank", null, null);
  487.     request.cancel(NS_BINDING_ABORTED);
  488.   },
  489.  
  490.   /* nsIFactory */
  491.   createInstance: function bch_CI(outer, iid) {
  492.     if (outer != null)
  493.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  494.  
  495.     return this.QueryInterface(iid);
  496.   },
  497.     
  498.   lockFactory : function bch_lock(lock) {
  499.     /* no-op */
  500.   }
  501. };
  502.  
  503. const bch_contractID = "@mozilla.org/browser/clh;1";
  504. const bch_CID = Components.ID("{5d0ce354-df01-421a-83fb-7ead0990c24e}");
  505. const CONTRACTID_PREFIX = "@mozilla.org/uriloader/content-handler;1?type=";
  506.  
  507. function handURIToExistingBrowser(uri, location)
  508. {
  509.   if (!shouldLoadURI(uri))
  510.     return;
  511.  
  512.   var navWin = getMostRecentBrowserWindow();
  513.   if (!navWin) {
  514.     // if we couldn't load it in an existing window, open a new one
  515.     openWindow(null, nsBrowserContentHandler.chromeURL, "_blank",
  516.                "chrome,dialog=no,all" + nsBrowserContentHandler.getFeatures(cmdLine),
  517.                uri.spec);
  518.     return;
  519.   }
  520.  
  521.   var navNav = navWin.QueryInterface(nsIInterfaceRequestor)
  522.                      .getInterface(nsIWebNavigation);
  523.   var rootItem = navNav.QueryInterface(nsIDocShellTreeItem).rootTreeItem;
  524.   var rootWin = rootItem.QueryInterface(nsIInterfaceRequestor)
  525.                         .getInterface(nsIDOMWindow);
  526.   var bwin = rootWin.QueryInterface(nsIDOMChromeWindow).browserDOMWindow;
  527.   bwin.openURI(uri, null, location,
  528.                nsIBrowserDOMWindow.OPEN_EXTERNAL);
  529. }
  530.  
  531.  
  532. var nsDefaultCommandLineHandler = {
  533.   /* nsISupports */
  534.   QueryInterface : function dch_QI(iid) {
  535.     if (!iid.equals(nsISupports) &&
  536.         !iid.equals(nsICommandLineHandler) &&
  537.         !iid.equals(nsIFactory))
  538.       throw Components.errors.NS_ERROR_NO_INTERFACE;
  539.  
  540.     return this;
  541.   },
  542.  
  543.   /* nsICommandLineHandler */
  544.   handle : function dch_handle(cmdLine) {
  545.     var urilist = [];
  546.  
  547.     try {
  548.       var ar;
  549.       while ((ar = cmdLine.handleFlagWithParam("url", false))) {
  550.         urilist.push(resolveURIInternal(cmdLine, ar));
  551.       }
  552.     }
  553.     catch (e) {
  554.       Components.utils.reportError(e);
  555.     }
  556.  
  557.     var count = cmdLine.length;
  558.  
  559.     for (var i = 0; i < count; ++i) {
  560.       var curarg = cmdLine.getArgument(i);
  561.       if (curarg.match(/^-/)) {
  562.         Components.utils.reportError("Warning: unrecognized command line flag " + curarg + "\n");
  563.         // To emulate the pre-nsICommandLine behavior, we ignore
  564.         // the argument after an unrecognized flag.
  565.         ++i;
  566.       } else {
  567.         try {
  568.           urilist.push(resolveURIInternal(cmdLine, curarg));
  569.         }
  570.         catch (e) {
  571.           Components.utils.reportError("Error opening URI '" + curarg + "' from the command line: " + e + "\n");
  572.         }
  573.       }
  574.     }
  575.  
  576.     if (urilist.length) {
  577.       if (cmdLine.state != nsICommandLine.STATE_INITIAL_LAUNCH &&
  578.           urilist.length == 1) {
  579.         // Try to find an existing window and load our URI into the
  580.         // current tab, new tab, or new window as prefs determine.
  581.         try {
  582.           handURIToExistingBrowser(urilist[0], nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW);
  583.           return;
  584.         }
  585.         catch (e) {
  586.         }
  587.       }
  588.  
  589.       var speclist = [];
  590.       for (var uri in urilist) {
  591.         if (shouldLoadURI(urilist[uri]))
  592.           speclist.push(urilist[uri].spec);
  593.       }
  594.  
  595.       if (speclist.length) {
  596.         openWindow(null, nsBrowserContentHandler.chromeURL, "_blank",
  597.                    "chrome,dialog=no,all" + nsBrowserContentHandler.getFeatures(cmdLine),
  598.                    speclist.join("|"));
  599.       }
  600.  
  601.     }
  602.     else if (!cmdLine.preventDefault) {
  603.       openWindow(null, nsBrowserContentHandler.chromeURL, "_blank",
  604.                  "chrome,dialog=no,all" + nsBrowserContentHandler.getFeatures(cmdLine),
  605.                  nsBrowserContentHandler.defaultArgs);
  606.     }
  607.   },
  608.  
  609.   // XXX localize me... how?
  610.   helpInfo : "Usage: firefox [-flags] [<url>]\n",
  611.  
  612.   /* nsIFactory */
  613.   createInstance: function dch_CI(outer, iid) {
  614.     if (outer != null)
  615.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  616.  
  617.     return this.QueryInterface(iid);
  618.   },
  619.     
  620.   lockFactory : function dch_lock(lock) {
  621.     /* no-op */
  622.   }
  623. };
  624.  
  625. const dch_contractID = "@mozilla.org/browser/final-clh;1";
  626. const dch_CID = Components.ID("{47cd0651-b1be-4a0f-b5c4-10e5a573ef71}");
  627.  
  628. var Module = {
  629.   /* nsISupports */
  630.   QueryInterface: function mod_QI(iid) {
  631.     if (iid.equals(Components.interfaces.nsIModule) ||
  632.         iid.equals(Components.interfaces.nsISupports))
  633.       return this;
  634.  
  635.     throw Components.results.NS_ERROR_NO_INTERFACE;
  636.   },
  637.  
  638.   /* nsIModule */
  639.   getClassObject: function mod_getco(compMgr, cid, iid) {
  640.     if (cid.equals(bch_CID))
  641.       return nsBrowserContentHandler.QueryInterface(iid);
  642.  
  643.     if (cid.equals(dch_CID))
  644.       return nsDefaultCommandLineHandler.QueryInterface(iid);
  645.  
  646.     throw Components.results.NS_ERROR_NO_INTERFACE;
  647.   },
  648.     
  649.   registerSelf: function mod_regself(compMgr, fileSpec, location, type) {
  650.     var compReg =
  651.       compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar );
  652.  
  653.     compReg.registerFactoryLocation( bch_CID,
  654.                                      "nsBrowserContentHandler",
  655.                                      bch_contractID,
  656.                                      fileSpec,
  657.                                      location,
  658.                                      type );
  659.     compReg.registerFactoryLocation( dch_CID,
  660.                                      "nsDefaultCommandLineHandler",
  661.                                      dch_contractID,
  662.                                      fileSpec,
  663.                                      location,
  664.                                      type );
  665.  
  666.     function registerType(contentType) {
  667.       compReg.registerFactoryLocation( bch_CID,
  668.                                        "Browser Cmdline Handler",
  669.                                        CONTRACTID_PREFIX + contentType,
  670.                                        fileSpec,
  671.                                        location,
  672.                                        type );
  673.     }
  674.  
  675.     registerType("text/html");
  676.     registerType("application/vnd.mozilla.xul+xml");
  677. //@line 706 "/build/buildd/firefox-1.99+2.0b1+dfsg/browser/components/nsBrowserContentHandler.js"
  678.     registerType("image/svg+xml");
  679. //@line 708 "/build/buildd/firefox-1.99+2.0b1+dfsg/browser/components/nsBrowserContentHandler.js"
  680.     registerType("text/rdf");
  681.     registerType("text/xml");
  682.     registerType("application/xhtml+xml");
  683.     registerType("text/css");
  684.     registerType("text/plain");
  685.     registerType("image/gif");
  686.     registerType("image/jpeg");
  687.     registerType("image/jpg");
  688.     registerType("image/png");
  689.     registerType("image/bmp");
  690.     registerType("image/x-icon");
  691.     registerType("image/vnd.microsoft.icon");
  692.     registerType("image/x-xbitmap");
  693.     registerType("application/http-index-format");
  694.  
  695.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  696.                            .getService(nsICategoryManager);
  697.  
  698.     catMan.addCategoryEntry("command-line-handler",
  699.                             "m-browser",
  700.                             bch_contractID, true, true);
  701.     catMan.addCategoryEntry("command-line-handler",
  702.                             "x-default",
  703.                             dch_contractID, true, true);
  704.   },
  705.     
  706.   unregisterSelf : function mod_unregself(compMgr, location, type) {
  707.     var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
  708.     compReg.unregisterFactoryLocation(bch_CID, location);
  709.     compReg.unregisterFactoryLocation(dch_CID, location);
  710.  
  711.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  712.                            .getService(nsICategoryManager);
  713.  
  714.     catMan.deleteCategoryEntry("command-line-handler",
  715.                                "m-browser", true);
  716.     catMan.deleteCategoryEntry("command-line-handler",
  717.                                "x-default", true);
  718.   },
  719.  
  720.   canUnload: function(compMgr) {
  721.     return true;
  722.   }
  723. };
  724.  
  725. // NSGetModule: Return the nsIModule object.
  726. function NSGetModule(compMgr, fileSpec) {
  727.   return Module;
  728. }
  729.