Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: ext/background.js

Issue 29516569: Issue 5347 - Check for windows API support (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Aug. 15, 2017, 2:08 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 { 481 {
482 items.splice(index, 1); 482 items.splice(index, 1);
483 updateContextMenu(); 483 updateContextMenu();
484 } 484 }
485 } 485 }
486 } 486 }
487 }; 487 };
488 488
489 chrome.tabs.onActivated.addListener(updateContextMenu); 489 chrome.tabs.onActivated.addListener(updateContextMenu);
490 490
491 chrome.windows.onFocusChanged.addListener(windowId => 491 if ("windows" in chrome)
492 { 492 {
493 if (windowId != chrome.windows.WINDOW_ID_NONE) 493 chrome.windows.onFocusChanged.addListener(windowId =>
494 updateContextMenu(); 494 {
495 }); 495 if (windowId != chrome.windows.WINDOW_ID_NONE)
496 updateContextMenu();
497 });
498 }
496 499
497 500
498 /* Web requests */ 501 /* Web requests */
499 502
500 let framesOfTabs = new Map(); 503 let framesOfTabs = new Map();
501 504
502 ext.getFrame = (tabId, frameId) => 505 ext.getFrame = (tabId, frameId) =>
503 { 506 {
504 let frames = framesOfTabs.get(tabId); 507 let frames = framesOfTabs.get(tabId);
505 return frames && frames.get(frameId); 508 return frames && frames.get(frameId);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 else 692 else
690 afterTabLoaded(callback)(tabs[0]); 693 afterTabLoaded(callback)(tabs[0]);
691 } 694 }
692 }); 695 });
693 }); 696 });
694 } 697 }
695 }; 698 };
696 } 699 }
697 else 700 else
698 { 701 {
699 // Edge does not yet support runtime.openOptionsPage (tested version 38) 702 // Edge does not yet support runtime.openOptionsPage (tested version 38)
Sebastian Noack 2017/08/15 14:40:19 This comment should be updated, also mentioning Fi
Manish Jethani 2017/08/15 16:24:12 I'm going to make another change for runtime.openO
700 // and so this workaround needs to stay for now. 703 // and so this workaround needs to stay for now.
701 // We are not using extension.getURL to get the absolute path here 704 // We are not using extension.getURL to get the absolute path here
702 // because of the Edge issue: 705 // because of the Edge issue:
703 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/1027 6332/ 706 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/1027 6332/
704 ext.showOptions = callback => 707 ext.showOptions = callback =>
705 { 708 {
706 chrome.windows.getLastFocused(win => 709 let optionsUrl = "options.html";
710 let queryInfo = {url: optionsUrl};
711
712 let open = win =>
707 { 713 {
708 let optionsUrl = "options.html";
709 let queryInfo = {url: optionsUrl};
710
711 // extension pages can't be accessed in incognito windows. In order to 714 // extension pages can't be accessed in incognito windows. In order to
712 // correctly mimic the way in which Chrome opens extension options, 715 // correctly mimic the way in which Chrome opens extension options,
713 // we have to focus the options page in any other window. 716 // we have to focus the options page in any other window.
714 if (!win.incognito) 717 if (win && !win.incognito)
715 queryInfo.windowId = win.id; 718 queryInfo.windowId = win.id;
716 719
717 chrome.tabs.query(queryInfo, tabs => 720 chrome.tabs.query(queryInfo, tabs =>
718 { 721 {
719 if (tabs.length > 0) 722 if (tabs.length > 0)
720 { 723 {
721 let tab = tabs[0]; 724 let tab = tabs[0];
722 725
723 chrome.windows.update(tab.windowId, {focused: true}); 726 if ("windows" in chrome)
727 chrome.windows.update(tab.windowId, {focused: true});
728
724 chrome.tabs.update(tab.id, {active: true}); 729 chrome.tabs.update(tab.id, {active: true});
725 730
726 if (callback) 731 if (callback)
727 callback(new Page(tab)); 732 callback(new Page(tab));
728 } 733 }
729 else 734 else
730 { 735 {
731 ext.pages.open(optionsUrl, callback); 736 ext.pages.open(optionsUrl, callback);
732 } 737 }
733 }); 738 });
734 }); 739 };
740
741 if ("windows" in chrome)
742 chrome.windows.getLastFocused(open);
743 else
744 open();
735 }; 745 };
736 } 746 }
737 747
738 /* Windows */ 748 /* Windows */
739 ext.windows = { 749 if ("windows" in chrome)
740 create(createData, callback) 750 {
741 { 751 ext.windows = {
Sebastian Noack 2017/08/15 14:40:19 What is about the code using ext.windows? I suppos
Manish Jethani 2017/08/15 16:24:12 ext.windows is only used from lib/filterComposer.j
Sebastian Noack 2017/08/18 10:25:21 I guess we can just leave the code here unchanged
Manish Jethani 2017/08/18 14:09:58 I just checked and the only way ext.windows can be
742 chrome.windows.create(createData, createdWindow => 752 create(createData, callback)
743 { 753 {
744 afterTabLoaded(callback)(createdWindow.tabs[0]); 754 chrome.windows.create(createData, createdWindow =>
745 }); 755 {
746 } 756 afterTabLoaded(callback)(createdWindow.tabs[0]);
747 }; 757 });
758 }
759 };
760 }
748 }()); 761 }());
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld