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

Side by Side Diff: lib/elemHideFF.js

Issue 29352634: Issue 4198 - Don't send Map objects in messages when using Firefox 40 and below (Closed) Base URL: https://hg.adblockplus.org/adblockplus
Patch Set: Created Sept. 12, 2016, 9:11 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
21
20 let {port} = require("messaging"); 22 let {port} = require("messaging");
21 let {ElemHide} = require("elemHide"); 23 let {ElemHide} = require("elemHide");
22 let {FilterNotifier} = require("filterNotifier"); 24 let {FilterNotifier} = require("filterNotifier");
23 let {FilterStorage} = require("filterStorage"); 25 let {FilterStorage} = require("filterStorage");
24 let {Prefs} = require("prefs"); 26 let {Prefs} = require("prefs");
25 let {Policy} = require("contentPolicy"); 27 let {Policy} = require("contentPolicy");
26 let {Utils} = require("utils"); 28 let {Utils} = require("utils");
27 29
28 let isDirty = false; 30 let isDirty = false;
29 FilterNotifier.on("elemhideupdate", () => 31 FilterNotifier.on("elemhideupdate", () =>
30 { 32 {
31 // Notify content process asynchronously, only one message per update batch. 33 // Notify content process asynchronously, only one message per update batch.
32 if (!isDirty) 34 if (!isDirty)
33 { 35 {
34 isDirty = true; 36 isDirty = true;
35 Utils.runAsync(() => { 37 Utils.runAsync(() => {
36 isDirty = false; 38 isDirty = false;
37 port.emit("elemhideupdate") 39 port.emit("elemhideupdate")
38 }); 40 });
39 } 41 }
40 }); 42 });
41 43
42 port.on("getSelectors", () => ElemHide.getSelectors()); 44 let translateMap = map => map;
45 if (Services.vc.compare(Utils.platformVersion, "40.0") <= 0)
46 {
47 translateMap = map =>
48 {
49 // We cannot send Map objects with Gecko 40 and below, "translate" them
50 // into nested arrays. This isn't very efficient but that should be ok as
51 // long as only outdated Firefox versions are affected.
52 let translated = [];
53 for (let [key, value] of map)
54 {
55 if (value instanceof Map)
56 translated.push([key, translateMap(value)]);
57 else
58 translated.push([key, value]);
59 }
60 return translated;
61 };
62 }
63
64 port.on("getSelectors", () => translateMap(ElemHide.getSelectors()));
43 65
44 port.on("elemhideEnabled", ({frames, isPrivate}) => 66 port.on("elemhideEnabled", ({frames, isPrivate}) =>
45 { 67 {
46 if (!Prefs.enabled) 68 if (!Prefs.enabled)
47 return {enabled: false}; 69 return {enabled: false};
48 70
49 let hit = Policy.isFrameWhitelisted(frames, true); 71 let hit = Policy.isFrameWhitelisted(frames, true);
50 if (hit) 72 if (hit)
51 { 73 {
52 let [frameIndex, contentType, docDomain, thirdParty, location, filter] = hit ; 74 let [frameIndex, contentType, docDomain, thirdParty, location, filter] = hit ;
53 if (contentType != "GENERICHIDE") 75 if (contentType != "GENERICHIDE")
54 { 76 {
55 if (!isPrivate) 77 if (!isPrivate)
56 FilterStorage.increaseHitCount(filter); 78 FilterStorage.increaseHitCount(filter);
57 return { 79 return {
58 enabled: false, 80 enabled: false,
59 contentType, docDomain, thirdParty, location, 81 contentType, docDomain, thirdParty, location,
60 filter: filter.text, filterType: filter.type 82 filter: filter.text, filterType: filter.type
61 }; 83 };
62 } 84 }
63 } 85 }
64 86
65 return {enabled: true}; 87 return {enabled: true};
66 }); 88 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld