| 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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 { | 510 { |
| 511 items.splice(index, 1); | 511 items.splice(index, 1); |
| 512 updateContextMenu(); | 512 updateContextMenu(); |
| 513 } | 513 } |
| 514 } | 514 } |
| 515 } | 515 } |
| 516 }; | 516 }; |
| 517 | 517 |
| 518 chrome.tabs.onActivated.addListener(updateContextMenu); | 518 chrome.tabs.onActivated.addListener(updateContextMenu); |
| 519 | 519 |
| 520 chrome.windows.onFocusChanged.addListener(windowId => | 520 if ("windows" in chrome) |
| 521 { | 521 { |
| 522 if (windowId != chrome.windows.WINDOW_ID_NONE) | 522 chrome.windows.onFocusChanged.addListener(windowId => |
| 523 updateContextMenu(); | 523 { |
| 524 }); | 524 if (windowId != chrome.windows.WINDOW_ID_NONE) |
| 525 updateContextMenu(); |
| 526 }); |
| 527 } |
| 525 | 528 |
| 526 | 529 |
| 527 /* Web requests */ | 530 /* Web requests */ |
| 528 | 531 |
| 529 let framesOfTabs = new Map(); | 532 let framesOfTabs = new Map(); |
| 530 | 533 |
| 531 ext.getFrame = (tabId, frameId) => | 534 ext.getFrame = (tabId, frameId) => |
| 532 { | 535 { |
| 533 let frames = framesOfTabs.get(tabId); | 536 let frames = framesOfTabs.get(tabId); |
| 534 return frames && frames.get(frameId); | 537 return frames && frames.get(frameId); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 } | 730 } |
| 728 } | 731 } |
| 729 else | 732 else |
| 730 { | 733 { |
| 731 // Edge does not yet support runtime.openOptionsPage (tested version 38) | 734 // Edge does not yet support runtime.openOptionsPage (tested version 38) |
| 732 // nor does Firefox for Android, | 735 // nor does Firefox for Android, |
| 733 // and so this workaround needs to stay for now. | 736 // and so this workaround needs to stay for now. |
| 734 // We are not using extension.getURL to get the absolute path here | 737 // We are not using extension.getURL to get the absolute path here |
| 735 // because of the Edge issue: | 738 // because of the Edge issue: |
| 736 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10
276332/ | 739 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10
276332/ |
| 737 chrome.windows.getLastFocused(win => | 740 let open = win => |
| 738 { | 741 { |
| 739 let optionsUrl = "options.html"; | 742 let optionsUrl = "options.html"; |
| 740 let queryInfo = {url: optionsUrl}; | 743 let queryInfo = {url: optionsUrl}; |
| 741 | 744 |
| 742 // extension pages can't be accessed in incognito windows. In order to | 745 // extension pages can't be accessed in incognito windows. In order to |
| 743 // correctly mimic the way in which Chrome opens extension options, | 746 // correctly mimic the way in which Chrome opens extension options, |
| 744 // we have to focus the options page in any other window. | 747 // we have to focus the options page in any other window. |
| 745 if (!win.incognito) | 748 if (win && !win.incognito) |
| 746 queryInfo.windowId = win.id; | 749 queryInfo.windowId = win.id; |
| 747 | 750 |
| 748 chrome.tabs.query(queryInfo, tabs => | 751 chrome.tabs.query(queryInfo, tabs => |
| 749 { | 752 { |
| 750 if (tabs && tabs.length > 0) | 753 if (tabs && tabs.length > 0) |
| 751 { | 754 { |
| 752 let tab = tabs[0]; | 755 let tab = tabs[0]; |
| 753 | 756 |
| 754 chrome.windows.update(tab.windowId, {focused: true}); | 757 if ("windows" in chrome) |
| 758 chrome.windows.update(tab.windowId, {focused: true}); |
| 759 |
| 755 chrome.tabs.update(tab.id, {active: true}); | 760 chrome.tabs.update(tab.id, {active: true}); |
| 756 | 761 |
| 757 if (callback) | 762 if (callback) |
| 758 callback(new Page(tab)); | 763 callback(new Page(tab)); |
| 759 } | 764 } |
| 760 else | 765 else |
| 761 { | 766 { |
| 762 ext.pages.open(optionsUrl, callback); | 767 ext.pages.open(optionsUrl, callback); |
| 763 } | 768 } |
| 764 }); | 769 }); |
| 765 }); | 770 }; |
| 771 |
| 772 if ("windows" in chrome) |
| 773 { |
| 774 chrome.windows.getLastFocused(open); |
| 775 } |
| 776 else |
| 777 { |
| 778 // Firefox for Android does not support the windows API. Since there is |
| 779 // effectively only one window on the mobile browser, there's no need |
| 780 // to bring it into focus. |
| 781 open(); |
| 782 } |
| 766 } | 783 } |
| 767 }; | 784 }; |
| 768 | 785 |
| 769 /* Windows */ | 786 /* Windows */ |
| 770 ext.windows = { | 787 ext.windows = { |
| 771 create(createData, callback) | 788 create(createData, callback) |
| 772 { | 789 { |
| 773 chrome.windows.create(createData, createdWindow => | 790 chrome.windows.create(createData, createdWindow => |
| 774 { | 791 { |
| 775 afterTabLoaded(callback)(createdWindow.tabs[0]); | 792 afterTabLoaded(callback)(createdWindow.tabs[0]); |
| 776 }); | 793 }); |
| 777 } | 794 } |
| 778 }; | 795 }; |
| 779 }()); | 796 }()); |
| OLD | NEW |