home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / components / nsDefaultCLH.js < prev    next >
Encoding:
Text File  |  2007-11-12  |  5.6 KB  |  168 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 nsICategoryManager       = Components.interfaces.nsICategoryManager;
  41. const nsIComponentRegistrar    = Components.interfaces.nsIComponentRegistrar;
  42. const nsICommandLine           = Components.interfaces.nsICommandLine;
  43. const nsICommandLineHandler    = Components.interfaces.nsICommandLineHandler;
  44. const nsIFactory               = Components.interfaces.nsIFactory;
  45. const nsIModule                = Components.interfaces.nsIModule;
  46. const nsIPrefBranch            = Components.interfaces.nsIPrefBranch;
  47. const nsISupportsString        = Components.interfaces.nsISupportsString;
  48. const nsIWindowWatcher         = Components.interfaces.nsIWindowWatcher;
  49.  
  50. /**
  51.  * This file provides a generic default command-line handler.
  52.  *
  53.  * It opens the chrome window specified by the pref "toolkit.defaultChromeURI"
  54.  * the arguments passed to the window are the nsICommandLine instance.
  55.  *
  56.  * It doesn't do anything if the pref is unset.
  57.  */
  58.  
  59. var nsDefaultCLH = {
  60.   /* nsISupports */
  61.  
  62.   QueryInterface : function clh_QI(iid) {
  63.     if (iid.equals(nsICommandLineHandler) ||
  64.         iid.equals(nsIFactory) ||
  65.         iid.equals(nsISupports))
  66.       return this;
  67.  
  68.     throw Components.results.NS_ERROR_NO_INTERFACE;
  69.   },
  70.  
  71.   /* nsICommandLineHandler */
  72.  
  73.   handle : function clh_handle(cmdLine) {
  74.     if (cmdLine.preventDefault)
  75.     return;
  76.  
  77.     var prefs = Components.classes["@mozilla.org/preferences-service;1"]
  78.                           .getService(nsIPrefBranch);
  79.  
  80.     // if the pref is missing, ignore the exception 
  81.     try {
  82.       var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI");
  83.  
  84.       var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  85.                             .getService(nsIWindowWatcher);
  86.       wwatch.openWindow(null, chromeURI, "_blank",
  87.                         "chrome,dialog=no,all", cmdLine);
  88.     }
  89.     catch (e) { }
  90.   },
  91.  
  92.   helpInfo : "",
  93.  
  94.   /* nsIFactory */
  95.  
  96.   createInstance : function mdh_CI(outer, iid) {
  97.     if (outer != null)
  98.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  99.  
  100.     return this.QueryInterface(iid);
  101.   },
  102.  
  103.   lockFactory : function mdh_lock(lock) {
  104.     /* no-op */
  105.   }
  106. };
  107.  
  108. const clh_contractID = "@mozilla.org/toolkit/default-clh;1";
  109. const clh_CID = Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}");
  110.  
  111. var Module = {
  112.   /* nsISupports */
  113.  
  114.   QueryInterface : function mod_QI(iid) {
  115.     if (iid.equals(nsIModule) ||
  116.         iid.equals(nsISupports))
  117.       return this;
  118.  
  119.     throw Components.results.NS_ERROR_NO_INTERFACE;
  120.   },
  121.  
  122.   /* nsIModule */
  123.  
  124.   getClassObject : function mod_gch(compMgr, cid, iid) {
  125.     if (cid.equals(clh_CID))
  126.       return nsDefaultCLH.QueryInterface(iid);
  127.  
  128.     throw components.results.NS_ERROR_FAILURE;
  129.   },
  130.  
  131.   registerSelf : function mod_regself(compMgr, fileSpec, location, type) {
  132.     var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
  133.  
  134.     compReg.registerFactoryLocation(clh_CID,
  135.                                     "nsDefaultCLH",
  136.                                     clh_contractID,
  137.                                     fileSpec,
  138.                                     location,
  139.                                     type);
  140.  
  141.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  142.                            .getService(nsICategoryManager);
  143.  
  144.     catMan.addCategoryEntry("command-line-handler",
  145.                             "y-default",
  146.                             clh_contractID, true, true);
  147.   },
  148.  
  149.   unregisterSelf : function mod_unreg(compMgr, location, type) {
  150.     var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
  151.     compReg.unregisterFactoryLocation(clh_CID, location);
  152.  
  153.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  154.                            .getService(nsICategoryManager);
  155.  
  156.     catMan.deleteCategoryEntry("command-line-handler",
  157.                                "y-default");
  158.   },
  159.  
  160.   canUnload : function (compMgr) {
  161.     return true;
  162.   }
  163. };
  164.  
  165. function NSGetModule(compMgr, fileSpec) {
  166.   return Module;
  167. }
  168.