Firefox driver refactoring, private browsing permissions

main
Elbert Alias 11 years ago
parent 155868d7bd
commit 3d1a64af72

@ -5,14 +5,9 @@
{Cc, Ci} = require('chrome'), {Cc, Ci} = require('chrome'),
main = require('wappalyzer'), main = require('wappalyzer'),
w = main.wappalyzer, w = main.wappalyzer,
mediator = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator),
tabCache = {}, tabCache = {},
headersCache = {}, headersCache = {},
categoryNames = {}, categoryNames = {},
data = require('sdk/self').data,
ss = require('sdk/simple-storage'),
sp = require("sdk/simple-prefs"),
tabs = require('sdk/tabs'),
initTab, initTab,
Panel, Panel,
panel, panel,
@ -44,11 +39,13 @@
}; };
initTab = function(tab) { initTab = function(tab) {
w.log('initTab');
tabCache[tab.id] = { count: 0, appsDetected: [] }; tabCache[tab.id] = { count: 0, appsDetected: [] };
tab.on('ready', function(tab) { tab.on('ready', function(tab) {
var worker = tab.attach({ var worker = tab.attach({
contentScriptFile: data.url('js/tab.js') contentScriptFile: require('sdk/self').data.url('js/tab.js')
}); });
worker.port.on('analyze', function(message) { worker.port.on('analyze', function(message) {
@ -67,15 +64,10 @@
}); });
}; };
tabs.on('open', initTab); require('sdk/tabs')
.on('open', initTab)
tabs.on('close', function(tab) { .on('close', function(tab) { tabCache[tab.id] = null; })
tabCache[tab.id] = null; .on('activate', function(tab) { w.driver.displayApps(); });
});
tabs.on('activate', function(tab) {
w.driver.displayApps();
});
Panel = function() { Panel = function() {
var self = this; var self = this;
@ -83,8 +75,8 @@
this.panel = require('sdk/panel').Panel({ this.panel = require('sdk/panel').Panel({
width: 250, width: 250,
height: 50, height: 50,
contentURL: data.url('panel.html'), contentURL: require('sdk/self').data.url('panel.html'),
contentScriptFile: data.url('js/panel.js'), contentScriptFile: require('sdk/self').data.url('js/panel.js'),
position: { right: 30, top: 30 } position: { right: 30, top: 30 }
}); });
@ -111,7 +103,7 @@
this.widget = require('sdk/widget').Widget({ this.widget = require('sdk/widget').Widget({
id: 'wappalyzer', id: 'wappalyzer',
label: 'Wappalyzer', label: 'Wappalyzer',
contentURL: data.url('images/icon32.png'), contentURL: require('sdk/self').data.url('images/icon32.png'),
panel: panel.get() panel: panel.get()
}); });
}; };
@ -133,7 +125,8 @@
self.panel.get().show(); self.panel.get().show();
} }
this.document = mediator.getMostRecentWindow('navigator:browser').document; this.document = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator)
.getMostRecentWindow('navigator:browser').document;
this.urlBar = this.document.createElement('hbox'); this.urlBar = this.document.createElement('hbox');
@ -156,7 +149,7 @@
url = typeof appName !== 'undefined' ? 'images/icons/' + appName + '.png' : 'images/icon32.png', 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'); tooltipText = ( typeof appName !== 'undefined' ? appName + ' - ' + require('sdk/l10n').get('clickForDetails') + ' - ' : '' ) + require('sdk/l10n').get('name');
icon.setAttribute('src', data.url(url)); icon.setAttribute('src', require('sdk/self').data.url(url));
icon.setAttribute('class', 'wappalyzer-icon'); icon.setAttribute('class', 'wappalyzer-icon');
icon.setAttribute('width', '16'); icon.setAttribute('width', '16');
icon.setAttribute('height', '16'); icon.setAttribute('height', '16');
@ -202,13 +195,18 @@
* Initialize * Initialize
*/ */
init: function(callback) { init: function(callback) {
var json = JSON.parse(data.load('apps.json')); var
id,
tab,
version,
httpRequestObserver,
json = JSON.parse(require('sdk/self').data.load('apps.json'));
w.log('driver.init'); w.log('driver.init');
panel = new Panel(); panel = new Panel();
if ( sp.prefs.urlbar ) { if ( require('sdk/simple-prefs').prefs.urlbar ) {
urlBar = new UrlBar(panel); urlBar = new UrlBar(panel);
} else { } else {
widget = new Widget(panel); widget = new Widget(panel);
@ -217,30 +215,30 @@
try { try {
var version = require('sdk/self').version; var version = require('sdk/self').version;
if ( !ss.storage.version ) { if ( !require('sdk/simple-storage').storage.version ) {
w.driver.goToURL({ url: w.config.websiteURL + 'installed', medium: 'install' }); w.driver.goToURL({ url: w.config.websiteURL + 'installed', medium: 'install' });
} else if ( version !== ss.storage.version ) { } else if ( version !== require('sdk/simple-storage').storage.version ) {
w.driver.goToURL({ url: w.config.websiteURL + 'upgraded', medium: 'upgrade', background: true }); w.driver.goToURL({ url: w.config.websiteURL + 'upgraded', medium: 'upgrade', background: true });
} }
ss.storage.version = version; require('sdk/simple-storage').storage.version = version;
} catch(e) { } } catch(e) { }
w.apps = json.apps; w.apps = json.apps;
w.categories = json.categories; w.categories = json.categories;
for ( var id in w.categories ) { for ( id in w.categories ) {
categoryNames[id] = require('sdk/l10n').get('cat' + id); categoryNames[id] = require('sdk/l10n').get('cat' + id);
} }
for each ( var tab in tabs ) { for each ( tab in require('sdk/tabs') ) {
initTab(tab); initTab(tab);
} }
sp.on('urlbar', function() { require('sdk/simple-prefs').on('urlbar', function() {
panel = new Panel(); panel = new Panel();
if ( !sp.prefs.urlbar ) { if ( !require('sdk/simple-prefs').prefs.urlbar ) {
urlBar.destroy(); urlBar.destroy();
widget = new Widget(panel); widget = new Widget(panel);
@ -253,7 +251,7 @@
w.driver.displayApps(); w.driver.displayApps();
}); });
var httpRequestObserver = { httpRequestObserver = {
init: function() { init: function() {
var observerService = Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService); var observerService = Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
@ -295,46 +293,51 @@
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: typeof args.background !== 'undefined' && args.background }); require('sdk/tabs').open({ url: url, inBackground: typeof args.background !== 'undefined' && args.background });
}, },
displayApps: function() { displayApps: function() {
var var url, count;
url = tabs.activeTab.url.replace(/#.*$/, ''),
count = w.detected[url] ? Object.keys(w.detected[url]).length : 0;
w.log('display apps'); w.log('display apps');
if ( !require('sdk/tabs').activeTab ) {
return;
}
url = require('sdk/tabs').activeTab.url.replace(/#.*$/, '');
count = w.detected[url] ? Object.keys(w.detected[url]).length : 0;
if ( !panel.get() ) { if ( !panel.get() ) {
panel = new Panel(); panel = new Panel();
if ( sp.prefs.urlbar ) { if ( require('sdk/simple-prefs').prefs.urlbar ) {
urlBar = new UrlBar(panel); urlBar = new UrlBar(panel);
} else { } else {
widget = new Widget(panel); widget = new Widget(panel);
} }
} }
if ( typeof tabCache[tabs.activeTab.id] === 'undefined' ) { if ( typeof tabCache[require('sdk/tabs').activeTab.id] === 'undefined' ) {
initTab(tabs.activeTab); initTab(require('sdk/tabs').activeTab);
} }
tabCache[tabs.activeTab.id].count = count; tabCache[require('sdk/tabs').activeTab.id].count = count;
tabCache[tabs.activeTab.id].appsDetected = w.detected[url]; tabCache[require('sdk/tabs').activeTab.id].appsDetected = w.detected[url];
if ( sp.prefs.urlbar ) { if ( require('sdk/simple-prefs').prefs.urlbar ) {
urlBar.clear(); urlBar.clear();
// Add icons // Add icons
if ( count ) { if ( count ) {
for ( appName in tabCache[tabs.activeTab.id].appsDetected ) { for ( appName in tabCache[require('sdk/tabs').activeTab.id].appsDetected ) {
urlBar.addIcon(appName); urlBar.addIcon(appName);
} }
} else { } else {
urlBar.addIcon(); urlBar.addIcon();
} }
} else { } else {
widget.get().contentURL = data.url('images/icon32_hot.png'); widget.get().contentURL = require('sdk/self').data.url('images/icon32_hot.png');
if ( count ) { if ( count ) {
// Find the main application to display // Find the main application to display
@ -346,7 +349,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.get().contentURL = data.url('images/icons/' + appName + '.png'), widget.get().contentURL = require('sdk/self').data.url('images/icons/' + appName + '.png'),
found = true; found = true;
} }
@ -356,13 +359,13 @@
} }
} }
panel.get().port.emit('displayApps', { tabCache: tabCache[tabs.activeTab.id], apps: w.apps, categories: w.categories, categoryNames: categoryNames }); panel.get().port.emit('displayApps', { tabCache: tabCache[require('sdk/tabs').activeTab.id], apps: w.apps, categories: w.categories, categoryNames: categoryNames });
}, },
ping: function() { ping: function() {
var Request = require('sdk/request').Request; var Request = require('sdk/request').Request;
if ( Object.keys(w.ping.hostnames).length && sp.prefs.tracking ) { if ( Object.keys(w.ping.hostnames).length && require('sdk/simple-prefs').prefs.tracking ) {
Request({ Request({
url: w.config.websiteURL + 'ping/v2/', url: w.config.websiteURL + 'ping/v2/',
content: { json: encodeURIComponent(JSON.stringify(w.ping)) }, content: { json: encodeURIComponent(JSON.stringify(w.ping)) },

@ -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.8", "version": "3.0.9",
"main": "driver", "main": "driver",
"preferences": [{ "preferences": [{
"name": "tracking", "name": "tracking",
@ -22,5 +22,8 @@
"description": "Uncheck to display toolbar button.", "description": "Uncheck to display toolbar button.",
"type": "bool", "type": "bool",
"value": true "value": true
}] }],
"permissions": {
"private-browsing": true
}
} }