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

Side by Side Diff: chrome/ext/background.js

Issue 29350213: Issue 4364 - Drop support for Chrome 29-40 and remove legacy code (Closed)
Patch Set: Rephrased comment Created Sept. 13, 2016, 3:20 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 | composer.postload.js » ('j') | 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 if (parentFrameId != -1) 476 if (parentFrameId != -1)
477 frames[details[i].frameId].parent = frames[parentFrameId]; 477 frames[details[i].frameId].parent = frames[parentFrameId];
478 } 478 }
479 } 479 }
480 }); 480 });
481 }); 481 });
482 }); 482 });
483 483
484 chrome.webRequest.onBeforeRequest.addListener(function(details) 484 chrome.webRequest.onBeforeRequest.addListener(function(details)
485 { 485 {
486 // the high-level code isn't interested in requests that aren't related 486 // The high-level code isn't interested in requests that aren't
487 // to a tab and since those can only be handled in Chrome, we ignore 487 // related to a tab or requests loading a top-level document,
488 // them here instead of in the browser independent high-level code. 488 // those should never be blocked.
489 if (details.tabId == -1) 489 if (details.tabId == -1 || details.type == "main_frame")
490 return; 490 return;
491 491
492 var isMainFrame = details.type == "main_frame" || ( 492 // We are looking for the frame that contains the element which
493 // assume that the first request belongs to the top frame. Chrome 29 493 // has triggered this request. For most requests (e.g. images) we
494 // may give the top frame the type "object" instead of "main_frame". 494 // can just use the request's frame ID, but for subdocument requests
495 // https://code.google.com/p/chromium/issues/detail?id=281711 495 // (e.g. iframes) we must instead use the request's parent frame ID.
496 details.frameId == 0 && !(details.tabId in framesOfTabs) 496 var frameId;
497 ); 497 var requestType;
498 if (details.type == "sub_frame")
499 {
500 frameId = details.parentFrameId;
501 requestType = "SUBDOCUMENT";
502 }
503 else
504 {
505 frameId = details.frameId;
506 requestType = details.type.toUpperCase();
507 }
498 508
499 if (!isMainFrame) 509 var frame = ext.getFrame(details.tabId, frameId);
510 if (frame)
500 { 511 {
501 // we are looking for the frame that contains the element that 512 var results = ext.webRequest.onBeforeRequest._dispatch(
502 // is about to load, however if a frame is loading the surrounding 513 new URL(details.url),
503 // frame is indicated by parentFrameId instead of frameId 514 requestType,
504 var frameId; 515 new Page({id: details.tabId}),
505 var requestType; 516 frame
506 if (details.type == "sub_frame") 517 );
507 {
508 frameId = details.parentFrameId;
509 requestType = "SUBDOCUMENT";
510 }
511 else
512 {
513 frameId = details.frameId;
514 requestType = details.type.toUpperCase();
515 }
516 518
517 var frame = ext.getFrame(details.tabId, frameId); 519 if (results.indexOf(false) != -1)
518 if (frame) 520 return {cancel: true};
519 {
520 var results = ext.webRequest.onBeforeRequest._dispatch(
521 new URL(details.url),
522 requestType,
523 new Page({id: details.tabId}),
524 frame
525 );
526
527 if (results.indexOf(false) != -1)
528 return {cancel: true};
529 }
530 } 521 }
531 }, {urls: ["http://*/*", "https://*/*"]}, ["blocking"]); 522 }, {urls: ["http://*/*", "https://*/*"]}, ["blocking"]);
532 523
533 524
534 /* Message passing */ 525 /* Message passing */
535 526
536 chrome.runtime.onMessage.addListener(function(message, rawSender, sendResponse ) 527 chrome.runtime.onMessage.addListener(function(message, rawSender, sendResponse )
537 { 528 {
538 var sender = {}; 529 var sender = {};
539 530
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 ext.windows = { 627 ext.windows = {
637 create: function(createData, callback) 628 create: function(createData, callback)
638 { 629 {
639 chrome.windows.create(createData, function(createdWindow) 630 chrome.windows.create(createData, function(createdWindow)
640 { 631 {
641 afterTabLoaded(callback)(createdWindow.tabs[0]); 632 afterTabLoaded(callback)(createdWindow.tabs[0]);
642 }); 633 });
643 } 634 }
644 }; 635 };
645 })(); 636 })();
OLDNEW
« no previous file with comments | « no previous file | composer.postload.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld