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

Delta Between Two Patch Sets: ext/background.js

Issue 29421712: Issue 5184 - Support Firefox-specific webRequest types (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Created April 25, 2017, 4:25 p.m.
Right Patch Set: Use for..in Created May 20, 2017, 6:54 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/requestBlocker.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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 483
484 chrome.windows.onFocusChanged.addListener(windowId => 484 chrome.windows.onFocusChanged.addListener(windowId =>
485 { 485 {
486 if (windowId != chrome.windows.WINDOW_ID_NONE) 486 if (windowId != chrome.windows.WINDOW_ID_NONE)
487 updateContextMenu(); 487 updateContextMenu();
488 }); 488 });
489 489
490 490
491 /* Web requests */ 491 /* Web requests */
492 492
493 const resourceTypeMap = Object.freeze(Object.assign(Object.create(null),
494 {
495 web_manifest: "OTHER",
496 xml_dtd: "OTHER",
497 xslt: "OTHER",
498 imageset: "IMAGE",
499 beacon: "PING"
500 }
501 ));
502
503 let framesOfTabs = Object.create(null); 493 let framesOfTabs = Object.create(null);
504 494
505 ext.getFrame = (tabId, frameId) => 495 ext.getFrame = (tabId, frameId) =>
506 { 496 {
507 return (framesOfTabs[tabId] || {})[frameId]; 497 return (framesOfTabs[tabId] || {})[frameId];
508 }; 498 };
509 499
510 let handlerBehaviorChangedQuota = 500 let handlerBehaviorChangedQuota =
511 chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES; 501 chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES;
512 502
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 if (url.protocol != "http:" && url.protocol != "https:" && 578 if (url.protocol != "http:" && url.protocol != "https:" &&
589 url.protocol != "ws:" && url.protocol != "wss:") 579 url.protocol != "ws:" && url.protocol != "wss:")
590 return; 580 return;
591 581
592 // We are looking for the frame that contains the element which 582 // We are looking for the frame that contains the element which
593 // has triggered this request. For most requests (e.g. images) we 583 // has triggered this request. For most requests (e.g. images) we
594 // 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
595 // (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.
596 let {frameId, type} = details; 586 let {frameId, type} = details;
597 if (type == "sub_frame") 587 if (type == "sub_frame")
598 {
599 frameId = details.parentFrameId; 588 frameId = details.parentFrameId;
600 type = "SUBDOCUMENT";
601 }
602 589
603 let frame = ext.getFrame(details.tabId, frameId); 590 let frame = ext.getFrame(details.tabId, frameId);
604 if (frame) 591 if (frame)
605 { 592 {
606 type = resourceTypeMap[type] || type.toUpperCase();
607
608 let results = ext.webRequest.onBeforeRequest._dispatch( 593 let results = ext.webRequest.onBeforeRequest._dispatch(
609 url, type, new Page({id: details.tabId}), frame 594 url, type, new Page({id: details.tabId}), frame
610 ); 595 );
611 596
612 if (results.indexOf(false) != -1) 597 if (results.indexOf(false) != -1)
613 return {cancel: true}; 598 return {cancel: true};
614 } 599 }
615 }, {urls: ["<all_urls>"]}, ["blocking"]); 600 }, {urls: ["<all_urls>"]}, ["blocking"]);
616 601
617 602
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 ext.windows = { 728 ext.windows = {
744 create(createData, callback) 729 create(createData, callback)
745 { 730 {
746 chrome.windows.create(createData, createdWindow => 731 chrome.windows.create(createData, createdWindow =>
747 { 732 {
748 afterTabLoaded(callback)(createdWindow.tabs[0]); 733 afterTabLoaded(callback)(createdWindow.tabs[0]);
749 }); 734 });
750 } 735 }
751 }; 736 };
752 }()); 737 }());
LEFTRIGHT

Powered by Google App Engine
This is Rietveld