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

Side by Side Diff: lib/elemHideStylesheet.js

Issue 29345667: Issue 4139 - Don't save element hiding filters on disk (Closed)
Patch Set: Rebased and updated dependency Created June 17, 2016, 12:10 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/child/elemHide.js ('k') | lib/main.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 "use strict";
19
20 let {port} = require("messaging");
21 let {ElemHide} = require("elemHide");
22 let {FilterNotifier} = require("filterNotifier");
23 let {Prefs} = require("prefs");
24 let {Utils} = require("utils");
25
26 /**
27 * Indicates whether the element hiding stylesheet is currently applied.
28 * @type Boolean
29 */
30 let applied = false;
31
32 /**
33 * Stylesheet URL to be registered
34 * @type nsIURI
35 */
36 let styleURL = Utils.makeURI("about:abp-elemhidehit?css");
37
38 function init()
39 {
40 port.on("getSelectors", () => ElemHide.getSelectors());
41
42 apply();
43 onShutdown.add(unapply);
44
45 Prefs.addListener(function(name)
46 {
47 if (name == "enabled")
48 apply();
49 });
50
51 FilterNotifier.on("elemhideupdate", onUpdate);
52 }
53
54 function onUpdate()
55 {
56 // Call apply() asynchronously and protect against reentrance - multiple
57 // change events shouldn't result in multiple calls.
58 if (onUpdate.inProgress)
59 return;
60
61 onUpdate.inProgress = true;
62 Utils.runAsync(() =>
63 {
64 onUpdate.inProgress = false;
65 apply();
66 });
67 }
68
69 function apply()
70 {
71 unapply();
72
73 if (!Prefs.enabled)
74 return;
75
76 try
77 {
78 Utils.styleService.loadAndRegisterSheet(styleURL,
79 Ci.nsIStyleSheetService.USER_SHEET);
80 applied = true;
81 }
82 catch (e)
83 {
84 Cu.reportError(e);
85 }
86 }
87
88 function unapply()
89 {
90 if (applied)
91 {
92 try
93 {
94 Utils.styleService.unregisterSheet(styleURL,
95 Ci.nsIStyleSheetService.USER_SHEET);
96 }
97 catch (e)
98 {
99 Cu.reportError(e);
100 }
101 applied = false;
102 }
103 }
104
105 // Send dummy message before initializing, this delay makes sure that the child
106 // modules are loaded and our protocol handler registered.
107 port.emitWithResponse("ping").then(init);
OLDNEW
« no previous file with comments | « lib/child/elemHide.js ('k') | lib/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld