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

Commit

Permalink
#475: whitelist behind-the-scene by default
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jan 22, 2015
1 parent 4b2dced commit 4c7f477
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 37 deletions.
12 changes: 6 additions & 6 deletions src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,11 @@ var onMessage = function(request, sender, callback) {
break;

case 'toggleNetFiltering':
µb.toggleNetFilteringSwitch(
request.url,
request.scope,
request.state
);
µb.updateBadgeAsync(request.tabId);
var pageStore = µb.pageStoreFromTabId(request.tabId);
if ( pageStore ) {
pageStore.toggleNetFilteringSwitch(request.url, request.scope, request.state);
µb.updateBadgeAsync(request.tabId);
}
break;

default:
Expand Down Expand Up @@ -912,6 +911,7 @@ var restoreUserData = function(userData) {

var onAllRemoved = function() {
// Be sure to adjust `countdown` if adding/removing anything below
µb.XAL.keyvalSetOne('version', userData.version);
µBlock.saveLocalSettings(onCountdown);
µb.XAL.keyvalSetMany(userData.userSettings, onCountdown);
µb.XAL.keyvalSetOne('remoteBlacklists', userData.filterLists, onCountdown);
Expand Down
35 changes: 21 additions & 14 deletions src/js/pagestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,7 @@ NetFilteringResultCache.prototype.init = function() {
/******************************************************************************/

NetFilteringResultCache.prototype.dispose = function() {
for ( var key in this.urls ) {
if ( this.urls.hasOwnProperty(key) === false ) {
continue;
}
this.urls[key].dispose();
}
this.urls = {};
this.count = 0;
if ( this.timer !== null ) {
clearTimeout(this.timer);
this.timer = null;
}
this.empty();
this.boundPruneAsyncCallback = null;
if ( netFilteringCacheJunkyard.length < netFilteringCacheJunkyardMax ) {
netFilteringCacheJunkyard.push(this);
Expand Down Expand Up @@ -335,8 +324,19 @@ NetFilteringResultCache.prototype.add = function(context, result) {

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

NetFilteringResultCache.prototype.fetchAll = function() {
return this.urls;
NetFilteringResultCache.prototype.empty = function() {
for ( var key in this.urls ) {
if ( this.urls.hasOwnProperty(key) === false ) {
continue;
}
this.urls[key].dispose();
}
this.urls = {};
this.count = 0;
if ( this.timer !== null ) {
clearTimeout(this.timer);
this.timer = null;
}
};

/******************************************************************************/
Expand Down Expand Up @@ -608,6 +608,13 @@ PageStore.prototype.getCosmeticFilteringSwitch = function() {

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

PageStore.prototype.toggleNetFilteringSwitch = function(url, scope, state) {
µb.toggleNetFilteringSwitch(url, scope, state);
this.netFilteringCache.empty();
};

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

PageStore.prototype.filterRequest = function(context) {
if ( this.getNetFilteringSwitch() === false ) {
this.cacheResult(context, '');
Expand Down
44 changes: 27 additions & 17 deletions src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@
/******************************************************************************/

µBlock.saveUserSettings = function() {
vAPI.storage.set(this.userSettings, function() {
µBlock.getBytesInUse();
});
vAPI.storage.set(this.userSettings);
};

/******************************************************************************/
Expand Down Expand Up @@ -97,9 +95,7 @@
var bin = {
'netWhitelist': this.stringFromWhitelist(this.netWhitelist)
};
vAPI.storage.set(bin, function() {
µBlock.getBytesInUse();
});
vAPI.storage.set(bin);
this.netWhitelistModifyTime = Date.now();
};

Expand Down Expand Up @@ -128,7 +124,7 @@
};

var bin = {
'netWhitelist': '',
'netWhitelist': 'behind-the-scene',
'netExceptionList': ''
};
vAPI.storage.get(bin, onWhitelistLoaded);
Expand Down Expand Up @@ -595,18 +591,10 @@
var µb = this;
var fromSelfie = false;

// Filter lists
// Whitelist
var countdown = 2;

// Final initialization steps after all needed assets are in memory.
// - Initialize internal state with maybe already existing tabs.
// - Schedule next update operation.
var doCountdown = function() {
countdown -= 1;
if ( countdown !== 0 ) {
return;
}
var onAllReady = function() {
// https://github.com/gorhill/uBlock/issues/426
// Important: remove barrier to remote fetching, this was useful only
// for launch time.
Expand All @@ -619,6 +607,29 @@
µb.updater.restart(µb.firstUpdateAfter);
};

// To bring older versions up to date
var onVersionReady = function(bin) {
var lastVersion = bin.version || '0.0.0.0';
// Whitelist behind-the-scene scope by default
if ( lastVersion.localeCompare('0.8.6.0') < 0 ) {
µb.toggleNetFilteringSwitch('http://behind-the-scene/', 'site', false);
}
vAPI.storage.set({ version: vAPI.app.version });
onAllReady();
};

// Filter lists
// Whitelist
var countdown = 2;
var doCountdown = function() {
countdown -= 1;
if ( countdown !== 0 ) {
return;
}
// Last step: do whatever is necessary when version changes
vAPI.storage.get('version', onVersionReady);
};

// Filters are in memory.
// Filter engines need PSL to be ready.
var onFiltersReady = function() {
Expand Down Expand Up @@ -689,5 +700,4 @@
this.loadUserSettings(onUserSettingsReady);
this.loadWhitelist(onWhitelistReady);
this.loadLocalSettings();
this.getBytesInUse();
};

0 comments on commit 4c7f477

Please sign in to comment.