summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Parri <simonparri@ganzeria.com>2025-08-13 11:18:51 -0500
committerSimon Parri <simonparri@ganzeria.com>2025-08-13 11:18:51 -0500
commit6d1aed740c2efb1283a8322b81c9ce5d0646aad9 (patch)
tree51d57e7314b7d56227285d38cba30c5cac2b026b
parentde25e333e17f05140b82793776dbce51fdec296d (diff)
parent836dadeb9ed2ad00465720301a21060ff48f7e11 (diff)
downloadlegacywolf-6d1aed740c2efb1283a8322b81c9ce5d0646aad9.tar.gz
legacywolf-6d1aed740c2efb1283a8322b81c9ce5d0646aad9.zip
Merge tag 'v5.0' into xpi
-rw-r--r--Makefile8
-rw-r--r--legacy/BootstrapLoader.sys.mjs8
-rw-r--r--legacy/LegacyFoxUtils.sys.mjs83
3 files changed, 95 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index fe19dba..e287869 100644
--- a/Makefile
+++ b/Makefile
@@ -10,13 +10,13 @@ all: $(archive)
$(archive): $(files)
zip $@ $(files)
-legacy.js: legacy/RDFDataSource.sys.mjs legacy/RDFManifestConverter.sys.mjs legacy/BootstrapLoader.sys.mjs legacy.base.js
+legacy.js: legacy/RDFDataSource.sys.mjs legacy/RDFManifestConverter.sys.mjs legacy/LegacyFoxUtils.sys.mjs legacy/BootstrapLoader.sys.mjs legacy.base.js
cat $^ >$@
clean:
rm -f $(archive) legacy.js
diff:
- @curl -s https://hg.mozilla.org/comm-central/raw-file/8a37a90aab4ec643fce1e1ab33984613ce0b492d/common/src/BootstrapLoader.jsm | diff --color -u - legacy/BootstrapLoader.sys.mjs ||:
- @curl -s https://hg.mozilla.org/comm-central/raw-file/8a37a90aab4ec643fce1e1ab33984613ce0b492d/common/src/RDFDataSource.jsm | diff --color -u - legacy/RDFDataSource.sys.mjs ||:
- @curl -s https://hg.mozilla.org/comm-central/raw-file/8a37a90aab4ec643fce1e1ab33984613ce0b492d/common/src/RDFManifestConverter.jsm | diff --color -u - legacy/RDFManifestConverter.sys.mjs ||:
+ @curl -sL https://hg.mozilla.org/comm-central/raw-file/8a37a90aab4ec643fce1e1ab33984613ce0b492d/common/src/BootstrapLoader.jsm | diff --color -u - legacy/BootstrapLoader.sys.mjs ||:
+ @curl -sL https://hg.mozilla.org/comm-central/raw-file/8a37a90aab4ec643fce1e1ab33984613ce0b492d/common/src/RDFDataSource.jsm | diff --color -u - legacy/RDFDataSource.sys.mjs ||:
+ @curl -sL https://hg.mozilla.org/comm-central/raw-file/8a37a90aab4ec643fce1e1ab33984613ce0b492d/common/src/RDFManifestConverter.jsm | diff --color -u - legacy/RDFManifestConverter.sys.mjs ||:
diff --git a/legacy/BootstrapLoader.sys.mjs b/legacy/BootstrapLoader.sys.mjs
index d28bf22..bd53689 100644
--- a/legacy/BootstrapLoader.sys.mjs
+++ b/legacy/BootstrapLoader.sys.mjs
@@ -336,7 +336,11 @@ return BootstrapLoader = {
startup(...args) {
if (addon.type == "extension") {
logger.debug(`Registering manifest for ${file.path}\n`);
+ try {
Components.manager.addBootstrappedManifestLocation(file);
+ } catch (e) { // mozilla142+
+ LegacyFoxUtils.addBootstrappedManifestLocation(file, addon, getURIForResourceInFile);
+ }
}
return startup(...args);
},
@@ -349,7 +353,11 @@ return BootstrapLoader = {
} finally {
if (reason != BOOTSTRAP_REASONS.APP_SHUTDOWN) {
logger.debug(`Removing manifest for ${file.path}\n`);
+ try {
Components.manager.removeBootstrappedManifestLocation(file);
+ } catch (e) { // mozilla142+
+ LegacyFoxUtils.removeBootstrappedManifestLocation(addon);
+ }
}
}
},
diff --git a/legacy/LegacyFoxUtils.sys.mjs b/legacy/LegacyFoxUtils.sys.mjs
new file mode 100644
index 0000000..6d13c2c
--- /dev/null
+++ b/legacy/LegacyFoxUtils.sys.mjs
@@ -0,0 +1,83 @@
+/**
+ * Replacements for Components.manager.addBootstrappedManifestLocation and
+ * Components.manager.removeBootstrappedManifestLocation, which have been nixed
+ * in mozilla142. Copyright 2025 Tobias Girstmair <https://gir.st/>, MPLv2.
+ */
+var LegacyFoxUtils = (function() {
+const ZipReader = Components.Constructor(
+ "@mozilla.org/libjar/zip-reader;1",
+ "nsIZipReader",
+ "open"
+);
+
+const ScriptableInputStream = Components.Constructor(
+ "@mozilla.org/scriptableinputstream;1",
+ "nsIScriptableInputStream",
+ "init"
+);
+
+const FileOutputStream = Components.Constructor(
+ "@mozilla.org/network/file-output-stream;1",
+ "nsIFileOutputStream",
+ "init"
+);
+
+return class LegacyFoxUtils {
+ static addBootstrappedManifestLocation(file, addon, uriMaker) {
+ // read chrome.manifest from .jar (or unpacked addon)
+ let zipReader = new ZipReader(file);
+ let istream = new ScriptableInputStream(zipReader.getInputStream("chrome.manifest"));
+ let manifestContents = istream.read(zipReader.getEntry("chrome.manifest").realSize);
+
+ // replace chrome:// and resource:// URIs with absolute paths to JAR
+ manifestContents = manifestContents
+ .split("\n")
+ .map(absolutizePaths.bind(null, uriMaker, file))
+ .join("\n");
+
+ // we store the temporary file in the user's profile, in a subdirectory
+ // analogous to webExtension's "browser-extension-data".
+ let manifest = Services.dirsvc.get('ProfD', Ci.nsIFile)
+ manifest.append('legacy-extension-data');
+ manifest.append(addon.id);
+ manifest.exists() || manifest.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
+ manifest.append('chrome.manifest'); /* created or truncated by ostream */
+
+ // write modified chrome.manifest to profile directory
+ let ostream = new FileOutputStream(manifest, -1, -1, 0);
+ ostream.write(manifestContents, manifestContents.length);
+ ostream.close();
+
+ // let Firefox read and parse it
+ Components.manager.QueryInterface(Ci.nsIComponentRegistrar).autoRegister(manifest);
+ }
+
+ static removeBootstrappedManifestLocation(addon) {
+ let manifestDir = Services.dirsvc.get('ProfD', Ci.nsIFile)
+ manifestDir.append('legacy-extension-data');
+ manifestDir.append(addon.id);
+ manifestDir.exists() && manifestDir.remove(/*recursive=*/true);
+ Cc['@mozilla.org/chrome/chrome-registry;1']
+ .getService(Ci.nsIXULChromeRegistry).checkForNewChrome();
+ }
+}
+
+function absolutizePaths(uriMaker, file, line) {
+ const manifestMethodPathLocation = {
+ content: 2, // content packagename uri/to/files/ [flags]
+ locale: 3, // locale packagename localename uri/to/files/ [flags]
+ skin: 3, // skin packagename skinname uri/to/files/ [flags]
+ resource: 2 // resource aliasname uri/to/files/ [flags]
+ };
+
+ let words = line.trim().split(/\s+/);
+ const index = manifestMethodPathLocation[words[0]];
+
+ if (index) {
+ words[index] = uriMaker(file, words[index]).spec;
+ line = words.join(" ");
+ }
+
+ return line;
+}
+})()