| 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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 if (parentFrameId != -1) | 556 if (parentFrameId != -1) |
| 557 frames[details[i].frameId].parent = frames[parentFrameId]; | 557 frames[details[i].frameId].parent = frames[parentFrameId]; |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 }); | 560 }); |
| 561 }); | 561 }); |
| 562 }); | 562 }); |
| 563 | 563 |
| 564 chrome.webRequest.onBeforeRequest.addListener(details => | 564 chrome.webRequest.onBeforeRequest.addListener(details => |
| 565 { | 565 { |
| 566 // Filter out requests from non web protocols since Chrome version | |
| 567 // 58 added support for webSocket connections to the webRequests API | |
|
Jon Sonesen
2017/04/20 19:19:58
this comment should likely be improved. perhaps we
Sebastian Noack
2017/04/20 19:34:15
"Filter out requests from non web protocols. Ideal
Jon Sonesen
2017/04/20 19:53:06
Acknowledged. Thank you, I think that is good.
| |
| 568 let blockURLs = new RegExp("https?|wss?"); | |
| 569 let url = new URL(details.url); | |
|
Sebastian Noack
2017/04/20 19:34:15
We are now creating two URL objects, one to valida
Jon Sonesen
2017/04/20 19:53:06
Ah, sorry about that.
| |
| 570 if (!blockURLs.exec(url.protocol)) | |
|
Sebastian Noack
2017/04/20 19:34:15
Since the regular expression doesn't make the code
Sebastian Noack
2017/04/20 19:36:22
I accidentally inverted the logic, should be of co
Jon Sonesen
2017/04/20 19:53:06
Yeah, happy to use this instead.
| |
| 571 { | |
|
Sebastian Noack
2017/04/20 19:34:15
We generally omit the braces if there is only one
Jon Sonesen
2017/04/20 19:53:06
Done.
| |
| 572 return {cancel: false}; | |
|
Sebastian Noack
2017/04/20 19:34:15
For consistency with the other bailout condition b
Jon Sonesen
2017/04/20 19:53:06
Done.
| |
| 573 } | |
| 566 // The high-level code isn't interested in requests that aren't | 574 // The high-level code isn't interested in requests that aren't |
| 567 // related to a tab or requests loading a top-level document, | 575 // related to a tab or requests loading a top-level document, |
| 568 // those should never be blocked. | 576 // those should never be blocked. |
| 569 if (details.tabId == -1 || details.type == "main_frame") | 577 if (details.tabId == -1 || details.type == "main_frame") |
| 570 return; | 578 return; |
| 571 | 579 |
| 572 // We are looking for the frame that contains the element which | 580 // We are looking for the frame that contains the element which |
| 573 // has triggered this request. For most requests (e.g. images) we | 581 // has triggered this request. For most requests (e.g. images) we |
| 574 // can just use the request's frame ID, but for subdocument requests | 582 // can just use the request's frame ID, but for subdocument requests |
| 575 // (e.g. iframes) we must instead use the request's parent frame ID. | 583 // (e.g. iframes) we must instead use the request's parent frame ID. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 586 let results = ext.webRequest.onBeforeRequest._dispatch( | 594 let results = ext.webRequest.onBeforeRequest._dispatch( |
| 587 new URL(details.url), | 595 new URL(details.url), |
| 588 type.toUpperCase(), | 596 type.toUpperCase(), |
| 589 new Page({id: details.tabId}), | 597 new Page({id: details.tabId}), |
| 590 frame | 598 frame |
| 591 ); | 599 ); |
| 592 | 600 |
| 593 if (results.indexOf(false) != -1) | 601 if (results.indexOf(false) != -1) |
| 594 return {cancel: true}; | 602 return {cancel: true}; |
| 595 } | 603 } |
| 596 }, {urls: ["https://*/*", "http://*/*", "ws://*/*", "wss://*/*"]}, ["blocking" ]); | 604 }, {urls: ["<all_urls>"]}, ["blocking"]); |
| 597 | 605 |
| 598 | 606 |
| 599 /* Message passing */ | 607 /* Message passing */ |
| 600 | 608 |
| 601 chrome.runtime.onMessage.addListener((message, rawSender, sendResponse) => | 609 chrome.runtime.onMessage.addListener((message, rawSender, sendResponse) => |
| 602 { | 610 { |
| 603 let sender = {}; | 611 let sender = {}; |
| 604 | 612 |
| 605 // Add "page" and "frame" if the message was sent by a content script. | 613 // Add "page" and "frame" if the message was sent by a content script. |
| 606 // If sent by popup or the background page itself, there is no "tab". | 614 // If sent by popup or the background page itself, there is no "tab". |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 724 ext.windows = { | 732 ext.windows = { |
| 725 create(createData, callback) | 733 create(createData, callback) |
| 726 { | 734 { |
| 727 chrome.windows.create(createData, createdWindow => | 735 chrome.windows.create(createData, createdWindow => |
| 728 { | 736 { |
| 729 afterTabLoaded(callback)(createdWindow.tabs[0]); | 737 afterTabLoaded(callback)(createdWindow.tabs[0]); |
| 730 }); | 738 }); |
| 731 } | 739 } |
| 732 }; | 740 }; |
| 733 }()); | 741 }()); |
| OLD | NEW |