| 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-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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 onActivated: new ext._EventTarget(), | 103 onActivated: new ext._EventTarget(), |
| 104 onRemoved: new ext._EventTarget() | 104 onRemoved: new ext._EventTarget() |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) | 107 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) |
| 108 { | 108 { |
| 109 if (changeInfo.status == "loading") | 109 if (changeInfo.status == "loading") |
| 110 ext.pages.onLoading._dispatch(new Page(tab)); | 110 ext.pages.onLoading._dispatch(new Page(tab)); |
| 111 }); | 111 }); |
| 112 | 112 |
| 113 function createFrame(tabId, frameId) | 113 function createFrame(tabId, frameId) |
|
Sebastian Noack
2016/09/09 14:39:51
The changes here are due to rebasing.
kzar
2016/09/13 12:30:01
Acknowledged.
| |
| 114 { | 114 { |
| 115 var frames = framesOfTabs[tabId]; | 115 var frames = framesOfTabs[tabId]; |
| 116 if (!frames) | 116 if (!frames) |
| 117 frames = framesOfTabs[tabId] = Object.create(null); | 117 frames = framesOfTabs[tabId] = Object.create(null); |
| 118 | 118 |
| 119 var frame = frames[frameId]; | 119 var frame = frames[frameId]; |
| 120 if (!frame) | 120 if (!frame) |
| 121 frame = frames[frameId] = {}; | 121 frame = frames[frameId] = {}; |
| 122 | 122 |
| 123 return frame; | 123 return frame; |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 that |
| 493 // assume that the first request belongs to the top frame. Chrome 29 | 493 // is about to load, however if a frame is loading the surrounding |
| 494 // may give the top frame the type "object" instead of "main_frame". | 494 // frame is indicated by parentFrameId instead of frameId |
| 495 // https://code.google.com/p/chromium/issues/detail?id=281711 | 495 var frameId; |
| 496 details.frameId == 0 && !(details.tabId in framesOfTabs) | 496 var requestType; |
| 497 ); | 497 if (details.type == "sub_frame") |
| 498 { | |
| 499 frameId = details.parentFrameId; | |
| 500 requestType = "SUBDOCUMENT"; | |
| 501 } | |
| 502 else | |
| 503 { | |
| 504 frameId = details.frameId; | |
| 505 requestType = details.type.toUpperCase(); | |
| 506 } | |
| 498 | 507 |
| 499 if (!isMainFrame) | 508 var frame = ext.getFrame(details.tabId, frameId); |
| 509 if (frame) | |
| 500 { | 510 { |
| 501 // we are looking for the frame that contains the element that | 511 var results = ext.webRequest.onBeforeRequest._dispatch( |
| 502 // is about to load, however if a frame is loading the surrounding | 512 new URL(details.url), |
| 503 // frame is indicated by parentFrameId instead of frameId | 513 requestType, |
| 504 var frameId; | 514 new Page({id: details.tabId}), |
| 505 var requestType; | 515 frame |
| 506 if (details.type == "sub_frame") | 516 ); |
| 507 { | |
| 508 frameId = details.parentFrameId; | |
| 509 requestType = "SUBDOCUMENT"; | |
| 510 } | |
| 511 else | |
| 512 { | |
| 513 frameId = details.frameId; | |
| 514 requestType = details.type.toUpperCase(); | |
| 515 } | |
| 516 | 517 |
| 517 var frame = ext.getFrame(details.tabId, frameId); | 518 if (results.indexOf(false) != -1) |
| 518 if (frame) | 519 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 } | 520 } |
| 531 }, {urls: ["http://*/*", "https://*/*"]}, ["blocking"]); | 521 }, {urls: ["http://*/*", "https://*/*"]}, ["blocking"]); |
| 532 | 522 |
| 533 | 523 |
| 534 /* Message passing */ | 524 /* Message passing */ |
| 535 | 525 |
| 536 chrome.runtime.onMessage.addListener(function(message, rawSender, sendResponse ) | 526 chrome.runtime.onMessage.addListener(function(message, rawSender, sendResponse ) |
| 537 { | 527 { |
| 538 var sender = {}; | 528 var sender = {}; |
| 539 | 529 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 ext.windows = { | 626 ext.windows = { |
| 637 create: function(createData, callback) | 627 create: function(createData, callback) |
| 638 { | 628 { |
| 639 chrome.windows.create(createData, function(createdWindow) | 629 chrome.windows.create(createData, function(createdWindow) |
| 640 { | 630 { |
| 641 afterTabLoaded(callback)(createdWindow.tabs[0]); | 631 afterTabLoaded(callback)(createdWindow.tabs[0]); |
| 642 }); | 632 }); |
| 643 } | 633 } |
| 644 }; | 634 }; |
| 645 })(); | 635 })(); |
| OLD | NEW |