Skip to content
This repository was archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
this addresses #7, #11
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jun 25, 2014
1 parent a908f20 commit 4d98233
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 24 deletions.
Empty file added css/noop.css
Empty file.
Binary file added img/noop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions js/abp-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ FilterContainer.prototype.match3rdPartyHostname = function(requestHostname) {

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

FilterContainer.prototype.matchString = function(pageStore, url, requestType, requestHostname) {
FilterContainer.prototype.matchString = function(pageDetails, url, requestType, requestHostname) {
// adbProfiler.countUrl();

// https://github.com/gorhill/httpswitchboard/issues/239
Expand All @@ -1397,24 +1397,24 @@ FilterContainer.prototype.matchString = function(pageStore, url, requestType, re
// This helps performance compared to testing against both classes of
// filters in the same loop.

var pageDomain = pageStore.pageDomain || '';
var pageDomain = pageDetails.pageDomain || '';
var party = requestHostname.slice(-pageDomain.length) === pageDomain ?
FirstParty :
ThirdParty;
var domainParty = this.toDomainBits(pageDomain);
var type = typeNameToTypeValue[requestType];
var categories = this.categories;

// This will be used by hostname-based filters
pageHostname = pageStore.pageHostname || '';

// Test hostname-based block filters
var bf = false;
bf = this.matchAnyPartyHostname(requestHostname);
if ( bf === false && party === ThirdParty ) {
bf = this.match3rdPartyHostname(requestHostname);
}

// This will be used by hostname-based filters
pageHostname = pageDetails.pageHostname || '';

// Test against block filters
if ( bf === false ) {
this.bucket0 = categories[this.makeCategoryKey(BlockAnyTypeAnyParty)];
Expand Down
3 changes: 1 addition & 2 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ return {

updateAssetsEvery: 5 * 24 * 60 * 60 * 1000,
projectServerRoot: 'https://raw2.github.com/gorhill/ublock/master/',
userFiltersPath: 'assets/user/filters.txt',

// list of remote blacklist locations
remoteBlacklists: {
Expand All @@ -59,8 +60,6 @@ return {
// Power switch to disengage µBlock
off: false,

userFiltersPath: 'assets/user/filters.txt',

storageQuota: chrome.storage.local.QUOTA_BYTES,
storageUsed: 0,

Expand Down
1 change: 1 addition & 0 deletions js/noop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
;
46 changes: 30 additions & 16 deletions js/traffic.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,40 @@

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

var typeToRedirectPathMap = {
'stylesheet': chrome.runtime.getURL('css/noop.css'),
'image': chrome.runtime.getURL('img/noop.png'),
'script': chrome.runtime.getURL('js/noop.js'),
'sub_frame': 'about:blank'
};

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

// Intercept and filter web requests according to white and black lists.

var onBeforeRequestHandler = function(details) {
var requestType = details.type;

// console.debug('onBeforeRequestHandler()> "%s": %o', details.url, details);

// Do not block behind the scene requests.
if ( details.tabId < 0 ) {
var tabId = details.tabId;
if ( tabId < 0 ) {
return;
}

var µb = µBlock;
var requestType = details.type;

// Never block root main doc.
if ( requestType === 'main_frame' && details.parentFrameId < 0 ) {
µb.bindTabToPageStats(tabId, details.url);
return;
}

var µb = µBlock;
var µburi = µb.URI;
var requestURL = µburi.set(details.url).normalizedURI();
var requestScheme = µburi.scheme;
var requestHostname = µburi.hostname;
var requestPath = µburi.path;

// Ignore non-http schemes
var requestScheme = µburi.scheme;
if ( requestScheme.indexOf('http') !== 0 ) {
return;
}
Expand All @@ -64,6 +73,9 @@ var onBeforeRequestHandler = function(details) {
return;
}

var requestHostname = µburi.hostname;
var requestPath = µburi.path;

// rhill 2013-12-15:
// Try to transpose generic `other` category into something more
// meaningful.
Expand All @@ -72,27 +84,29 @@ var onBeforeRequestHandler = function(details) {
}

// Lookup the page store associated with this tab id.
var pageStore = µb.pageStoreFromTabId(details.tabId) || {};
var pageStore = µb.pageStoreFromTabId(tabId) || {};

var reason = false;
if ( µb.getNetFilteringSwitch(pageStore.pageHostname) ) {
reason = µb.abpFilters.matchString(pageStore, requestURL, requestType, requestHostname);
}
// Record what happened.
if ( pageStore ) {
pageStore.recordRequest(requestType, requestURL, reason);
}

// Block using ABP filters?
pageStore.recordRequest(requestType, requestURL, reason);

// whitelisted?
// Not blocked?
if ( reason === false ) {
return;
}

// blacklisted
// Blocked
// console.debug('onBeforeRequestHandler()> BLOCK "%s": %o', details.url, details);

// If it's a blacklisted frame, redirect to something harmless.
if ( requestType === 'sub_frame' ) {
return { 'redirectUrl': 'about:blank' };
// Redirect to noop versions whenever possible.
var redirectPath = typeToRedirectPathMap[requestType];
if ( redirectPath ) {
return { 'redirectUrl': redirectPath };
}

return { 'cancel': true };
Expand Down
7 changes: 6 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": "__MSG_extName__",
"short_name": "µBlock",
"version": "0.1.0.5",
"version": "0.1.0.6",
"description": "__MSG_extShortDesc__",
"icons": {
"16": "img/icon_16.png",
Expand Down Expand Up @@ -48,5 +48,10 @@
"webRequestBlocking",
"http://*/*",
"https://*/*"
],
"web_accessible_resources": [
"css/noop.css",
"img/noop.png",
"js/noop.js"
]
}

0 comments on commit 4d98233

Please sign in to comment.