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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 } | 561 } |
562 }); | 562 }); |
563 }); | 563 }); |
564 }); | 564 }); |
565 | 565 |
566 chrome.webRequest.onBeforeRequest.addListener(details => | 566 chrome.webRequest.onBeforeRequest.addListener(details => |
567 { | 567 { |
568 // The high-level code isn't interested in requests that aren't | 568 // The high-level code isn't interested in requests that aren't |
569 // related to a tab or requests loading a top-level document, | 569 // related to a tab or requests loading a top-level document, |
570 // those should never be blocked. | 570 // those should never be blocked. |
571 if (details.tabId == -1 || details.type == "main_frame") | 571 if (details.type == "main_frame") |
572 return; | 572 return; |
573 | 573 |
574 // Filter out requests from non web protocols. Ideally, we'd explicitly | 574 // Filter out requests from non web protocols. Ideally, we'd explicitly |
575 // specify the protocols we are interested in (i.e. http://, https://, | 575 // specify the protocols we are interested in (i.e. http://, https://, |
576 // ws:// and wss://) with the url patterns, given below, when adding this | 576 // ws:// and wss://) with the url patterns, given below, when adding this |
577 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket | 577 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket |
578 // protocol and is causing an error if it is given. | 578 // protocol and is causing an error if it is given. |
579 let url = new URL(details.url); | 579 let url = new URL(details.url); |
580 if (url.protocol != "http:" && url.protocol != "https:" && | 580 if (url.protocol != "http:" && url.protocol != "https:" && |
581 url.protocol != "ws:" && url.protocol != "wss:") | 581 url.protocol != "ws:" && url.protocol != "wss:") |
582 return; | 582 return; |
583 | 583 |
584 // We are looking for the frame that contains the element which | 584 // We are looking for the frame that contains the element which |
585 // has triggered this request. For most requests (e.g. images) we | 585 // has triggered this request. For most requests (e.g. images) we |
586 // can just use the request's frame ID, but for subdocument requests | 586 // can just use the request's frame ID, but for subdocument requests |
587 // (e.g. iframes) we must instead use the request's parent frame ID. | 587 // (e.g. iframes) we must instead use the request's parent frame ID. |
588 let {frameId, type} = details; | 588 let {frameId, type} = details; |
589 if (type == "sub_frame") | 589 if (type == "sub_frame") |
590 frameId = details.parentFrameId; | 590 frameId = details.parentFrameId; |
591 | 591 |
592 let frame = ext.getFrame(details.tabId, frameId); | 592 // Sometimes requests are not associated with a browser tab and |
593 if (frame) | 593 // in this case we want to still be able to view the url being called. |
| 594 let frame = null; |
| 595 let page = null; |
| 596 if (details.tabId != -1) |
594 { | 597 { |
595 let results = ext.webRequest.onBeforeRequest._dispatch( | 598 frame = ext.getFrame(details.tabId, frameId); |
596 url, type, new Page({id: details.tabId}), frame | 599 page = new Page({id: details.tabId}); |
597 ); | 600 } |
598 | 601 |
599 if (results.indexOf(false) != -1) | 602 if (ext.webRequest.onBeforeRequest._dispatch( |
600 return {cancel: true}; | 603 url, type, page, frame).includes(false)) |
601 } | 604 return {cancel: true}; |
602 }, {urls: ["<all_urls>"]}, ["blocking"]); | 605 }, {urls: ["<all_urls>"]}, ["blocking"]); |
603 | 606 |
604 | 607 |
605 /* Message passing */ | 608 /* Message passing */ |
606 | 609 |
607 chrome.runtime.onMessage.addListener((message, rawSender, sendResponse) => | 610 chrome.runtime.onMessage.addListener((message, rawSender, sendResponse) => |
608 { | 611 { |
609 let sender = {}; | 612 let sender = {}; |
610 | 613 |
611 // Add "page" and "frame" if the message was sent by a content script. | 614 // Add "page" and "frame" if the message was sent by a content script. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 ext.windows = { | 733 ext.windows = { |
731 create(createData, callback) | 734 create(createData, callback) |
732 { | 735 { |
733 chrome.windows.create(createData, createdWindow => | 736 chrome.windows.create(createData, createdWindow => |
734 { | 737 { |
735 afterTabLoaded(callback)(createdWindow.tabs[0]); | 738 afterTabLoaded(callback)(createdWindow.tabs[0]); |
736 }); | 739 }); |
737 } | 740 } |
738 }; | 741 }; |
739 }()); | 742 }()); |
OLD | NEW |