Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
Merge branch 'source-script-detection'
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostwords committed Jul 18, 2014
2 parents 50b3ba8 + a67be17 commit 25d7a59
Show file tree
Hide file tree
Showing 12 changed files with 345 additions and 127 deletions.
5 changes: 0 additions & 5 deletions chrome/css/panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ body {
width: 310px;
}

caption {
font-size: 14px;
margin: 10px 0;
}

hr {
background-color: #ddd;
border: 0;
Expand Down
108 changes: 73 additions & 35 deletions chrome/js/builds/background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

},{}],2:[function(require,module,exports){
/*!
* Chameleon
*
Expand All @@ -20,7 +18,8 @@ var ALL_URLS = { urls: ['http://*/*', 'https://*/*'] },
ENABLED = true;

var tabData = require('../lib/tabdata'),
sendMessage = require('../lib/utils').sendMessage;
sendMessage = require('../lib/content_script_utils').sendMessage,
utils = require('../lib/utils');

// TODO https://developer.chrome.com/extensions/webRequest#life_cycle_footnote
// The following headers are currently not provided to the onBeforeSendHeaders event.
Expand Down Expand Up @@ -103,7 +102,7 @@ function updateBadge(tab_id) {
text = '';

if (data) {
text = _.size(data.counts).toString();
text = utils.getAccessCount(data.counts).toString();
}

chrome.browserAction.setBadgeText({
Expand Down Expand Up @@ -228,7 +227,52 @@ chrome.webNavigation.onCommitted.addListener(onNavigation);
// TODO switch to chrome.alarms?
setInterval(tabData.clean, 300000);

},{"../lib/tabdata":3,"../lib/utils":4}],3:[function(require,module,exports){
},{"../lib/content_script_utils":2,"../lib/tabdata":3,"../lib/utils":4}],2:[function(require,module,exports){
/*!
* Chameleon
*
* Copyright 2014 ghostwords.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/

/*
* This module needs to work both inside content scripts and the rest of the
* extension, like the browser popup.
*
* Content scripts have certain limitations in Chrome:
* https://developer.chrome.com/extensions/content_scripts
*/

// acceptable signatures:
// name
// name, message
// name, callback
// name, message, callback
module.exports.sendMessage = function (name, message, callback) {
var args = [{ name: name }];

if (Object.prototype.toString.call(message) == '[object Function]') {
// name, callback
args.push(message);
} else {
if (message) {
// name, message, [callback]
args[0].message = message;
}
if (callback) {
// name, [message], callback
args.push(callback);
}
}

chrome.runtime.sendMessage.apply(chrome.runtime, args);
};

},{}],3:[function(require,module,exports){
/*!
* Chameleon
*
Expand All @@ -246,7 +290,8 @@ var data = {};

var tabData = {
record: function (tab_id, access) {
var key = access.obj + '.' + access.prop;
var key = access.obj + '.' + access.prop,
script_url = access.scriptUrl || '<unknown>';

if (!data.hasOwnProperty(tab_id)) {
data[tab_id] = {
Expand All @@ -255,15 +300,22 @@ var tabData = {
};
}

var datum = data[tab_id];

// font enumeration
if (access.prop == 'style.fontFamily') {
data[tab_id].fontEnumeration = true;
datum.fontEnumeration = true;
}

if (!data[tab_id].counts.hasOwnProperty(key)) {
data[tab_id].counts[key] = 0;
// javascript property access counts indexed by script URL
if (!datum.counts.hasOwnProperty(script_url)) {
datum.counts[script_url] = {};
}

data[tab_id].counts[key]++;
var counts = datum.counts[script_url];
if (!counts.hasOwnProperty(key)) {
counts[key] = 0;
}
counts[key]++;
},

get: function (tab_id) {
Expand Down Expand Up @@ -300,33 +352,19 @@ module.exports = tabData;
*
*/

/*
* This module needs to work both inside content scripts and the browser popup.
*/
// used by the badge and the popup
module.exports.getAccessCount = function (counts) {
// count unique keys across all counts objects
var props = {};

// acceptable signatures:
// name
// name, message
// name, callback
// name, message, callback
module.exports.sendMessage = function (name, message, callback) {
var args = [{ name: name }];

if (Object.prototype.toString.call(message) == '[object Function]') {
// name, callback
args.push(message);
} else {
if (message) {
// name, message, [callback]
args[0].message = message;
}
if (callback) {
// name, [message], callback
args.push(callback);
// no need for hasOwnProperty loop checks in this context
for (var url in counts) { // jshint ignore:line
for (var prop in counts[url]) { // jshint ignore:line
props[prop] = true;
}
}

chrome.runtime.sendMessage.apply(chrome.runtime, args);
return Object.keys(props).length;
};

},{}]},{},[2])
},{}]},{},[1])
4 changes: 2 additions & 2 deletions chrome/js/builds/inject.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chrome/js/builds/injected.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 80 additions & 23 deletions chrome/js/builds/panel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

},{}],2:[function(require,module,exports){
/** @jsx React.DOM */

/*!
Expand All @@ -17,7 +15,8 @@
/*jshint newcap:false */

var React = require('react'),
sendMessage = require('../lib/utils').sendMessage;
sendMessage = require('../lib/content_script_utils').sendMessage,
utils = require('../lib/utils');

var PanelApp = React.createClass({displayName: 'PanelApp',
getInitialState: function () {
Expand Down Expand Up @@ -71,8 +70,8 @@ var PanelApp = React.createClass({displayName: 'PanelApp',
toggle:this.toggle} ),
React.DOM.hr(null ),
Report(
{fontEnumeration:this.state.fontEnumeration,
counts:this.state.counts} )
{counts:this.state.counts,
fontEnumeration:this.state.fontEnumeration} )
)
);
}
Expand Down Expand Up @@ -124,28 +123,62 @@ var Header = React.createClass({displayName: 'Header',

var Report = React.createClass({displayName: 'Report',
render: function () {
var rows = [],
fontEnumeration,
table;
var fontEnumeration,
reports = [];

if (this.props.fontEnumeration) {
fontEnumeration = (
React.DOM.p(null, "Font enumeration detected.")
);
}

Object.keys(this.props.counts).sort().forEach(function (url) {
reports.push(
ScriptReport(
{key:url,
url:url,
counts:this.props.counts[url]} )
);
}, this);

var status = reports.length ?
React.DOM.p(null,
React.DOM.b(null, utils.getAccessCount(this.props.counts)), " property"+' '+
"accesses detected across ", React.DOM.b(null, reports.length), " scripts."
) :
React.DOM.p(null, "No property accesses detected.");

return (
React.DOM.div(null,
fontEnumeration,
status,
reports
)
);
}
});

var ScriptReport = React.createClass({displayName: 'ScriptReport',
render: function () {
var rows = [];

Object.keys(this.props.counts).sort().forEach(function (name) {
rows.push(
ReportRow( {key:name, name:name, count:this.props.counts[name]} )
);
}, this);

if (rows.length) {
table = (
return (
React.DOM.div(null,
React.DOM.p( {title:this.props.url, style:{
margin: '20px 0 5px',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}},
this.props.url
),
React.DOM.table(null,
React.DOM.caption(null,
React.DOM.b(null, rows.length), " property accesses detected"
),
React.DOM.thead(null,
React.DOM.tr(null,
React.DOM.th(null, "property"),
Expand All @@ -156,13 +189,6 @@ var Report = React.createClass({displayName: 'Report',
rows
)
)
);
}

return (
React.DOM.div(null,
fontEnumeration,
table ? table : React.DOM.p(null, "No property accesses detected.")
)
);
}
Expand All @@ -185,7 +211,7 @@ var ReportRow = React.createClass({displayName: 'ReportRow',

React.renderComponent(PanelApp(null ), document.body);

},{"../lib/utils":3}],3:[function(require,module,exports){
},{"../lib/content_script_utils":2,"../lib/utils":3}],2:[function(require,module,exports){
/*!
* Chameleon
*
Expand All @@ -198,7 +224,11 @@ React.renderComponent(PanelApp(null ), document.body);
*/

/*
* This module needs to work both inside content scripts and the browser popup.
* This module needs to work both inside content scripts and the rest of the
* extension, like the browser popup.
*
* Content scripts have certain limitations in Chrome:
* https://developer.chrome.com/extensions/content_scripts
*/

// acceptable signatures:
Expand Down Expand Up @@ -226,4 +256,31 @@ module.exports.sendMessage = function (name, message, callback) {
chrome.runtime.sendMessage.apply(chrome.runtime, args);
};

},{}]},{},[2])
},{}],3:[function(require,module,exports){
/*!
* Chameleon
*
* Copyright 2014 ghostwords.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/

// used by the badge and the popup
module.exports.getAccessCount = function (counts) {
// count unique keys across all counts objects
var props = {};

// no need for hasOwnProperty loop checks in this context
for (var url in counts) { // jshint ignore:line
for (var prop in counts[url]) { // jshint ignore:line
props[prop] = true;
}
}

return Object.keys(props).length;
};

},{}]},{},[1])
5 changes: 3 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var ALL_URLS = { urls: ['http://*/*', 'https://*/*'] },
ENABLED = true;

var tabData = require('../lib/tabdata'),
sendMessage = require('../lib/utils').sendMessage;
sendMessage = require('../lib/content_script_utils').sendMessage,
utils = require('../lib/utils');

// TODO https://developer.chrome.com/extensions/webRequest#life_cycle_footnote
// The following headers are currently not provided to the onBeforeSendHeaders event.
Expand Down Expand Up @@ -100,7 +101,7 @@ function updateBadge(tab_id) {
text = '';

if (data) {
text = _.size(data.counts).toString();
text = utils.getAccessCount(data.counts).toString();
}

chrome.browserAction.setBadgeText({
Expand Down
2 changes: 1 addition & 1 deletion src/js/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

(function () {

var sendMessage = require('../lib/utils').sendMessage;
var sendMessage = require('../lib/content_script_utils').sendMessage;

function insertScript(url, data) {
var head = document.getElementsByTagName('head')[0] || document.documentElement,
Expand Down
Loading

0 comments on commit 25d7a59

Please sign in to comment.