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/. */
5 /* eslint-env mozilla/chrome-worker */
9 importScripts("resource://gre/modules/osfile.jsm");
11 const FILE_ENTRY = "201: ";
13 onmessage = async function(msg) {
15 let extractedPaths = [];
16 let jarPath = "jar:file://" + msg.data.zipPath + "!/";
17 let jarResponse = await fetch(jarPath);
18 let dirListing = await jarResponse.text();
19 let lines = dirListing.split("\n");
20 let reader = new FileReader();
21 for (let line of lines) {
22 if (!line.startsWith(FILE_ENTRY)) {
23 // Not a file entry, skip.
26 let lineSplits = line.split(" ");
27 let fileName = lineSplits[1];
28 // We don't need these types of files.
30 fileName == "verified_contents.json" ||
31 fileName == "icon-128x128.png"
35 let filePath = jarPath + fileName;
36 let filePathResponse = await fetch(filePath);
37 let fileContents = await filePathResponse.blob();
38 let fileData = await new Promise(resolve => {
39 reader.onloadend = function() {
40 resolve(reader.result);
42 reader.readAsArrayBuffer(fileContents);
44 let profileDirPath = OS.Constants.Path.profileDir;
45 let installToDirPath = OS.Path.join(
47 msg.data.relativeInstallPath
49 await OS.File.makeDir(installToDirPath, {
54 // Do not extract into directories. Extract all files to the same
56 let destPath = OS.Path.join(installToDirPath, fileName);
57 await OS.File.writeAtomic(destPath, new Uint8Array(fileData), {
58 tmpPath: destPath + ".tmp",
60 // Ensure files are writable and executable. Otherwise, we may be
61 // unable to execute or uninstall them.
62 await OS.File.setPermissions(destPath, { unixMode: 0o700 });
63 if (OS.Constants.Sys.Name == "Darwin") {
64 // If we're on MacOS Firefox will add the quarantine xattr to files it
65 // downloads. In this case we want to clear that xattr so we can load
68 await OS.File.macRemoveXAttr(destPath, "com.apple.quarantine");
70 // Failed to remove the attribute. This could be because the profile
71 // exists on a file system without xattr support.
73 // Don't fail the extraction here, as in this case it's likely we
74 // didn't set quarantine on these files in the first place.
77 extractedPaths.push(destPath);