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

Unified Diff: lib/elemHide.js

Issue 6266581101314048: WIP: Have one global element hide stylesheet and inject the other ones per site (Closed)
Patch Set: rebased Created Aug. 19, 2014, 12:15 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 | « no previous file | lib/elemHideHitRegistration.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/elemHide.js
===================================================================
--- a/lib/elemHide.js
+++ b/lib/elemHide.js
@@ -136,16 +136,48 @@ let ElemHide = exports.ElemHide =
return;
if (!Prefs.enabled)
return;
if (Policy.shouldNeverBlockWindow(subject))
return;
+ let domain = null;
+ let filters = null;
+ try
+ {
+ domain = subject.document.documentURIObject.host;
+ if (domain)
+ filters = ElemHide.getFiltersWithKeyForDomain(domain, true);
+ } catch (e) {}
+
+ if (filters)
+ {
+ let list = Object.create(null);
+ for (let {key, filter} of filters)
+ list[key] = filter;
+
+ let css = "";
+ for (let line in this._generateCSSContent(list, false))
+ css += line + "\n";
+
+ let uri = Services.io.newURI("data:text/css;base64," + btoa(css), null, null);
+ try
+ {
+ let utils = subject.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils);
+ utils.loadSheet(uri, Ci.nsIStyleSheetService.USER_SHEET);
+ }
+ catch (e)
+ {
+ Cu.reportError(e);
+ }
+ }
+
if (styleSheet)
{
try
{
let utils = subject.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
utils.addSheet(styleSheet, Ci.nsIStyleSheetService.USER_SHEET);
}
@@ -296,17 +328,17 @@ let ElemHide = exports.ElemHide =
ElemHide.unapply();
TimeLine.log("ElemHide.unapply() finished");
}
TimeLine.leave("ElemHide.apply() done (no file changes)");
return;
}
- IO.writeToFile(styleURL.file, this._generateCSSContent(), function(e)
+ IO.writeToFile(styleURL.file, this._generateCSSContent(filterByKey, useNew), function(e)
{
TimeLine.enter("ElemHide.apply() write callback");
this._applying = false;
// _generateCSSContent is throwing NS_ERROR_NOT_AVAILABLE to indicate that
// there are no filters. If that exception is passed through XPCOM we will
// see a proper exception here, otherwise a number.
let noFilters = (e == Cr.NS_ERROR_NOT_AVAILABLE || (e && e.result == Cr.NS_ERROR_NOT_AVAILABLE));
@@ -340,39 +372,43 @@ let ElemHide = exports.ElemHide =
styleSheet = Utils.styleService.preloadSheet(styleURL, Ci.nsIStyleSheetService.USER_SHEET);
ElemHide.applied = true;
}
catch (e)
{
Cu.reportError(e);
}
TimeLine.log("Applying stylesheet finished");
+ Cu.reportError("applying finished");
}
FilterNotifier.triggerListeners("elemhideupdate");
}
TimeLine.leave("ElemHide.apply() write callback done");
}.bind(this), "ElemHideWrite");
this._applying = true;
TimeLine.leave("ElemHide.apply() done", "ElemHideWrite");
},
- _generateCSSContent: function()
+ _generateCSSContent: function(filters, onlyGlobal)
{
// Grouping selectors by domains
TimeLine.log("start grouping selectors");
let domains = Object.create(null);
let hasFilters = false;
- for (let key in filterByKey)
+ for (let key in filters)
{
- let filter = filterByKey[key];
+ let filter = filters[key];
let domain = filter.selectorDomain || "";
+ if (onlyGlobal && domain)
+ continue;
+
let list;
if (domain in domains)
list = domains[domain];
else
{
list = Object.create(null);
domains[domain] = list;
}
@@ -458,10 +494,27 @@ let ElemHide = exports.ElemHide =
if (specificOnly && (!domains || domains[""]))
continue;
if (filter.isActiveOnDomain(domain) && !this.getException(filter, domain))
result.push(filter.selector);
}
return result;
+ },
+
+ getFiltersWithKeyForDomain: function(/**String*/ domain)
+ {
+ let result = [];
+ for (let key in filterByKey)
+ {
+ let filter = filterByKey[key];
+
+ if (!filter.domains)
+ continue
+
+ if (filter.isActiveOnDomain(domain) && !this.getException(filter, domain))
+ result.push({key, filter});
+ }
+ return result;
}
+
};
« no previous file with comments | « no previous file | lib/elemHideHitRegistration.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld