Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: ext/background.js

Issue 29418659: Issue 5130 - Changes listener to register <all_urls> and filter non ws http requests (Closed)
Patch Set: remove regex, style changes, remove redundant object creations Created April 20, 2017, 7:52 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-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
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. Ideally, we'd explicitly
567 // specify the protocols we are interested in (i.e. http://, https://,
568 // ws:// and wss://) with the url patterns, given below, when adding this
569 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket
570 // protocol and is causing an error if it is given.
571 let url = new URL(details.url);
Sebastian Noack 2017/04/20 19:59:48 Perhaps move this after the check below, so that w
Jon Sonesen 2017/04/20 20:04:48 Done.
572 if (url.protocol != "http:" && url.protocol != "https:" &&
573 url.protocol != "ws:" && url.protocol != "wss:")
574 return;
575
566 // The high-level code isn't interested in requests that aren't 576 // The high-level code isn't interested in requests that aren't
567 // related to a tab or requests loading a top-level document, 577 // related to a tab or requests loading a top-level document,
568 // those should never be blocked. 578 // those should never be blocked.
569 if (details.tabId == -1 || details.type == "main_frame") 579 if (details.tabId == -1 || details.type == "main_frame")
570 return; 580 return;
571 581
572 // We are looking for the frame that contains the element which 582 // We are looking for the frame that contains the element which
573 // has triggered this request. For most requests (e.g. images) we 583 // has triggered this request. For most requests (e.g. images) we
574 // can just use the request's frame ID, but for subdocument requests 584 // 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. 585 // (e.g. iframes) we must instead use the request's parent frame ID.
576 let {frameId, type} = details; 586 let {frameId, type} = details;
577 if (type == "sub_frame") 587 if (type == "sub_frame")
578 { 588 {
579 frameId = details.parentFrameId; 589 frameId = details.parentFrameId;
580 type = "SUBDOCUMENT"; 590 type = "SUBDOCUMENT";
581 } 591 }
582 592
583 let frame = ext.getFrame(details.tabId, frameId); 593 let frame = ext.getFrame(details.tabId, frameId);
584 if (frame) 594 if (frame)
585 { 595 {
586 let results = ext.webRequest.onBeforeRequest._dispatch( 596 let results = ext.webRequest.onBeforeRequest._dispatch(
587 new URL(details.url), 597 url,
Sebastian Noack 2017/04/20 19:59:48 Nit: Wrapping after each argument, while most argu
Jon Sonesen 2017/04/20 20:04:48 Done.
588 type.toUpperCase(), 598 type.toUpperCase(),
589 new Page({id: details.tabId}), 599 new Page({id: details.tabId}),
590 frame 600 frame
591 ); 601 );
592 602
593 if (results.indexOf(false) != -1) 603 if (results.indexOf(false) != -1)
594 return {cancel: true}; 604 return {cancel: true};
595 } 605 }
596 }, {urls: ["https://*/*", "http://*/*", "ws://*/*", "wss://*/*"]}, ["blocking" ]); 606 }, {urls: ["<all_urls>"]}, ["blocking"]);
597 607
598 608
599 /* Message passing */ 609 /* Message passing */
600 610
601 chrome.runtime.onMessage.addListener((message, rawSender, sendResponse) => 611 chrome.runtime.onMessage.addListener((message, rawSender, sendResponse) =>
602 { 612 {
603 let sender = {}; 613 let sender = {};
604 614
605 // Add "page" and "frame" if the message was sent by a content script. 615 // 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". 616 // 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
724 ext.windows = { 734 ext.windows = {
725 create(createData, callback) 735 create(createData, callback)
726 { 736 {
727 chrome.windows.create(createData, createdWindow => 737 chrome.windows.create(createData, createdWindow =>
728 { 738 {
729 afterTabLoaded(callback)(createdWindow.tabs[0]); 739 afterTabLoaded(callback)(createdWindow.tabs[0]);
730 }); 740 });
731 } 741 }
732 }; 742 };
733 }()); 743 }());
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