| LEFT | RIGHT |
| 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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 /* Message passing */ | 489 /* Message passing */ |
| 490 | 490 |
| 491 chrome.runtime.onMessage.addListener(function(message, rawSender, sendResponse
) | 491 chrome.runtime.onMessage.addListener(function(message, rawSender, sendResponse
) |
| 492 { | 492 { |
| 493 var sender = {}; | 493 var sender = {}; |
| 494 | 494 |
| 495 // Add "page" and "frame" if the message was sent by a content script. | 495 // Add "page" and "frame" if the message was sent by a content script. |
| 496 // If sent by popup or the background page itself, there is no "tab". | 496 // If sent by popup or the background page itself, there is no "tab". |
| 497 if ("tab" in rawSender) | 497 if ("tab" in rawSender) |
| 498 { | 498 { |
| 499 console.log(rawSender.url); | |
| 500 sender.page = new Page(rawSender.tab); | 499 sender.page = new Page(rawSender.tab); |
| 501 sender.frame = { | 500 sender.frame = { |
| 502 url: new URL(rawSender.url), | 501 url: new URL(rawSender.url), |
| 503 get parent() | 502 get parent() |
| 504 { | 503 { |
| 505 var frames = framesOfTabs[rawSender.tab.id]; | 504 var frames = framesOfTabs[rawSender.tab.id]; |
| 506 | 505 |
| 507 if (!frames) | 506 if (!frames) |
| 508 return null; | 507 return null; |
| 509 | 508 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 525 } | 524 } |
| 526 | 525 |
| 527 return frames[0]; | 526 return frames[0]; |
| 528 } | 527 } |
| 529 }; | 528 }; |
| 530 } | 529 } |
| 531 | 530 |
| 532 return ext.onMessage._dispatch(message, sender, sendResponse).indexOf(true)
!= -1; | 531 return ext.onMessage._dispatch(message, sender, sendResponse).indexOf(true)
!= -1; |
| 533 }); | 532 }); |
| 534 | 533 |
| 535 // We have to ensure there is at least one listener for the onConnect event. | |
| 536 // Otherwise we can't connect a port later, which we need to do in order to | |
| 537 // detect when the extension is reloaded, disabled or uninstalled. | |
| 538 chrome.runtime.onConnect.addListener(function() {}); | |
| 539 | |
| 540 | 534 |
| 541 /* Storage */ | 535 /* Storage */ |
| 542 | 536 |
| 543 ext.storage = { | 537 ext.storage = { |
| 544 get: function(keys, callback) | 538 get: function(keys, callback) |
| 545 { | 539 { |
| 546 chrome.storage.local.get(keys, callback); | 540 chrome.storage.local.get(keys, callback); |
| 547 }, | 541 }, |
| 548 set: function(key, value, callback) | 542 set: function(key, value, callback) |
| 549 { | 543 { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 if (callback) | 579 if (callback) |
| 586 callback(new Page(tab)); | 580 callback(new Page(tab)); |
| 587 } | 581 } |
| 588 else | 582 else |
| 589 { | 583 { |
| 590 ext.pages.open(optionsUrl, callback); | 584 ext.pages.open(optionsUrl, callback); |
| 591 } | 585 } |
| 592 }); | 586 }); |
| 593 }); | 587 }); |
| 594 }; | 588 }; |
| 595 | |
| 596 | |
| 597 /* Devtools panel */ | |
| 598 | |
| 599 var Panel = function(inspectedTabId, port) | |
| 600 { | |
| 601 this.inspectedTabId = inspectedTabId; | |
| 602 this._port = port; | |
| 603 }; | |
| 604 Panel.prototype = { | |
| 605 sendMessage: function(message) | |
| 606 { | |
| 607 this._port.postMessage(message); | |
| 608 }, | |
| 609 get onRemoved() | |
| 610 { | |
| 611 return this._port.onDisconnect; | |
| 612 } | |
| 613 }; | |
| 614 | |
| 615 ext.devtools = { | |
| 616 onCreated: new ext._EventTarget() | |
| 617 }; | |
| 618 | |
| 619 // If this code should ever be removed, note that we still have to | |
| 620 // ensure that there is at least one listener for the onConnect event. | |
| 621 // Otherwise we can't connect a port later, in order to detect when | |
| 622 // the extension is reloaded,disabled or uninstalled. | |
| 623 chrome.runtime.onConnect.addListener(function(port) | |
| 624 { | |
| 625 var match = port.name.match(/^devtools-(\d+)$/); | |
| 626 if (match) | |
| 627 { | |
| 628 var panel = new Panel(parseInt(match[1], 10), port); | |
| 629 ext.devtools.onCreated._dispatch(panel); | |
| 630 } | |
| 631 }); | |
| 632 })(); | 589 })(); |
| LEFT | RIGHT |