| OLD | NEW |
| 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 {port} = require("messaging"); | 20 let {port} = require("messaging"); |
| 21 let {ElemHide} = require("elemHide"); | 21 let {ElemHide} = require("elemHide"); |
| 22 let {FilterNotifier} = require("filterNotifier"); | 22 let {FilterNotifier} = require("filterNotifier"); |
| 23 let {FilterStorage} = require("filterStorage"); | 23 let {FilterStorage} = require("filterStorage"); |
| 24 let {Prefs} = require("prefs"); | 24 let {Prefs} = require("prefs"); |
| 25 let {Policy} = require("contentPolicy"); | 25 let {Policy} = require("contentPolicy"); |
| 26 let {Utils} = require("utils"); |
| 26 | 27 |
| 27 FilterNotifier.on("elemhideupdate", () => port.emit("elemhideupdate")); | 28 let isDirty = false; |
| 29 FilterNotifier.on("elemhideupdate", () => |
| 30 { |
| 31 // Notify content process asynchronously, only one message per update batch. |
| 32 if (!isDirty) |
| 33 { |
| 34 isDirty = true; |
| 35 Utils.runAsync(() => { |
| 36 isDirty = false; |
| 37 port.emit("elemhideupdate") |
| 38 }); |
| 39 } |
| 40 }); |
| 28 | 41 |
| 29 port.on("getSelectors", () => ElemHide.getSelectors()); | 42 port.on("getSelectors", () => ElemHide.getSelectors()); |
| 30 | 43 |
| 31 port.on("elemhideEnabled", ({frames, isPrivate}) => | 44 port.on("elemhideEnabled", ({frames, isPrivate}) => |
| 32 { | 45 { |
| 33 if (!Prefs.enabled) | 46 if (!Prefs.enabled) |
| 34 return {enabled: false}; | 47 return {enabled: false}; |
| 35 | 48 |
| 36 let hit = Policy.isFrameWhitelisted(frames, true); | 49 let hit = Policy.isFrameWhitelisted(frames, true); |
| 37 if (hit) | 50 if (hit) |
| 38 { | 51 { |
| 39 let [frameIndex, contentType, docDomain, thirdParty, location, filter] = hit
; | 52 let [frameIndex, contentType, docDomain, thirdParty, location, filter] = hit
; |
| 40 if (!isPrivate) | 53 if (!isPrivate) |
| 41 FilterStorage.increaseHitCount(filter); | 54 FilterStorage.increaseHitCount(filter); |
| 42 return { | 55 return { |
| 43 enabled: false, | 56 enabled: false, |
| 44 contentType, docDomain, thirdParty, location, | 57 contentType, docDomain, thirdParty, location, |
| 45 filter: filter.text, filterType: filter.type | 58 filter: filter.text, filterType: filter.type |
| 46 }; | 59 }; |
| 47 } | 60 } |
| 48 else | 61 else |
| 49 return {enabled: true}; | 62 return {enabled: true}; |
| 50 }); | 63 }); |
| OLD | NEW |