home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Multimedia / Songbird / Songbird_2.0.0-2311_windows-i686-msvc8.exe / components / sbDndSourceTracker.js < prev    next >
Text File  |  2012-06-08  |  3KB  |  115 lines

  1. /**
  2. //
  3. // BEGIN SONGBIRD GPL
  4. // 
  5. // This file is part of the Songbird web player.
  6. //
  7. // Copyright(c) 2005-2008 POTI, Inc.
  8. // http://songbirdnest.com
  9. // 
  10. // This file may be licensed under the terms of of the
  11. // GNU General Public License Version 2 (the "GPL").
  12. // 
  13. // Software distributed under the License is distributed 
  14. // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
  15. // express or implied. See the GPL for the specific language 
  16. // governing rights and limitations.
  17. //
  18. // You should have received a copy of the GPL along with this 
  19. // program. If not, go to http://www.gnu.org/licenses/gpl.html
  20. // or write to the Free Software Foundation, Inc., 
  21. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. // 
  23. // END SONGBIRD GPL
  24. //
  25.  */
  26.  
  27. /**
  28.  * \file sbDndSourceTracker.js
  29.  */
  30.  
  31. const Cc = Components.classes;
  32. const Ci = Components.interfaces;
  33. const Cr = Components.results;
  34.  
  35. const CONTRACTID = "@songbirdnest.com/Songbird/DndSourceTracker;1";
  36. const CLASSNAME = "Songbird Drag and Drop Source Tracker Service";
  37. const CID = Components.ID("{54b21a93-5b1b-46a2-a60f-5378ccf7f65c}");
  38. const IID = Ci.sbIDndSourceTracker;
  39.  
  40. function DndSourceTracker() {
  41.   this._sources = {};
  42. }
  43. DndSourceTracker.prototype = {
  44.   _sources: null,
  45.   _nextHandle: 0,
  46.  
  47.   reset: function reset() {
  48.     this._sources = {};
  49.   },
  50.  
  51.   registerSource: function registerSource(aSource) {
  52.     var handle = this._nextHandle.toString();
  53.     this._nextHandle++;
  54.     this._sources[handle] = aSource;
  55.     return handle;
  56.   },
  57.  
  58.   getSource: function getSource(aHandle) {
  59.     if (aHandle in this._sources) {
  60.       return this._sources[aHandle];
  61.     }
  62.     throw Cr.NS_ERROR_NOT_AVAILABLE;
  63.   },
  64.  
  65.   getSourceSupports: function getSourceSupports(aHandle) {
  66.     return this.getSource(aHandle.data);
  67.   },
  68.  
  69.   QueryInterface: function(iid) {
  70.     if (!iid.equals(IID) &&
  71.         !iid.equals(Ci.nsISupports))
  72.       throw Cr.NS_ERROR_NO_INTERFACE;
  73.     return this;
  74.   }
  75. };
  76.  
  77. /**
  78.  * ----------------------------------------------------------------------------
  79.  * Registration for XPCOM
  80.  * ----------------------------------------------------------------------------
  81.  */
  82. var gModule = {
  83.   registerSelf: function(componentManager, fileSpec, location, type) {
  84.     componentManager = componentManager.QueryInterface(Ci.nsIComponentRegistrar);
  85.     componentManager.registerFactoryLocation(CID, CLASSNAME, CONTRACTID,
  86.                                              fileSpec, location, type);
  87.   },
  88.  
  89.   getClassObject: function(componentManager, cid, iid) {
  90.     if (!iid.equals(Ci.nsIFactory))
  91.       throw Cr.NS_ERROR_NOT_IMPLEMENTED;
  92.  
  93.     if (cid.equals(CID)) {
  94.        return {
  95.           createInstance: function(outer, iid) {
  96.             if (outer != null)
  97.               throw Cr.NS_ERROR_NO_AGGREGATION;
  98.             return (new DndSourceTracker()).QueryInterface(iid);;
  99.           }
  100.        };
  101.     }
  102.  
  103.     throw Cr.NS_ERROR_NO_INTERFACE;
  104.   },
  105.  
  106.   canUnload: function(componentManager) { 
  107.     return true; 
  108.   }
  109. };
  110.  
  111. function NSGetModule(comMgr, fileSpec) {
  112.   return gModule;
  113. }
  114.  
  115.