| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 chrome.webRequest.onBeforeRequest.addListener(function(details) | 359 chrome.webRequest.onBeforeRequest.addListener(function(details) |
| 360 { | 360 { |
| 361 try | 361 try |
| 362 { | 362 { |
| 363 // the high-level code isn't interested in requests that aren't related | 363 // the high-level code isn't interested in requests that aren't related |
| 364 // to a tab and since those can only be handled in Chrome, we ignore | 364 // to a tab and since those can only be handled in Chrome, we ignore |
| 365 // them here instead of in the browser independent high-level code. | 365 // them here instead of in the browser independent high-level code. |
| 366 if (details.tabId == -1) | 366 if (details.tabId == -1) |
| 367 return; | 367 return; |
| 368 | 368 |
| 369 var requestType = details.type; | 369 var isMainFrame = details.type == "main_frame" || ( |
| 370 var isMainFrame = requestType == "main_frame" || ( | |
| 371 | 370 |
| 372 // assume that the first request belongs to the top frame. Chrome | 371 // assume that the first request belongs to the top frame. Chrome |
| 373 // may give the top frame the type "object" instead of "main_frame". | 372 // may give the top frame the type "object" instead of "main_frame". |
| 374 // https://code.google.com/p/chromium/issues/detail?id=281711 | 373 // https://code.google.com/p/chromium/issues/detail?id=281711 |
| 375 details.frameId == 0 && !(details.tabId in framesOfTabs) | 374 details.frameId == 0 && !(details.tabId in framesOfTabs) |
| 376 ); | 375 ); |
| 377 | 376 |
| 378 var frames = null; | 377 var frames = null; |
| 379 if (!isMainFrame) | 378 if (!isMainFrame) |
| 380 frames = framesOfTabs[details.tabId]; | 379 frames = framesOfTabs[details.tabId]; |
| 381 if (!frames) | 380 if (!frames) |
| 382 frames = framesOfTabs[details.tabId] = Object.create(null); | 381 frames = framesOfTabs[details.tabId] = Object.create(null); |
| 383 | 382 |
| 384 var frame = null; | 383 var frame = null; |
| 385 var url = new URL(details.url); | 384 var url = new URL(details.url); |
| 386 if (!isMainFrame) | 385 if (!isMainFrame) |
| 387 { | 386 { |
| 388 // we are looking for the frame that contains the element that | 387 // we are looking for the frame that contains the element that |
| 389 // is about to load, however if a frame is loading the surrounding | 388 // is about to load, however if a frame is loading the surrounding |
| 390 // frame is indicated by parentFrameId instead of frameId | 389 // frame is indicated by parentFrameId instead of frameId |
| 391 var frameId; | 390 var frameId; |
| 392 if (requestType == "sub_frame") | 391 var requestType; |
| 392 if (details.type == "sub_frame") |
| 393 { |
| 393 frameId = details.parentFrameId; | 394 frameId = details.parentFrameId; |
| 395 requestType = "SUBDOCUMENT"; |
| 396 } |
| 394 else | 397 else |
| 398 { |
| 395 frameId = details.frameId; | 399 frameId = details.frameId; |
| 400 requestType = details.type.toUpperCase(); |
| 401 } |
| 396 | 402 |
| 397 frame = frames[frameId] || frames[Object.keys(frames)[0]]; | 403 frame = frames[frameId] || frames[Object.keys(frames)[0]]; |
| 398 | 404 |
| 399 if (frame) | 405 if (frame) |
| 400 { | 406 { |
| 401 // Since Chrome 38 requests of type 'object' (e.g. requests | 407 // Since Chrome 38 requests of type 'object' (e.g. requests |
| 402 // initiated by Flash) are mistakenly reported with the type 'other'. | 408 // initiated by Flash) are mistakenly reported with the type 'other'. |
| 403 // https://code.google.com/p/chromium/issues/detail?id=410382 | 409 // https://code.google.com/p/chromium/issues/detail?id=410382 |
| 404 if (requestType == "other" && parseInt(navigator.userAgent.match(/\bCh
rome\/(\d+)/)[1], 10) >= 38) | 410 if (requestType == "OTHER" && parseInt(navigator.userAgent.match(/\bCh
rome\/(\d+)/)[1], 10) >= 38) |
| 405 requestType = "object"; | 411 requestType = "OBJECT"; |
| 406 | 412 |
| 407 var results = ext.webRequest.onBeforeRequest._dispatch( | 413 var results = ext.webRequest.onBeforeRequest._dispatch( |
| 408 url, | 414 url, |
| 409 requestType, | 415 requestType, |
| 410 new Page({id: details.tabId}), | 416 new Page({id: details.tabId}), |
| 411 frame | 417 frame |
| 412 ); | 418 ); |
| 413 | 419 |
| 414 if (results.indexOf(false) != -1) | 420 if (results.indexOf(false) != -1) |
| 415 return {cancel: true}; | 421 return {cancel: true}; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 callback(new Page(tab)); | 520 callback(new Page(tab)); |
| 515 } | 521 } |
| 516 else | 522 else |
| 517 { | 523 { |
| 518 ext.pages.open(optionsUrl, callback); | 524 ext.pages.open(optionsUrl, callback); |
| 519 } | 525 } |
| 520 }); | 526 }); |
| 521 }); | 527 }); |
| 522 }; | 528 }; |
| 523 })(); | 529 })(); |
| OLD | NEW |