[tor-browser#43258] Remove content script crypto.subtle dependency.

This commit is contained in:
hackademix 2024-10-29 12:56:26 +01:00
parent 1519a63254
commit e9508889a7
No known key found for this signature in database
GPG Key ID: 231A83AFDA9C2434
3 changed files with 34 additions and 24 deletions

View File

@ -18,6 +18,9 @@
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
// depends on /nscl/common/sha256.js
// depends on /nscl/common/uuid.js
"use strict"; "use strict";
var LifeCycle = (() => { var LifeCycle = (() => {
@ -108,30 +111,45 @@ var LifeCycle = (() => {
unrestrictedTabs: [...ns.unrestrictedTabs] unrestrictedTabs: [...ns.unrestrictedTabs]
})); }));
let attr;
try { try {
// random attribute name for DOM storage
const attr = await sha256(data.concat(uuid()));
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
let l = async (tabId, changeInfo) => {
if (!!attr || tabId !== tab.id) return; let stored = false;
debug("Survival tab updating", changeInfo); const storeInTab = async (tabId, tabInfo) => {
if (changeInfo.status !== "complete") return; if (stored) {
browser.tabs.onUpdated.removeListener(storeInTab);
return;
}
if (tabId !== tab.id) {
return;
}
debug("Survival tab updating", tabInfo);
if (tabInfo.status !== "complete") {
return;
}
try { try {
attr = await Messages.send("store", {url, data: toBase64(new Uint8Array(cypherText))}, {tabId, frameId: 0}); stored = await Messages.send("store", {
url,
data: toBase64(new Uint8Array(cypherText)),
attr,
},
{tabId, frameId: 0}
);
resolve(); resolve();
debug("Survival tab updated"); debug(`Survival tab updated, stored: ${stored}`);
} catch (e) { } catch (e) {
if (!Messages.isMissingEndpoint(e)) { if (!Messages.isMissingEndpoint(e)) {
error(e, "Survival tab failed"); error(e, "Survival tab failed");
reject(e); reject(e);
} // otherwise we keep waiting for further updates from the tab until content script is ready to answer } // otherwise we keep waiting for further updates from the tab until content script is ready to answer
return false;
}; };
return true;
}; };
storeInTab(tabId, tab).then(() => {
l(tabId, tab).then(r => { if (!stored) browser.tabs.onUpdated.addListener(storeInTab);
if (!r) browser.tabs.onUpdated.addListener(l);
}); });
}); });
@ -218,8 +236,6 @@ var LifeCycle = (() => {
return { return {
async onInstalled(details) { async onInstalled(details) {
browser.runtime.onInstalled.removeListener(this.onInstalled);
if (!UA.isMozilla) { if (!UA.isMozilla) {
// Chromium does not inject content scripts at startup automatically for already loaded pages, // Chromium does not inject content scripts at startup automatically for already loaded pages,
// let's hack it manually. // let's hack it manually.
@ -318,9 +334,9 @@ var LifeCycle = (() => {
if (Ver.is(previousVersion, "<=", "11.4.1rc3")) { if (Ver.is(previousVersion, "<=", "11.4.1rc3")) {
// show theme switcher on update unless user has already chosen between Vintage Blue and Modern Red // show theme switcher on update unless user has already chosen between Vintage Blue and Modern Red
(async () => { (async () => {
await ns.initializing;
let isVintage = await Themes.isVintage(); let isVintage = await Themes.isVintage();
if (typeof isVintage === "boolean") return; if (typeof isVintage === "boolean") return;
await ns.init;
ns.openOptionsPage({tab: 2, focus: "#opt-vintageTheme", hilite: "#sect-themes"}); ns.openOptionsPage({tab: 2, focus: "#opt-vintageTheme", hilite: "#sect-themes"});
})(); })();
} }

View File

@ -90,19 +90,14 @@ Messages.addHandler({
return list; return list;
}, },
async store(event) { async store(event) {
if (document.URL !== event.url) return; if (document.URL !== event.url) return false;
const {data} = event; const {data, attr} = event;
const attr = await sha256(data.concat(Math.random()));
document.documentElement.dataset[attr] = data; document.documentElement.dataset[attr] = data;
return attr; return true;
}, },
retrieve(event) { retrieve(event) {
if (document.URL !== event.url) return; if (document.URL !== event.url) return;
let {attr, preserve} = event; let {attr, preserve} = event;
if (!attr) {
// legacy, < 11.0.39rc8
return document.documentElement.lastChild.textContent;
}
let data = document.documentElement.dataset[attr]; let data = document.documentElement.dataset[attr];
if (!preserve) delete document.documentElement.dataset[attr]; if (!preserve) delete document.documentElement.dataset[attr];
return data; return data;

View File

@ -86,7 +86,6 @@
"all_frames": true, "all_frames": true,
"js": [ "js": [
"/nscl/lib/browser-polyfill.js", "/nscl/lib/browser-polyfill.js",
"/nscl/common/sha256.js",
"/nscl/common/UA.js", "/nscl/common/UA.js",
"/nscl/common/uuid.js", "/nscl/common/uuid.js",
"/nscl/common/log.js", "/nscl/common/log.js",