diff --git a/js/info.js b/js/info.js index b5b7c8b..4b5ec9c 100644 --- a/js/info.js +++ b/js/info.js @@ -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(); diff --git a/js/popup.js b/js/popup.js index e6791f8..548a101 100644 --- a/js/popup.js +++ b/js/popup.js @@ -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) { @@ -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); diff --git a/js/start.js b/js/start.js index afe205b..1d7ee24 100644 --- a/js/start.js +++ b/js/start.js @@ -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; } @@ -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 + var hostname = getHostnameFromURL(details.url); + setJavascript(hostname, HTTPSB.whitelisted(details.url, 'script', hostname)); +} + +chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigateCallback); + +/******************************************************************************/ + // Load user settings load(); diff --git a/js/storage.js b/js/storage.js index 5281687..c9068a5 100644 --- a/js/storage.js +++ b/js/storage.js @@ -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 diff --git a/js/tab.js b/js/tab.js index 65e0c23..7b31b86 100644 --- a/js/tab.js +++ b/js/tab.js @@ -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; diff --git a/js/traffic.js b/js/traffic.js index 79ec55e..7812b88 100644 --- a/js/traffic.js +++ b/js/traffic.js @@ -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. diff --git a/js/utils.js b/js/utils.js index 3339e29..f040d74 100644 --- a/js/utils.js +++ b/js/utils.js @@ -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); + }); +} diff --git a/manifest.json b/manifest.json index e71f6c8..66d8de8 100644 --- a/manifest.json +++ b/manifest.json @@ -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" @@ -26,6 +26,7 @@ "cookies", "storage", "tabs", + "webNavigation", "webRequest", "webRequestBlocking", "" diff --git a/settings.html b/settings.html index a63385b..36200f3 100644 --- a/settings.html +++ b/settings.html @@ -24,7 +24,7 @@

HTTP Switchboard — Settings

Under construction. -

Display

+

Display

Matrix text size:
    @@ -33,7 +33,7 @@

    Display

-

Strict blocking

+

Strict blocking

Strict blocking, introduced in version 0.3.6, @@ -52,7 +52,7 @@

Strict blocking

-

Cookies

+

Cookies

Blacklisted cookies are not prevented by HTTP Switchboard from entering your browser. However they are prevented from leaving your browser, which @@ -70,7 +70,7 @@

Cookies

-

Chromium: behind-the-scene requests

+

Chromium: behind-the-scene requests

According to Google Chrome Privacy Whitepaper, Chromium might send HTTP requests to Google without the user