mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-05 18:32:30 +01:00
code reivew of c5d8588118
: immediate scriptlets injection works well only on Chromium-based browsers for now
This commit is contained in:
parent
e693e308d4
commit
b4306e3297
@ -120,6 +120,7 @@ var µBlock = (function() { // jshint ignore:line
|
||||
privacySettingsSupported: vAPI.browserSettings instanceof Object,
|
||||
cloudStorageSupported: vAPI.cloud instanceof Object,
|
||||
canFilterResponseBody: vAPI.net.canFilterResponseBody === true,
|
||||
canInjectScriptletsNow: vAPI.webextFlavor.soup.has('chromium'),
|
||||
|
||||
// https://github.com/chrisaljoudi/uBlock/issues/180
|
||||
// Whitelist directives need to be loaded once the PSL is available
|
||||
|
@ -349,12 +349,16 @@ vAPI.matchesProp = (function() {
|
||||
|
||||
vAPI.injectScriptlet = function(doc, text) {
|
||||
if ( !doc ) { return; }
|
||||
let script;
|
||||
try {
|
||||
var script = doc.createElement('script');
|
||||
script = doc.createElement('script');
|
||||
script.appendChild(doc.createTextNode(text));
|
||||
(doc.head || doc.documentElement).appendChild(script);
|
||||
} catch (ex) {
|
||||
}
|
||||
if ( script && script.parentNode ) {
|
||||
script.parentNode.removeChild(script);
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -520,6 +520,9 @@ var onMessage = function(request, sender, callback) {
|
||||
request.entity = µb.URI.entityFromDomain(request.domain);
|
||||
response.specificCosmeticFilters =
|
||||
µb.cosmeticFilteringEngine.retrieveDomainSelectors(request, response);
|
||||
if ( µb.canInjectScriptletsNow === false ) {
|
||||
response.scriptlets = µb.scriptletFilteringEngine.retrieve(request);
|
||||
}
|
||||
if ( request.isRootFrame && µb.logger.isEnabled() ) {
|
||||
µb.logCosmeticFilters(tabId);
|
||||
}
|
||||
|
@ -224,9 +224,8 @@
|
||||
return;
|
||||
}
|
||||
|
||||
var domain = request.domain,
|
||||
entity = request.entity,
|
||||
entries, entry;
|
||||
let domain = request.domain,
|
||||
entity = request.entity;
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/1954
|
||||
// Implicit
|
||||
@ -243,13 +242,13 @@
|
||||
}
|
||||
|
||||
// Explicit
|
||||
entries = [];
|
||||
let entries = [];
|
||||
if ( domain !== '' ) {
|
||||
scriptletDB.retrieve(domain, hostname, entries);
|
||||
scriptletDB.retrieve(entity, entity, entries);
|
||||
}
|
||||
scriptletDB.retrieve('', hostname, entries);
|
||||
for ( entry of entries ) {
|
||||
for ( let entry of entries ) {
|
||||
lookupScriptlet(entry.token, reng, scriptletsRegister);
|
||||
}
|
||||
|
||||
@ -262,15 +261,15 @@
|
||||
scriptletDB.retrieve('!' + entity, entity, entries);
|
||||
}
|
||||
scriptletDB.retrieve('!', hostname, entries);
|
||||
for ( entry of entries ) {
|
||||
for ( let entry of entries ) {
|
||||
exceptionsRegister.add(entry.token);
|
||||
}
|
||||
|
||||
// Return an array of scriptlets, and log results if needed.
|
||||
var out = [],
|
||||
let out = [],
|
||||
logger = µb.logger.isEnabled() ? µb.logger : null,
|
||||
isException;
|
||||
for ( entry of scriptletsRegister ) {
|
||||
for ( let entry of scriptletsRegister ) {
|
||||
if ( (isException = exceptionsRegister.has(entry[0])) === false ) {
|
||||
out.push(entry[1]);
|
||||
}
|
||||
@ -284,6 +283,9 @@
|
||||
|
||||
if ( out.length === 0 ) { return; }
|
||||
|
||||
if ( µb.hiddenSettings.debugScriptlets ) {
|
||||
out.unshift('debugger;');
|
||||
}
|
||||
return out.join('\n');
|
||||
};
|
||||
|
||||
@ -303,9 +305,6 @@
|
||||
let scriptlets = µb.scriptletFilteringEngine.retrieve(request);
|
||||
if ( scriptlets === undefined ) { return; }
|
||||
let code = contentscriptCode.assemble(request.hostname, scriptlets);
|
||||
if ( µb.hiddenSettings.debugScriptlets ) {
|
||||
code = 'debugger;\n' + code;
|
||||
}
|
||||
chrome.tabs.executeScript(
|
||||
details.tabId,
|
||||
{
|
||||
|
@ -493,7 +493,9 @@ vAPI.tabs.onNavigation = function(details) {
|
||||
pageStore.journalAddRootFrame('committed', details.url);
|
||||
}
|
||||
}
|
||||
µb.scriptletFilteringEngine.injectNow(details);
|
||||
if ( µb.canInjectScriptletsNow ) {
|
||||
µb.scriptletFilteringEngine.injectNow(details);
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user