Left: | ||
Right: |
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 if (parentFrameId != -1) | 462 if (parentFrameId != -1) |
463 frames[details[i].frameId].parent = frames[parentFrameId]; | 463 frames[details[i].frameId].parent = frames[parentFrameId]; |
464 } | 464 } |
465 } | 465 } |
466 }); | 466 }); |
467 }); | 467 }); |
468 }); | 468 }); |
469 | 469 |
470 chrome.webRequest.onBeforeRequest.addListener(function(details) | 470 chrome.webRequest.onBeforeRequest.addListener(function(details) |
471 { | 471 { |
472 // the high-level code isn't interested in requests that aren't related | 472 // the high-level code isn't interested in requests that aren't |
473 // to a tab and since those can only be handled in Chrome, we ignore | 473 // related to a tab or requests loading a top-level document, |
474 // them here instead of in the browser independent high-level code. | 474 // those should never be blocked |
475 if (details.tabId == -1) | 475 if (details.tabId == -1 || details.type == "main_frame") |
476 return; | 476 return; |
477 | 477 |
478 var isMainFrame = details.type == "main_frame" || ( | 478 // we are looking for the frame that contains the element that |
kzar
2016/08/30 13:14:09
Mind making this comment a bit clearer (or removin
Sebastian Noack
2016/09/09 14:39:50
Well, this comment isn't new and it makes sense to
kzar
2016/09/13 12:30:01
Fair enough, well how about this?
"We are looking
Sebastian Noack
2016/09/13 15:21:30
Done.
kzar
2016/09/13 17:08:58
Looks great, thanks.
| |
479 // assume that the first request belongs to the top frame. Chrome 29 | 479 // is about to load, however if a frame is loading the surrounding |
480 // may give the top frame the type "object" instead of "main_frame". | 480 // frame is indicated by parentFrameId instead of frameId |
481 // https://code.google.com/p/chromium/issues/detail?id=281711 | 481 var frameId; |
482 details.frameId == 0 && !(details.tabId in framesOfTabs) | 482 var requestType; |
483 ); | 483 if (details.type == "sub_frame") |
484 { | |
485 frameId = details.parentFrameId; | |
486 requestType = "SUBDOCUMENT"; | |
487 } | |
488 else | |
489 { | |
490 frameId = details.frameId; | |
491 requestType = details.type.toUpperCase(); | |
492 } | |
484 | 493 |
485 if (!isMainFrame) | 494 var frame = ext.getFrame(details.tabId, frameId); |
495 if (frame) | |
486 { | 496 { |
487 // we are looking for the frame that contains the element that | 497 var results = ext.webRequest.onBeforeRequest._dispatch( |
488 // is about to load, however if a frame is loading the surrounding | 498 new URL(details.url), |
489 // frame is indicated by parentFrameId instead of frameId | 499 requestType, |
490 var frameId; | 500 new Page({id: details.tabId}), |
491 var requestType; | 501 frame |
492 if (details.type == "sub_frame") | 502 ); |
493 { | |
494 frameId = details.parentFrameId; | |
495 requestType = "SUBDOCUMENT"; | |
496 } | |
497 else | |
498 { | |
499 frameId = details.frameId; | |
500 requestType = details.type.toUpperCase(); | |
501 } | |
502 | 503 |
503 var frame = ext.getFrame(details.tabId, frameId); | 504 if (results.indexOf(false) != -1) |
504 if (frame) | 505 return {cancel: true}; |
505 { | |
506 var results = ext.webRequest.onBeforeRequest._dispatch( | |
507 new URL(details.url), | |
508 requestType, | |
509 new Page({id: details.tabId}), | |
510 frame | |
511 ); | |
512 | |
513 if (results.indexOf(false) != -1) | |
514 return {cancel: true}; | |
515 } | |
516 } | 506 } |
517 }, {urls: ["http://*/*", "https://*/*"]}, ["blocking"]); | 507 }, {urls: ["http://*/*", "https://*/*"]}, ["blocking"]); |
518 | 508 |
519 | 509 |
520 /* Message passing */ | 510 /* Message passing */ |
521 | 511 |
522 chrome.runtime.onMessage.addListener(function(message, rawSender, sendResponse ) | 512 chrome.runtime.onMessage.addListener(function(message, rawSender, sendResponse ) |
523 { | 513 { |
524 var sender = {}; | 514 var sender = {}; |
525 | 515 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 ext.windows = { | 612 ext.windows = { |
623 create: function(createData, callback) | 613 create: function(createData, callback) |
624 { | 614 { |
625 chrome.windows.create(createData, function(createdWindow) | 615 chrome.windows.create(createData, function(createdWindow) |
626 { | 616 { |
627 afterTabLoaded(callback)(createdWindow.tabs[0]); | 617 afterTabLoaded(callback)(createdWindow.tabs[0]); |
628 }); | 618 }); |
629 } | 619 } |
630 }; | 620 }; |
631 })(); | 621 })(); |
OLD | NEW |