Improved compartmentalisation and memory management of Firefox driver

main
Elbert Alias 11 years ago
parent c7a2d33e3d
commit b14f89314c

@ -13,15 +13,35 @@
ss = require('sdk/simple-storage'), ss = require('sdk/simple-storage'),
sp = require("sdk/simple-prefs"), sp = require("sdk/simple-prefs"),
tabs = require('sdk/tabs'), tabs = require('sdk/tabs'),
initTab,
Panel,
panel, panel,
Widget,
widget, widget,
initTab, UrlBar,
addIcon, urlBar;
removeIcons,
createPanel, exports.main = function(options, callbacks) {
createWidget, w.log('main: ' + options.loadReason);
getUrlBar,
getDocument; w.init();
};
exports.onUnload = function(reason) {
w.log('unload: ' + reason);
if ( urlBar ) {
urlBar.destroy();
}
if ( widget ) {
widget.destroy();
}
if ( panel ) {
panel.destroy();
}
};
initTab = function(tab) { initTab = function(tab) {
tabCache[tab.id] = { count: 0, appsDetected: [] }; tabCache[tab.id] = { count: 0, appsDetected: [] };
@ -34,7 +54,7 @@
worker.port.on('analyze', function(message) { worker.port.on('analyze', function(message) {
var url = message.url.replace(/#.*$/, ''); var url = message.url.replace(/#.*$/, '');
if ( headersCache[url] !== undefined ) { if ( typeof headersCache[url] !== 'undefined' ) {
message.analyze.headers = headersCache[url]; message.analyze.headers = headersCache[url];
} }
@ -57,42 +77,10 @@
w.driver.displayApps(); w.driver.displayApps();
}); });
addIcon = function(appName) { Panel = function() {
var var self = this;
icon = getDocument().createElement('image'),
url = appName !== undefined ? 'images/icons/' + appName + '.png' : 'images/icon32.png',
tooltipText = ( appName !== undefined ? appName + ' - ' + require('sdk/l10n').get('clickForDetails') + ' - ' : '' ) + require('sdk/l10n').get('name');
icon.setAttribute('src', data.url(url)); this.panel = require('sdk/panel').Panel({
icon.setAttribute('class', 'wappalyzer-icon');
icon.setAttribute('width', '16');
icon.setAttribute('height', '16');
icon.setAttribute('style', 'margin: 0 1px;');
icon.setAttribute('tooltiptext', tooltipText);
getUrlBar().appendChild(icon);
return icon;
};
removeIcons = function() {
var icons;
do {
icons = getUrlBar().getElementsByClassName('wappalyzer-icon');
if ( icons.length ) {
getUrlBar().removeChild(icons[0]);
}
} while ( icons.length );
};
createPanel = function() {
if ( panel ) {
panel.destroy();
}
panel = require('sdk/panel').Panel({
width: 250, width: 250,
height: 50, height: 50,
contentURL: data.url('panel.html'), contentURL: data.url('panel.html'),
@ -100,70 +88,106 @@
position: { right: 30, top: 30 } position: { right: 30, top: 30 }
}); });
panel.port.on('resize', function(height) { this.panel.port.on('resize', function(height) {
panel.height = height; self.panel.height = height;
}); });
panel.port.on('goToUrl', function(url) { this.panel.port.on('goToUrl', function(url) {
panel.hide(); self.panel.hide();
w.driver.goToURL({ url: w.config.websiteURL + url, medium: 'panel' }); w.driver.goToURL({ url: w.config.websiteURL + url, medium: 'panel' });
}); });
} };
createWidget = function() { Panel.prototype.get = function() {
createPanel(); return this.panel;
};
widget = require('sdk/widget').Widget({ Panel.prototype.destroy = function() {
this.panel.destroy();
};
Widget = function(panel) {
this.widget = require('sdk/widget').Widget({
id: 'wappalyzer', id: 'wappalyzer',
label: 'Wappalyzer', label: 'Wappalyzer',
contentURL: data.url('images/icon32.png'), contentURL: data.url('images/icon32.png'),
panel: panel panel: panel.get()
}); });
} };
getUrlBar = function() { Widget.prototype.get = function() {
var return this.widget;
urlBar = getDocument().getElementById('wappalyzer-urlbar'), };
show = true;
if ( !urlBar ) { Widget.prototype.destroy = function() {
urlBar = getDocument().createElement('hbox'); this.widget.destroy();
};
UrlBar = function(panel) {
var self = this;
urlBar.setAttribute('id', 'wappalyzer-urlbar'); this.panel = panel;
urlBar.setAttribute('style', 'cursor: pointer; margin: 0 2px;');
urlBar.setAttribute('tooltiptext', require('sdk/l10n').get('name'));
urlBar.addEventListener('mouseover', function() { this.onClick = function() {
if ( panel.isShowing ) { self.panel.get().show();
show = false;
} }
});
urlBar.addEventListener('mouseout', function() { this.document = mediator.getMostRecentWindow('navigator:browser').document;
show = true;
});
urlBar.addEventListener('click', function() { this.urlBar = this.document.createElement('hbox');
if ( show ) {
panel.show();
show = false; this.urlBar.setAttribute('id', 'wappalyzer-urlbar');
} else { this.urlBar.setAttribute('style', 'cursor: pointer; margin: 0 2px;');
panel.hide(); this.urlBar.setAttribute('tooltiptext', require('sdk/l10n').get('name'));
show = true; this.urlBar.addEventListener('click', this.onClick);
}
}, false);
getDocument().getElementById('urlbar-icons').appendChild(urlBar); this.document.getElementById('urlbar-icons').appendChild(this.urlBar);
} };
UrlBar.prototype.get = function() {
return this.urlBar;
};
UrlBar.prototype.addIcon = function(appName) {
var
icon = this.document.createElement('image'),
url = typeof appName !== 'undefined' ? 'images/icons/' + appName + '.png' : 'images/icon32.png',
tooltipText = ( typeof appName !== 'undefined' ? appName + ' - ' + require('sdk/l10n').get('clickForDetails') + ' - ' : '' ) + require('sdk/l10n').get('name');
icon.setAttribute('src', data.url(url));
icon.setAttribute('class', 'wappalyzer-icon');
icon.setAttribute('width', '16');
icon.setAttribute('height', '16');
icon.setAttribute('style', 'margin: 0 1px;');
icon.setAttribute('tooltiptext', tooltipText);
this.get().appendChild(icon);
return urlBar; return this;
};
UrlBar.prototype.clear = function() {
var icons;
do {
icons = this.get().getElementsByClassName('wappalyzer-icon');
if ( icons.length ) {
urlBar.get().removeChild(icons[0]);
} }
} while ( icons.length );
return this;
};
UrlBar.prototype.destroy = function() {
this.urlBar.removeEventListener('click', this.onClick);
this.urlBar.remove();
getDocument = function() { return this;
return mediator.getMostRecentWindow('navigator:browser').document;
} }
w.driver = { w.driver = {
@ -180,10 +204,14 @@
init: function(callback) { init: function(callback) {
var json = JSON.parse(data.load('apps.json')); var json = JSON.parse(data.load('apps.json'));
w.log('driver.init');
panel = new Panel();
if ( sp.prefs.urlbar ) { if ( sp.prefs.urlbar ) {
createPanel(); urlBar = new UrlBar(panel);
} else { } else {
createWidget(); widget = new Widget(panel);
} }
try { try {
@ -210,14 +238,16 @@
} }
sp.on('urlbar', function() { sp.on('urlbar', function() {
panel = new Panel();
if ( !sp.prefs.urlbar ) { if ( !sp.prefs.urlbar ) {
removeIcons(); urlBar.destroy();
createWidget(); widget = new Widget(panel);
} else { } else {
widget.destroy(); urlBar = new UrlBar(panel);
createPanel(); widget.get().destroy();
} }
w.driver.displayApps(); w.driver.displayApps();
@ -246,7 +276,7 @@
} }
if ( subject.contentType === 'text/html' ) { if ( subject.contentType === 'text/html' ) {
if ( headersCache[uri] === undefined ) { if ( typeof headersCache[uri] === 'undefined' ) {
headersCache[uri] = {}; headersCache[uri] = {};
} }
@ -258,12 +288,14 @@
}; };
httpRequestObserver.init(); httpRequestObserver.init();
w.driver.displayApps();
}, },
goToURL: function(args) { goToURL: function(args) {
var url = args.url + ( typeof args.medium === 'undefined' ? '' : '?pk_campaign=firefox&pk_kwd=' + args.medium); var url = args.url + ( typeof args.medium === 'undefined' ? '' : '?pk_campaign=firefox&pk_kwd=' + args.medium);
tabs.open({ url: url, inBackground: args.background !== undefined && args.background }); tabs.open({ url: url, inBackground: typeof args.background !== 'undefined' && args.background });
}, },
displayApps: function() { displayApps: function() {
@ -273,15 +305,17 @@
w.log('display apps'); w.log('display apps');
if ( panel === undefined ) { if ( !panel.get() ) {
panel = new Panel();
if ( sp.prefs.urlbar ) { if ( sp.prefs.urlbar ) {
createPanel(); urlBar = new UrlBar(panel);
} else { } else {
createWidget(); widget = new Widget(panel);
} }
} }
if ( tabCache[tabs.activeTab.id] === undefined ) { if ( typeof tabCache[tabs.activeTab.id] === 'undefined' ) {
initTab(tabs.activeTab); initTab(tabs.activeTab);
} }
@ -289,18 +323,18 @@
tabCache[tabs.activeTab.id].appsDetected = w.detected[url]; tabCache[tabs.activeTab.id].appsDetected = w.detected[url];
if ( sp.prefs.urlbar ) { if ( sp.prefs.urlbar ) {
removeIcons(); urlBar.clear();
// Add icons // Add icons
if ( count ) { if ( count ) {
for ( appName in tabCache[tabs.activeTab.id].appsDetected ) { for ( appName in tabCache[tabs.activeTab.id].appsDetected ) {
addIcon(appName); urlBar.addIcon(appName);
} }
} else { } else {
addIcon(); urlBar.addIcon();
} }
} else { } else {
widget.contentURL = data.url('images/icon32_hot.png'); widget.get().contentURL = data.url('images/icon32_hot.png');
if ( count ) { if ( count ) {
// Find the main application to display // Find the main application to display
@ -312,7 +346,7 @@
for ( appName in w.detected[url] ) { for ( appName in w.detected[url] ) {
w.apps[appName].cats.forEach(function(cat) { w.apps[appName].cats.forEach(function(cat) {
if ( cat == match && !found ) { if ( cat == match && !found ) {
widget.contentURL = data.url('images/icons/' + appName + '.png'), widget.get().contentURL = data.url('images/icons/' + appName + '.png'),
found = true; found = true;
} }
@ -322,7 +356,7 @@
} }
} }
panel.port.emit('displayApps', { tabCache: tabCache[tabs.activeTab.id], apps: w.apps, categories: w.categories, categoryNames: categoryNames }); panel.get().port.emit('displayApps', { tabCache: tabCache[tabs.activeTab.id], apps: w.apps, categories: w.categories, categoryNames: categoryNames });
}, },
ping: function() { ping: function() {
@ -386,7 +420,5 @@
36, // Advertising Network 36, // Advertising Network
19 // Miscellaneous 19 // Miscellaneous
] ]
} };
w.init();
}()); }());

@ -8,7 +8,7 @@
"description": "Identifies software on the web", "description": "Identifies software on the web",
"author": "Elbert Alias", "author": "Elbert Alias",
"license": "GPLv3", "license": "GPLv3",
"version": "3.0.5", "version": "3.0.8",
"main": "driver", "main": "driver",
"preferences": [{ "preferences": [{
"name": "tracking", "name": "tracking",

@ -1,19 +0,0 @@
{
"name": "Wappalyzer",
"version": "1.1.2",
"description": "Wappalyzer is a cross-platform utility that uncovers the technologies used on websites. It detects content management systems, web shops, web servers, JavaScript frameworks, analytics tools and many more.",
"main": "./share/js/wappalyzer.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/ElbertF/Wappalyzer"
},
"author": "ElbertF",
"license": "GNU GPL",
"bugs": {
"url": "https://github.com/ElbertF/Wappalyzer/issues"
},
"homepage": "https://wappalyzer.com/"
}

@ -790,7 +790,7 @@
"DTG": { "DTG": {
"website": "www.dtg.nl", "website": "www.dtg.nl",
"cats": [ 1 ], "cats": [ 1 ],
"html": [ "<a href=\"http://www\\.dtg\\.nl/\" target=\"_blank\" rel=\"nofollow\" id=\"poweredBy\" title=\"Site Powered by DTG\">Site Powered by DTG</a>", "var u=\\(\\('https:' == d\\.location\\.protocol\\) \\? 'https://resellerstat\\.mono\\.net/dtg/' : 'http://resellerstat\\.mono\\.net/dtg/'\\);" ], "html": [ "<a href=\"http://www\\.dtg\\.nl/\"[^>]+>Site Powered by DTG", "var u=\\(\\('https:' == d\\.location\\.protocol\\) \\? 'https://resellerstat\\.mono\\.net/dtg/' : 'http://resellerstat\\.mono\\.net/dtg/'\\);" ],
"implies": "Mono.net" "implies": "Mono.net"
}, },
"DreamWeaver": { "DreamWeaver": {