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: Fixed nit Created Feb. 11, 2016, 1:44 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 let opener = this._openers.get(subject);
318 opener = subject.opener; 320 if (opener && Components.utils.isDeadWrapper(opener))
321 opener = null;
322
319 if (!opener) 323 if (!opener)
320 return; 324 {
325 // We don't know the opener for this window yet, try to find it
326 if (subject instanceof Ci.nsIDOMWindow)
327 opener = subject.opener;
328
329 if (!opener)
330 return;
331
332 // The opener might be an intermediate window, get the real one
333 while (opener.location == "about:blank" && opener.opener)
334 opener = opener.opener;
335
336 this._openers.set(subject, opener);
337 }
321 338
322 if (!uri && subject instanceof Ci.nsIDOMWindow) 339 if (!uri && subject instanceof Ci.nsIDOMWindow)
323 uri = subject.location.href; 340 uri = subject.location.href;
324 if (!shouldAllow(opener, opener.document, "POPUP", uri)) 341 if (!shouldAllow(opener, opener.document, "POPUP", uri))
325 { 342 {
326 subject.stop(); 343 subject.stop();
327 Utils.runAsync(() => subject.close()); 344 Utils.runAsync(() => subject.close());
328 } 345 }
329 else if (uri == "about:blank") 346 else if (uri == "about:blank")
330 { 347 {
331 // An about:blank pop-up most likely means that a load will be 348 // An about:blank pop-up most likely means that a load will be
332 // initiated asynchronously. Wait for that. 349 // initiated asynchronously. Wait for that.
333 Utils.runAsync(() => 350 Utils.runAsync(() =>
334 { 351 {
335 let channel = subject.QueryInterface(Ci.nsIInterfaceRequestor) 352 let channel = subject.QueryInterface(Ci.nsIInterfaceRequestor)
336 .getInterface(Ci.nsIDocShell) 353 .getInterface(Ci.nsIDocShell)
337 .QueryInterface(Ci.nsIDocumentLoader) 354 .QueryInterface(Ci.nsIDocumentLoader)
338 .documentChannel; 355 .documentChannel;
339 if (channel) 356 if (channel)
340 this.observe(subject, topic, data, channel.URI.spec, opener); 357 this.observe(subject, topic, data, channel.URI.spec);
341 }); 358 });
342 } 359 }
343 break; 360 break;
344 } 361 }
345 } 362 }
346 }, 363 },
347 364
348 // 365 //
349 // nsIChannelEventSink interface implementation 366 // nsIChannelEventSink interface implementation
350 // 367 //
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 let property = (hasCols ? "cols" : "rows"); 480 let property = (hasCols ? "cols" : "rows");
464 let weights = parentNode[property].split(","); 481 let weights = parentNode[property].split(",");
465 weights[index] = "0"; 482 weights[index] = "0";
466 parentNode[property] = weights.join(","); 483 parentNode[property] = weights.join(",");
467 } 484 }
468 } 485 }
469 else 486 else
470 node.classList.add(collapsedClass); 487 node.classList.add(collapsedClass);
471 } 488 }
472 } 489 }
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