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: Created June 8, 2016, 8:27 p.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 try
74 {
75 Utils.styleService.loadAndRegisterSheet(styleURL,
76 Ci.nsIStyleSheetService.USER_SHEET);
77 applied = true;
78 }
79 catch (e)
80 {
81 Cu.reportError(e);
82 }
83 }
84
85 function unapply()
86 {
87 if (applied)
88 {
89 try
90 {
91 Utils.styleService.unregisterSheet(styleURL,
92 Ci.nsIStyleSheetService.USER_SHEET);
93 }
94 catch (e)
95 {
96 Cu.reportError(e);
97 }
98 applied = false;
99 }
100 }
101
102 // Send dummy message before initializing, this delay makes sure that the child
103 // modules are loaded and our protocol handler registered.
104 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