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

Delta Between Two Patch Sets: lib/contentPolicy.js

Issue 29329571: Issue 3208 - Separate contentPolicy module into a parent and child part (Closed)
Left Patch Set: Addressed comments Created Nov. 11, 2015, 5:36 p.m.
Right Patch Set: Fixed JSDoc comment Created Nov. 12, 2015, 3:13 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/child/main.js ('k') | lib/elemHide.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
(...skipping 15 matching lines...) Expand all
26 26
27 let {Utils} = require("utils"); 27 let {Utils} = require("utils");
28 let {Prefs} = require("prefs"); 28 let {Prefs} = require("prefs");
29 let {FilterStorage} = require("filterStorage"); 29 let {FilterStorage} = require("filterStorage");
30 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); 30 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses");
31 let {defaultMatcher} = require("matcher"); 31 let {defaultMatcher} = require("matcher");
32 let {objectMouseEventHander} = require("objectTabs"); 32 let {objectMouseEventHander} = require("objectTabs");
33 let {ElemHide} = require("elemHide"); 33 let {ElemHide} = require("elemHide");
34 34
35 /** 35 /**
36 * Randomly generated class name, to be applied to collapsed nodes.
37 */
38 let collapsedClass = "";
Thomas Greiner 2015/11/11 18:07:32 Detail: This variable is only used inside `Policy.
Wladimir Palant 2015/11/12 12:28:52 Done.
39
40 /**
41 * Public policy checking functions and auxiliary objects 36 * Public policy checking functions and auxiliary objects
42 * @class 37 * @class
43 */ 38 */
44 var Policy = exports.Policy = 39 var Policy = exports.Policy =
45 { 40 {
46 /** 41 /**
47 * Set of explicitly supported content types 42 * Set of explicitly supported content types
48 * @type Set 43 * @type Set
49 */ 44 */
50 contentTypes: new Set([ 45 contentTypes: new Set([
(...skipping 26 matching lines...) Expand all
77 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) 72 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" "))
78 this.whitelistSchemes.add(scheme); 73 this.whitelistSchemes.add(scheme);
79 74
80 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] 75 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
81 .getService(Ci.nsIMessageListenerManager) 76 .getService(Ci.nsIMessageListenerManager)
82 .QueryInterface(Ci.nsIMessageBroadcaster); 77 .QueryInterface(Ci.nsIMessageBroadcaster);
83 let handler = (message => this.shouldAllow(message.data)); 78 let handler = (message => this.shouldAllow(message.data));
84 messageManager.addMessageListener("AdblockPlus:ShouldAllow", handler); 79 messageManager.addMessageListener("AdblockPlus:ShouldAllow", handler);
85 onShutdown.add(() => messageManager.removeMessageListener("AdblockPlus:Shoul dAllow", handler)); 80 onShutdown.add(() => messageManager.removeMessageListener("AdblockPlus:Shoul dAllow", handler));
86 81
82 // Generate class identifier used to collapse nodes and register
83 // corresponding stylesheet.
84 let collapsedClass = "";
85 let offset = "a".charCodeAt(0);
86 for (let i = 0; i < 20; i++)
87 collapsedClass += String.fromCharCode(offset + Math.random() * 26);
88
87 let handler2 = () => collapsedClass; 89 let handler2 = () => collapsedClass;
88 messageManager.addMessageListener("AdblockPlus:GetCollapsedClass", handler2) ; 90 messageManager.addMessageListener("AdblockPlus:GetCollapsedClass", handler2) ;
89 onShutdown.add(() => messageManager.removeMessageListener("AdblockPlus:GetCo llapsedClass", handler2)); 91 onShutdown.add(() => messageManager.removeMessageListener("AdblockPlus:GetCo llapsedClass", handler2));
90
91 // Generate class identifier used to collapse node and register correspondin g
92 // stylesheet.
93 let offset = "a".charCodeAt(0);
94 for (let i = 0; i < 20; i++)
95 collapsedClass += String.fromCharCode(offset + Math.random() * 26);
96 92
97 let collapseStyle = Services.io.newURI("data:text/css," + 93 let collapseStyle = Services.io.newURI("data:text/css," +
98 encodeURIComponent("." + collapsedClass + 94 encodeURIComponent("." + collapsedClass +
99 "{-moz-binding: url(chrome://global/content/bindings/general.xml#foobarb azdummy) !important;}"), null, null); 95 "{-moz-binding: url(chrome://global/content/bindings/general.xml#foobarb azdummy) !important;}"), null, null);
100 Utils.styleService.loadAndRegisterSheet(collapseStyle, Ci.nsIStyleSheetServi ce.USER_SHEET); 96 Utils.styleService.loadAndRegisterSheet(collapseStyle, Ci.nsIStyleSheetServi ce.USER_SHEET);
101 onShutdown.add(() => 97 onShutdown.add(() =>
102 { 98 {
103 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService. USER_SHEET); 99 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService. USER_SHEET);
104 }); 100 });
105 }, 101 },
106 102
107 /** 103 /**
108 * Checks whether a node should be blocked, hides it if necessary 104 * Checks whether a node should be blocked, hides it if necessary
109 * @param {Object} data request data 105 * @param {Object} data request data
110 * @param {String} data.contentType 106 * @param {String} data.contentType
111 * @param {String} data.location 107 * @param {String} data.location
112 * @param {Object[]} data.frames 108 * @param {Object[]} data.frames
113 * @param {Boolean} data.isPrivate true if the request belongs to a private b rowsing window 109 * @param {Boolean} data.isPrivate true if the request belongs to a private b rowsing window
114 * @return {Object} An object containing properties block, collapse and hits 110 * @return {Object} An object containing properties allow, collapse and hits
115 * indicating how this request should be handled. 111 * indicating how this request should be handled.
116 */ 112 */
117 shouldAllow: function({contentType, location, frames, isPrivate}) 113 shouldAllow: function({contentType, location, frames, isPrivate})
118 { 114 {
119 let hits = []; 115 let hits = [];
120 116
121 function addHit(frameIndex, contentType, docDomain, thirdParty, location, fi lter) 117 function addHit(frameIndex, contentType, docDomain, thirdParty, location, fi lter)
122 { 118 {
123 if (filter && !isPrivate) 119 if (filter && !isPrivate)
124 FilterStorage.increaseHitCount(filter); 120 FilterStorage.increaseHitCount(filter);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 if (!wnd || wnd.closed) 407 if (!wnd || wnd.closed)
412 return; 408 return;
413 409
414 if (entry.type == "OBJECT") 410 if (entry.type == "OBJECT")
415 { 411 {
416 node.removeEventListener("mouseover", objectMouseEventHander, true); 412 node.removeEventListener("mouseover", objectMouseEventHander, true);
417 node.removeEventListener("mouseout", objectMouseEventHander, true); 413 node.removeEventListener("mouseout", objectMouseEventHander, true);
418 } 414 }
419 Policy.processNode(wnd, node, entry.type, entry.location, true); 415 Policy.processNode(wnd, node, entry.type, entry.location, true);
420 } 416 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld