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/. */
6 var EXPORTED_SYMBOLS = ["InstallRDF"];
8 ChromeUtils.defineModuleGetter(this, "RDFDataSource",
9 "resource://legacy/RDFDataSource.jsm");
11 const RDFURI_INSTALL_MANIFEST_ROOT = "urn:mozilla:install-manifest";
13 function EM_R(aProperty) {
14 return `http://www.mozilla.org/2004/em-rdf#${aProperty}`;
17 function getValue(literal) {
18 return literal && literal.getValue();
21 function getProperty(resource, property) {
22 return getValue(resource.getProperty(EM_R(property)));
30 static loadFromString(text) {
31 return new this(RDFDataSource.loadFromString(text));
34 static loadFromBuffer(buffer) {
35 return new this(RDFDataSource.loadFromBuffer(buffer));
38 static async loadFromFile(uri) {
39 return new this(await RDFDataSource.loadFromFile(uri));
43 class InstallRDF extends Manifest {
44 _readProps(source, obj, props) {
45 for (let prop of props) {
46 let val = getProperty(source, prop);
53 _readArrayProp(source, obj, prop, target, decode = getValue) {
54 let result = Array.from(source.getObjects(EM_R(prop)),
55 target => decode(target));
61 _readArrayProps(source, obj, props, decode = getValue) {
62 for (let [prop, target] of Object.entries(props)) {
63 this._readArrayProp(source, obj, prop, target, decode);
67 _readLocaleStrings(source, obj) {
68 this._readProps(source, obj, ["name", "description", "creator", "homepageURL"]);
69 this._readArrayProps(source, obj, {
71 developer: "developers",
72 translator: "translators",
73 contributor: "contributors",
78 let root = this.ds.getResource(RDFURI_INSTALL_MANIFEST_ROOT);
81 let props = ["id", "version", "type", "updateURL", "optionsURL",
82 "optionsType", "aboutURL", "iconURL",
83 "bootstrap", "unpack", "strictCompatibility"];
84 this._readProps(root, result, props);
86 let decodeTargetApplication = source => {
88 this._readProps(source, app, ["id", "minVersion", "maxVersion"]);
92 let decodeLocale = source => {
94 this._readLocaleStrings(source, localized);
98 this._readLocaleStrings(root, result);
100 this._readArrayProps(root, result, {"targetPlatform": "targetPlatforms"});
101 this._readArrayProps(root, result, {"targetApplication": "targetApplications"},
102 decodeTargetApplication);
103 this._readArrayProps(root, result, {"localized": "localized"},
105 this._readArrayProps(root, result, {"dependency": "dependencies"},
106 source => getProperty(source, "id"));