| 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-2015 Eyeo GmbH | 3  * Copyright (C) 2006-2015 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 /** | 18 /** | 
| 19  * @fileOverview Content policy implementation, responsible for blocking things. | 19  * @fileOverview Content policy implementation, responsible for blocking things. | 
| 20  */ | 20  */ | 
| 21 | 21 | 
| 22 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 22 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 
| 23 Cu.import("resource://gre/modules/Services.jsm"); | 23 Cu.import("resource://gre/modules/Services.jsm"); | 
| 24 | 24 | 
| 25 let {Utils} = require("utils"); | 25 let {Utils} = require("utils"); | 
| 26 let {Prefs} = require("prefs"); | 26 let {Prefs} = require("prefs"); | 
| 27 let {FilterStorage} = require("filterStorage"); | 27 let {FilterStorage} = require("filterStorage"); | 
| 28 let {BlockingFilter, WhitelistFilter} = require("filterClasses"); | 28 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); | 
| 29 let {defaultMatcher} = require("matcher"); | 29 let {defaultMatcher} = require("matcher"); | 
| 30 let {objectMouseEventHander} = require("objectTabs"); | 30 let {objectMouseEventHander} = require("objectTabs"); | 
| 31 let {RequestNotifier} = require("requestNotifier"); | 31 let {RequestNotifier} = require("requestNotifier"); | 
| 32 let {ElemHide} = require("elemHide"); | 32 let {ElemHide} = require("elemHide"); | 
| 33 | 33 | 
| 34 /** | 34 /** | 
| 35  * List of explicitly supported content types | 35  * List of explicitly supported content types | 
| 36  * @type string[] | 36  * @type string[] | 
| 37  */ | 37  */ | 
| 38 let contentTypes = ["OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCU
     MENT", "DOCUMENT", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA"]; | 38 let contentTypes = ["OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCU
     MENT", "DOCUMENT", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA"]; | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 60    */ | 60    */ | 
| 61   type: {}, | 61   type: {}, | 
| 62 | 62 | 
| 63   /** | 63   /** | 
| 64    * Map of content type names by their identifiers (reverse of type map). | 64    * Map of content type names by their identifiers (reverse of type map). | 
| 65    * @type Object | 65    * @type Object | 
| 66    */ | 66    */ | 
| 67   typeDescr: {}, | 67   typeDescr: {}, | 
| 68 | 68 | 
| 69   /** | 69   /** | 
|  | 70    * Map of numerical content types with their corresponding masks | 
|  | 71    * @type Object | 
|  | 72    */ | 
|  | 73   typeMask: {}, | 
|  | 74 | 
|  | 75   /** | 
| 70    * Map of localized content type names by their identifiers. | 76    * Map of localized content type names by their identifiers. | 
| 71    * @type Object | 77    * @type Object | 
| 72    */ | 78    */ | 
| 73   localizedDescr: {}, | 79   localizedDescr: {}, | 
| 74 | 80 | 
| 75   /** | 81   /** | 
| 76    * Lists the non-visual content types. | 82    * Lists the non-visual content types. | 
| 77    * @type Object | 83    * @type Object | 
| 78    */ | 84    */ | 
| 79   nonVisual: {}, | 85   nonVisual: {}, | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 92     // type constant by type description and type description by type constant | 98     // type constant by type description and type description by type constant | 
| 93     let iface = Ci.nsIContentPolicy; | 99     let iface = Ci.nsIContentPolicy; | 
| 94     for (let typeName of contentTypes) | 100     for (let typeName of contentTypes) | 
| 95     { | 101     { | 
| 96       if ("TYPE_" + typeName in iface) | 102       if ("TYPE_" + typeName in iface) | 
| 97       { | 103       { | 
| 98         let id = iface["TYPE_" + typeName]; | 104         let id = iface["TYPE_" + typeName]; | 
| 99         this.type[typeName] = id; | 105         this.type[typeName] = id; | 
| 100         this.typeDescr[id] = typeName; | 106         this.typeDescr[id] = typeName; | 
| 101         this.localizedDescr[id] = Utils.getString("type_label_" + typeName.toLow
     erCase()); | 107         this.localizedDescr[id] = Utils.getString("type_label_" + typeName.toLow
     erCase()); | 
|  | 108         this.typeMask[id] = RegExpFilter.typeMap[typeName]; | 
| 102       } | 109       } | 
| 103     } | 110     } | 
| 104 | 111 | 
| 105     this.type.ELEMHIDE = 0xFFFD; | 112     this.type.ELEMHIDE = 0xFFFD; | 
| 106     this.typeDescr[0xFFFD] = "ELEMHIDE"; | 113     this.typeDescr[0xFFFD] = "ELEMHIDE"; | 
| 107     this.localizedDescr[0xFFFD] = Utils.getString("type_label_elemhide"); | 114     this.localizedDescr[0xFFFD] = Utils.getString("type_label_elemhide"); | 
|  | 115     this.typeMask[0xFFFD] = RegExpFilter.typeMap.ELEMHIDE; | 
| 108 | 116 | 
| 109     this.type.POPUP = 0xFFFE; | 117     this.type.POPUP = 0xFFFE; | 
| 110     this.typeDescr[0xFFFE] = "POPUP"; | 118     this.typeDescr[0xFFFE] = "POPUP"; | 
| 111     this.localizedDescr[0xFFFE] = Utils.getString("type_label_popup"); | 119     this.localizedDescr[0xFFFE] = Utils.getString("type_label_popup"); | 
|  | 120     this.typeMask[0xFFFE] = RegExpFilter.typeMap.POPUP; | 
| 112 | 121 | 
| 113     for (let type of nonVisualTypes) | 122     for (let type of nonVisualTypes) | 
| 114       this.nonVisual[this.type[type]] = true; | 123       this.nonVisual[this.type[type]] = true; | 
| 115 | 124 | 
| 116     // whitelisted URL schemes | 125     // whitelisted URL schemes | 
| 117     for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) | 126     for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) | 
| 118       this.whitelistSchemes[scheme] = true; | 127       this.whitelistSchemes[scheme] = true; | 
| 119 | 128 | 
| 120     // Generate class identifier used to collapse node and register correspondin
     g | 129     // Generate class identifier used to collapse node and register correspondin
     g | 
