nsUrlClassifierLib.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. // We wastefully reload the same JS files across components. This puts all
  5. // the common JS files used by safebrowsing and url-classifier into a
  6. // single component.
  7. const Cc = Components.classes;
  8. const Ci = Components.interfaces;
  9. const G_GDEBUG = false;
  10. Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
  11. #include ./content/moz/lang.js
  12. #include ./content/moz/preferences.js
  13. #include ./content/moz/debug.js
  14. #include ./content/moz/alarm.js
  15. #include ./content/moz/cryptohasher.js
  16. #include ./content/moz/observer.js
  17. #include ./content/moz/protocol4.js
  18. #include ./content/request-backoff.js
  19. #include ./content/xml-fetcher.js
  20. // Wrap a general-purpose |RequestBackoff| to a v4-specific one
  21. // since both listmanager and hashcompleter would use it.
  22. // Note that |maxRequests| and |requestPeriod| is still configurable
  23. // to throttle pending requests.
  24. function RequestBackoffV4(maxRequests, requestPeriod) {
  25. let rand = Math.random();
  26. let retryInterval = Math.floor(15 * 60 * 1000 * (rand + 1)); // 15 ~ 30 min.
  27. let backoffInterval = Math.floor(30 * 60 * 1000 * (rand + 1)); // 30 ~ 60 min.
  28. return new RequestBackoff(2 /* max errors */,
  29. retryInterval /* retry interval, 15~30 min */,
  30. maxRequests /* num requests */,
  31. requestPeriod /* request time, 60 min */,
  32. backoffInterval /* backoff interval, 60 min */,
  33. 24 * 60 * 60 * 1000 /* max backoff, 24hr */);
  34. }
  35. // Expose this whole component.
  36. var lib = this;
  37. function UrlClassifierLib() {
  38. this.wrappedJSObject = lib;
  39. }
  40. UrlClassifierLib.prototype.classID = Components.ID("{26a4a019-2827-4a89-a85c-5931a678823a}");
  41. UrlClassifierLib.prototype.QueryInterface = XPCOMUtils.generateQI([]);
  42. this.NSGetFactory = XPCOMUtils.generateNSGetFactory([UrlClassifierLib]);