home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Multimedia / Songbird / Songbird_2.0.0-2311_windows-i686-msvc8.exe / components / sbAboutDRM.js < prev    next >
Text File  |  2012-06-08  |  3KB  |  103 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. const Cc = Components.classes;
  28. const Ci = Components.interfaces;
  29. const Cr = Components.results;
  30.  
  31. const DESCRIPTION = "sbAboutDRM";
  32. const CID         = "416a028e-1dd2-11b2-a247-cc08533670be";
  33. const CONTRACTID  = "@mozilla.org/network/protocol/about;1?what=drm";
  34.  
  35. Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
  36.  
  37. var Application = Cc["@mozilla.org/fuel/application;1"]
  38.                     .getService(Ci.fuelIApplication);
  39.  
  40. function hash(str) {
  41.   var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
  42.       .createInstance(Ci.nsIScriptableUnicodeConverter);
  43.  
  44.   converter.charset = "UTF-8";
  45.   // result is an out parameter,
  46.   // result.value will contain the array length
  47.   var result = {};
  48.   // data is an array of bytes
  49.   var data = converter.convertToByteArray(str, result);
  50.   var ch = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsICryptoHash);
  51.   ch.init(ch.MD5);
  52.   ch.update(data, data.length);
  53.   var hash = ch.finish(true);
  54.  
  55.   // return the two-digit hexadecimal code for a byte
  56.   function toHexString(charCode) {
  57.     return ("0" + charCode.toString(16)).slice(-2);
  58.   }
  59.  
  60.   // convert the binary hash data to a hex string.
  61.   var s = [toHexString(hash.charCodeAt(i)) for (i in hash)].join("");
  62.   return s;
  63. }
  64.  
  65. function sbAboutDRM() {
  66. }
  67. sbAboutDRM.prototype = {
  68.   classDescription: DESCRIPTION,
  69.   classID:          Components.ID(CID),
  70.   contractID:       CONTRACTID,
  71.  
  72.   newChannel: function(uri) {
  73.     var env = Cc["@mozilla.org/process/environment;1"]
  74.                 .getService(Ci.nsIEnvironment);
  75.     var username = hash(env.get("USER"));
  76.     var url;
  77.  
  78.     if (username == "3542497335674c50367976365951515551494c6f69413d3d" ||
  79.         username == "78636249353331464e4c6f3539612f7368714f694f673d3d" ||
  80.         Application.prefs.getValue("songbird.buildNumber","42") != "0")
  81.     {
  82.       url = "http://wikipedia.org/wiki/Digital_rights_management#Controversy";
  83.     } else {
  84.       url = "chrome://songbird/content/html/aboutDRM.xhtml";
  85.     }
  86.     var ioService = Cc["@mozilla.org/network/io-service;1"]
  87.                       .getService(Ci.nsIIOService);
  88.     var childURI = ioService.newURI(url, null, null);
  89.     var channel = ioService.newChannelFromURI(childURI);
  90.     channel.originalURI = uri;
  91.  
  92.     return channel;
  93.   },
  94.  
  95.   getURIFlags: function(uri) {
  96.     return Ci.nsIAboutModule.ALLOW_SCRIPT;
  97.   },
  98.  
  99.   QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule])
  100. }
  101.  
  102. var NSGetModule = XPCOMUtils.generateNSGetModule([sbAboutDRM]);
  103.