xhr.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. "use strict";
  5. module.metadata = {
  6. "stability": "stable"
  7. };
  8. const { deprecateFunction } = require("../util/deprecate");
  9. const { Cc, Ci } = require("chrome");
  10. const XMLHttpRequest = require("../addon/window").window.XMLHttpRequest;
  11. Object.defineProperties(XMLHttpRequest.prototype, {
  12. mozBackgroundRequest: {
  13. value: true,
  14. },
  15. forceAllowThirdPartyCookie: {
  16. configurable: true,
  17. value: deprecateFunction(function() {
  18. forceAllowThirdPartyCookie(this);
  19. }, "`xhr.forceAllowThirdPartyCookie()` is deprecated, please use" +
  20. "`require('sdk/net/xhr').forceAllowThirdPartyCookie(request)` instead")
  21. }
  22. });
  23. exports.XMLHttpRequest = XMLHttpRequest;
  24. function forceAllowThirdPartyCookie(xhr) {
  25. if (xhr.channel instanceof Ci.nsIHttpChannelInternal)
  26. xhr.channel.forceAllowThirdPartyCookie = true;
  27. }
  28. exports.forceAllowThirdPartyCookie = forceAllowThirdPartyCookie;
  29. // No need to handle add-on unloads as addon/window is closed at unload
  30. // and it will take down all the associated requests.