| 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-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 { | |
| 590 frameId = details.parentFrameId; | 591 frameId = details.parentFrameId; |
| 592 type = "SUBDOCUMENT"; | |
|
Sebastian Noack
2017/05/30 11:10:48
We no longer map "sub_frame" to "SUBDOCUMENT" here
Jon Sonesen
2017/05/31 08:28:17
Acknowledged.
| |
| 593 } | |
| 591 | 594 |
| 592 let frame = ext.getFrame(details.tabId, frameId); | 595 // Sometimes requests are not associated with a browser tab and |
| 593 if (frame) | 596 // in this case we want to still be able to view the url being called. |
| 597 let frame = null; | |
| 598 let page = null; | |
| 599 if (details.tabId != -1) | |
| 594 { | 600 { |
| 595 let results = ext.webRequest.onBeforeRequest._dispatch( | 601 frame = ext.getFrame(details.tabId, frameId); |
| 596 url, type, new Page({id: details.tabId}), frame | 602 page = new Page({id: details.tabId}); |
| 597 ); | 603 } |
| 598 | 604 |
| 599 if (results.indexOf(false) != -1) | 605 if (ext.webRequest.onBeforeRequest._dispatch( |
| 600 return {cancel: true}; | 606 url, type.toUpperCase(), page, frame).includes(false)) |
|
Sebastian Noack
2017/05/30 11:10:48
We no longer convert the type to upper case here.
Jon Sonesen
2017/05/31 08:28:17
Acknowledged.
| |
| 601 } | 607 return {cancel: true}; |
| 602 }, {urls: ["<all_urls>"]}, ["blocking"]); | 608 }, {urls: ["<all_urls>"]}, ["blocking"]); |
| 603 | 609 |
| 604 | 610 |
| 605 /* Message passing */ | 611 /* Message passing */ |
| 606 | 612 |
| 607 chrome.runtime.onMessage.addListener((message, rawSender, sendResponse) => | 613 chrome.runtime.onMessage.addListener((message, rawSender, sendResponse) => |
| 608 { | 614 { |
| 609 let sender = {}; | 615 let sender = {}; |
| 610 | 616 |
| 611 // Add "page" and "frame" if the message was sent by a content script. | 617 // 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 = { | 736 ext.windows = { |
| 731 create(createData, callback) | 737 create(createData, callback) |
| 732 { | 738 { |
| 733 chrome.windows.create(createData, createdWindow => | 739 chrome.windows.create(createData, createdWindow => |
| 734 { | 740 { |
| 735 afterTabLoaded(callback)(createdWindow.tabs[0]); | 741 afterTabLoaded(callback)(createdWindow.tabs[0]); |
| 736 }); | 742 }); |
| 737 } | 743 } |
| 738 }; | 744 }; |
| 739 }()); | 745 }()); |
| OLD | NEW |