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

Delta Between Two Patch Sets: ext/background.js

Issue 29417597: Issue 5161 - Use maps and sets where appropriate (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Revert previous change and remove unnecessary logic Created May 19, 2017, 4:15 p.m.
Right Patch Set: Minor unrelated changes Created May 21, 2017, 10:15 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/devtools.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 tabs.forEach(tab => 544 tabs.forEach(tab =>
545 { 545 {
546 chrome.webNavigation.getAllFrames({tabId: tab.id}, details => 546 chrome.webNavigation.getAllFrames({tabId: tab.id}, details =>
547 { 547 {
548 if (details && details.length > 0) 548 if (details && details.length > 0)
549 { 549 {
550 let frames = new Map(); 550 let frames = new Map();
551 framesOfTabs.set(tab.id, frames); 551 framesOfTabs.set(tab.id, frames);
552 552
553 for (let detail of details) 553 for (let detail of details)
554 frames.set(detail.frameId, {url: new URL(detail.url)});
555
556 for (let detail of details)
557 { 554 {
558 let {parentFrameId} = detail; 555 let frame = {url: new URL(detail.url)};
559 556 frames.set(detail.frameId, frame);
560 if (parentFrameId != -1) 557
561 frames.get(detail.frameId).parent = frames.get(parentFrameId); 558 if (detail.parentFrameId != -1)
559 frame.parent = frames.get(detail.parentFrameId);
562 } 560 }
563 } 561 }
564 }); 562 });
565 }); 563 });
566 }); 564 });
567 565
568 chrome.webRequest.onBeforeRequest.addListener(details => 566 chrome.webRequest.onBeforeRequest.addListener(details =>
569 { 567 {
570 // 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
571 // related to a tab or requests loading a top-level document, 569 // related to a tab or requests loading a top-level document,
572 // those should never be blocked. 570 // those should never be blocked.
573 if (details.tabId == -1 || details.type == "main_frame") 571 if (details.tabId == -1 || details.type == "main_frame")
572 return;
573
574 // Filter out requests from non web protocols. Ideally, we'd explicitly
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
577 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket
578 // protocol and is causing an error if it is given.
579 let url = new URL(details.url);
580 if (url.protocol != "http:" && url.protocol != "https:" &&
581 url.protocol != "ws:" && url.protocol != "wss:")
574 return; 582 return;
575 583
576 // We are looking for the frame that contains the element which 584 // We are looking for the frame that contains the element which
577 // has triggered this request. For most requests (e.g. images) we 585 // has triggered this request. For most requests (e.g. images) we
578 // 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
579 // (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.
580 let {frameId, type} = details; 588 let {frameId, type} = details;
581 if (type == "sub_frame") 589 if (type == "sub_frame")
582 {
583 frameId = details.parentFrameId; 590 frameId = details.parentFrameId;
584 type = "SUBDOCUMENT";
585 }
586 591
587 let frame = ext.getFrame(details.tabId, frameId); 592 let frame = ext.getFrame(details.tabId, frameId);
588 if (frame) 593 if (frame)
589 { 594 {
590 let results = ext.webRequest.onBeforeRequest._dispatch( 595 let results = ext.webRequest.onBeforeRequest._dispatch(
591 new URL(details.url), 596 url, type, new Page({id: details.tabId}), frame
592 type.toUpperCase(),
593 new Page({id: details.tabId}),
594 frame
595 ); 597 );
596 598
597 if (results.indexOf(false) != -1) 599 if (results.indexOf(false) != -1)
598 return {cancel: true}; 600 return {cancel: true};
599 } 601 }
600 }, {urls: ["<all_urls>"]}, ["blocking"]); 602 }, {urls: ["<all_urls>"]}, ["blocking"]);
601 603
602 604
603 /* Message passing */ 605 /* Message passing */
604 606
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 ext.windows = { 730 ext.windows = {
729 create(createData, callback) 731 create(createData, callback)
730 { 732 {
731 chrome.windows.create(createData, createdWindow => 733 chrome.windows.create(createData, createdWindow =>
732 { 734 {
733 afterTabLoaded(callback)(createdWindow.tabs[0]); 735 afterTabLoaded(callback)(createdWindow.tabs[0]);
734 }); 736 });
735 } 737 }
736 }; 738 };
737 }()); 739 }());
LEFTRIGHT
« no previous file | lib/devtools.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld