New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

chrome-tailor-jetpack

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chrome-tailor-jetpack - npm Package Compare versions

Comparing version

to
0.0.2

.travis.yml

77

crx.js

@@ -6,7 +6,76 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

const self = require("sdk/self");
const contentScripts = require("./manifest-actions/content_scripts");
const background = require("./manifest-actions/background");
const browserAction = require("./manifest-actions/browser_action");
const overrides = require("./manifest-actions/chrome_url_overrides");
const events = require("sdk/system/events");
function getURL(path) {
return self.data.url("./crx/" + path);
function load(options) {
const rootURI = options.rootURI;
const manifest = require(rootURI + "manifest.json");
var browserActionBtn;
var backgroundPage;
var contentScriptMod;
function getURL(path) {
return rootURI + path;
}
if (manifest.background) {
let options = JSON.parse(JSON.stringify(manifest.background));
options.scripts = (Array.isArray(options.scripts) ? options.scripts : []).map(script => getURL(script));
if (options.page) {
options.page = getURL(options.page);
}
options.rootURI = rootURI;
backgroundPage = background(options);
}
if (manifest.browser_action) {
let options = JSON.parse(JSON.stringify(manifest.browser_action));
options.default_popup = getURL(options.default_popup);
options.default_icon = getURL(options.default_icon);
options.rootURI = rootURI;
browserActionBtn = browserAction(options);
}
if (manifest.chrome_url_overrides) {
let options = JSON.parse(JSON.stringify(manifest.chrome_url_overrides));
if (options.newtab) {
options.newtab = getURL(options.newtab);
}
options.rootURI = rootURI;
overrides(options);
}
if (manifest.content_scripts) {
manifest.content_scripts.forEach(def => {
let options = JSON.parse(JSON.stringify(def));
options.rootURI = rootURI;
if (options.js) {
options.js = options.js.map(getURL);
}
if (options.css) {
options.css = options.css.map(getURL);
}
contentScriptMod = contentScripts(options)
});
}
return {
unload: function() {
events.emit("crx-unload", {
subject: {
name: manifest.name
}
});
// TODO: close all overriden pages
}
}
}
exports.getURL = getURL;
exports.load = load;

@@ -14,2 +14,5 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

var runtime = createObjectIn(chrome, { defineAs: "runtime" });
var onMessage = createObjectIn(runtime, { defineAs: "onMessage" });
var browserAction = createObjectIn(chrome, { defineAs: "browserAction" });

@@ -19,2 +22,3 @@ var onClicked = createObjectIn(browserAction, { defineAs: "onClicked" });

var id = 0;
var runtimeCallbacks = [];

@@ -139,5 +143,122 @@

function tabsSendMessage(tabId, message, options, callback) {
var queryID = id++;
if (typeof options == "function") {
callback = options;
options = null;
}
self.port.on("tabs:got:message", function wait(data) {
if (data.id == queryID) {
self.port.removeListener("tabs:got:message", wait);
// TODO: implement results
callback && callback(data.result);
}
return null;
});
self.port.emit("tabs:send:message", {
id: queryID,
tabId: tabId,
message: message
});
}
exportFunction(tabsSendMessage, tabs, { defineAs: "sendMessage" });
self.port.on("tabs:send:message", function(data) {
var responseMade = false;
function sendResponse(result) {
if (responseMade) {
return null;
}
responseMade = true;
self.port.emit("tabs:message:response", {
id: data.id,
result: result
})
}
var MessageSender = {};
if (data.tabId) {
MessageSender.tab = {
id: data.tabId
};
}
runtimeCallbacks.forEach(cb => {
cb(cleanse(data.message), cleanse(MessageSender), sendResponse);
});
});
// END: chrome.tabs.*
// START: chrome.runtime.*
exportFunction(extGetURL, runtime, { defineAs: "getURL" });
function getCRXManifest() {
return self.options.manifest;
}
exportFunction(getCRXManifest, runtime, { defineAs: "getManifest" });
function runtimeSendMessage(extensionId, message, options, responseCallback) {
var queryID = id++;
if (typeof options == "function") {
responseCallback = options;
options = {};
}
self.port.on("runtime:message:response:callback", function wait(data) {
if (queryID != data.id) {
return null;
}
self.port.removeListener("runtime:message:response:callback", wait);
responseCallback(data.response);
});
self.port.emit("runtime:send:message", {
id: queryID,
extensionId: extensionId,
message: message
});
}
exportFunction(runtimeSendMessage, runtime, { defineAs: "sendMessage" });
// Note: PageMods do not recieve this message
self.port.on("runtime:send:message", function(data) {
function sendResponse(response) {
self.port.emit("runtime:message:response:callback", {
id: data.id,
response: response
});
}
var MessageSender = {};
if (data.tabId) {
MessageSender.tab = {
id: data.tabId
};
}
if (data.extensionId) {
MessageSender.id = extensionId;
}
runtimeCallbacks.forEach(cb => {
cb(cleanse(data.message), cleanse(MessageSender), sendResponse);
});
});
function runtimeOnMessage(callback) {
if (typeof callback == "function") {
runtimeCallbacks.push(callback);
}
}
exportFunction(runtimeOnMessage, onMessage, { defineAs: "addListener" });
// END: chrome.runtime.*
// START: chrome.extension.*

@@ -144,0 +265,0 @@

31

index.js

@@ -7,28 +7,7 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

const self = require("sdk/self");
const { getURL } = require("./crx");
const { load } = require("./crx");
// the chrome extension data is in data/crx
const manifest = require("./data/crx/manifest.json");
const background = require("./background");
var backgroundPage;
const browserAction = require("./browser_action");
var browserActionBtn;
const overrides = require("./overrides");
if (manifest.background) {
backgroundPage = background.create(manifest.background);
console.log("Created background page!");
}
if (manifest.browser_action) {
browserActionBtn = browserAction.create(manifest.browser_action);
console.log("Created browser_action!");
}
if (manifest.chrome_url_overrides) {
overrides.setup(manifest.chrome_url_overrides);
console.log("Overrides completed!");
}
var rootURI = self.data.url("/crx/");
var crx = load({
rootURI: rootURI
});

@@ -9,2 +9,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

const self = require("sdk/self");
const { PageMod } = require("sdk/page-mod");
const { newURI } = require("sdk/url/utils");

@@ -23,2 +24,24 @@ const { search } = require("sdk/places/history");

var tabIndex = 0;
var tabsMap = new WeakMap();
function getTabID(tab) {
if (!tabsMap.has(tab)) {
tabsMap.set(tab, tabIndex++);
}
return tabsMap.get(tab);
}
exports.getTabID = getTabID;
function getTabForID(id) {
for (let i = tabs.length -1; i >= 0; i--) {
let tab = tabs[i];
let tabID = getTabID(tab);
if (tabID == id) {
return tab;
}
}
return null;
}
exports.getTabForID = getTabForID;
function setup(options) {

@@ -30,3 +53,3 @@ var target = options.target;

var id = data.id;
var url = tabs[tabID].url;
var url = getTabForID(tabID).url;

@@ -39,2 +62,3 @@ tabs.open({

tab: {
id: getTabID(tab),
url: url,

@@ -53,5 +77,5 @@ title: tab.title,

var id = data.id;
for (let i = tabIDs.length - 1, tabID; i >= 0; i--) {
let tab = tabs[tabIDs[i]];
tab.close();
for (let i = tabIDs.length - 1; i >= 0; i--) {
let tab = getTabForID(tabIDs[i]);
tab && tab.close();
}

@@ -78,15 +102,7 @@

target.port.on("tabs:get:current", function(data) {
var i = 0;
var activeTab = tabs.activeTab;
for (let tab of tabs) {
if (tab === activeTab) {
break;
}
i++;
}
target.port.emit("tabs:got:current", {
id: data.id,
tab: {
id: i,
id: getTabID(activeTab),
url: activeTab.url

@@ -97,2 +113,36 @@ }

target.port.on("runtime:send:message", function(data) {
emit(emitter, "runtime:send:message", data);
});
if (!(target instanceof PageMod)) {
on(emitter, "runtime:send:message", function(data) {
target.port.emit("runtime:send:message", data);
});
target.port.on("runtime:message:response:callback", function(data) {
emit(emitter, "runtime:message:response:callback", data);
});
}
on(emitter, "runtime:message:response:callback", function(data) {
target.port.emit("runtime:message:response:callback", data);
});
target.port.on("tabs:send:message", function(data) {
emit(emitter, "tabs:send:message", data);
});
target.port.on("tabs:message:response", function(data) {
emit(emitter, "tabs:got:message", data);
});
function tabsGotMessage(data) {
target.port.emit("tabs:got:message", data);
}
on(emitter, "tabs:got:message", tabsGotMessage);
target.once("detach", () => {
off(emitter, "tabs:got:message", tabsGotMessage);
})
target.port.on("tabs:create", function(data) {

@@ -107,2 +157,3 @@ var url = data.options.url;

tab: {
id: getTabID(tab),
url: url,

@@ -201,2 +252,3 @@ title: tab.title,

tab: {
id: getTabID(tab),
url: tab.url,

@@ -203,0 +255,0 @@ title: tab.title

{
"name": "chrome-tailor-jetpack",
"version": "0.0.1",
"version": "0.0.2",
"description": "Enables Google Chrome extensions on Firefox.",

@@ -21,4 +21,3 @@ "main": "index.js",

"dependencies": {
"bluebird": "2.9.24"
}
}