self.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 { CC } = require('chrome');
  9. const { id, name, prefixURI, rootURI, metadata,
  10. version, loadReason, preferencesBranch } = require('@loader/options');
  11. const { readURISync } = require('./net/url');
  12. const addonDataURI = prefixURI + name + '/data/';
  13. const uri = (path="") =>
  14. path.contains(":") ? path : addonDataURI + path;
  15. // Some XPCOM APIs require valid URIs as an argument for certain operations
  16. // (see `nsILoginManager` for example). This property represents add-on
  17. // associated unique URI string that can be used for that.
  18. exports.uri = 'addon:' + id;
  19. exports.id = id;
  20. exports.preferencesBranch = preferencesBranch || id;
  21. exports.name = name;
  22. exports.loadReason = loadReason;
  23. exports.version = version;
  24. // If `rootURI` is jar:file://...!/ than add-on is packed.
  25. exports.packed = (rootURI || '').indexOf('jar:') === 0;
  26. exports.data = Object.freeze({
  27. url: uri,
  28. load: function read(path) {
  29. return readURISync(uri(path));
  30. }
  31. });
  32. exports.isPrivateBrowsingSupported = ((metadata || {}).permissions || {})['private-browsing'] === true;