2014-06-24 00:42:43 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2016-03-07 15:55:04 +01:00
|
|
|
uBlock Origin - a browser extension to block requests.
|
2017-01-18 19:17:47 +01:00
|
|
|
Copyright (C) 2014-2017 Raymond Hill
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
|
|
|
|
|
|
Home: https://github.com/gorhill/uBlock
|
|
|
|
*/
|
|
|
|
|
2014-10-17 21:44:19 +02:00
|
|
|
/******************************************************************************/
|
2014-11-16 14:09:28 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-08-06 18:05:01 +02:00
|
|
|
'use strict';
|
|
|
|
|
2014-11-16 15:49:55 +01:00
|
|
|
// Default handler
|
2014-10-17 21:44:19 +02:00
|
|
|
|
2014-11-16 15:49:55 +01:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
var µb = µBlock;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var getDomainNames = function(targets) {
|
|
|
|
var out = [];
|
|
|
|
var µburi = µb.URI;
|
|
|
|
var target, domain;
|
|
|
|
for ( var i = 0; i < targets.length; i++ ) {
|
|
|
|
target = targets[i];
|
|
|
|
if ( target.indexOf('/') !== -1 ) {
|
|
|
|
domain = µburi.domainFromURI(target) || '';
|
|
|
|
} else {
|
|
|
|
domain = µburi.domainFromHostname(target) || target;
|
|
|
|
}
|
|
|
|
out.push(domain);
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-10-17 21:44:19 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
var onMessage = function(request, sender, callback) {
|
2014-11-16 15:49:55 +01:00
|
|
|
// Async
|
2014-10-17 21:44:19 +02:00
|
|
|
switch ( request.what ) {
|
2015-04-25 13:28:35 +02:00
|
|
|
case 'getAssetContent':
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/417
|
2017-01-23 16:13:07 +01:00
|
|
|
µb.assets.get(request.url, { dontCache: true }, callback);
|
2015-04-25 13:28:35 +02:00
|
|
|
return;
|
2014-10-17 21:44:19 +02:00
|
|
|
|
2015-06-13 17:21:55 +02:00
|
|
|
case 'listsFromNetFilter':
|
|
|
|
µb.staticFilteringReverseLookup.fromNetFilter(
|
|
|
|
request.compiledFilter,
|
|
|
|
request.rawFilter,
|
|
|
|
callback
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'listsFromCosmeticFilter':
|
|
|
|
µb.staticFilteringReverseLookup.fromCosmeticFilter(
|
|
|
|
request.hostname,
|
|
|
|
request.rawFilter,
|
|
|
|
callback
|
|
|
|
);
|
2015-06-11 18:12:23 +02:00
|
|
|
return;
|
|
|
|
|
2015-06-26 06:08:41 +02:00
|
|
|
case 'reloadAllFilters':
|
2017-01-18 19:17:47 +01:00
|
|
|
µb.loadFilterLists();
|
2015-06-26 06:08:41 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case 'scriptlet':
|
|
|
|
µb.scriptlets.inject(request.tabId, request.scriptlet, callback);
|
|
|
|
return;
|
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
default:
|
|
|
|
break;
|
2014-11-16 15:49:55 +01:00
|
|
|
}
|
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
var tabId = sender && sender.tab ? sender.tab.id : 0;
|
|
|
|
|
2014-11-16 15:49:55 +01:00
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2017-01-22 22:05:16 +01:00
|
|
|
case 'applyFilterListSelection':
|
|
|
|
response = µb.applyFilterListSelection(request);
|
2015-04-25 13:28:35 +02:00
|
|
|
break;
|
2014-10-17 21:44:19 +02:00
|
|
|
|
2016-12-25 22:56:39 +01:00
|
|
|
case 'compileCosmeticFilterSelector':
|
|
|
|
response = µb.cosmeticFilteringEngine.compileSelector(request.selector);
|
|
|
|
break;
|
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
case 'cosmeticFiltersInjected':
|
2015-04-25 14:27:27 +02:00
|
|
|
µb.cosmeticFilteringEngine.addToSelectorCache(request);
|
|
|
|
/* falls through */
|
|
|
|
case 'cosmeticFiltersActivated':
|
2015-04-25 13:28:35 +02:00
|
|
|
// Net-based cosmetic filters are of no interest for logging purpose.
|
2015-05-19 19:59:53 +02:00
|
|
|
if ( µb.logger.isEnabled() && request.type !== 'net' ) {
|
2015-04-25 13:28:35 +02:00
|
|
|
µb.logCosmeticFilters(tabId);
|
|
|
|
}
|
|
|
|
break;
|
2015-03-11 04:46:18 +01:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
case 'createUserFilter':
|
|
|
|
µb.appendUserFilters(request.filters);
|
2016-07-07 22:42:01 +02:00
|
|
|
// https://github.com/gorhill/uBlock/issues/1786
|
|
|
|
µb.cosmeticFilteringEngine.removeFromSelectorCache(request.pageDomain);
|
2015-06-07 00:31:38 +02:00
|
|
|
break;
|
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
case 'forceUpdateAssets':
|
2017-01-18 19:17:47 +01:00
|
|
|
µb.scheduleAssetUpdater(0);
|
|
|
|
µb.assets.updateStart({ delay: µb.hiddenSettings.manualUpdateAssetFetchPeriod || 2000 });
|
2015-04-25 13:28:35 +02:00
|
|
|
break;
|
2014-12-01 17:25:33 +01:00
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
case 'getAppData':
|
|
|
|
response = {name: vAPI.app.name, version: vAPI.app.version};
|
|
|
|
break;
|
2014-10-17 21:44:19 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
case 'getDomainNames':
|
|
|
|
response = getDomainNames(request.targets);
|
|
|
|
break;
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
case 'getWhitelist':
|
|
|
|
response = µb.stringFromWhitelist(µb.netWhitelist);
|
|
|
|
break;
|
|
|
|
|
2015-05-25 00:50:09 +02:00
|
|
|
case 'launchElementPicker':
|
|
|
|
// Launched from some auxiliary pages, clear context menu coords.
|
2015-09-10 19:46:18 +02:00
|
|
|
µb.mouseX = µb.mouseY = -1;
|
2017-05-27 17:51:24 +02:00
|
|
|
µb.elementPickerExec(request.tabId, request.targetURL, request.zap);
|
2015-05-25 00:50:09 +02:00
|
|
|
break;
|
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
case 'gotoURL':
|
2016-09-16 23:41:17 +02:00
|
|
|
µb.openNewTab(request.details);
|
2015-04-25 13:28:35 +02:00
|
|
|
break;
|
2014-10-17 21:44:19 +02:00
|
|
|
|
2017-01-22 22:05:16 +01:00
|
|
|
case 'mouseClick':
|
|
|
|
µb.mouseX = request.x;
|
|
|
|
µb.mouseY = request.y;
|
|
|
|
µb.mouseURL = request.url;
|
|
|
|
break;
|
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
case 'reloadTab':
|
|
|
|
if ( vAPI.isBehindTheSceneTabId(request.tabId) === false ) {
|
|
|
|
vAPI.tabs.reload(request.tabId);
|
|
|
|
if ( request.select && vAPI.tabs.select ) {
|
|
|
|
vAPI.tabs.select(request.tabId);
|
2015-01-20 00:42:58 +01:00
|
|
|
}
|
2015-04-25 13:28:35 +02:00
|
|
|
}
|
|
|
|
break;
|
2015-01-06 14:01:15 +01:00
|
|
|
|
2015-06-26 06:08:41 +02:00
|
|
|
case 'scriptletResponse':
|
|
|
|
µb.scriptlets.report(tabId, request.scriptlet, request.response);
|
|
|
|
break;
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
case 'setWhitelist':
|
|
|
|
µb.netWhitelist = µb.whitelistFromString(request.whitelist);
|
|
|
|
µb.saveWhitelist();
|
|
|
|
break;
|
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
case 'toggleHostnameSwitch':
|
|
|
|
µb.toggleHostnameSwitch(request);
|
|
|
|
break;
|
2015-03-27 18:00:55 +01:00
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
case 'userSettings':
|
|
|
|
response = µb.changeUserSettings(request.name, request.value);
|
|
|
|
break;
|
2014-10-17 21:44:19 +02:00
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-10-17 21:44:19 +02:00
|
|
|
}
|
2014-11-16 15:49:55 +01:00
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
|
|
|
vAPI.messaging.setup(onMessage);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
2014-10-17 21:44:19 +02:00
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
// channel: popupPanel
|
2014-09-28 18:05:46 +02:00
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
(function() {
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var µb = µBlock;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-12-30 22:36:29 +01:00
|
|
|
var getHostnameDict = function(hostnameToCountMap) {
|
2016-10-08 16:15:31 +02:00
|
|
|
var r = Object.create(null),
|
|
|
|
domainEntry,
|
|
|
|
domainFromHostname = µb.URI.domainFromHostname,
|
|
|
|
domain, blockCount, allowCount,
|
2017-05-19 16:12:55 +02:00
|
|
|
hostname, counts;
|
|
|
|
// Note: destructuring assignment not supported before Chromium 49.
|
|
|
|
for ( var entry of hostnameToCountMap ) {
|
|
|
|
hostname = entry[0];
|
|
|
|
if ( r[hostname] !== undefined ) { continue; }
|
2015-01-11 15:47:14 +01:00
|
|
|
domain = domainFromHostname(hostname) || hostname;
|
2016-10-08 16:15:31 +02:00
|
|
|
counts = hostnameToCountMap.get(domain) || 0;
|
2015-02-17 03:15:09 +01:00
|
|
|
blockCount = counts & 0xFFFF;
|
|
|
|
allowCount = counts >>> 16 & 0xFFFF;
|
2016-10-08 16:15:31 +02:00
|
|
|
if ( r[domain] === undefined ) {
|
|
|
|
domainEntry = r[domain] = {
|
2015-02-17 03:15:09 +01:00
|
|
|
domain: domain,
|
|
|
|
blockCount: blockCount,
|
|
|
|
allowCount: allowCount,
|
2016-02-22 21:54:07 +01:00
|
|
|
totalBlockCount: blockCount,
|
|
|
|
totalAllowCount: allowCount
|
2015-02-17 03:15:09 +01:00
|
|
|
};
|
|
|
|
} else {
|
2016-10-08 16:15:31 +02:00
|
|
|
domainEntry = r[domain];
|
2015-02-17 03:15:09 +01:00
|
|
|
}
|
2017-05-19 16:12:55 +02:00
|
|
|
counts = entry[1];
|
2015-02-17 03:15:09 +01:00
|
|
|
blockCount = counts & 0xFFFF;
|
|
|
|
allowCount = counts >>> 16 & 0xFFFF;
|
2016-10-08 16:15:31 +02:00
|
|
|
domainEntry.totalBlockCount += blockCount;
|
|
|
|
domainEntry.totalAllowCount += allowCount;
|
2017-05-19 16:12:55 +02:00
|
|
|
if ( hostname === domain ) { continue; }
|
2014-12-30 22:36:29 +01:00
|
|
|
r[hostname] = {
|
|
|
|
domain: domain,
|
2015-02-17 03:15:09 +01:00
|
|
|
blockCount: blockCount,
|
2015-08-18 17:44:24 +02:00
|
|
|
allowCount: allowCount,
|
|
|
|
totalBlockCount: 0,
|
|
|
|
totalAllowCount: 0
|
2014-12-30 22:36:29 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-02-11 06:26:45 +01:00
|
|
|
var getFirewallRules = function(srcHostname, desHostnames) {
|
2014-12-28 16:07:43 +01:00
|
|
|
var r = {};
|
2015-05-21 20:15:17 +02:00
|
|
|
var df = µb.sessionFirewall;
|
2017-05-12 16:35:11 +02:00
|
|
|
r['/ * *'] = df.lookupRuleData('*', '*', '*');
|
|
|
|
r['/ * image'] = df.lookupRuleData('*', '*', 'image');
|
|
|
|
r['/ * 3p'] = df.lookupRuleData('*', '*', '3p');
|
|
|
|
r['/ * inline-script'] = df.lookupRuleData('*', '*', 'inline-script');
|
|
|
|
r['/ * 1p-script'] = df.lookupRuleData('*', '*', '1p-script');
|
|
|
|
r['/ * 3p-script'] = df.lookupRuleData('*', '*', '3p-script');
|
|
|
|
r['/ * 3p-frame'] = df.lookupRuleData('*', '*', '3p-frame');
|
2014-12-30 22:36:29 +01:00
|
|
|
if ( typeof srcHostname !== 'string' ) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2017-05-12 16:35:11 +02:00
|
|
|
r['. * *'] = df.lookupRuleData(srcHostname, '*', '*');
|
|
|
|
r['. * image'] = df.lookupRuleData(srcHostname, '*', 'image');
|
|
|
|
r['. * 3p'] = df.lookupRuleData(srcHostname, '*', '3p');
|
|
|
|
r['. * inline-script'] = df.lookupRuleData(srcHostname, '*', 'inline-script');
|
|
|
|
r['. * 1p-script'] = df.lookupRuleData(srcHostname, '*', '1p-script');
|
|
|
|
r['. * 3p-script'] = df.lookupRuleData(srcHostname, '*', '3p-script');
|
|
|
|
r['. * 3p-frame'] = df.lookupRuleData(srcHostname, '*', '3p-frame');
|
2014-12-30 22:36:29 +01:00
|
|
|
|
|
|
|
for ( var desHostname in desHostnames ) {
|
2017-05-12 16:35:11 +02:00
|
|
|
r['/ ' + desHostname + ' *'] = df.lookupRuleData('*', desHostname, '*');
|
|
|
|
r['. ' + desHostname + ' *'] = df.lookupRuleData(srcHostname, desHostname, '*');
|
2014-12-30 22:36:29 +01:00
|
|
|
}
|
2014-12-28 16:07:43 +01:00
|
|
|
return r;
|
2014-10-06 20:02:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-18 16:39:20 +02:00
|
|
|
var popupDataFromTabId = function(tabId, tabTitle) {
|
2016-11-06 22:27:21 +01:00
|
|
|
var tabContext = µb.tabContextManager.mustLookup(tabId),
|
|
|
|
rootHostname = tabContext.rootHostname;
|
2014-06-24 00:42:43 +02:00
|
|
|
var r = {
|
2015-01-06 17:44:06 +01:00
|
|
|
advancedUserEnabled: µb.userSettings.advancedUserEnabled,
|
2014-12-01 17:25:33 +01:00
|
|
|
appName: vAPI.app.name,
|
|
|
|
appVersion: vAPI.app.version,
|
2015-04-22 16:46:10 +02:00
|
|
|
colorBlindFriendly: µb.userSettings.colorBlindFriendly,
|
2015-01-06 17:44:06 +01:00
|
|
|
cosmeticFilteringSwitch: false,
|
|
|
|
dfEnabled: µb.userSettings.dynamicFilteringEnabled,
|
2015-02-17 03:15:09 +01:00
|
|
|
firewallPaneMinimized: µb.userSettings.firewallPaneMinimized,
|
2014-06-24 00:42:43 +02:00
|
|
|
globalAllowedRequestCount: µb.localSettings.allowedRequestCount,
|
2015-01-06 17:44:06 +01:00
|
|
|
globalBlockedRequestCount: µb.localSettings.blockedRequestCount,
|
2016-11-06 22:27:21 +01:00
|
|
|
fontSize: µb.hiddenSettings.popupFontSize,
|
2015-01-06 17:44:06 +01:00
|
|
|
netFilteringSwitch: false,
|
2015-04-09 00:46:08 +02:00
|
|
|
rawURL: tabContext.rawURL,
|
|
|
|
pageURL: tabContext.normalURL,
|
2016-01-17 19:30:43 +01:00
|
|
|
pageHostname: rootHostname,
|
2015-04-09 00:46:08 +02:00
|
|
|
pageDomain: tabContext.rootDomain,
|
2014-06-24 00:42:43 +02:00
|
|
|
pageAllowedRequestCount: 0,
|
2015-01-06 17:44:06 +01:00
|
|
|
pageBlockedRequestCount: 0,
|
2016-01-04 16:48:28 +01:00
|
|
|
popupBlockedCount: 0,
|
2015-03-02 19:49:34 +01:00
|
|
|
tabId: tabId,
|
2015-12-13 06:33:53 +01:00
|
|
|
tabTitle: tabTitle,
|
|
|
|
tooltipsDisabled: µb.userSettings.tooltipsDisabled
|
2014-06-24 00:42:43 +02:00
|
|
|
};
|
2015-04-09 00:46:08 +02:00
|
|
|
|
2014-12-30 22:36:29 +01:00
|
|
|
var pageStore = µb.pageStoreFromTabId(tabId);
|
2014-06-24 00:42:43 +02:00
|
|
|
if ( pageStore ) {
|
2016-10-29 17:15:04 +02:00
|
|
|
// https://github.com/gorhill/uBlock/issues/2105
|
|
|
|
// Be sure to always include the current page's hostname -- it might
|
|
|
|
// not be present when the page itself is pulled from the browser's
|
|
|
|
// short-term memory cache. This needs to be done before calling
|
|
|
|
// getHostnameDict().
|
|
|
|
if (
|
|
|
|
pageStore.hostnameToCountMap.has(rootHostname) === false &&
|
|
|
|
µb.URI.isNetworkURI(tabContext.rawURL)
|
|
|
|
) {
|
|
|
|
pageStore.hostnameToCountMap.set(rootHostname, 0);
|
|
|
|
}
|
2014-06-24 00:42:43 +02:00
|
|
|
r.pageBlockedRequestCount = pageStore.perLoadBlockedRequestCount;
|
|
|
|
r.pageAllowedRequestCount = pageStore.perLoadAllowedRequestCount;
|
2014-08-02 17:40:27 +02:00
|
|
|
r.netFilteringSwitch = pageStore.getNetFilteringSwitch();
|
2014-12-30 22:36:29 +01:00
|
|
|
r.hostnameDict = getHostnameDict(pageStore.hostnameToCountMap);
|
2015-01-10 17:23:28 +01:00
|
|
|
r.contentLastModified = pageStore.contentLastModified;
|
2016-01-17 19:30:43 +01:00
|
|
|
r.firewallRules = getFirewallRules(rootHostname, r.hostnameDict);
|
2017-05-27 17:51:24 +02:00
|
|
|
r.canElementPicker = µb.URI.isNetworkURI(r.rawURL);
|
2016-01-17 19:30:43 +01:00
|
|
|
r.noPopups = µb.hnSwitches.evaluateZ('no-popups', rootHostname);
|
2016-01-04 16:48:28 +01:00
|
|
|
r.popupBlockedCount = pageStore.popupBlockedCount;
|
2016-01-17 19:30:43 +01:00
|
|
|
r.noCosmeticFiltering = µb.hnSwitches.evaluateZ('no-cosmetic-filtering', rootHostname);
|
|
|
|
r.noLargeMedia = µb.hnSwitches.evaluateZ('no-large-media', rootHostname);
|
|
|
|
r.largeMediaCount = pageStore.largeMediaCount;
|
|
|
|
r.noRemoteFonts = µb.hnSwitches.evaluateZ('no-remote-fonts', rootHostname);
|
|
|
|
r.remoteFontCount = pageStore.remoteFontCount;
|
2014-12-30 22:36:29 +01:00
|
|
|
} else {
|
|
|
|
r.hostnameDict = {};
|
2015-02-11 06:26:45 +01:00
|
|
|
r.firewallRules = getFirewallRules();
|
|
|
|
}
|
2015-04-09 00:46:08 +02:00
|
|
|
r.matrixIsDirty = !µb.sessionFirewall.hasSameRules(
|
|
|
|
µb.permanentFirewall,
|
2016-01-17 19:30:43 +01:00
|
|
|
rootHostname,
|
2015-04-09 00:46:08 +02:00
|
|
|
r.hostnameDict
|
|
|
|
);
|
2014-06-24 00:42:43 +02:00
|
|
|
return r;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-18 16:39:20 +02:00
|
|
|
var popupDataFromRequest = function(request, callback) {
|
|
|
|
if ( request.tabId ) {
|
|
|
|
callback(popupDataFromTabId(request.tabId, ''));
|
|
|
|
return;
|
2015-01-20 00:42:58 +01:00
|
|
|
}
|
2015-01-21 17:13:32 +01:00
|
|
|
|
2015-05-18 16:39:20 +02:00
|
|
|
// Still no target tab id? Use currently selected tab.
|
|
|
|
vAPI.tabs.get(null, function(tab) {
|
|
|
|
var tabId = '';
|
|
|
|
var tabTitle = '';
|
|
|
|
if ( tab ) {
|
|
|
|
tabId = tab.id;
|
|
|
|
tabTitle = tab.title || '';
|
|
|
|
}
|
|
|
|
callback(popupDataFromTabId(tabId, tabTitle));
|
|
|
|
});
|
2015-01-20 00:42:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
var onMessage = function(request, sender, callback) {
|
2016-08-06 18:05:01 +02:00
|
|
|
var pageStore;
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
2016-08-06 18:05:01 +02:00
|
|
|
case 'getPopupLazyData':
|
|
|
|
pageStore = µb.pageStoreFromTabId(request.tabId);
|
|
|
|
if ( pageStore !== null ) {
|
|
|
|
pageStore.hiddenElementCount = 0;
|
|
|
|
µb.scriptlets.injectDeep(request.tabId, 'cosmetic-survey');
|
|
|
|
}
|
2015-04-24 14:36:19 +02:00
|
|
|
return;
|
2015-04-05 18:03:14 +02:00
|
|
|
|
2015-04-24 14:36:19 +02:00
|
|
|
case 'getPopupData':
|
2015-05-18 16:39:20 +02:00
|
|
|
popupDataFromRequest(request, callback);
|
2015-04-24 14:36:19 +02:00
|
|
|
return;
|
2014-10-17 21:44:19 +02:00
|
|
|
|
2015-04-24 14:36:19 +02:00
|
|
|
default:
|
|
|
|
break;
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2015-04-24 14:36:19 +02:00
|
|
|
case 'hasPopupContentChanged':
|
|
|
|
pageStore = µb.pageStoreFromTabId(request.tabId);
|
|
|
|
var lastModified = pageStore ? pageStore.contentLastModified : 0;
|
|
|
|
response = lastModified !== request.contentLastModified;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'revertFirewallRules':
|
|
|
|
µb.sessionFirewall.copyRules(
|
|
|
|
µb.permanentFirewall,
|
|
|
|
request.srcHostname,
|
|
|
|
request.desHostnames
|
|
|
|
);
|
2015-05-09 14:25:05 +02:00
|
|
|
// https://github.com/gorhill/uBlock/issues/188
|
|
|
|
µb.cosmeticFilteringEngine.removeFromSelectorCache(request.srcHostname, 'net');
|
2015-05-18 16:39:20 +02:00
|
|
|
response = popupDataFromTabId(request.tabId);
|
2015-04-24 14:36:19 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'saveFirewallRules':
|
|
|
|
µb.permanentFirewall.copyRules(
|
|
|
|
µb.sessionFirewall,
|
|
|
|
request.srcHostname,
|
|
|
|
request.desHostnames
|
|
|
|
);
|
|
|
|
µb.savePermanentFirewallRules();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'toggleFirewallRule':
|
|
|
|
µb.toggleFirewallRule(request);
|
2015-05-18 16:39:20 +02:00
|
|
|
response = popupDataFromTabId(request.tabId);
|
2015-04-24 14:36:19 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'toggleNetFiltering':
|
|
|
|
pageStore = µb.pageStoreFromTabId(request.tabId);
|
|
|
|
if ( pageStore ) {
|
|
|
|
pageStore.toggleNetFilteringSwitch(request.url, request.scope, request.state);
|
|
|
|
µb.updateBadgeAsync(request.tabId);
|
|
|
|
}
|
|
|
|
break;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
2015-04-24 14:36:19 +02:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
vAPI.messaging.listen('popupPanel', onMessage);
|
2014-09-28 18:05:46 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
// channel: contentscript
|
2014-06-27 23:06:42 +02:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-08-02 17:40:27 +02:00
|
|
|
var µb = µBlock;
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var tagNameToRequestTypeMap = {
|
|
|
|
'embed': 'object',
|
|
|
|
'iframe': 'sub_frame',
|
|
|
|
'img': 'image',
|
|
|
|
'object': 'object'
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-07-25 14:18:17 +02:00
|
|
|
// Evaluate many requests.
|
|
|
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/1782
|
|
|
|
// Treat `data:` URIs as 1st-party resources.
|
2014-09-14 22:20:40 +02:00
|
|
|
|
|
|
|
var filterRequests = function(pageStore, details) {
|
2015-03-29 18:13:28 +02:00
|
|
|
var requests = details.requests;
|
|
|
|
if ( µb.userSettings.collapseBlocked === false ) {
|
|
|
|
return requests;
|
|
|
|
}
|
|
|
|
|
|
|
|
//console.debug('messaging.js/contentscript-end.js: processing %d requests', requests.length);
|
|
|
|
|
2016-11-08 21:53:08 +01:00
|
|
|
var hostnameFromURI = µb.URI.hostnameFromURI,
|
|
|
|
redirectEngine = µb.redirectEngine,
|
|
|
|
punycodeURL = vAPI.punycodeURL;
|
2014-12-28 16:07:43 +01:00
|
|
|
|
|
|
|
// Create evaluation context
|
2016-11-08 21:53:08 +01:00
|
|
|
var context = pageStore.createContextFromFrameHostname(details.pageHostname),
|
2017-05-13 14:51:56 +02:00
|
|
|
request,
|
2016-11-08 21:53:08 +01:00
|
|
|
i = requests.length;
|
2014-09-14 22:20:40 +02:00
|
|
|
while ( i-- ) {
|
2015-03-29 18:13:28 +02:00
|
|
|
request = requests[i];
|
2016-08-23 01:13:52 +02:00
|
|
|
context.requestURL = punycodeURL(request.url);
|
|
|
|
context.requestHostname = hostnameFromURI(context.requestURL);
|
2016-08-08 15:53:35 +02:00
|
|
|
context.requestType = tagNameToRequestTypeMap[request.tag];
|
2017-05-13 14:51:56 +02:00
|
|
|
if ( pageStore.filterRequest(context) !== 1 ) { continue; }
|
2015-11-26 23:56:30 +01:00
|
|
|
// Redirected? (We do not hide redirected resources.)
|
2017-05-13 14:57:30 +02:00
|
|
|
request.collapse = redirectEngine.matches(context) !== true;
|
2014-09-14 22:20:40 +02:00
|
|
|
}
|
2016-07-01 04:03:29 +02:00
|
|
|
|
|
|
|
context.dispose();
|
2015-03-29 18:13:28 +02:00
|
|
|
return requests;
|
2014-09-14 22:20:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
var onMessage = function(request, sender, callback) {
|
2014-06-27 23:06:42 +02:00
|
|
|
// Async
|
2015-04-25 13:28:35 +02:00
|
|
|
switch ( request.what ) {
|
|
|
|
default:
|
|
|
|
break;
|
2014-06-27 23:06:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
var pageStore;
|
|
|
|
if ( sender && sender.tab ) {
|
2014-08-02 17:40:27 +02:00
|
|
|
pageStore = µb.pageStoreFromTabId(sender.tab.id);
|
2014-06-27 23:06:42 +02:00
|
|
|
}
|
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
switch ( request.what ) {
|
2016-08-12 14:55:35 +02:00
|
|
|
case 'retrieveContentScriptParameters':
|
2016-03-06 16:51:06 +01:00
|
|
|
if ( pageStore && pageStore.getNetFilteringSwitch() ) {
|
2016-08-12 14:55:35 +02:00
|
|
|
response = {
|
|
|
|
loggerEnabled: µb.logger.isEnabled(),
|
|
|
|
collapseBlocked: µb.userSettings.collapseBlocked,
|
|
|
|
noCosmeticFiltering: µb.cosmeticFilteringEngine.acceptedCount === 0 || pageStore.noCosmeticFiltering === true,
|
|
|
|
noGenericCosmeticFiltering: pageStore.noGenericCosmeticFiltering === true
|
|
|
|
};
|
|
|
|
response.specificCosmeticFilters = µb.cosmeticFilteringEngine.retrieveDomainSelectors(
|
|
|
|
request,
|
|
|
|
response.noCosmeticFiltering
|
|
|
|
);
|
2016-03-06 16:51:06 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
case 'retrieveGenericCosmeticSelectors':
|
2016-08-13 22:42:58 +02:00
|
|
|
if ( pageStore && pageStore.getGenericCosmeticFilteringSwitch() ) {
|
|
|
|
response = {
|
|
|
|
result: µb.cosmeticFilteringEngine.retrieveGenericSelectors(request)
|
|
|
|
};
|
2015-04-25 13:28:35 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-06-27 23:06:42 +02:00
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
case 'filterRequests':
|
2016-08-13 22:42:58 +02:00
|
|
|
if ( pageStore && pageStore.getNetFilteringSwitch() ) {
|
|
|
|
response = {
|
|
|
|
result: filterRequests(pageStore, request),
|
|
|
|
netSelectorCacheCountMax: µb.cosmeticFilteringEngine.netSelectorCacheCountMax
|
|
|
|
};
|
2015-04-25 13:28:35 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-11-16 14:09:28 +01:00
|
|
|
|
2015-04-25 13:28:35 +02:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-10-20 13:26:02 +02:00
|
|
|
}
|
2014-06-24 00:42:43 +02:00
|
|
|
|
2014-10-20 13:26:02 +02:00
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
vAPI.messaging.listen('contentscript', onMessage);
|
2014-10-20 13:26:02 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
// channel: elementPicker
|
2014-10-20 13:26:02 +02:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-09-28 18:05:46 +02:00
|
|
|
|
2014-10-20 13:26:02 +02:00
|
|
|
var µb = µBlock;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMessage = function(request, sender, callback) {
|
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
2015-05-19 19:59:53 +02:00
|
|
|
case 'elementPickerArguments':
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('GET', 'epicker.html', true);
|
|
|
|
xhr.overrideMimeType('text/html;charset=utf-8');
|
|
|
|
xhr.responseType = 'text';
|
|
|
|
xhr.onload = function() {
|
|
|
|
this.onload = null;
|
|
|
|
var i18n = {
|
|
|
|
bidi_dir: document.body.getAttribute('dir'),
|
|
|
|
create: vAPI.i18n('pickerCreate'),
|
|
|
|
pick: vAPI.i18n('pickerPick'),
|
|
|
|
quit: vAPI.i18n('pickerQuit'),
|
2016-04-16 17:20:01 +02:00
|
|
|
preview: vAPI.i18n('pickerPreview'),
|
2015-05-19 19:59:53 +02:00
|
|
|
netFilters: vAPI.i18n('pickerNetFilters'),
|
|
|
|
cosmeticFilters: vAPI.i18n('pickerCosmeticFilters'),
|
|
|
|
cosmeticFiltersHint: vAPI.i18n('pickerCosmeticFiltersHint')
|
|
|
|
};
|
|
|
|
var reStrings = /\{\{(\w+)\}\}/g;
|
|
|
|
var replacer = function(a0, string) {
|
|
|
|
return i18n[string];
|
2014-07-13 02:32:44 +02:00
|
|
|
};
|
2015-03-20 16:39:20 +01:00
|
|
|
|
2015-05-19 19:59:53 +02:00
|
|
|
callback({
|
|
|
|
frameContent: this.responseText.replace(reStrings, replacer),
|
2015-05-25 00:50:09 +02:00
|
|
|
target: µb.epickerTarget,
|
2015-09-10 19:46:18 +02:00
|
|
|
clientX: µb.mouseX,
|
|
|
|
clientY: µb.mouseY,
|
2017-05-27 17:51:24 +02:00
|
|
|
zap: µb.epickerZap,
|
2015-05-19 19:59:53 +02:00
|
|
|
eprom: µb.epickerEprom
|
|
|
|
});
|
|
|
|
|
2015-05-25 00:50:09 +02:00
|
|
|
µb.epickerTarget = '';
|
2015-09-10 19:46:18 +02:00
|
|
|
µb.mouseX = -1;
|
|
|
|
µb.mouseY = -1;
|
2015-05-19 19:59:53 +02:00
|
|
|
};
|
|
|
|
xhr.send();
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-02-08 19:34:28 +01:00
|
|
|
}
|
2014-07-13 02:32:44 +02:00
|
|
|
|
2015-02-08 19:34:28 +01:00
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2015-05-19 19:59:53 +02:00
|
|
|
case 'elementPickerEprom':
|
|
|
|
µb.epickerEprom = request;
|
|
|
|
break;
|
2015-03-20 16:39:20 +01:00
|
|
|
|
2015-05-19 19:59:53 +02:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-07-13 02:32:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
vAPI.messaging.listen('elementPicker', onMessage);
|
2014-09-28 18:05:46 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
2015-08-11 21:29:14 +02:00
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
// channel: cloudWidget
|
2015-08-11 21:29:14 +02:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMessage = function(request, sender, callback) {
|
2016-10-16 19:04:31 +02:00
|
|
|
// Cloud storage support is optional.
|
2016-10-19 16:20:26 +02:00
|
|
|
if ( µBlock.cloudStorageSupported !== true ) {
|
2016-10-16 19:04:31 +02:00
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-11 21:29:14 +02:00
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
|
|
|
case 'cloudGetOptions':
|
|
|
|
vAPI.cloud.getOptions(function(options) {
|
2016-10-16 19:04:31 +02:00
|
|
|
options.enabled = µBlock.userSettings.cloudStorageEnabled === true;
|
2015-08-11 21:29:14 +02:00
|
|
|
callback(options);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'cloudSetOptions':
|
|
|
|
vAPI.cloud.setOptions(request.options, callback);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'cloudPull':
|
|
|
|
return vAPI.cloud.pull(request.datakey, callback);
|
|
|
|
|
|
|
|
case 'cloudPush':
|
|
|
|
return vAPI.cloud.push(request.datakey, request.data, callback);
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
|
|
|
// For when cloud storage is disabled.
|
|
|
|
case 'cloudPull':
|
|
|
|
// fallthrough
|
|
|
|
case 'cloudPush':
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
vAPI.messaging.listen('cloudWidget', onMessage);
|
2014-12-31 23:26:17 +01:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
// channel: dashboard
|
2014-07-17 16:52:43 +02:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
2014-07-17 16:52:43 +02:00
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
var µb = µBlock;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
// Settings
|
2014-09-28 18:05:46 +02:00
|
|
|
|
2015-03-07 05:36:09 +01:00
|
|
|
var getLocalData = function(callback) {
|
|
|
|
var onStorageInfoReady = function(bytesInUse) {
|
|
|
|
var o = µb.restoreBackupSettings;
|
2014-10-07 14:59:35 +02:00
|
|
|
callback({
|
2015-03-07 05:36:09 +01:00
|
|
|
storageUsed: bytesInUse,
|
|
|
|
lastRestoreFile: o.lastRestoreFile,
|
|
|
|
lastRestoreTime: o.lastRestoreTime,
|
|
|
|
lastBackupFile: o.lastBackupFile,
|
2016-10-16 19:04:31 +02:00
|
|
|
lastBackupTime: o.lastBackupTime,
|
2016-10-19 16:20:26 +02:00
|
|
|
cloudStorageSupported: µb.cloudStorageSupported,
|
|
|
|
privacySettingsSupported: µb.privacySettingsSupported
|
2014-10-07 14:59:35 +02:00
|
|
|
});
|
|
|
|
};
|
2015-03-07 05:36:09 +01:00
|
|
|
|
|
|
|
µb.getBytesInUse(onStorageInfoReady);
|
|
|
|
};
|
|
|
|
|
|
|
|
var backupUserData = function(callback) {
|
2015-04-16 18:14:43 +02:00
|
|
|
var userData = {
|
|
|
|
timeStamp: Date.now(),
|
|
|
|
version: vAPI.app.version,
|
|
|
|
userSettings: µb.userSettings,
|
2017-01-26 16:17:38 +01:00
|
|
|
selectedFilterLists: µb.selectedFilterLists,
|
2016-11-03 16:20:47 +01:00
|
|
|
hiddenSettingsString: µb.stringFromHiddenSettings(),
|
2015-04-16 18:14:43 +02:00
|
|
|
netWhitelist: µb.stringFromWhitelist(µb.netWhitelist),
|
|
|
|
dynamicFilteringString: µb.permanentFirewall.toString(),
|
2015-05-21 20:15:17 +02:00
|
|
|
urlFilteringString: µb.permanentURLFiltering.toString(),
|
2015-04-16 18:14:43 +02:00
|
|
|
hostnameSwitchesString: µb.hnSwitches.toString(),
|
2017-01-26 16:17:38 +01:00
|
|
|
userFilters: '',
|
2017-01-18 19:17:47 +01:00
|
|
|
// TODO(seamless migration):
|
|
|
|
// The following is strictly for convenience, to be minimally
|
|
|
|
// forward-compatible. This will definitely be removed in the
|
|
|
|
// short term, as I do not expect the need to install an older
|
|
|
|
// version of uBO to ever be needed beyond the short term.
|
|
|
|
// >>>>>>>>
|
2017-01-26 16:17:38 +01:00
|
|
|
filterLists: µb.oldDataFromNewListKeys(µb.selectedFilterLists)
|
2017-01-18 19:17:47 +01:00
|
|
|
// <<<<<<<<
|
2017-01-26 16:17:38 +01:00
|
|
|
};
|
2015-04-16 18:14:43 +02:00
|
|
|
|
2017-01-26 16:17:38 +01:00
|
|
|
var onUserFiltersReady = function(details) {
|
|
|
|
userData.userFilters = details.content;
|
2015-03-07 05:36:09 +01:00
|
|
|
var filename = vAPI.i18n('aboutBackupFilename')
|
2016-10-13 19:25:57 +02:00
|
|
|
.replace('{{datetime}}', µb.dateNowToSensibleString())
|
2015-03-07 05:36:09 +01:00
|
|
|
.replace(/ +/g, '_');
|
|
|
|
µb.restoreBackupSettings.lastBackupFile = filename;
|
|
|
|
µb.restoreBackupSettings.lastBackupTime = Date.now();
|
2015-04-10 15:52:16 +02:00
|
|
|
vAPI.storage.set(µb.restoreBackupSettings);
|
2017-04-04 22:45:50 +02:00
|
|
|
getLocalData(function(localData) {
|
|
|
|
callback({ localData: localData, userData: userData });
|
|
|
|
});
|
2015-03-07 05:36:09 +01:00
|
|
|
};
|
|
|
|
|
2016-02-17 15:28:20 +01:00
|
|
|
µb.assets.get(µb.userFiltersPath, onUserFiltersReady);
|
2014-10-07 14:59:35 +02:00
|
|
|
};
|
|
|
|
|
2015-03-07 05:36:09 +01:00
|
|
|
var restoreUserData = function(request) {
|
|
|
|
var userData = request.userData;
|
2014-10-11 22:44:56 +02:00
|
|
|
|
2017-02-03 14:12:26 +01:00
|
|
|
var restart = function() {
|
|
|
|
vAPI.app.restart();
|
|
|
|
};
|
|
|
|
|
2014-10-11 22:44:56 +02:00
|
|
|
var onAllRemoved = function() {
|
2015-11-29 23:06:58 +01:00
|
|
|
µBlock.saveLocalSettings();
|
2017-01-18 19:17:47 +01:00
|
|
|
vAPI.storage.set(userData.userSettings);
|
2016-11-03 16:20:47 +01:00
|
|
|
µb.hiddenSettingsFromString(userData.hiddenSettingsString || '');
|
2015-04-10 15:52:16 +02:00
|
|
|
vAPI.storage.set({
|
2017-01-18 19:17:47 +01:00
|
|
|
netWhitelist: userData.netWhitelist || '',
|
|
|
|
dynamicFilteringString: userData.dynamicFilteringString || '',
|
|
|
|
urlFilteringString: userData.urlFilteringString || '',
|
|
|
|
hostnameSwitchesString: userData.hostnameSwitchesString || '',
|
2015-03-07 05:36:09 +01:00
|
|
|
lastRestoreFile: request.file || '',
|
|
|
|
lastRestoreTime: Date.now(),
|
|
|
|
lastBackupFile: '',
|
|
|
|
lastBackupTime: 0
|
2017-01-18 19:17:47 +01:00
|
|
|
});
|
|
|
|
µb.assets.put(µb.userFiltersPath, userData.userFilters);
|
|
|
|
|
|
|
|
// 'filterLists' is available up to uBO v1.10.4, not beyond.
|
|
|
|
// 'selectedFilterLists' is available from uBO v1.11 and beyond.
|
2017-02-03 14:12:26 +01:00
|
|
|
var listKeys;
|
2017-01-18 19:17:47 +01:00
|
|
|
if ( Array.isArray(userData.selectedFilterLists) ) {
|
2017-02-03 14:12:26 +01:00
|
|
|
listKeys = userData.selectedFilterLists;
|
2017-01-18 19:17:47 +01:00
|
|
|
} else if ( userData.filterLists instanceof Object ) {
|
2017-02-03 14:12:26 +01:00
|
|
|
listKeys = µb.newListKeysFromOldData(userData.filterLists);
|
|
|
|
}
|
|
|
|
if ( listKeys !== undefined ) {
|
|
|
|
µb.saveSelectedFilterLists(listKeys, restart);
|
|
|
|
} else {
|
|
|
|
restart();
|
2017-01-18 19:17:47 +01:00
|
|
|
}
|
2014-10-11 22:44:56 +02:00
|
|
|
};
|
|
|
|
|
2015-04-07 03:26:05 +02:00
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/1102
|
2015-03-27 14:50:31 +01:00
|
|
|
// Ensure all currently cached assets are flushed from storage AND memory.
|
|
|
|
µb.assets.rmrf();
|
|
|
|
|
2014-10-07 16:46:10 +02:00
|
|
|
// If we are going to restore all, might as well wipe out clean local
|
|
|
|
// storage
|
2016-10-28 14:40:38 +02:00
|
|
|
vAPI.cacheStorage.clear();
|
2015-04-10 08:17:12 +02:00
|
|
|
vAPI.storage.clear(onAllRemoved);
|
2014-10-07 14:59:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var resetUserData = function() {
|
2016-10-28 14:40:38 +02:00
|
|
|
vAPI.cacheStorage.clear();
|
2015-04-10 08:17:12 +02:00
|
|
|
vAPI.storage.clear();
|
2016-11-03 16:20:47 +01:00
|
|
|
vAPI.localStorage.removeItem('hiddenSettings');
|
2015-03-11 16:05:13 +01:00
|
|
|
|
2014-10-07 14:59:35 +02:00
|
|
|
// Keep global counts, people can become quite attached to numbers
|
2015-11-29 23:06:58 +01:00
|
|
|
µb.saveLocalSettings();
|
2015-03-11 16:05:13 +01:00
|
|
|
|
2014-12-02 17:02:17 +01:00
|
|
|
vAPI.app.restart();
|
2014-10-07 14:59:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
// 3rd-party filters
|
|
|
|
|
|
|
|
var prepListEntries = function(entries) {
|
|
|
|
var µburi = µb.URI;
|
|
|
|
var entry, hn;
|
|
|
|
for ( var k in entries ) {
|
2017-01-18 19:17:47 +01:00
|
|
|
if ( entries.hasOwnProperty(k) === false ) { continue; }
|
2016-03-06 16:51:06 +01:00
|
|
|
entry = entries[k];
|
|
|
|
if ( typeof entry.supportURL === 'string' && entry.supportURL !== '' ) {
|
|
|
|
entry.supportName = µburi.hostnameFromURI(entry.supportURL);
|
|
|
|
} else if ( typeof entry.homeURL === 'string' && entry.homeURL !== '' ) {
|
|
|
|
hn = µburi.hostnameFromURI(entry.homeURL);
|
|
|
|
entry.supportURL = 'http://' + hn + '/';
|
|
|
|
entry.supportName = µburi.domainFromHostname(hn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var getLists = function(callback) {
|
|
|
|
var r = {
|
|
|
|
autoUpdate: µb.userSettings.autoUpdate,
|
|
|
|
available: null,
|
|
|
|
cache: null,
|
|
|
|
cosmeticFilterCount: µb.cosmeticFilteringEngine.getFilterCount(),
|
2017-01-18 19:17:47 +01:00
|
|
|
current: µb.availableFilterLists,
|
2017-01-22 22:05:16 +01:00
|
|
|
externalLists: µb.userSettings.externalLists,
|
2016-08-13 22:42:58 +02:00
|
|
|
ignoreGenericCosmeticFilters: µb.userSettings.ignoreGenericCosmeticFilters,
|
2016-03-06 16:51:06 +01:00
|
|
|
netFilterCount: µb.staticNetFilteringEngine.getFilterCount(),
|
2017-01-22 22:05:16 +01:00
|
|
|
parseCosmeticFilters: µb.userSettings.parseAllABPHideFilters,
|
2017-01-18 19:17:47 +01:00
|
|
|
userFiltersPath: µb.userFiltersPath,
|
|
|
|
aliases: µb.assets.listKeyAliases
|
2016-03-06 16:51:06 +01:00
|
|
|
};
|
|
|
|
var onMetadataReady = function(entries) {
|
|
|
|
r.cache = entries;
|
|
|
|
prepListEntries(r.cache);
|
|
|
|
callback(r);
|
|
|
|
};
|
|
|
|
var onLists = function(lists) {
|
|
|
|
r.available = lists;
|
|
|
|
prepListEntries(r.available);
|
|
|
|
µb.assets.metadata(onMetadataReady);
|
|
|
|
};
|
|
|
|
µb.getAvailableLists(onLists);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// My rules
|
|
|
|
|
|
|
|
var getRules = function() {
|
|
|
|
return {
|
|
|
|
permanentRules: µb.permanentFirewall.toString() + '\n' + µb.permanentURLFiltering.toString(),
|
|
|
|
sessionRules: µb.sessionFirewall.toString() + '\n' + µb.sessionURLFiltering.toString(),
|
|
|
|
hnSwitches: µb.hnSwitches.toString()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Untangle firewall rules, url rules and switches.
|
|
|
|
var untangleRules = function(s) {
|
|
|
|
var textEnd = s.length;
|
|
|
|
var lineBeg = 0, lineEnd;
|
|
|
|
var line;
|
|
|
|
var firewallRules = [];
|
|
|
|
var urlRules = [];
|
|
|
|
var switches = [];
|
|
|
|
|
|
|
|
while ( lineBeg < textEnd ) {
|
|
|
|
lineEnd = s.indexOf('\n', lineBeg);
|
|
|
|
if ( lineEnd < 0 ) {
|
|
|
|
lineEnd = s.indexOf('\r', lineBeg);
|
|
|
|
if ( lineEnd < 0 ) {
|
|
|
|
lineEnd = textEnd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line = s.slice(lineBeg, lineEnd).trim();
|
|
|
|
lineBeg = lineEnd + 1;
|
|
|
|
|
|
|
|
if ( line.indexOf('://') !== -1 ) {
|
|
|
|
urlRules.push(line);
|
|
|
|
} else if ( line.indexOf(':') === -1 ) {
|
|
|
|
firewallRules.push(line);
|
|
|
|
} else {
|
|
|
|
switches.push(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
firewallRules: firewallRules.join('\n'),
|
|
|
|
urlRules: urlRules.join('\n'),
|
|
|
|
switches: switches.join('\n')
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
var onMessage = function(request, sender, callback) {
|
2014-06-24 00:42:43 +02:00
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
2015-05-19 19:59:53 +02:00
|
|
|
case 'backupUserData':
|
|
|
|
return backupUserData(callback);
|
2015-03-07 05:36:09 +01:00
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
case 'getLists':
|
|
|
|
return getLists(callback);
|
|
|
|
|
2015-05-19 19:59:53 +02:00
|
|
|
case 'getLocalData':
|
|
|
|
return getLocalData(callback);
|
2014-06-24 00:42:43 +02:00
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
case 'readUserFilters':
|
|
|
|
return µb.loadUserFilters(callback);
|
|
|
|
|
|
|
|
case 'writeUserFilters':
|
|
|
|
return µb.saveUserFilters(request.content, callback);
|
|
|
|
|
2015-05-19 19:59:53 +02:00
|
|
|
default:
|
|
|
|
break;
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2016-03-06 16:51:06 +01:00
|
|
|
case 'getRules':
|
|
|
|
response = getRules();
|
|
|
|
break;
|
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
case 'purgeAllCaches':
|
|
|
|
if ( request.hard ) {
|
|
|
|
µb.assets.remove(/./);
|
|
|
|
} else {
|
2017-01-23 15:35:05 +01:00
|
|
|
µb.assets.purge(/./, 'public_suffix_list.dat');
|
2017-01-18 19:17:47 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
case 'purgeCache':
|
2017-01-18 19:17:47 +01:00
|
|
|
µb.assets.purge(request.assetKey);
|
|
|
|
µb.assets.remove('compiled/' + request.assetKey);
|
2017-02-09 19:33:32 +01:00
|
|
|
// https://github.com/gorhill/uBlock/pull/2314#issuecomment-278716960
|
|
|
|
if ( request.assetKey === 'ublock-filters' ) {
|
|
|
|
µb.assets.purge('ublock-resources');
|
|
|
|
}
|
2016-03-06 16:51:06 +01:00
|
|
|
break;
|
|
|
|
|
2016-11-03 16:20:47 +01:00
|
|
|
case 'readHiddenSettings':
|
|
|
|
response = µb.stringFromHiddenSettings();
|
|
|
|
break;
|
|
|
|
|
2015-05-19 19:59:53 +02:00
|
|
|
case 'restoreUserData':
|
|
|
|
restoreUserData(request);
|
|
|
|
break;
|
2014-10-07 14:59:35 +02:00
|
|
|
|
2015-05-19 19:59:53 +02:00
|
|
|
case 'resetUserData':
|
|
|
|
resetUserData();
|
|
|
|
break;
|
2014-11-16 14:09:28 +01:00
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
case 'setSessionRules':
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/772
|
|
|
|
µb.cosmeticFilteringEngine.removeFromSelectorCache('*');
|
|
|
|
response = untangleRules(request.rules);
|
|
|
|
µb.sessionFirewall.fromString(response.firewallRules);
|
|
|
|
µb.sessionURLFiltering.fromString(response.urlRules);
|
|
|
|
µb.hnSwitches.fromString(response.switches);
|
|
|
|
µb.saveHostnameSwitches();
|
|
|
|
response = getRules();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'setPermanentRules':
|
|
|
|
response = untangleRules(request.rules);
|
|
|
|
µb.permanentFirewall.fromString(response.firewallRules);
|
|
|
|
µb.savePermanentFirewallRules();
|
|
|
|
µb.permanentURLFiltering.fromString(response.urlRules);
|
|
|
|
µb.savePermanentURLFilteringRules();
|
|
|
|
µb.hnSwitches.fromString(response.switches);
|
|
|
|
µb.saveHostnameSwitches();
|
|
|
|
response = getRules();
|
|
|
|
break;
|
|
|
|
|
2016-12-26 17:35:37 +01:00
|
|
|
case 'validateWhitelistString':
|
|
|
|
response = µb.validateWhitelistString(request.raw);
|
|
|
|
break;
|
|
|
|
|
2016-11-03 16:20:47 +01:00
|
|
|
case 'writeHiddenSettings':
|
|
|
|
µb.hiddenSettingsFromString(request.content);
|
|
|
|
break;
|
|
|
|
|
2015-05-19 19:59:53 +02:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
vAPI.messaging.listen('dashboard', onMessage);
|
2014-09-28 18:05:46 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
2015-01-06 14:01:15 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
// channel: loggerUI
|
2015-01-06 14:01:15 +01:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var µb = µBlock;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-21 20:15:17 +02:00
|
|
|
var getURLFilteringData = function(details) {
|
|
|
|
var colors = {};
|
|
|
|
var response = {
|
|
|
|
dirty: false,
|
|
|
|
colors: colors
|
|
|
|
};
|
|
|
|
var suf = µb.sessionURLFiltering;
|
|
|
|
var puf = µb.permanentURLFiltering;
|
|
|
|
var urls = details.urls,
|
|
|
|
context = details.context,
|
|
|
|
type = details.type;
|
|
|
|
var url, colorEntry;
|
|
|
|
var i = urls.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
url = urls[i];
|
|
|
|
colorEntry = colors[url] = { r: 0, own: false };
|
|
|
|
if ( suf.evaluateZ(context, url, type).r !== 0 ) {
|
|
|
|
colorEntry.r = suf.r;
|
2017-03-14 20:09:40 +01:00
|
|
|
colorEntry.own = suf.r !== 0 && suf.context === context && suf.url === url && suf.type === type;
|
2015-05-21 20:15:17 +02:00
|
|
|
}
|
|
|
|
if ( response.dirty ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
puf.evaluateZ(context, url, type);
|
2017-03-14 20:09:40 +01:00
|
|
|
response.dirty = colorEntry.own !== (puf.r !== 0 && puf.context === context && puf.url === url && puf.type === type);
|
2015-05-21 20:15:17 +02:00
|
|
|
}
|
|
|
|
return response;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-01-06 14:01:15 +01:00
|
|
|
var onMessage = function(request, sender, callback) {
|
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
2015-05-19 19:59:53 +02:00
|
|
|
default:
|
|
|
|
break;
|
2015-01-06 14:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2015-05-19 19:59:53 +02:00
|
|
|
case 'readAll':
|
|
|
|
var tabIds = {}, pageStore;
|
|
|
|
var loggerURL = vAPI.getURL('logger-ui.html');
|
|
|
|
for ( var tabId in µb.pageStores ) {
|
|
|
|
pageStore = µb.pageStoreFromTabId(tabId);
|
|
|
|
if ( pageStore === null ) {
|
|
|
|
continue;
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
2015-12-15 16:40:40 +01:00
|
|
|
if ( pageStore.rawURL.startsWith(loggerURL) ) {
|
2015-05-19 19:59:53 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
tabIds[tabId] = pageStore.title;
|
|
|
|
}
|
|
|
|
response = {
|
|
|
|
colorBlind: µb.userSettings.colorBlindFriendly,
|
|
|
|
entries: µb.logger.readAll(),
|
|
|
|
maxEntries: µb.userSettings.requestLogMaxEntries,
|
|
|
|
noTabId: vAPI.noTabId,
|
|
|
|
tabIds: tabIds,
|
|
|
|
tabIdsToken: µb.pageStoresToken
|
|
|
|
};
|
|
|
|
break;
|
2015-01-06 14:01:15 +01:00
|
|
|
|
2015-05-21 20:15:17 +02:00
|
|
|
case 'saveURLFilteringRules':
|
2015-05-22 14:05:55 +02:00
|
|
|
response = µb.permanentURLFiltering.copyRules(
|
|
|
|
µb.sessionURLFiltering,
|
|
|
|
request.context,
|
|
|
|
request.urls,
|
|
|
|
request.type
|
|
|
|
);
|
|
|
|
if ( response ) {
|
2015-05-21 20:15:17 +02:00
|
|
|
µb.savePermanentURLFilteringRules();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'setURLFilteringRule':
|
|
|
|
µb.toggleURLFilteringRule(request);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'getURLFilteringData':
|
|
|
|
response = getURLFilteringData(request);
|
|
|
|
break;
|
|
|
|
|
2015-05-19 19:59:53 +02:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2015-01-06 14:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
vAPI.messaging.listen('loggerUI', onMessage);
|
2015-01-06 14:01:15 +01:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
2014-08-20 02:41:52 +02:00
|
|
|
// https://www.youtube.com/watch?v=3_WcygKJP1k
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
2015-03-09 17:57:52 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
// channel: documentBlocked
|
2015-03-26 00:28:22 +01:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMessage = function(request, sender, callback) {
|
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
2015-05-19 19:59:53 +02:00
|
|
|
default:
|
|
|
|
break;
|
2015-03-26 00:28:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2015-05-19 19:59:53 +02:00
|
|
|
case 'temporarilyWhitelistDocument':
|
|
|
|
µBlock.webRequest.temporarilyWhitelistDocument(request.hostname);
|
|
|
|
break;
|
2015-03-26 00:28:22 +01:00
|
|
|
|
2015-05-19 19:59:53 +02:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2015-03-26 00:28:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
vAPI.messaging.listen('documentBlocked', onMessage);
|
2015-03-26 00:28:22 +01:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
2015-03-09 17:57:52 +01:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2015-05-25 00:50:09 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
// channel: scriptlets
|
2015-05-25 00:50:09 +02:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var µb = µBlock;
|
2016-08-06 18:05:01 +02:00
|
|
|
var broadcastTimers = Object.create(null);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var cosmeticallyFilteredElementCountChanged = function(tabId) {
|
|
|
|
delete broadcastTimers[tabId + '-cosmeticallyFilteredElementCountChanged'];
|
|
|
|
|
|
|
|
var pageStore = µb.pageStoreFromTabId(tabId);
|
|
|
|
if ( pageStore === null ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vAPI.messaging.broadcast({
|
|
|
|
what: 'cosmeticallyFilteredElementCountChanged',
|
|
|
|
tabId: tabId,
|
|
|
|
count: pageStore.hiddenElementCount
|
|
|
|
});
|
|
|
|
};
|
2015-05-25 00:50:09 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var logCosmeticFilters = function(tabId, details) {
|
|
|
|
if ( µb.logger.isEnabled() === false ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var selectors = details.matchedSelectors;
|
|
|
|
|
|
|
|
selectors.sort();
|
|
|
|
|
|
|
|
for ( var i = 0; i < selectors.length; i++ ) {
|
|
|
|
µb.logger.writeOne(
|
|
|
|
tabId,
|
|
|
|
'cosmetic',
|
2017-05-12 16:35:11 +02:00
|
|
|
{ source: 'cosmetic', raw: '##' + selectors[i] },
|
2015-05-25 00:50:09 +02:00
|
|
|
'dom',
|
2015-06-13 17:21:55 +02:00
|
|
|
details.frameURL,
|
|
|
|
null,
|
|
|
|
details.frameHostname
|
2015-05-25 00:50:09 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMessage = function(request, sender, callback) {
|
2015-06-26 06:08:41 +02:00
|
|
|
var tabId = sender && sender.tab ? sender.tab.id : 0;
|
2016-01-17 19:30:43 +01:00
|
|
|
var pageStore = µb.pageStoreFromTabId(tabId);
|
2015-06-26 06:08:41 +02:00
|
|
|
|
2015-05-25 00:50:09 +02:00
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2016-08-06 18:05:01 +02:00
|
|
|
case 'cosmeticallyFilteredElementCount':
|
|
|
|
if ( pageStore !== null && request.filteredElementCount ) {
|
|
|
|
pageStore.hiddenElementCount += request.filteredElementCount;
|
|
|
|
var broadcastKey = tabId + '-cosmeticallyFilteredElementCountChanged';
|
|
|
|
if ( broadcastTimers[broadcastKey] === undefined ) {
|
|
|
|
broadcastTimers[broadcastKey] = vAPI.setTimeout(
|
|
|
|
cosmeticallyFilteredElementCountChanged.bind(null, tabId),
|
|
|
|
250
|
|
|
|
);
|
|
|
|
}
|
2015-05-25 00:50:09 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'logCosmeticFilteringData':
|
|
|
|
logCosmeticFilters(tabId, request);
|
|
|
|
break;
|
|
|
|
|
2016-01-17 19:30:43 +01:00
|
|
|
case 'temporarilyAllowLargeMediaElement':
|
|
|
|
if ( pageStore !== null ) {
|
|
|
|
pageStore.allowLargeMediaElementsUntil = Date.now() + 2000;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'subscriberData':
|
|
|
|
response = {
|
2017-01-22 22:05:16 +01:00
|
|
|
confirmStr: vAPI.i18n('subscriberConfirm')
|
2016-01-17 19:30:43 +01:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
2015-05-25 00:50:09 +02:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
|
|
|
vAPI.messaging.listen('scriptlets', onMessage);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
2015-06-26 06:08:41 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|