Bug 1068440: Uplift Add-on SDK to Firefox.

cc3242d1ca...cbf6cdd0d6
This commit is contained in:
Dave Townsend
2014-09-26 08:32:55 -07:00
parent caf3c1bdc9
commit f1e5377077
88 changed files with 1206 additions and 1464 deletions

View File

@@ -5,6 +5,8 @@
import os
import xml.dom.minidom
import StringIO
import codecs
import glob
RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
EM_NS = "http://www.mozilla.org/2004/em-rdf#"
@@ -20,9 +22,10 @@ class RDF(object):
# have .encoding hardwired to "ascii" and put only bytes in
# the backing store, so we can't use them here).
#
# The encoding= argument to dom.writexml() merely sets the XML header's
# encoding= attribute. It still writes unencoded unicode to the output file,
# so we have to encode it for real afterwards.
# The encoding= argument to dom.writexml() merely sets the
# XML header's encoding= attribute. It still writes unencoded
# unicode to the output file, so we have to encode it for
# real afterwards.
#
# Also see: https://bugzilla.mozilla.org/show_bug.cgi?id=567660
@@ -112,7 +115,12 @@ class RDFManifest(RDF):
return True;
def gen_manifest(template_root_dir, target_cfg, jid,
def add_node(self, node):
top = self.dom.documentElement.getElementsByTagName("Description")[0];
top.appendChild(node)
def gen_manifest(template_root_dir, target_cfg, jid, harness_options={},
update_url=None, bootstrap=True, enable_mobile=False):
install_rdf = os.path.join(template_root_dir, "install.rdf")
manifest = RDFManifest(install_rdf)
@@ -121,13 +129,51 @@ def gen_manifest(template_root_dir, target_cfg, jid,
manifest.set("em:id", jid)
manifest.set("em:version",
target_cfg.get('version', '1.0'))
if "locale" in harness_options:
# addon_title -> <em:name>
# addon_author -> <em:creator>
# addon_description -> <em:description>
# addon_homepageURL -> <em:homepageURL>
localizable_in = ["title", "author", "description", "homepage"]
localized_out = ["name", "creator", "description", "homepageURL"]
for lang in harness_options["locale"]:
desc = dom.createElement("Description")
for value_in in localizable_in:
key_in = "extensions." + target_cfg.get("id", "") + "." + value_in
tag_out = localized_out[localizable_in.index(value_in)]
if key_in in harness_options["locale"][lang]:
elem = dom.createElement("em:" + tag_out)
elem_value = harness_options["locale"][lang][key_in]
elem.appendChild(dom.createTextNode(elem_value))
desc.appendChild(elem)
# Don't add language if no localizeable field was localized
if desc.hasChildNodes():
locale = dom.createElement("em:locale")
locale.appendChild(dom.createTextNode(lang))
desc.appendChild(locale)
localized = dom.createElement("em:localized")
localized.appendChild(desc)
manifest.add_node(localized)
manifest.set("em:name",
target_cfg.get('title', target_cfg.get('fullName', target_cfg['name'])))
manifest.set("em:description",
target_cfg.get("description", ""))
manifest.set("em:creator",
target_cfg.get("author", ""))
if target_cfg.get("homepage"):
manifest.set("em:homepageURL", target_cfg.get("homepage"))
else:
manifest.remove("em:homepageURL")
manifest.set("em:bootstrap", str(bootstrap).lower())
# XPIs remain packed by default, but package.json can override that. The
# RDF format accepts "true" as True, anything else as False. We expect
# booleans in the .json file, not strings.
@@ -136,7 +182,7 @@ def gen_manifest(template_root_dir, target_cfg, jid,
for translator in target_cfg.get("translators", [ ]):
elem = dom.createElement("em:translator");
elem.appendChild(dom.createTextNode(translator))
dom.documentElement.getElementsByTagName("Description")[0].appendChild(elem)
manifest.add_node(elem)
for developer in target_cfg.get("developers", [ ]):
elem = dom.createElement("em:developer");
@@ -146,7 +192,7 @@ def gen_manifest(template_root_dir, target_cfg, jid,
for contributor in target_cfg.get("contributors", [ ]):
elem = dom.createElement("em:contributor");
elem.appendChild(dom.createTextNode(contributor))
dom.documentElement.getElementsByTagName("Description")[0].appendChild(elem)
manifest.add_node(elem)
if update_url:
manifest.set("em:updateURL", update_url)
@@ -169,7 +215,7 @@ def gen_manifest(template_root_dir, target_cfg, jid,
if enable_mobile:
target_app = dom.createElement("em:targetApplication")
dom.documentElement.getElementsByTagName("Description")[0].appendChild(target_app)
manifest.add_node(target_app)
ta_desc = dom.createElement("Description")
target_app.appendChild(ta_desc)
@@ -186,11 +232,6 @@ def gen_manifest(template_root_dir, target_cfg, jid,
elem.appendChild(dom.createTextNode("30.0a1"))
ta_desc.appendChild(elem)
if target_cfg.get("homepage"):
manifest.set("em:homepageURL", target_cfg.get("homepage"))
else:
manifest.remove("em:homepageURL")
return manifest
if __name__ == "__main__":