Bug 1269347 - Part2 Add support for embedded webextension in SDK test addons. draft
authorLuca Greco <lgreco@mozilla.com>
Mon, 23 May 2016 23:02:18 +0200
changeset 371398 6dfd254aeecf6fc678c0fe548d4a9a4caf7b3b71
parent 371397 11060b6664b08c3801113fb1d2833f8ae9bd582a
child 371399 dfe4c3453e7f4e57f9a21e08a09307faad1bf318
push id19318
push userluca.greco@alcacoop.it
push dateThu, 26 May 2016 15:05:11 +0000
bugs1269347
milestone49.0a1
Bug 1269347 - Part2 Add support for embedded webextension in SDK test addons. MozReview-Commit-ID: 4WS5ZYkl8FY
addon-sdk/source/app-extension/bootstrap.js
addon-sdk/source/python-lib/cuddlefish/rdf.py
addon-sdk/source/python-lib/cuddlefish/xpi.py
--- a/addon-sdk/source/app-extension/bootstrap.js
+++ b/addon-sdk/source/app-extension/bootstrap.js
@@ -252,16 +252,19 @@ function startup(data, reasonCode) {
           checkMemory: options.check_memory,
         }
       }
     });
 
     let module = cuddlefish.Module('sdk/loader/cuddlefish', cuddlefishURI);
     let require = cuddlefish.Require(loader, module);
 
+    // Init the 'sdk/webextension' module from the bootstrap addon parameter.
+    require("sdk/webextension").initFromBootstrapAddonParam(data);
+
     require('sdk/addon/runner').startup(reason, {
       loader: loader,
       main: main,
       prefsURI: rootURI + 'defaults/preferences/prefs.js'
     });
   } catch (error) {
     dump('Bootstrap error: ' +
          (error.message ? error.message : String(error)) + '\n' +
--- a/addon-sdk/source/python-lib/cuddlefish/rdf.py
+++ b/addon-sdk/source/python-lib/cuddlefish/rdf.py
@@ -128,16 +128,21 @@ def gen_manifest(template_root_dir, targ
     manifest.set("em:creator",
                  target_cfg.get("author", ""))
     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.
     manifest.set("em:unpack", "true" if target_cfg.get("unpack") else "false")
 
+    if target_cfg.get('enableEmbeddedWebExtension', False):
+        elem = dom.createElement("em:enableEmbeddedWebExtension");
+        elem.appendChild(dom.createTextNode("true"))
+        dom.documentElement.getElementsByTagName("Description")[0].appendChild(elem)
+
     for translator in target_cfg.get("translators", [ ]):
         elem = dom.createElement("em:translator");
         elem.appendChild(dom.createTextNode(translator))
         dom.documentElement.getElementsByTagName("Description")[0].appendChild(elem)
 
     for developer in target_cfg.get("developers", [ ]):
         elem = dom.createElement("em:developer");
         elem.appendChild(dom.createTextNode(developer))
--- a/addon-sdk/source/python-lib/cuddlefish/xpi.py
+++ b/addon-sdk/source/python-lib/cuddlefish/xpi.py
@@ -43,37 +43,42 @@ def build_xpi(template_root_dir, manifes
     if 'icon64' in harness_options:
         zf.write(os.path.join(str(harness_options['icon64'])), 'icon64.png')
         del harness_options['icon64']
 
     # chrome.manifest
     if os.path.isfile(os.path.join(pkgdir, 'chrome.manifest')):
       files_to_copy['chrome.manifest'] = os.path.join(pkgdir, 'chrome.manifest')
 
-    # chrome folder (would contain content, skin, and locale folders typically)
-    folder = 'chrome'
-    if os.path.exists(os.path.join(pkgdir, folder)):
-      dirs_to_create.add('chrome')
-      # cp -r folder
-      abs_dirname = os.path.join(pkgdir, folder)
-      for dirpath, dirnames, filenames in os.walk(abs_dirname):
+    def add_special_dir(folder):
+      if os.path.exists(os.path.join(pkgdir, folder)):
+        dirs_to_create.add(folder)
+        # cp -r folder
+        abs_dirname = os.path.join(pkgdir, folder)
+        for dirpath, dirnames, filenames in os.walk(abs_dirname):
           goodfiles = list(filter_filenames(filenames, IGNORED_FILES))
           dirnames[:] = filter_dirnames(dirnames)
           for dirname in dirnames:
             arcpath = make_zipfile_path(template_root_dir,
                                         os.path.join(dirpath, dirname))
             dirs_to_create.add(arcpath)
           for filename in goodfiles:
               abspath = os.path.join(dirpath, filename)
               arcpath = ZIPSEP.join(
                   [folder,
                    make_zipfile_path(abs_dirname, os.path.join(dirpath, filename)),
                    ])
               files_to_copy[str(arcpath)] = str(abspath)
 
+
+    # chrome folder (would contain content, skin, and locale folders typically)
+    add_special_dir('chrome')
+    # optionally include a `webextension/` dir from the add-on dir.
+    add_special_dir('webextension')
+
     for dirpath, dirnames, filenames in os.walk(template_root_dir):
         if template_root_dir == dirpath:
             filenames = list(filter_filenames(filenames, IGNORED_TOP_LVL_FILES))
         filenames = list(filter_filenames(filenames, IGNORED_FILES))
         dirnames[:] = filter_dirnames(dirnames)
         for dirname in dirnames:
             arcpath = make_zipfile_path(template_root_dir,
                                         os.path.join(dirpath, dirname))