| 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-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 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 // let potentially some ads through, rather than blocking legit requests. | 426 // let potentially some ads through, rather than blocking legit requests. | 
| 427 console.error(e); | 427 console.error(e); | 
| 428 } | 428 } | 
| 429 }, {urls: ["http://*/*", "https://*/*"]}, ["blocking"]); | 429 }, {urls: ["http://*/*", "https://*/*"]}, ["blocking"]); | 
| 430 | 430 | 
| 431 | 431 | 
| 432 /* Message passing */ | 432 /* Message passing */ | 
| 433 | 433 | 
| 434 chrome.runtime.onMessage.addListener(function(message, rawSender, sendResponse ) | 434 chrome.runtime.onMessage.addListener(function(message, rawSender, sendResponse ) | 
| 435 { | 435 { | 
| 436 var sender = { | 436 var sender = {}; | 
| 437 page: new Page(rawSender.tab), | 437 | 
| 438 frame: { | 438 // Add "page" and "frame" if messsage were sent by content script. | 
| 
 
kzar
2015/03/02 19:00:32
Nit: "...if the message was sent by a..."
 
Sebastian Noack
2015/03/02 19:42:08
Done.
 
 | |
| 439 // If sent by popup or the background page itself, there is no "tab". | |
| 440 if ("tab" in rawSender) | |
| 441 { | |
| 442 sender.page = new Page(rawSender.tab); | |
| 443 sender.frame = { | |
| 439 url: new URL(rawSender.url), | 444 url: new URL(rawSender.url), | 
| 440 get parent() | 445 get parent() | 
| 441 { | 446 { | 
| 442 var frames = framesOfTabs[rawSender.tab.id]; | 447 var frames = framesOfTabs[rawSender.tab.id]; | 
| 443 | 448 | 
| 444 if (!frames) | 449 if (!frames) | 
| 445 return null; | 450 return null; | 
| 446 | 451 | 
| 447 if ("frameId" in rawSender) | 452 if ("frameId" in rawSender) | 
| 448 { | 453 { | 
| 449 // Chrome 41+ | 454 // Chrome 41+ | 
| 450 var frame = frames[rawSender.frameId]; | 455 var frame = frames[rawSender.frameId]; | 
| 451 if (frame) | 456 if (frame) | 
| 452 return frame.parent; | 457 return frame.parent; | 
| 453 } | 458 } | 
| 454 else | 459 else | 
| 455 { | 460 { | 
| 456 // Chrome 28-40 | 461 // Chrome 28-40 | 
| 457 for (var frameId in frames) | 462 for (var frameId in frames) | 
| 458 { | 463 { | 
| 459 if (frames[frameId].url.href == this.url.href) | 464 if (frames[frameId].url.href == this.url.href) | 
| 460 return frames[frameId].parent; | 465 return frames[frameId].parent; | 
| 461 } | 466 } | 
| 462 } | 467 } | 
| 463 | 468 | 
| 464 return frames[0]; | 469 return frames[0]; | 
| 465 } | 470 } | 
| 466 } | 471 }; | 
| 467 }; | 472 } | 
| 468 | 473 | 
| 469 return ext.onMessage._dispatch(message, sender, sendResponse).indexOf(true) != -1; | 474 return ext.onMessage._dispatch(message, sender, sendResponse).indexOf(true) != -1; | 
| 470 }); | 475 }); | 
| 471 | 476 | 
| 472 // We have to ensure there is at least one listener for the onConnect event. | 477 // We have to ensure there is at least one listener for the onConnect event. | 
| 473 // Otherwise we can't connect a port later, which we need to do in order to | 478 // Otherwise we can't connect a port later, which we need to do in order to | 
| 474 // detect when the extension is reloaded, disabled or uninstalled. | 479 // detect when the extension is reloaded, disabled or uninstalled. | 
| 475 chrome.runtime.onConnect.addListener(function() {}); | 480 chrome.runtime.onConnect.addListener(function() {}); | 
| 476 | 481 | 
| 477 | 482 | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 callback(new Page(tab)); | 519 callback(new Page(tab)); | 
| 515 } | 520 } | 
| 516 else | 521 else | 
| 517 { | 522 { | 
| 518 ext.pages.open(optionsUrl, callback); | 523 ext.pages.open(optionsUrl, callback); | 
| 519 } | 524 } | 
| 520 }); | 525 }); | 
| 521 }); | 526 }); | 
| 522 }; | 527 }; | 
| 523 })(); | 528 })(); | 
| OLD | NEW |