Bug 1269347 - Part2 Add support for embedded webextension in SDK test addons. r=mossop
authorLuca Greco <lgreco@mozilla.com>
Mon, 23 May 2016 23:02:18 +0200
changeset 314413 013eb78e6709ad5ccbfb64dfc3980d8b0756081e
parent 314412 70c93b940d716bf091c3ba95658aafdeb783386a
child 314414 28459fc537c796d0ac0ca76887e82af239cf4451
push id20574
push usercbook@mozilla.com
push dateTue, 20 Sep 2016 10:05:16 +0000
treeherderfx-team@14705f779a46 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1269347
milestone51.0a1
Bug 1269347 - Part2 Add support for embedded webextension in SDK test addons. r=mossop This commit make it possible the creation of hybrid addons as part of the set of SDK test addons. Unfortunately these SDK test addons are build using the old cfx tool and the its related module loader, and so this patch applies the changes needed to: - optionally include an `hasEmbeddedWebExtension` option in the generated "install.rdf" (if the test addon "package.json" contains a property with the same name in its "package.json") - initialize the "sdk/webextension" from the bootstrap method params (as already done in the previous patch for the new SDK module loader) - include the "webextension/" dir in the generated xpi, if any (similarly to how it is already done for the "chrome/" dir, which an SDK addon can optionally contain) 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('hasEmbeddedWebExtension', False):
+        elem = dom.createElement("em:hasEmbeddedWebExtension");
+        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))