Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Commit

Permalink
this fixes #87, #91
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Dec 17, 2013
1 parent 498586b commit de1b9cb
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 121 deletions.
8 changes: 8 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
"message": "cookies",
"description": "..."
},
"stylesheetPrettyName": {
"message": "css",
"description": "HAS TO FIT IN MATRIX HEADER!"
},
"stylesheetPrettyNamePlural": {
"message": "css",
"description": "..."
},
"imagePrettyName": {
"message": "image",
"description": "HAS TO FIT IN MATRIX HEADER!"
Expand Down
8 changes: 8 additions & 0 deletions _locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
"message": "cookies",
"description": "..."
},
"stylesheetPrettyName": {
"message": "css",
"description": "HAS TO FIT IN MATRIX HEADER!"
},
"stylesheetPrettyNamePlural": {
"message": "css",
"description": "..."
},
"imagePrettyName": {
"message": "image",
"description": "HAS TO FIT IN MATRIX HEADER!"
Expand Down
Binary file modified img/permanent-black-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/permanent-white-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions info.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ <h3 data-i18n="statsPageOverview"></h3>
All:<br>
Pages:<br>
<a href="http://en.wikipedia.org/wiki/Http_cookie">Cookies</a>:<br>
<a href="https://en.wikipedia.org/wiki/Cascading_Style_Sheets">CSS</a>:<br>
Images:<br>
<span title="i.e. Flash, ActiveX, Java applets, etc.">Plugins</span>:<br>
<a href="http://en.wikipedia.org/wiki/HTML_scripting">Scripts</a>:<br>
Expand All @@ -126,6 +127,7 @@ <h3 data-i18n="statsPageOverview"></h3>
<span id="blockedAllCount"></span><br>
<span id="blockedMainFrameCount"></span><br>
<span id="blockedCookieCount"></span><br>
<span id="blockedStylesheetCount"></span><br>
<span id="blockedImageCount"></span><br>
<span id="blockedObjectCount"></span><br>
<span id="blockedScriptCount"></span><br>
Expand All @@ -138,6 +140,7 @@ <h3 data-i18n="statsPageOverview"></h3>
<span id="allowedAllCount"></span><br>
<span id="allowedMainFrameCount"></span><br>
<span id="allowedCookieCount"></span><br>
<span id="allowedStylesheetCount"></span><br>
<span id="allowedImageCount"></span><br>
<span id="allowedObjectCount"></span><br>
<span id="allowedScriptCount"></span><br>
Expand All @@ -160,6 +163,7 @@ <h3 data-i18n="statsPageDetailed"></h3>
<input id="show-allowed" type="checkbox" checked value="1"><span style="color:#070" data-i18n="statsPageAllowed">Allowed</span>&emsp;
<input id="show-cookie" type="checkbox" checked value="1">Cookies&emsp;
<input id="show-image" type="checkbox" checked value="1">Images&emsp;
<input id="show-stylesheet" type="checkbox" checked value="1">CSS&emsp;
<input id="show-object" type="checkbox" checked value="1">Objects&emsp;
<input id="show-script" type="checkbox" checked value="1">Scripts&emsp;
<input id="show-xmlhttprequest" type="checkbox" checked value="1">XHRs&emsp;
Expand Down
3 changes: 2 additions & 1 deletion js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ var HTTPSB = {
blacklistReadonlyCount: 0,

// https://github.com/gorhill/httpswitchboard/issues/19
excludeRegex: /^https?:\/\/chrome\.google\.com\/(extensions|webstore)/,
// https://github.com/gorhill/httpswitchboard/issues/91
excludeRegex: /^https:\/\/(chrome\.google\.com\/(extensions|webstore)|talkgadget\.google\.com\/talkgadget)/,

// various stats
requestStats: new WebRequestStats(),
Expand Down
6 changes: 6 additions & 0 deletions js/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ var cookieHunter = {
if ( !this.cookieMatchDomains(cookieKey, ' ' + Object.keys(pageStats[pageURL].domains).join(' ') + ' ') ) {
continue;
}
// rhill 2013-12-16: it's an app, do not delete the cookie it
// might be using.
// https://github.com/gorhill/httpswitchboard/issues/91
if ( pageStats.ignore ) {
return false;
}
if ( httpsb.whitelisted(pageURL, 'cookie', cookieDomain) ) {
return false;
}
Expand Down
13 changes: 13 additions & 0 deletions js/httpsb.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ HTTPSB.evaluate = function(src, type, hostname) {

/******************************************************************************/

HTTPSB.transposeType = function(type, url) {
if ( type === 'other' ) {
var path = uriTools.uri(url).path();
var pos = path.lastIndexOf('.');
if ( pos > 0 && path.slice(pos+1).search(/^eot|ttf|otf|svg|woff$/i) === 0 ) {
return 'stylesheet';
}
}
return type;
}

/******************************************************************************/

// Whitelist something

HTTPSB.whitelistTemporarily = function(src, type, hostname) {
Expand Down
2 changes: 2 additions & 0 deletions js/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ function renderStats() {
'#blockedAllCount': requestStats.blocked.all,
'#blockedMainFrameCount': blockedStats.main_frame,
'#blockedCookieCount': blockedStats.cookie,
'#blockedStylesheetCount': blockedStats.stylesheet,
'#blockedImageCount': blockedStats.image,
'#blockedObjectCount': blockedStats.object,
'#blockedScriptCount': blockedStats.script,
Expand All @@ -215,6 +216,7 @@ function renderStats() {
'#allowedAllCount': allowedStats.all,
'#allowedMainFrameCount': allowedStats.main_frame,
'#allowedCookieCount': allowedStats.cookie,
'#allowedStylesheetCount': allowedStats.stylesheet,
'#allowedImageCount': allowedStats.image,
'#allowedObjectCount': allowedStats.object,
'#allowedScriptCount': allowedStats.script,
Expand Down
47 changes: 26 additions & 21 deletions js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ function HostnameStats(hostname) {
this.types = {
'*': new EntryStats(hostname, '*'),
main_frame: new EntryStats(hostname, 'main_frame'),
stylesheet: new EntryStats(hostname, 'stylesheet'),
cookie: new EntryStats(hostname, 'cookie'),
stylesheet: new EntryStats(hostname, 'stylesheet'),
image: new EntryStats(hostname, 'image'),
object: new EntryStats(hostname, 'object'),
script: new EntryStats(hostname, 'script'),
Expand Down Expand Up @@ -130,8 +130,8 @@ HostnameStats.prototype.reset = function(hostname) {
}
this.types['*'].reset(hostname);
this.types.main_frame.reset(hostname);
this.types.stylesheet.reset(hostname);
this.types.cookie.reset(hostname);
this.types.stylesheet.reset(hostname);
this.types.image.reset(hostname);
this.types.object.reset(hostname);
this.types.script.reset(hostname);
Expand All @@ -150,6 +150,7 @@ HostnameStats.prototype.colourize = function(httpsb, scopeURL) {
this.types['*'].colourize(httpsb, scopeURL);
this.types.main_frame.colourize(httpsb, scopeURL);
this.types.cookie.colourize(httpsb, scopeURL);
this.types.stylesheet.colourize(httpsb, scopeURL);
this.types.image.colourize(httpsb, scopeURL);
this.types.object.colourize(httpsb, scopeURL);
this.types.script.colourize(httpsb, scopeURL);
Expand All @@ -163,8 +164,8 @@ HostnameStats.prototype.add = function(other) {
var otherTypes = other.types;
thisTypes['*'].add(otherTypes['*']);
thisTypes.main_frame.add(otherTypes.main_frame);
thisTypes.stylesheet.add(otherTypes.stylesheet);
thisTypes.cookie.add(otherTypes.cookie);
thisTypes.stylesheet.add(otherTypes.stylesheet);
thisTypes.image.add(otherTypes.image);
thisTypes.object.add(otherTypes.object);
thisTypes.script.add(otherTypes.script);
Expand Down Expand Up @@ -224,6 +225,7 @@ var HTTPSBPopup = {
matrixHeaderPrettyNames: {
'all': '',
'cookie': '',
'stylesheet': '',
'image': '',
'object': '',
'script': '',
Expand Down Expand Up @@ -716,12 +718,13 @@ function renderMatrixHeaderRow() {
var cells = matHead.find('.matCell');
$(cells[0]).prop({reqType: '*', hostname: '*'}).addClass(getCellClass('*', '*'));
$(cells[1]).prop({reqType: 'cookie', hostname: '*'}).addClass(getCellClass('*', 'cookie'));
$(cells[2]).prop({reqType: 'image', hostname: '*'}).addClass(getCellClass('*', 'image'));
$(cells[3]).prop({reqType: 'object', hostname: '*'}).addClass(getCellClass('*', 'object'));
$(cells[4]).prop({reqType: 'script', hostname: '*'}).addClass(getCellClass('*', 'script'));
$(cells[5]).prop({reqType: 'xmlhttprequest', hostname: '*'}).addClass(getCellClass('*', 'xmlhttprequest'));
$(cells[6]).prop({reqType: 'sub_frame', hostname: '*'}).addClass(getCellClass('*', 'sub_frame'));
$(cells[7]).prop({reqType: 'other', hostname: '*'}).addClass(getCellClass('*', 'other'));
$(cells[2]).prop({reqType: 'stylesheet', hostname: '*'}).addClass(getCellClass('*', 'stylesheet'));
$(cells[3]).prop({reqType: 'image', hostname: '*'}).addClass(getCellClass('*', 'image'));
$(cells[4]).prop({reqType: 'object', hostname: '*'}).addClass(getCellClass('*', 'object'));
$(cells[5]).prop({reqType: 'script', hostname: '*'}).addClass(getCellClass('*', 'script'));
$(cells[6]).prop({reqType: 'xmlhttprequest', hostname: '*'}).addClass(getCellClass('*', 'xmlhttprequest'));
$(cells[7]).prop({reqType: 'sub_frame', hostname: '*'}).addClass(getCellClass('*', 'sub_frame'));
$(cells[8]).prop({reqType: 'other', hostname: '*'}).addClass(getCellClass('*', 'other'));
$('#matHead .matRow').css('display', '');
}

Expand Down Expand Up @@ -761,12 +764,13 @@ function renderMatrixCellType(cell, hostname, type, stats) {

function renderMatrixCellTypes(cells, hostname, stats) {
renderMatrixCellType(cells[1], hostname, 'cookie', stats.cookie);
renderMatrixCellType(cells[2], hostname, 'image', stats.image);
renderMatrixCellType(cells[3], hostname, 'object', stats.object);
renderMatrixCellType(cells[4], hostname, 'script', stats.script);
renderMatrixCellType(cells[5], hostname, 'xmlhttprequest', stats.xmlhttprequest);
renderMatrixCellType(cells[6], hostname, 'sub_frame', stats.sub_frame);
renderMatrixCellType(cells[7], hostname, 'other', stats.other);
renderMatrixCellType(cells[2], hostname, 'stylesheet', stats.stylesheet);
renderMatrixCellType(cells[3], hostname, 'image', stats.image);
renderMatrixCellType(cells[4], hostname, 'object', stats.object);
renderMatrixCellType(cells[5], hostname, 'script', stats.script);
renderMatrixCellType(cells[6], hostname, 'xmlhttprequest', stats.xmlhttprequest);
renderMatrixCellType(cells[7], hostname, 'sub_frame', stats.sub_frame);
renderMatrixCellType(cells[8], hostname, 'other', stats.other);
}

/******************************************************************************/
Expand Down Expand Up @@ -813,12 +817,13 @@ function makeMatrixMetaRow(stats) {
.addClass('matCell rdt')
.html('<i>' + typeStats['*'].count + ' blacklisted hostname(s)</i>');
renderMatrixMetaCellType(cells[1], typeStats.cookie.count);
renderMatrixMetaCellType(cells[2], typeStats.image.count);
renderMatrixMetaCellType(cells[3], typeStats.object.count);
renderMatrixMetaCellType(cells[4], typeStats.script.count);
renderMatrixMetaCellType(cells[5], typeStats.xmlhttprequest.count);
renderMatrixMetaCellType(cells[6], typeStats.sub_frame.count);
renderMatrixMetaCellType(cells[7], typeStats.other.count);
renderMatrixMetaCellType(cells[2], typeStats.stylesheet.count);
renderMatrixMetaCellType(cells[3], typeStats.image.count);
renderMatrixMetaCellType(cells[4], typeStats.object.count);
renderMatrixMetaCellType(cells[5], typeStats.script.count);
renderMatrixMetaCellType(cells[6], typeStats.xmlhttprequest.count);
renderMatrixMetaCellType(cells[7], typeStats.sub_frame.count);
renderMatrixMetaCellType(cells[8], typeStats.other.count);
return matrixRow;
}

Expand Down
1 change: 1 addition & 0 deletions js/reqstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ _WebRequestStats.prototype.reset = function() {
this.main_frame =
this.sub_frame =
this.script =
this.stylesheet =
this.image =
this.object =
this.xmlhttprequest =
Expand Down
12 changes: 7 additions & 5 deletions js/rulemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ var recipeWidth = 40;

var friendlyTypeNames = {
'*': '*',
'cookie': 'cookies/local storages',
'cookie': 'cookies',
'stylesheet': 'css',
'image': 'images',
'object': 'plugins',
'script': 'scripts',
Expand All @@ -43,7 +44,8 @@ var friendlyTypeNames = {

var hostileTypeNames = {
'*': '*',
'cookies/local storages': 'cookie',
'cookies': 'cookie',
'css': 'stylesheet',
'images': 'image',
'plugins': 'object',
'scripts': 'script',
Expand Down Expand Up @@ -301,7 +303,7 @@ function renderScopeToHTML(scopeKey) {

/******************************************************************************/

function renderPerpageScopes() {
function renderPersiteScopes() {
var httpsb = getHTTPSB();
var ulRoot = $('<ul>');
// Iterate scopes
Expand All @@ -321,7 +323,7 @@ function renderPerpageScopes() {
liScope = renderScopeToHTML(scopeKey);
liScope.appendTo(ulRoot);
}
$('#perpage').empty().append(ulRoot);
$('#persite').empty().append(ulRoot);
}

/******************************************************************************/
Expand All @@ -343,7 +345,7 @@ function renderRecipe() {

function renderAll() {
renderGlobalScope();
renderPerpageScopes();
renderPersiteScopes();
}

/******************************************************************************/
Expand Down
16 changes: 12 additions & 4 deletions js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function readLocalTextFile(path) {
if ( url.search(/^https?:\/\//) < 0 ) {
url = chrome.runtime.getURL(path);
}
console.log('HTTP Switchboard > readLocalTextFile > "%s"', url);
// console.log('HTTP Switchboard > readLocalTextFile > "%s"', url);

// rhill 2013-10-24: Beware, our own requests could be blocked by our own
// behind-the-scene requests processor.
Expand All @@ -111,7 +111,7 @@ function readLocalTextFile(path) {

function saveUserSettings() {
chrome.storage.local.set(HTTPSB.userSettings, function() {
console.log('HTTP Switchboard > saved user settings');
// console.log('HTTP Switchboard > saved user settings');
});
}

Expand All @@ -120,7 +120,7 @@ function saveUserSettings() {
function loadUserSettings() {
chrome.storage.local.get(HTTPSB.userSettings, function(store) {
HTTPSB.userSettings = store;
console.log('HTTP Switchboard > loaded user settings');
// console.log('HTTP Switchboard > loaded user settings');
});
}

Expand All @@ -139,6 +139,12 @@ function loadUserLists() {
if ( store.scopes !== '' ) {
httpsb.permanentScopes.fromString(store.scopes);
httpsb.temporaryScopes.fromString(store.scopes);
// rhill 2013-12-15: New type `stylesheet`. Sensible default:
// - If `stylesheet` is graylisted, whitelist `stylesheet`
if ( store.version.slice(5) < '0.7.0' ) {
httpsb.whitelistTemporarily('*', 'stylesheet', '*');
httpsb.whitelistPermanently('*', 'stylesheet', '*');
}
} else if ( store.whitelist !== '' || store.blacklist !== '' || store.graylist !== '') {
// Pre v0.5.0
console.log('HTTP Switchboard > loadUserLists > using default white/black/gray lists');
Expand All @@ -150,6 +156,8 @@ function loadUserLists() {
httpsb.temporaryScopes.scopes['*'].white.fromString(store.whitelist);
} else {
// Sensible defaults
httpsb.whitelistTemporarily('*', 'stylesheet', '*');
httpsb.whitelistPermanently('*', 'stylesheet', '*');
httpsb.whitelistTemporarily('*', 'image', '*');
httpsb.whitelistPermanently('*', 'image', '*');
httpsb.blacklistTemporarily('*', 'object', '*');
Expand All @@ -163,7 +171,7 @@ function loadUserLists() {
// rhill 2013-09-23: ok, there is no point in blacklisting
// 'main_frame|*', since there is only one such page per tab. It is
// reasonable to whitelist by default 'main_frame|*', and top page of
// blacklisted domain name will not be loaded anyways (because domain
// blacklisted domain name will not load anyways (because domain
// name has precedence over type). Now this way we save precious real
// estate pixels in popup menu.
httpsb.whitelistTemporarily('*', 'main_frame', '*');
Expand Down
19 changes: 8 additions & 11 deletions js/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ function garbageCollectStalePageStatsCallback() {
chrome.tabs.query({ 'url': '<all_urls>' }, garbageCollectStalePageStatsWithNoTabsCallback);

// Prune content of chromium-behind-the-scene virtual tab
// When `suggest-as-you-type` is on in Chromium, this can lead to a
// LOT of uninteresting behind the scene requests.
var pageStats = httpsb.pageStats[httpsb.behindTheSceneURL];
if ( pageStats ) {
var reqKeys = pageStats.requests.getRequestKeys();
Expand Down Expand Up @@ -502,6 +504,10 @@ function createPageStats(pageUrl) {
var pageStats = httpsb.pageStats[pageUrl];
if ( !pageStats ) {
pageStats = PageStatsEntry.factory(pageUrl);
// These counters are used so that icon presents an overview of how
// much allowed/blocked.
pageStats.perLoadAllowedRequestCount =
pageStats.perLoadBlockedRequestCount = 0;
httpsb.pageStats[pageUrl] = pageStats;
} else if ( pageStats.pageUrl !== pageUrl ) {
pageStats.init(pageUrl);
Expand Down Expand Up @@ -680,17 +686,8 @@ function computeTabState(tabId) {
// `stylesheet` or `other`? Depends of domain of request.
// https://github.com/gorhill/httpswitchboard/issues/85
type = PageStatsRequests.typeFromRequestKey(reqKey);
typeToEval = typeToRecord = type;
if ( type === 'stylesheet' ) {
if ( uriTools.domainFromHostname(hostname) === pageStats.pageDomain ) {
typeToEval = 'main_frame';
} else {
typeToEval = typeToRecord = 'other';
}
}

if ( httpsb.blacklisted(pageUrl, typeToEval, hostname) ) {
computedState[typeToRecord + '|' + hostname] = true;
if ( httpsb.blacklisted(pageUrl, type, hostname) ) {
computedState[type + '|' + hostname] = true;
}
}
return computedState;
Expand Down
Loading

0 comments on commit de1b9cb

Please sign in to comment.