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

Side by Side Diff: lib/child/contentPolicy.js

Issue 29329751: Issue 3251 - Add shouldAllowAsync() function for non-urgent policy checks (Closed)
Patch Set: Created Nov. 4, 2015, 3 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 | « 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-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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 * @type Map.<number,string> 53 * @type Map.<number,string>
54 */ 54 */
55 let types = new Map(); 55 let types = new Map();
56 56
57 /** 57 /**
58 * Checks whether a request should be allowed, hides it if necessary 58 * Checks whether a request should be allowed, hides it if necessary
59 * @param wnd {nsIDOMWindow} 59 * @param wnd {nsIDOMWindow}
60 * @param node {nsIDOMElement} 60 * @param node {nsIDOMElement}
61 * @param contentType {String} 61 * @param contentType {String}
62 * @param location {String} 62 * @param location {String}
63 * @param [callback] {Function} If present, the request will be sent
64 * asynchronously and callback called with the
65 * response
63 * @return {Boolean} false if the request should be blocked 66 * @return {Boolean} false if the request should be blocked
64 */ 67 */
65 function shouldAllow(window, node, contentType, location) 68 function shouldAllow(window, node, contentType, location, callback)
tschuster 2015/11/12 13:38:13 This should really be two functions. If you reuse
Wladimir Palant 2015/11/12 15:01:13 Done.
66 { 69 {
67 let response = sendSyncMessage("AdblockPlus:ShouldAllow", { 70 function processResponse(response)
71 {
72 if (typeof response == "undefined")
73 return true;
74
75 let {allow, collapse, hits} = response;
76 for (let {frameIndex, contentType, docDomain, thirdParty, location, filter} of hits)
77 {
78 let context = node;
79 if (typeof frameIndex == "number")
80 {
81 context = window;
82 for (let i = 0; i < frameIndex; i++)
83 context = context.parent;
84 context = context.document;
85 }
86 RequestNotifier.addNodeData(context, window.top, contentType, docDomain, t hirdParty, location, filter);
87 }
88
89 if (node.nodeType == Ci.nsIDOMNode.ELEMENT_NODE)
90 {
91 // Track mouse events for objects
92 if (allow && contentType == "OBJECT")
93 {
94 node.addEventListener("mouseover", objectMouseEventHander, true);
95 node.addEventListener("mouseout", objectMouseEventHander, true);
96 }
97
98 if (collapse)
99 schedulePostProcess(node);
100 }
101 return allow;
102 }
Wladimir Palant 2015/11/04 15:05:22 The diff is messy but all the code above has merel
103
104 let data = {
68 contentType: contentType, 105 contentType: contentType,
69 location: location, 106 location: location,
70 frames: getFrames(window), 107 frames: getFrames(window),
71 isPrivate: isPrivate(window) 108 isPrivate: isPrivate(window)
72 }); 109 };
73 if (typeof response == "undefined") 110 if (typeof callback == "function")
74 return true;
75
76 let {allow, collapse, hits} = response;
77 for (let {frameIndex, contentType, docDomain, thirdParty, location, filter} of hits)
78 { 111 {
79 let context = node; 112 sendAsyncMessage("AdblockPlus:ShouldAllow", data, (data) => {
80 if (typeof frameIndex == "number") 113 callback(processResponse(data));
81 { 114 });
82 context = window;
83 for (let i = 0; i < frameIndex; i++)
84 context = context.parent;
85 context = context.document;
86 }
87 RequestNotifier.addNodeData(context, window.top, contentType, docDomain, thi rdParty, location, filter);
88 } 115 }
89 116 else
90 if (node.nodeType == Ci.nsIDOMNode.ELEMENT_NODE) 117 return processResponse(sendSyncMessage("AdblockPlus:ShouldAllow", data));
91 {
92 // Track mouse events for objects
93 if (allow && contentType == "OBJECT")
94 {
95 node.addEventListener("mouseover", objectMouseEventHander, true);
96 node.addEventListener("mouseout", objectMouseEventHander, true);
97 }
98
99 if (collapse)
100 schedulePostProcess(node);
101 }
102
103 return allow;
104 } 118 }
105 119
106 /** 120 /**
107 * Actual nsIContentPolicy and nsIChannelEventSink implementation 121 * Actual nsIContentPolicy and nsIChannelEventSink implementation
108 * @class 122 * @class
109 */ 123 */
110 var PolicyImplementation = 124 var PolicyImplementation =
111 { 125 {
112 classDescription: "Adblock Plus content policy", 126 classDescription: "Adblock Plus content policy",
113 classID: Components.ID("cfeaabe6-1dd1-11b2-a0c6-cb5c268894c9"), 127 classID: Components.ID("cfeaabe6-1dd1-11b2-a0c6-cb5c268894c9"),
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 241 }
228 } 242 }
229 }, 243 },
230 244
231 // 245 //
232 // nsIChannelEventSink interface implementation 246 // nsIChannelEventSink interface implementation
233 // 247 //
234 248
235 asyncOnChannelRedirect: function(oldChannel, newChannel, flags, callback) 249 asyncOnChannelRedirect: function(oldChannel, newChannel, flags, callback)
236 { 250 {
237 let result = Cr.NS_OK; 251 let async = false;
238 try 252 try
239 { 253 {
240 // nsILoadInfo.contentPolicyType was introduced in Gecko 35, then 254 // nsILoadInfo.contentPolicyType was introduced in Gecko 35, then
241 // renamed to nsILoadInfo.externalContentPolicyType in Gecko 44. 255 // renamed to nsILoadInfo.externalContentPolicyType in Gecko 44.
242 let loadInfo = oldChannel.loadInfo; 256 let loadInfo = oldChannel.loadInfo;
243 let contentType = ("externalContentPolicyType" in loadInfo ? 257 let contentType = ("externalContentPolicyType" in loadInfo ?
244 loadInfo.externalContentPolicyType : loadInfo.contentPolicyType); 258 loadInfo.externalContentPolicyType : loadInfo.contentPolicyType);
245 if (!contentType) 259 if (!contentType)
246 return; 260 return;
247 261
248 let wnd = Utils.getRequestWindow(newChannel); 262 let wnd = Utils.getRequestWindow(newChannel);
249 if (!wnd) 263 if (!wnd)
250 return; 264 return;
251 265
252 if (contentType == Ci.nsIContentPolicy.TYPE_DOCUMENT) 266 if (contentType == Ci.nsIContentPolicy.TYPE_DOCUMENT)
253 { 267 {
254 if (wnd.history.length <= 1 && wnd.opener) 268 if (wnd.history.length <= 1 && wnd.opener)
255 { 269 {
256 // Special treatment for pop-up windows. Note that we might not have 270 // Special treatment for pop-up windows. Note that we might not have
257 // seen the original channel yet because the redirect happened before 271 // seen the original channel yet because the redirect happened before
258 // the async code in observe() had a chance to run. 272 // the async code in observe() had a chance to run.
259 this.observe(wnd, "content-document-global-created", null, oldChannel. URI.spec); 273 this.observe(wnd, "content-document-global-created", null, oldChannel. URI.spec);
260 this.observe(wnd, "content-document-global-created", null, newChannel. URI.spec); 274 this.observe(wnd, "content-document-global-created", null, newChannel. URI.spec);
261 } 275 }
262 return; 276 return;
263 } 277 }
264 278
265 if (!shouldAllow(wnd, wnd.document, types.get(contentType), newChannel.URI .spec)) 279 shouldAllow(wnd, wnd.document, types.get(contentType), newChannel.URI.spec , function(allow)
266 result = Cr.NS_BINDING_ABORTED; 280 {
281 callback.onRedirectVerifyCallback(allow ? Cr.NS_OK : Cr.NS_BINDING_ABORT ED);
282 });
283 async = true;
267 } 284 }
268 catch (e) 285 catch (e)
269 { 286 {
270 // We shouldn't throw exceptions here - this will prevent the redirect. 287 // We shouldn't throw exceptions here - this will prevent the redirect.
271 Cu.reportError(e); 288 Cu.reportError(e);
272 } 289 }
273 finally 290 finally
274 { 291 {
275 callback.onRedirectVerifyCallback(result); 292 if (!async)
293 callback.onRedirectVerifyCallback(Cr.NS_OK);
276 } 294 }
277 }, 295 },
278 296
279 // 297 //
280 // nsIFactory interface implementation 298 // nsIFactory interface implementation
281 // 299 //
282 300
283 createInstance: function(outer, iid) 301 createInstance: function(outer, iid)
284 { 302 {
285 if (outer) 303 if (outer)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 let property = (hasCols ? "cols" : "rows"); 366 let property = (hasCols ? "cols" : "rows");
349 let weights = parentNode[property].split(","); 367 let weights = parentNode[property].split(",");
350 weights[index] = "0"; 368 weights[index] = "0";
351 parentNode[property] = weights.join(","); 369 parentNode[property] = weights.join(",");
352 } 370 }
353 } 371 }
354 else 372 else
355 node.classList.add(collapsedClass); 373 node.classList.add(collapsedClass);
356 } 374 }
357 } 375 }
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