| 121     // stylesheet. | 130     // stylesheet. | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 192     let locationText = location.spec; | 201     let locationText = location.spec; | 
| 193     if (!match && contentType == Policy.type.ELEMHIDE) | 202     if (!match && contentType == Policy.type.ELEMHIDE) | 
| 194     { | 203     { | 
| 195       let testWnd = wnd; | 204       let testWnd = wnd; | 
| 196       let parentWndLocation = getWindowLocation(testWnd); | 205       let parentWndLocation = getWindowLocation(testWnd); | 
| 197       while (true) | 206       while (true) | 
| 198       { | 207       { | 
| 199         let testWndLocation = parentWndLocation; | 208         let testWndLocation = parentWndLocation; | 
| 200         parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi
     ndowLocation(testWnd.parent)); | 209         parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi
     ndowLocation(testWnd.parent)); | 
| 201         let parentDocDomain = getHostname(parentWndLocation); | 210         let parentDocDomain = getHostname(parentWndLocation); | 
| 202         match = defaultMatcher.matchesAny(testWndLocation, "ELEMHIDE", parentDoc
     Domain, false, sitekey); | 211         match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap.
     ELEMHIDE, parentDocDomain, false, sitekey); | 
| 203         if (match instanceof WhitelistFilter) | 212         if (match instanceof WhitelistFilter) | 
| 204         { | 213         { | 
| 205           FilterStorage.increaseHitCount(match, wnd); | 214           FilterStorage.increaseHitCount(match, wnd); | 
| 206           RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par
     entDocDomain, false, testWndLocation, match); | 215           RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par
     entDocDomain, false, testWndLocation, match); | 
| 207           return true; | 216           return true; | 
| 208         } | 217         } | 
| 209 | 218 | 
| 210         if (testWnd.parent == testWnd) | 219         if (testWnd.parent == testWnd) | 
| 211           break; | 220           break; | 
| 212         else | 221         else | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 224       if (exception) | 233       if (exception) | 
| 225       { | 234       { | 
| 226         FilterStorage.increaseHitCount(exception, wnd); | 235         FilterStorage.increaseHitCount(exception, wnd); | 
| 227         RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false,
      locationText, exception); | 236         RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false,
      locationText, exception); | 
| 228         return true; | 237         return true; | 
| 229       } | 238       } | 
| 230     } | 239     } | 
| 231 | 240 | 
| 232     let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty
     (location, docDomain)); | 241     let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty
     (location, docDomain)); | 
| 233 | 242 | 
| 234     if (!match && Prefs.enabled) | 243     if (!match && Prefs.enabled && contentType in Policy.typeMask) | 
| 235     { | 244     { | 
| 236       match = defaultMatcher.matchesAny(locationText, Policy.typeDescr[contentTy
     pe] || "", docDomain, thirdParty, sitekey); | 245       match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp
     e], docDomain, thirdParty, sitekey); | 
| 237       if (match instanceof BlockingFilter && node.ownerDocument && !(contentType
      in Policy.nonVisual)) | 246       if (match instanceof BlockingFilter && node.ownerDocument && !(contentType
      in Policy.nonVisual)) | 
| 238       { | 247       { | 
| 239         let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas
     tcollapse); | 248         let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas
     tcollapse); | 
| 240         if (collapse || prefCollapse) | 249         if (collapse || prefCollapse) | 
| 241           schedulePostProcess(node); | 250           schedulePostProcess(node); | 
| 242       } | 251       } | 
| 243 | 252 | 
| 244       // Track mouse events for objects | 253       // Track mouse events for objects | 
| 245       if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI
     DOMNode.ELEMENT_NODE) | 254       if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI
     DOMNode.ELEMENT_NODE) | 
| 246       { | 255       { | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 285       return null; | 294       return null; | 
| 286 | 295 | 
| 287     if (!parentUrl) | 296     if (!parentUrl) | 
| 288       parentUrl = url; | 297       parentUrl = url; | 
| 289 | 298 | 
| 290     // Ignore fragment identifier | 299     // Ignore fragment identifier | 
| 291     let index = url.indexOf("#"); | 300     let index = url.indexOf("#"); | 
| 292     if (index >= 0) | 301     if (index >= 0) | 
| 293       url = url.substring(0, index); | 302       url = url.substring(0, index); | 
| 294 | 303 | 
| 295     let result = defaultMatcher.matchesAny(url, "DOCUMENT", getHostname(parentUr
     l), false, sitekey); | 304     let result = defaultMatcher.matchesAny(url, RegExpFilter.typeMap.DOCUMENT, g
     etHostname(parentUrl), false, sitekey); | 
| 296     return (result instanceof WhitelistFilter ? result : null); | 305     return (result instanceof WhitelistFilter ? result : null); | 
| 297   }, | 306   }, | 
| 298 | 307 | 
| 299   /** | 308   /** | 
| 300    * Checks whether the page loaded in a window is whitelisted for indication in
      the UI. | 309    * Checks whether the page loaded in a window is whitelisted for indication in
      the UI. | 
| 301    * @param wnd {nsIDOMWindow} | 310    * @param wnd {nsIDOMWindow} | 
| 302    * @return {Filter} matching exception rule or null if not whitelisted | 311    * @return {Filter} matching exception rule or null if not whitelisted | 
| 303    */ | 312    */ | 
| 304   isWindowWhitelisted: function(wnd) | 313   isWindowWhitelisted: function(wnd) | 
| 305   { | 314   { | 
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 786   if (!wnd || wnd.closed) | 795   if (!wnd || wnd.closed) | 
| 787     return; | 796     return; | 
| 788 | 797 | 
| 789   if (entry.type == Policy.type.OBJECT) | 798   if (entry.type == Policy.type.OBJECT) | 
| 790   { | 799   { | 
| 791     node.removeEventListener("mouseover", objectMouseEventHander, true); | 800     node.removeEventListener("mouseover", objectMouseEventHander, true); | 
| 792     node.removeEventListener("mouseout", objectMouseEventHander, true); | 801     node.removeEventListener("mouseout", objectMouseEventHander, true); | 
| 793   } | 802   } | 
| 794   Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true)
     ; | 803   Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true)
     ; | 
| 795 } | 804 } | 
| OLD | NEW | 
|---|