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 Initial Developer of the Original Code is Fireinput Inc.
 15  *
 16  * Portions created by the Initial Developer are Copyright (C) 2007
 17  * the Initial Developer. All Rights Reserved.
 18  *
 19  * Contributor(s):
 20  *     Olly Ja <ollyja@gmail.com>
 21  *
 22  * Alternatively, the contents of this file may be used under the terms of
 23  * either the GNU General Public License Version 2 or later (the "GPL"), or
 24  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 25  * in which case the provisions of the GPL or the LGPL are applicable instead
 26  * of those above. If you wish to allow use of your version of this file only
 27  * under the terms of either the GPL or the LGPL, and not to allow others to
 28  * use your version of this file under the terms of the MPL, indicate your
 29  * decision by deleting the provisions above and replace them with the notice
 30  * and other provisions required by the GPL or the LGPL. If you do not delete
 31  * the provisions above, a recipient may use your version of this file under
 32  * the terms of any one of the MPL, the GPL or the LGPL.
 33  *
 34  * ***** END LICENSE BLOCK ***** 
 35  */
 36 
 37 // Fireinput Component constants 
 38 const CLASS_ID = Components.ID('{b3d34bb1-405f-485d-a11b-39d90de735b4}');
 39 const CLASS_NAME = 'Fireinput Service';
 40 const CONTRACT_ID = '@fireinput.com/fireinput;1';
 41 
 42 
 43 const SOURCE = 'chrome://fireinput/components/fireinputService.js';
 44 const INTERFACE = Components.interfaces.nsIFireinput; 
 45 
 46 const CC = Components.classes;
 47 const CI = Components.interfaces;
 48 const CR = Components.results;
 49 
 50 const Cc = Components.classes;
 51 const Ci = Components.interfaces;
 52 const Cr = Components.results;
 53 
 54 var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
 55 var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
 56 
 57 function FireinputService() 
 58 {
 59     this.observers = []; 
 60 }
 61 
 62 FireinputService.prototype = 
 63 {
 64     disableIME: function(handle, of)
 65     {
 66        if(typeof(this.objectList[handle]) != 'undefined')
 67        {
 68           var l = this.objectList[handle]; 
 69           if(typeof(l[of]) == 'undefined')
 70              l[of] = true; 
 71        }
 72        else 
 73        {
 74           this.objectList[handle] = new Array(); 
 75           this.objectList[handle][of]= true; 
 76        }
 77     }, 
 78 
 79     enableIME: function(handle, of)
 80     {
 81        if(typeof(this.objectList[handle]) != 'undefined')
 82        {
 83           var l = this.objectList[handle]; 
 84           if(typeof(l[of]) != 'undefined')
 85              delete l[of]; 
 86           if(l.length <= 0)
 87             this.objectList[handle] = null; 
 88        }
 89     }, 
 90 
 91     QueryInterface: function(aIID) 
 92     {
 93         if(!aIID.equals(INTERFACE) &&
 94            !aIID.equals(CI.nsISupports))
 95             throw CR.NS_ERROR_NO_INTERFACE;
 96         return this;
 97     }
 98 };
 99 
100 // loader.loadSubScript(SOURCE, Component.prototype);
101 
102 var FireinputFactory = 
103 {
104     createInstance: function(aOuter, aIID) {
105 
106         if(aOuter != null)
107             throw CR.NS_ERROR_NO_AGGREGATION;
108 
109         return (new FireinputService()).QueryInterface(aIID);
110     }
111 };
112 
113 var FireinputModule = {
114     _firstTime: true,
115 
116     registerSelf: function(aCompMgr, aFileSpec, aLocation, aType) 
117     {
118         if (this._firstTime) 
119         {
120             this._firstTime = false;
121             throw CR.NS_ERROR_FACTORY_REGISTER_AGAIN;
122         };
123         aCompMgr = aCompMgr.QueryInterface(CI.nsIComponentRegistrar);
124         aCompMgr.registerFactoryLocation(
125             CLASS_ID, CLASS_NAME, CONTRACT_ID, aFileSpec, aLocation, aType);
126     },
127 
128     unregisterSelf: function(aCompMgr, aLocation, aType) 
129     {
130         aCompMgr = aCompMgr.QueryInterface(CI.nsIComponentRegistrar);
131         aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);
132     },
133 
134     getClassObject: function(aCompMgr, aCID, aIID) {
135         if (!aIID.equals(CI.nsIFactory))
136             throw CR.NS_ERROR_NOT_IMPLEMENTED;
137 
138         if (aCID.equals(CLASS_ID))
139             return FireinputFactory;
140 
141         throw CR.NS_ERROR_NO_INTERFACE;        
142     },
143 
144     canUnload: function(aCompMgr) 
145     { 
146         return true; 
147     }
148 };
149 
150 function NSGetModule(aCompMgr, aFileSpec) { return FireinputModule; }


syntax highlighted by Code2HTML, v. 0.9.1