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

Commit 8093be7

Browse files
committed
This fixes #53
1 parent fda70f9 commit 8093be7

File tree

9 files changed

+72
-25
lines changed

9 files changed

+72
-25
lines changed

js/info.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ function renderBlacklistDetails() {
123123
var blacklist;
124124
var liTemplate = $('#remoteBlacklistDetails', ul);
125125
var li, a;
126-
var date = new Date();
127126
while ( i-- ) {
128127
blacklist = blacklists[keys[i]];
129128
li = liTemplate.clone();

js/popup.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,12 @@ function renderMatrixCellSubdomain(cell, domain, subomain) {
531531
}
532532

533533
function renderMatrixCellType(cell, hostname, type, stats) {
534-
var cell = $(cell);
534+
cell = $(cell);
535535
cell.prop({filterType: type, filterDomain: hostname})
536536
.addClass(stats.temporaryColor);
537537
if ( stats.count ) {
538538
cell.text(stats.count);
539539
}
540-
return cell;
541540
}
542541

543542
function renderMatrixCellTypes(cells, hostname, stats) {
@@ -571,7 +570,7 @@ function makeMatrixRowSubdomain(domain, subdomain) {
571570
/******************************************************************************/
572571

573572
function renderMatrixMetaCellType(cell, count) {
574-
var cell = $(cell);
573+
cell = $(cell);
575574
cell.addClass('rpt');
576575
if ( count ) {
577576
cell.text(count);

js/start.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ function onUpdatedTabsHandler(tabId, changeInfo, tab) {
107107
return;
108108
}
109109

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

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

147147
/******************************************************************************/
148148

149+
// Could this fix:
150+
// https://github.com/gorhill/httpswitchboard/issues/53
151+
// ?
152+
153+
function onBeforeNavigateCallback(details) {
154+
if ( details.url.search(/^https?:\/\//) < 0 ) {
155+
return;
156+
}
157+
if ( HTTPSB.excludeRegex.test(details.url) ) {
158+
return;
159+
}
160+
// Might help.
161+
// https://github.com/gorhill/httpswitchboard/issues/35
162+
var hostname = getHostnameFromURL(details.url);
163+
setJavascript(hostname, HTTPSB.whitelisted(details.url, 'script', hostname));
164+
}
165+
166+
chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigateCallback);
167+
168+
/******************************************************************************/
169+
149170
// Load user settings
150171

151172
load();

js/storage.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ function loadUserLists() {
129129
// Sensible defaults
130130
httpsb.whitelistTemporarily('*', 'image', '*');
131131
httpsb.whitelistPermanently('*', 'image', '*');
132-
httpsb.blacklistTemporarily('*', 'object', '*')
133-
httpsb.blacklistPermanently('*', 'object', '*')
134-
httpsb.blacklistTemporarily('*', 'sub_frame', '*')
135-
httpsb.blacklistPermanently('*', 'sub_frame', '*')
132+
httpsb.blacklistTemporarily('*', 'object', '*');
133+
httpsb.blacklistPermanently('*', 'object', '*');
134+
httpsb.blacklistTemporarily('*', 'sub_frame', '*');
135+
httpsb.blacklistPermanently('*', 'sub_frame', '*');
136136
}
137137

138138
// rhill 2013-09-23: ok, there is no point in blacklisting

js/tab.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,10 @@ function smartReloadTab(tabId) {
390390
}
391391
var newState = computeTabState(tabId);
392392
if ( getStateHash(newState) != getStateHash(pageStats.state) ) {
393-
// https://github.com/gorhill/httpswitchboard/issues/35
394393
// Appears to help.
394+
// https://github.com/gorhill/httpswitchboard/issues/35
395395
var hostname = getHostnameFromURL(pageUrl);
396-
var blocked = HTTPSB.blacklisted(pageUrl, 'script', hostname);
397-
chrome.contentSettings.javascript.set({
398-
primaryPattern: '*://' + hostname + '/*',
399-
setting: blocked ? 'block' : 'allow'
400-
});
396+
setJavascript(hostname, HTTPSB.whitelisted(pageUrl, 'script', hostname));
401397
// console.debug('reloaded content of tab id %d', tabId);
402398
// console.debug('old="%s"\nnew="%s"', getStateHash(pageStats.state), getStateHash(newState));
403399
pageStats.state = newState;

js/traffic.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,7 @@ function webRequestHandler(details) {
186186
// hostname, disable scripts for this hostname, necessary since inline
187187
// script tags are not passed through web request handler.
188188
if ( isMainFrame ) {
189-
chrome.contentSettings.javascript.set({
190-
primaryPattern: '*://' + hostname + '/*',
191-
setting: httpsb.blacklisted(pageURL, 'script', hostname) ? 'block' : 'allow'
192-
});
189+
setJavascript(hostname, httpsb.whitelisted(pageURL, 'script', hostname));
193190
// when the tab is updated, we will check if page has at least one
194191
// script tag, this takes care of inline scripting, which doesn't
195192
// generate 'script' type web requests.

js/utils.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,38 @@ function getParentHostnameFromHostname(hostname) {
9898
return subdomain.slice(dot+1) + '.' + domain;
9999
}
100100

101+
/******************************************************************************/
102+
103+
// Enable/disable javascript for a specific hostname.
104+
105+
function setJavascriptCallback(windows, hostname, setting) {
106+
// Need to do this to avoid "You cannot set a preference with scope
107+
// 'incognito_session_only' when no incognito window is open."
108+
var i = windows.length;
109+
while ( i-- ) {
110+
if ( windows[i].incognito ) {
111+
chrome.contentSettings.javascript.set({
112+
scope: 'incognito_session_only',
113+
primaryPattern: hostname,
114+
setting: setting
115+
});
116+
break;
117+
}
118+
}
119+
}
120+
121+
function setJavascript(hostname, state) {
122+
var hostname = '*://' + hostname + '/*';
123+
var setting = state ? 'allow' : 'block';
124+
// https://github.com/gorhill/httpswitchboard/issues/53
125+
// Until chromium fixes:
126+
// https://code.google.com/p/chromium/issues/detail?id=319400
127+
chrome.contentSettings.javascript.set({
128+
primaryPattern: hostname,
129+
setting: setting
130+
});
131+
chrome.windows.getAll(function(windows) {
132+
setJavascriptCallback(windows, hostname, setting);
133+
});
134+
}
101135

manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"name": "HTTP Switchboard",
44
"short_name": "HTTPSB",
5-
"version": "0.5.4",
5+
"version": "0.5.5",
66
"description": "Point & click to forbid/allow any class of requests made by your browser. Use it to block scripts, iframes, ads, facebook, etc.",
77
"icons": {
88
"128": "icon_128.png"
@@ -26,6 +26,7 @@
2626
"cookies",
2727
"storage",
2828
"tabs",
29+
"webNavigation",
2930
"webRequest",
3031
"webRequestBlocking",
3132
"<all_urls>"

settings.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ <h1>HTTP Switchboard &mdash; Settings</h1>
2424

2525
<div>
2626
Under construction.
27-
<h2>Display</h3>
27+
<h2>Display</h2>
2828
<div>
2929
Matrix text size:
3030
<ul style="list-style:none">
@@ -33,7 +33,7 @@ <h2>Display</h3>
3333
</ul>
3434
</div>
3535

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

55-
<h2>Cookies</h3>
55+
<h2>Cookies</h2>
5656
<div>
5757
<p>Blacklisted cookies are not prevented by <i>HTTP Switchboard</i> from entering
5858
your browser. However they are prevented from leaving your browser, which
@@ -70,7 +70,7 @@ <h2>Cookies</h3>
7070
</ul>
7171
</div>
7272

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

0 commit comments

Comments
 (0)