Skip to content

Commit

Permalink
Merge branch 'current' of github.com:MrAlex94/Waterfox into current
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Kontos committed Feb 23, 2021
2 parents a625551 + f80c3d1 commit 7885d33
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 36 deletions.
24 changes: 24 additions & 0 deletions browser/components/extensions/parent/ext-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,30 @@ this.tabs = class extends ExtensionAPI {
return Promise.resolve(tabData);
},

async getSelected(windowId) {
let queryInfo = {
active: true, attention: null, audible: null, camera: null,
cookieStoreId: null, currentWindow: null, discarded: null,
hidden: null, highlighted: null, index: null,
lastFocusedWindow: null, microphone: null, muted: null,
openerTabId: null, pinned: null, screen: null, status: null,
title: null, url: null, windowId: windowId, windowType: null
};
return this.query(queryInfo);
},

async getAllInWindow(windowId) {
let queryInfo = {
active: null, attention: null, audible: null, camera: null,
cookieStoreId: null, currentWindow: true, discarded: null,
hidden: null, highlighted: null, index: null,
lastFocusedWindow: null, microphone: null, muted: null,
openerTabId: null, pinned: null, screen: null, status: null,
title: null, url: null, windowId: windowId, windowType: null
};
return this.query(queryInfo);
},

async query(queryInfo) {
if (!extension.hasPermission("tabs")) {
if (queryInfo.url !== null || queryInfo.title !== null) {
Expand Down
18 changes: 7 additions & 11 deletions browser/components/extensions/schemas/tabs.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,6 @@
},
{
"name": "getSelected",
"deprecated": "Please use $(ref:tabs.query) <code>{active: true}</code>.",
"unsupported": true,
"type": "function",
"description": "Gets the tab that is selected in the specified window.",
"async": "callback",
Expand All @@ -520,8 +518,6 @@
},
{
"name": "getAllInWindow",
"deprecated": "Please use $(ref:tabs.query) <code>{windowId: windowId}</code>.",
"unsupported": true,
"type": "function",
"description": "Gets details about all tabs in the specified window.",
"async": "callback",
Expand All @@ -533,13 +529,13 @@
"optional": true,
"description": "Defaults to the $(topic:current-window)[current window]."
},
{
"type": "function",
"name": "callback",
"parameters": [
{"name": "tabs", "type": "array", "items": { "$ref": "Tab" } }
]
}
{
"type": "function",
"name": "callback",
"parameters": [
{"name": "tabs", "type": "array", "items": { "$ref": "Tab" } }
]
}
]
},
{
Expand Down
4 changes: 1 addition & 3 deletions toolkit/mozapps/extensions/amContentHandler.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ amContentHandler.prototype = {
// Define nsiFiles
let nsiFileXpi = StoreHandler.getNsiFile(xpiPath);
let nsiManifest = StoreHandler.getNsiFile(manifestPath);
// get channel
let channel = StoreHandler.getChannel({uri: uri.spec, loadUsingSystemPrincipal: true});
// attempt install, wrapped async functions
StoreHandler.attemptInstall(channel, xpiPath, nsiFileXpi, nsiManifest);
StoreHandler.attemptInstall(uri, xpiPath, nsiFileXpi, nsiManifest);
return; // don't want any of the rest of the ContentHandler to execute
} else if (aMimetype != XPI_CONTENT_TYPE) {
throw Components.Exception("", Cr.NS_ERROR_WONT_HANDLE_CONTENT);
Expand Down
39 changes: 17 additions & 22 deletions toolkit/mozapps/extensions/amStoreHandler.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ var StoreHandler = {
)
},

/**
* Open a channel to be used to fetch a resource
* @param options Object to create channel
* example:
* {uri: uri.spec, loadUsingSystemPrincipal: true}
*/
getChannel(options) {
return NetUtil.newChannel(options);
},

/**
* Get an nsiFile object from a given path
* @param path string path to file
Expand All @@ -115,17 +105,18 @@ var StoreHandler = {

/**
* Attempt to install a crx extension
* @param channel nsiChannel from download uri
* @param uri object uri of request
* @param xpiPath string path to tmp extension file
* @param nsiFileXpi nsiFile tmp xpi file
* @param nsiManifest nsiFile tmp manifest.json
* @param retry bool is this a retry attempt or not
*/
attemptInstall(channel, xpiPath, nsiFileXpi, nsiManifest) {
attemptInstall(uri, xpiPath, nsiFileXpi, nsiManifest, retry=false) {
let channel = NetUtil.newChannel({uri: uri.spec, loadUsingSystemPrincipal: true});
NetUtil.asyncFetch(channel, (aInputStream, aResult) => {
// Check that we had success.
if (!Components.isSuccessCode(aResult)) {
// delete any tmp files
this._cleanup(nsiFileXpi);
if (retry == false) {this.attemptInstall(uri, xpiPath, nsiFileXpi, nsiManifest, true);return false;}
this._installFailedMsg("Fetching resource failed");
return false;
};
Expand Down Expand Up @@ -184,6 +175,7 @@ var StoreHandler = {
};
if (i == 3000) {
Services.console.logStringMessage("Magic not found");
return false;
};
// remove Chrome ext headers
let zipBuffer = arrayBuffer.slice(i);
Expand All @@ -207,7 +199,8 @@ var StoreHandler = {
let manifest = this._parseManifest(zr);
// only manifest version 2 currently supported
if (manifest.manifest_version != 2) {
Services.console.logStringMessage("Manifest version not supported, must be manifest_version: 2");
this._installFailedMsg("Manifest version not supported, must be manifest_version: 2");
return false;
}
// ensure locale properties set correctly
manifest = this._localeCheck(manifest, zr);
Expand Down Expand Up @@ -282,14 +275,16 @@ var StoreHandler = {
"contentSettings",
"contextMenus",
"debugger",
"pageCapture"
"pageCapture",
"tabCapture"
],
"options_page":"",
"permissions":
["background",
"contentSettings",
"debugger",
"pageCapture"
"pageCapture",
"tabCapture"
],
"version_name":""
}
Expand All @@ -315,7 +310,7 @@ var StoreHandler = {
arr[1].forEach((value) => {
if (unsupported[arr[0]].includes(value)) {permissionArr.push(value);}
})
if (permissionArr > 0) {
if (permissionArr.length > 0) {
unsupportedInManifest.push(permissionArr.join(","));
}
} else if (Object.keys(unsupported).includes(arr[0]) &&
Expand Down Expand Up @@ -347,19 +342,19 @@ var StoreHandler = {
},

/**
*
* Ensure manifest compliance based on extension contents
* @param manifest
* @param zr
*/
_localeCheck: function __localeCheck(manifest, zr) {
let entryPointer = "_locales";
let entryPointer = "_locales/";
if (zr.hasEntry(entryPointer)) {
if (!manifest.default_locale) {
zr.hasEntry("en") ? manifest.default_locale = "en" : manifest.default_locale = "en-US";
zr.hasEntry("_locales/en/") ? manifest.default_locale = "en" : manifest.default_locale = "en-US";
}
} else {
if (manifest.default_locale) {
delete manifest.defalt_locale;
delete manifest.default_locale;
}
}
return manifest;
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions toolkit/mozapps/extensions/test/xpcshell/head_addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ ChromeUtils.defineModuleGetter(
"setTimeout",
"resource://gre/modules/Timer.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"StoreHandler",
"resource://gre/modules/amStoreHandler.jsm"
);

XPCOMUtils.defineLazyServiceGetter(
this,
Expand All @@ -111,6 +116,12 @@ XPCOMUtils.defineLazyServiceGetter(
"amIAddonManagerStartup"
);

const ZipReader = Components.Constructor(
"@mozilla.org/libjar/zip-reader;1",
"nsIZipReader",
"open"
);

const {
createAppInfo,
createHttpServer,
Expand Down
97 changes: 97 additions & 0 deletions toolkit/mozapps/extensions/test/xpcshell/test_storehandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const MANIFESTS = {
success: {

},
fail: {

}
};

const profileDir = gProfD.clone();
profileDir.append("extensions");

add_task(async function setup() {
await promiseStartupManager();
});

// test remove chrome headers
add_task(async function test_remove_chrome_header() {
// set up example crx file
let crx = OS.Path.join(profileDir.path, "test.crx");
let testCrx = do_get_file("data/test.crx");
testCrx.copyTo(profileDir, "test.crx");
// call StoreHandler func
let res = await StoreHandler._removeChromeHeaders(crx);
equal(res, true);
// assert that reading the updated crx starts with correct bytes
let updatedCrx = await OS.File.read(crx);
let magic = new Uint8Array(updatedCrx.slice(0,4));
equal(JSON.stringify(Array.from(magic)), JSON.stringify([80,75,3,4]));
// corrupt file (no zip magic) should fail
let small = "data/invalid.xpi";
let res2 = await StoreHandler._removeChromeHeaders(small);
equal(res2, false);
});

add_task(async function test_parse_manifest() {
// parse manifest
let xpi = do_get_file("data/nolocale.xpi");
let zr = new ZipReader(xpi);
let res = StoreHandler._parseManifest(zr);
equal(typeof res, "object");
});

add_task(async function test_locale_check() {
// _locales and subdir en present, no default_locale in manifest
let locale = do_get_file("data/locale.xpi")
let zr = new ZipReader(locale);
let manifest = StoreHandler._parseManifest(zr);
equal(manifest.default_locale, undefined);
let res = StoreHandler._localeCheck(manifest, zr);
// en should be added as default_locale
equal(res.default_locale, "en")
// _locales not present, default_locale in manifest
let noLocale = do_get_file("data/nolocale.xpi");
let zr2 = new ZipReader(noLocale);
let manifest2 = StoreHandler._parseManifest(zr2);
equal(manifest2.default_locale, "en");
let res2 = StoreHandler._localeCheck(manifest2, zr2);
// default_locale should be deleted from manifest
equal(res2.default_locale, undefined);
}).only();

add_task(async function test_compat_check() {
// compat check
// should return list of all unsupported APIs
});

add_task(async function test_amend_manifest() {
// fail if manifest v > 2
// manifest_version not present
// if unsupportedAPIs return Array, else Object
// add guid
// delete update url
// stringify manifest
// failure
});

// test write tmp manifest
add_task(async function test_write_tmp_manifest() {

});
// failure
// test replace xpi manifest
add_task(async function test_replace_manifest() {

});
// failure
// test install updated addon
add_task(async function test_install_xpi() {

});
// failure
1 change: 1 addition & 0 deletions toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ skip-if = require_signing || !allow_legacy_extensions
head = head_addons.js head_sideload.js
skip-if = os == "linux" # Bug 1613268
[test_startup_enable.js]
[test_storehandler.js]
[test_strictcompatibility.js]
head = head_addons.js head_compat.js
[test_syncGUID.js]
Expand Down

0 comments on commit 7885d33

Please sign in to comment.