WellKnownOpportunisticUtils.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. 'use strict';
  6. const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
  7. Cu.import("resource://gre/modules/XPCOMUtils.jsm");
  8. const WELLKNOWNOPPORTUNISTICUTILS_CONTRACTID = "@mozilla.org/network/well-known-opportunistic-utils;1";
  9. const WELLKNOWNOPPORTUNISTICUTILS_CID = Components.ID("{b4f96c89-5238-450c-8bda-e12c26f1d150}");
  10. function WellKnownOpportunisticUtils() {
  11. this.valid = false;
  12. this.mixed = false;
  13. this.lifetime = 0;
  14. }
  15. WellKnownOpportunisticUtils.prototype = {
  16. classID: WELLKNOWNOPPORTUNISTICUTILS_CID,
  17. contractID: WELLKNOWNOPPORTUNISTICUTILS_CONTRACTID,
  18. classDescription: "Well-Known Opportunistic Utils",
  19. QueryInterface: XPCOMUtils.generateQI([Ci.nsIWellKnownOpportunisticUtils]),
  20. verify: function(aJSON, aOrigin, aAlternatePort) {
  21. try {
  22. let obj = JSON.parse(aJSON.toLowerCase());
  23. let ports = obj[aOrigin.toLowerCase()]['tls-ports'];
  24. if (ports.indexOf(aAlternatePort) == -1) {
  25. throw "invalid port";
  26. }
  27. this.lifetime = obj[aOrigin.toLowerCase()]['lifetime'];
  28. this.mixed = obj[aOrigin.toLowerCase()]['mixed-scheme'];
  29. } catch (e) {
  30. return;
  31. }
  32. this.valid = true;
  33. },
  34. };
  35. this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WellKnownOpportunisticUtils]);