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 import {RDFDataSource} from "resource://legacy/RDFDataSource.sys.mjs";
10 const RDFURI_INSTALL_MANIFEST_ROOT = "urn:mozilla:install-manifest";
12 function EM_R(aProperty) {
13 return `http://www.mozilla.org/2004/em-rdf#${aProperty}`;
16 function getValue(literal) {
17 return literal && literal.getValue();
20 function getProperty(resource, property) {
21 return getValue(resource.getProperty(EM_R(property)));
29 static loadFromString(text) {
30 return new this(RDFDataSource.loadFromString(text));
33 static loadFromBuffer(buffer) {
34 return new this(RDFDataSource.loadFromBuffer(buffer));
37 static async loadFromFile(uri) {
38 return new this(await RDFDataSource.loadFromFile(uri));
42 export class InstallRDF extends Manifest {
43 _readProps(source, obj, props) {
44 for (let prop of props) {
45 let val = getProperty(source, prop);
52 _readArrayProp(source, obj, prop, target, decode = getValue) {
53 let result = Array.from(source.getObjects(EM_R(prop)),
54 target => decode(target));
60 _readArrayProps(source, obj, props, decode = getValue) {
61 for (let [prop, target] of Object.entries(props)) {
62 this._readArrayProp(source, obj, prop, target, decode);
66 _readLocaleStrings(source, obj) {
67 this._readProps(source, obj, ["name", "description", "creator", "homepageURL"]);
68 this._readArrayProps(source, obj, {
70 developer: "developers",
71 translator: "translators",
72 contributor: "contributors",
77 let root = this.ds.getResource(RDFURI_INSTALL_MANIFEST_ROOT);
80 let props = ["id", "version", "type", "updateURL", "optionsURL",
81 "optionsType", "aboutURL", "iconURL",
82 "bootstrap", "unpack", "strictCompatibility"];
83 this._readProps(root, result, props);
85 let decodeTargetApplication = source => {
87 this._readProps(source, app, ["id", "minVersion", "maxVersion"]);
91 let decodeLocale = source => {
93 this._readLocaleStrings(source, localized);
97 this._readLocaleStrings(root, result);
99 this._readArrayProps(root, result, {"targetPlatform": "targetPlatforms"});
100 this._readArrayProps(root, result, {"targetApplication": "targetApplications"},
101 decodeTargetApplication);
102 this._readArrayProps(root, result, {"localized": "localized"},
104 this._readArrayProps(root, result, {"dependency": "dependencies"},
105 source => getProperty(source, "id"));