Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/contentFiltering.js

Issue 29893559: Issue 6999 - Generate style sheets in background page (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Rebase Created Sept. 28, 2018, 7:43 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include.preload.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/contentFiltering.js
===================================================================
--- a/lib/contentFiltering.js
+++ b/lib/contentFiltering.js
@@ -92,22 +92,19 @@
browser.tabs.removeCSS(tabId, {
code: styleSheet,
cssOrigin: "user",
frameId,
matchAboutBlank: true
});
}
-function updateFrameStyles(tabId, frameId, selectors, groupName, appendOnly)
+function updateFrameStyles(tabId, frameId, styleSheet, groupName = "standard",
+ appendOnly = false)
{
- let styleSheet = "";
- if (selectors.length > 0)
- styleSheet = createStyleSheet(selectors);
-
let frame = ext.getFrame(tabId, frameId);
if (!frame)
return false;
if (!frame.injectedStyleSheets)
frame.injectedStyleSheets = new Map();
let oldStyleSheet = frame.injectedStyleSheets.get(groupName);
@@ -189,16 +186,17 @@
// tabs.insertCSS for why we catch any error here and simply
// return a rejected promise.
return Promise.reject(error);
}
}
port.on("content.applyFilters", (message, sender) =>
{
+ let styleSheet = "";
let selectors = [];
let emulatedPatterns = [];
let trace = HitLogger.hasListener(sender.page.id);
let inline = !userStyleSheetsSupported;
let {elemhide, snippets} = message.filterTypes ||
{elemhide: true, snippets: true};
@@ -227,38 +225,44 @@
}
if (elemhide && !checkWhitelisted(sender.page, sender.frame, null,
RegExpFilter.typeMap.ELEMHIDE))
{
let specificOnly = checkWhitelisted(sender.page, sender.frame, null,
RegExpFilter.typeMap.GENERICHIDE);
selectors = ElemHide.getSelectorsForDomain(docDomain, specificOnly);
+ styleSheet = createStyleSheet(selectors);
for (let filter of ElemHideEmulation.getRulesForDomain(docDomain))
emulatedPatterns.push({selector: filter.selector, text: filter.text});
}
}
if (!inline && !updateFrameStyles(sender.page.id, sender.frame.id,
- selectors, "standard"))
+ styleSheet))
{
inline = true;
}
let response = {trace, inline, emulatedPatterns};
- if (trace || inline)
+
+ if (inline)
+ response.styleSheet = styleSheet;
+
+ if (trace)
response.selectors = selectors;
return response;
});
port.on("content.injectSelectors", (message, sender) =>
{
- updateFrameStyles(sender.page.id, sender.frame.id, message.selectors,
+ updateFrameStyles(sender.page.id, sender.frame.id,
+ createStyleSheet(message.selectors),
message.groupName, message.appendOnly);
});
fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"})
.then(response => response.ok ? response.text() : "")
.then(text =>
{
snippetsLibrarySource = text;
« no previous file with comments | « include.preload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld