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

Commit

Permalink
This fixes #53
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Nov 14, 2013
1 parent fda70f9 commit 8093be7
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 25 deletions.
1 change: 0 additions & 1 deletion js/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ function renderBlacklistDetails() {
var blacklist;
var liTemplate = $('#remoteBlacklistDetails', ul);
var li, a;
var date = new Date();
while ( i-- ) {
blacklist = blacklists[keys[i]];
li = liTemplate.clone();
Expand Down
5 changes: 2 additions & 3 deletions js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,12 @@ function renderMatrixCellSubdomain(cell, domain, subomain) {
}

function renderMatrixCellType(cell, hostname, type, stats) {
var cell = $(cell);
cell = $(cell);
cell.prop({filterType: type, filterDomain: hostname})
.addClass(stats.temporaryColor);
if ( stats.count ) {
cell.text(stats.count);
}
return cell;
}

function renderMatrixCellTypes(cells, hostname, stats) {
Expand Down Expand Up @@ -571,7 +570,7 @@ function makeMatrixRowSubdomain(domain, subdomain) {
/******************************************************************************/

function renderMatrixMetaCellType(cell, count) {
var cell = $(cell);
cell = $(cell);
cell.addClass('rpt');
if ( count ) {
cell.text(count);
Expand Down
25 changes: 23 additions & 2 deletions js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ function onUpdatedTabsHandler(tabId, changeInfo, tab) {
return;
}

// Chrome webstore can't be injected with foreign code following is to
// Chrome webstore can't be injected with foreign code, following is to
// avoid error message.
if ( pageStats.ignore ) {
if ( HTTPSB.excludeRegex.test(tab.url) ) {
return;
}

Expand Down Expand Up @@ -146,6 +146,27 @@ chrome.tabs.onRemoved.addListener(onRemovedTabHandler);

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

// Could this fix:
// https://github.com/gorhill/httpswitchboard/issues/53
// ?

function onBeforeNavigateCallback(details) {
if ( details.url.search(/^https?:\/\//) < 0 ) {
return;
}
if ( HTTPSB.excludeRegex.test(details.url) ) {
return;
}
// Might help.
// https://github.com/gorhill/httpswitchboard/issues/35

This comment has been minimized.

Copy link
@GuardianMajor

GuardianMajor Nov 15, 2013

I think you mean 53, right?

This comment has been minimized.

Copy link
@gorhill

gorhill Nov 15, 2013

Author Owner

I put this particular code back while investigating #53, but finally it is unrelated. I leave the code there anyways because I suspect it might help #35 by changing js permissions sooner than later.

This comment has been minimized.

Copy link
@GuardianMajor

GuardianMajor Nov 15, 2013

Forgive me, it just seemed like the numbers were transposed, my apology.

var hostname = getHostnameFromURL(details.url);
setJavascript(hostname, HTTPSB.whitelisted(details.url, 'script', hostname));
}

chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigateCallback);

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

// Load user settings

load();
Expand Down
8 changes: 4 additions & 4 deletions js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ function loadUserLists() {
// Sensible defaults
httpsb.whitelistTemporarily('*', 'image', '*');
httpsb.whitelistPermanently('*', 'image', '*');
httpsb.blacklistTemporarily('*', 'object', '*')
httpsb.blacklistPermanently('*', 'object', '*')
httpsb.blacklistTemporarily('*', 'sub_frame', '*')
httpsb.blacklistPermanently('*', 'sub_frame', '*')
httpsb.blacklistTemporarily('*', 'object', '*');
httpsb.blacklistPermanently('*', 'object', '*');
httpsb.blacklistTemporarily('*', 'sub_frame', '*');
httpsb.blacklistPermanently('*', 'sub_frame', '*');
}

// rhill 2013-09-23: ok, there is no point in blacklisting
Expand Down
8 changes: 2 additions & 6 deletions js/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,10 @@ function smartReloadTab(tabId) {
}
var newState = computeTabState(tabId);
if ( getStateHash(newState) != getStateHash(pageStats.state) ) {
// https://github.com/gorhill/httpswitchboard/issues/35
// Appears to help.
// https://github.com/gorhill/httpswitchboard/issues/35
var hostname = getHostnameFromURL(pageUrl);
var blocked = HTTPSB.blacklisted(pageUrl, 'script', hostname);
chrome.contentSettings.javascript.set({
primaryPattern: '*://' + hostname + '/*',
setting: blocked ? 'block' : 'allow'
});
setJavascript(hostname, HTTPSB.whitelisted(pageUrl, 'script', hostname));
// console.debug('reloaded content of tab id %d', tabId);
// console.debug('old="%s"\nnew="%s"', getStateHash(pageStats.state), getStateHash(newState));
pageStats.state = newState;
Expand Down
5 changes: 1 addition & 4 deletions js/traffic.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,7 @@ function webRequestHandler(details) {
// hostname, disable scripts for this hostname, necessary since inline
// script tags are not passed through web request handler.
if ( isMainFrame ) {
chrome.contentSettings.javascript.set({
primaryPattern: '*://' + hostname + '/*',
setting: httpsb.blacklisted(pageURL, 'script', hostname) ? 'block' : 'allow'
});
setJavascript(hostname, httpsb.whitelisted(pageURL, 'script', hostname));
// when the tab is updated, we will check if page has at least one
// script tag, this takes care of inline scripting, which doesn't
// generate 'script' type web requests.
Expand Down
34 changes: 34 additions & 0 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,38 @@ function getParentHostnameFromHostname(hostname) {
return subdomain.slice(dot+1) + '.' + domain;
}

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

// Enable/disable javascript for a specific hostname.

function setJavascriptCallback(windows, hostname, setting) {
// Need to do this to avoid "You cannot set a preference with scope
// 'incognito_session_only' when no incognito window is open."
var i = windows.length;
while ( i-- ) {
if ( windows[i].incognito ) {
chrome.contentSettings.javascript.set({
scope: 'incognito_session_only',
primaryPattern: hostname,
setting: setting
});
break;
}
}
}

function setJavascript(hostname, state) {
var hostname = '*://' + hostname + '/*';
var setting = state ? 'allow' : 'block';
// https://github.com/gorhill/httpswitchboard/issues/53
// Until chromium fixes:
// https://code.google.com/p/chromium/issues/detail?id=319400
chrome.contentSettings.javascript.set({
primaryPattern: hostname,
setting: setting
});
chrome.windows.getAll(function(windows) {
setJavascriptCallback(windows, hostname, setting);
});
}

3 changes: 2 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "HTTP Switchboard",
"short_name": "HTTPSB",
"version": "0.5.4",
"version": "0.5.5",
"description": "Point & click to forbid/allow any class of requests made by your browser. Use it to block scripts, iframes, ads, facebook, etc.",
"icons": {
"128": "icon_128.png"
Expand All @@ -26,6 +26,7 @@
"cookies",
"storage",
"tabs",
"webNavigation",
"webRequest",
"webRequestBlocking",
"<all_urls>"
Expand Down
8 changes: 4 additions & 4 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1>HTTP Switchboard &mdash; Settings</h1>

<div>
Under construction.
<h2>Display</h3>
<h2>Display</h2>
<div>
Matrix text size:
<ul style="list-style:none">
Expand All @@ -33,7 +33,7 @@ <h2>Display</h3>
</ul>
</div>

<h2>Strict blocking</h3>
<h2>Strict blocking</h2>
<div>
<p><strong><a href="https://github.com/gorhill/httpswitchboard/wiki/%22Strict-blocking%22-illustrated">Strict blocking</a></strong>,
introduced in <a href="https://github.com/gorhill/httpswitchboard/wiki/Change-log#036">version 0.3.6</a>,
Expand All @@ -52,7 +52,7 @@ <h2>Strict blocking</h3>
</ul>
</div>

<h2>Cookies</h3>
<h2>Cookies</h2>
<div>
<p>Blacklisted cookies are not prevented by <i>HTTP Switchboard</i> from entering
your browser. However they are prevented from leaving your browser, which
Expand All @@ -70,7 +70,7 @@ <h2>Cookies</h3>
</ul>
</div>

<h2>Chromium: behind-the-scene requests</h3>
<h2>Chromium: behind-the-scene requests</h2>
<div>
<p>According to <a href="http://www.google.com/intl/en/chrome/browser/privacy/whitepaper.html">Google Chrome Privacy Whitepaper</a>,
<i>Chromium</i> might send HTTP requests to <i>Google</i> without the user
Expand Down

0 comments on commit 8093be7

Please sign in to comment.