| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 | 69 |
| 70 /* Pages */ | 70 /* Pages */ |
| 71 | 71 |
| 72 let Page = ext.Page = function(tab) | 72 let Page = ext.Page = function(tab) |
| 73 { | 73 { |
| 74 this.id = tab.id; | 74 this.id = tab.id; |
| 75 this._url = tab.url && new URL(tab.url); | 75 this._url = tab.url && new URL(tab.url); |
| 76 | 76 |
| 77 this.browserAction = new BrowserAction(tab.id); | 77 this.browserAction = new BrowserAction(tab.id); |
| 78 this.contextMenus = new ContextMenus(this); | |
| 79 }; | 78 }; |
| 80 Page.prototype = { | 79 Page.prototype = { |
| 81 get url() | 80 get url() |
| 82 { | 81 { |
| 83 // usually our Page objects are created from Chrome's Tab objects, which | 82 // usually our Page objects are created from Chrome's Tab objects, which |
| 84 // provide the url. So we can return the url given in the constructor. | 83 // provide the url. So we can return the url given in the constructor. |
| 85 if (this._url) | 84 if (this._url) |
| 86 return this._url; | 85 return this._url; |
| 87 | 86 |
| 88 // but sometimes we only have the tab id when we create a Page object. | 87 // but sometimes we only have the tab id when we create a Page object. |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 if ("number" in badge) | 415 if ("number" in badge) |
| 417 this._addChange("badgeText", badge.number.toString()); | 416 this._addChange("badgeText", badge.number.toString()); |
| 418 | 417 |
| 419 if ("color" in badge) | 418 if ("color" in badge) |
| 420 this._addChange("badgeColor", badge.color); | 419 this._addChange("badgeColor", badge.color); |
| 421 } | 420 } |
| 422 } | 421 } |
| 423 }; | 422 }; |
| 424 | 423 |
| 425 | 424 |
| 426 /* Context menus */ | |
| 427 | |
| 428 let contextMenuItems = new ext.PageMap(); | |
| 429 let contextMenuUpdating = false; | |
| 430 | |
| 431 let updateContextMenu = () => | |
| 432 { | |
| 433 // Firefox for Android does not support context menus. | |
| 434 // https://bugzilla.mozilla.org/show_bug.cgi?id=1269062 | |
| 435 if (!("contextMenus" in browser) || contextMenuUpdating) | |
| 436 return; | |
| 437 | |
| 438 contextMenuUpdating = true; | |
| 439 | |
| 440 browser.tabs.query({active: true, lastFocusedWindow: true}, tabs => | |
| 441 { | |
| 442 browser.contextMenus.removeAll(() => | |
| 443 { | |
| 444 contextMenuUpdating = false; | |
| 445 | |
| 446 if (tabs.length == 0) | |
| 447 return; | |
| 448 | |
| 449 let items = contextMenuItems.get({id: tabs[0].id}); | |
| 450 | |
| 451 if (!items) | |
| 452 return; | |
| 453 | |
| 454 items.forEach(item => | |
| 455 { | |
| 456 browser.contextMenus.create({ | |
| 457 title: item.title, | |
| 458 contexts: item.contexts, | |
| 459 onclick(info, tab) | |
| 460 { | |
| 461 item.onclick(new Page(tab)); | |
| 462 } | |
| 463 }); | |
| 464 }); | |
| 465 }); | |
| 466 }); | |
| 467 }; | |
| 468 | |
| 469 let ContextMenus = function(page) | |
| 470 { | |
| 471 this._page = page; | |
| 472 }; | |
| 473 ContextMenus.prototype = { | |
| 474 create(item) | |
| 475 { | |
| 476 let items = contextMenuItems.get(this._page); | |
| 477 if (!items) | |
| 478 contextMenuItems.set(this._page, items = []); | |
| 479 | |
| 480 items.push(item); | |
| 481 updateContextMenu(); | |
| 482 }, | |
| 483 remove(item) | |
| 484 { | |
| 485 let items = contextMenuItems.get(this._page); | |
| 486 if (items) | |
| 487 { | |
| 488 let index = items.indexOf(item); | |
| 489 if (index != -1) | |
| 490 { | |
| 491 items.splice(index, 1); | |
| 492 updateContextMenu(); | |
| 493 } | |
| 494 } | |
| 495 } | |
| 496 }; | |
| 497 | |
| 498 browser.tabs.onActivated.addListener(updateContextMenu); | |
| 499 | |
| 500 if ("windows" in browser) | |
| 501 { | |
| 502 browser.windows.onFocusChanged.addListener(windowId => | |
| 503 { | |
| 504 if (windowId != browser.windows.WINDOW_ID_NONE) | |
| 505 updateContextMenu(); | |
| 506 }); | |
| 507 } | |
| 508 | |
| 509 | |
| 510 /* Web requests */ | 425 /* Web requests */ |
| 511 | 426 |
| 512 let framesOfTabs = new Map(); | 427 let framesOfTabs = new Map(); |
| 513 | 428 |
| 514 ext.getFrame = (tabId, frameId) => | 429 ext.getFrame = (tabId, frameId) => |
| 515 { | 430 { |
| 516 let frames = framesOfTabs.get(tabId); | 431 let frames = framesOfTabs.get(tabId); |
| 517 return frames && frames.get(frameId); | 432 return frames && frames.get(frameId); |
| 518 }; | 433 }; |
| 519 | 434 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 return frames.get(0) || null; | 516 return frames.get(0) || null; |
| 602 } | 517 } |
| 603 }; | 518 }; |
| 604 } | 519 } |
| 605 | 520 |
| 606 return ext.onMessage._dispatch( | 521 return ext.onMessage._dispatch( |
| 607 message, sender, sendResponse | 522 message, sender, sendResponse |
| 608 ).includes(true); | 523 ).includes(true); |
| 609 }); | 524 }); |
| 610 } | 525 } |
| OLD | NEW |