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

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

Issue 29336233: Issue 3568 - Block pop-ups opened via an intermediate window (Closed)
Patch Set: Created Feb. 10, 2016, 3:10 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 }, 301 },
302 302
303 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode , mimeType, extra) 303 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode , mimeType, extra)
304 { 304 {
305 return Ci.nsIContentPolicy.ACCEPT; 305 return Ci.nsIContentPolicy.ACCEPT;
306 }, 306 },
307 307
308 // 308 //
309 // nsIObserver interface implementation 309 // nsIObserver interface implementation
310 // 310 //
311 observe: function(subject, topic, data, uri, opener) 311 _openers: new WeakMap(),
312
313 observe: function(subject, topic, data, uri)
312 { 314 {
313 switch (topic) 315 switch (topic)
314 { 316 {
315 case "content-document-global-created": 317 case "content-document-global-created":
316 { 318 {
317 if (!opener && subject instanceof Ci.nsIDOMWindow) 319 var opener = this._openers.get(subject);
318 opener = subject.opener; 320 if (!opener || Components.utils.isDeadWrapper(opener))
319 if (!opener) 321 {
320 return; 322 // We don't know the opener for this window yet, try to find it
323 if (subject instanceof Ci.nsIDOMWindow)
324 opener = subject.opener;
325
326 if (!opener)
327 return;
328
329 // The opener might be an intermediate window, get the real one
330 while (opener.location == "about:blank" && opener.opener)
331 opener = opener.opener;
332
333 this._openers.set(subject, opener);
334 }
321 335
322 if (!uri && subject instanceof Ci.nsIDOMWindow) 336 if (!uri && subject instanceof Ci.nsIDOMWindow)
323 uri = subject.location.href; 337 uri = subject.location.href;
324 if (!shouldAllow(opener, opener.document, "POPUP", uri)) 338 if (!shouldAllow(opener, opener.document, "POPUP", uri))
325 { 339 {
326 subject.stop(); 340 subject.stop();
327 Utils.runAsync(() => subject.close()); 341 Utils.runAsync(() => subject.close());
328 } 342 }
329 else if (uri == "about:blank") 343 else if (uri == "about:blank")
330 { 344 {
331 // An about:blank pop-up most likely means that a load will be 345 // An about:blank pop-up most likely means that a load will be
332 // initiated asynchronously. Wait for that. 346 // initiated asynchronously. Wait for that.
333 Utils.runAsync(() => 347 Utils.runAsync(() =>
334 { 348 {
335 let channel = subject.QueryInterface(Ci.nsIInterfaceRequestor) 349 let channel = subject.QueryInterface(Ci.nsIInterfaceRequestor)
336 .getInterface(Ci.nsIDocShell) 350 .getInterface(Ci.nsIDocShell)
337 .QueryInterface(Ci.nsIDocumentLoader) 351 .QueryInterface(Ci.nsIDocumentLoader)
338 .documentChannel; 352 .documentChannel;
339 if (channel) 353 if (channel)
340 this.observe(subject, topic, data, channel.URI.spec, opener); 354 this.observe(subject, topic, data, channel.URI.spec);
341 }); 355 });
342 } 356 }
343 break; 357 break;
344 } 358 }
345 } 359 }
346 }, 360 },
347 361
348 // 362 //
349 // nsIChannelEventSink interface implementation 363 // nsIChannelEventSink interface implementation
350 // 364 //
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 let property = (hasCols ? "cols" : "rows"); 477 let property = (hasCols ? "cols" : "rows");
464 let weights = parentNode[property].split(","); 478 let weights = parentNode[property].split(",");
465 weights[index] = "0"; 479 weights[index] = "0";
466 parentNode[property] = weights.join(","); 480 parentNode[property] = weights.join(",");
467 } 481 }
468 } 482 }
469 else 483 else
470 node.classList.add(collapsedClass); 484 node.classList.add(collapsedClass);
471 } 485 }
472 } 486 }
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