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

Side by Side Diff: ext/background.js

Issue 29516684: Issue 5347 - Open options page on Firefox for Android when browser action is clicked (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Aug. 16, 2017, 12:38 a.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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 chrome.tabs.onRemoved.addListener(forgetTab); 310 chrome.tabs.onRemoved.addListener(forgetTab);
311 311
312 chrome.tabs.onActivated.addListener(details => 312 chrome.tabs.onActivated.addListener(details =>
313 { 313 {
314 ext.pages.onActivated._dispatch(new Page({id: details.tabId})); 314 ext.pages.onActivated._dispatch(new Page({id: details.tabId}));
315 }); 315 });
316 316
317 317
318 /* Browser actions */ 318 /* Browser actions */
319 319
320 // On Firefox for Android, open the options page directly when the browser
321 // action is clicked.
322 if (!("getPopup" in chrome.browserAction))
Manish Jethani 2017/08/16 00:44:45 We're checking for browserAction.getPopup, i.e. wh
323 {
324 chrome.browserAction.onClicked.addListener(() =>
325 {
326 ext.showOptions();
327 });
328 }
329
320 let BrowserAction = function(tabId) 330 let BrowserAction = function(tabId)
321 { 331 {
322 this._tabId = tabId; 332 this._tabId = tabId;
323 this._changes = null; 333 this._changes = null;
324 }; 334 };
325 BrowserAction.prototype = { 335 BrowserAction.prototype = {
326 _applyChanges() 336 _applyChanges()
327 { 337 {
328 if ("iconPath" in this._changes) 338 if ("iconPath" in this._changes)
329 { 339 {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 }, 668 },
659 remove(key, callback) 669 remove(key, callback)
660 { 670 {
661 chrome.storage.local.remove(key, callback); 671 chrome.storage.local.remove(key, callback);
662 }, 672 },
663 onChanged: chrome.storage.onChanged 673 onChanged: chrome.storage.onChanged
664 }; 674 };
665 675
666 /* Options */ 676 /* Options */
667 677
668 if ("openOptionsPage" in chrome.runtime) 678 ext.showOptions = callback =>
Manish Jethani 2017/08/16 00:44:44 Note that now it's one function with the if...else
669 { 679 {
670 ext.showOptions = callback => 680 let {application} = require("info");
681
682 if ("openOptionsPage" in chrome.runtime &&
683 // Firefox for Android does have a runtime.openOptionsPage but it
684 // doesn't do anything.
685 application && application != "unknown" &&
686 application != "fennec")
Wladimir Palant 2017/08/17 12:21:21 This value comes from browser's internal data, not
Manish Jethani 2017/08/17 13:21:26 This information is fetched asynchronously, it may
Sebastian Noack 2017/08/18 10:13:47 The functionality here is triggered by user intera
Manish Jethani 2017/08/18 14:20:30 This can be mitigated by adding an additional chec
671 { 687 {
672 if (!callback) 688 if (!callback)
673 { 689 {
674 chrome.runtime.openOptionsPage(); 690 chrome.runtime.openOptionsPage();
675 } 691 }
676 else 692 else
677 { 693 {
678 chrome.runtime.openOptionsPage(() => 694 chrome.runtime.openOptionsPage(() =>
679 { 695 {
680 if (chrome.runtime.lastError) 696 if (chrome.runtime.lastError)
Manish Jethani 2017/08/18 14:20:30 Shouldn't this still call the callback even though
Wladimir Palant 2017/08/18 21:03:35 Yes, we could easily do that if we start returning
681 return; 697 return;
682 698
683 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => 699 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
684 { 700 {
685 if (tabs.length > 0) 701 if (tabs.length > 0)
686 { 702 {
687 if (tabs[0].status == "complete") 703 if (tabs[0].status == "complete")
688 callback(new Page(tabs[0])); 704 callback(new Page(tabs[0]));
689 else 705 else
690 afterTabLoaded(callback)(tabs[0]); 706 afterTabLoaded(callback)(tabs[0]);
691 } 707 }
692 }); 708 });
693 }); 709 });
694 } 710 }
695 }; 711 }
696 } 712 else
697 else
698 {
699 // Edge does not yet support runtime.openOptionsPage (tested version 38)
700 // and so this workaround needs to stay for now.
701 // We are not using extension.getURL to get the absolute path here
702 // because of the Edge issue:
703 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/1027 6332/
704 ext.showOptions = callback =>
705 { 713 {
714 // Edge does not yet support runtime.openOptionsPage (tested version 38)
715 // nor does Firefox for Android,
716 // and so this workaround needs to stay for now.
717 // We are not using extension.getURL to get the absolute path here
718 // because of the Edge issue:
719 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10 276332/
706 chrome.windows.getLastFocused(win => 720 chrome.windows.getLastFocused(win =>
707 { 721 {
708 let optionsUrl = "options.html"; 722 let optionsUrl = "options.html";
709 let queryInfo = {url: optionsUrl}; 723 let queryInfo = {url: optionsUrl};
710 724
711 // extension pages can't be accessed in incognito windows. In order to 725 // extension pages can't be accessed in incognito windows. In order to
712 // correctly mimic the way in which Chrome opens extension options, 726 // correctly mimic the way in which Chrome opens extension options,
713 // we have to focus the options page in any other window. 727 // we have to focus the options page in any other window.
714 if (!win.incognito) 728 if (!win.incognito)
715 queryInfo.windowId = win.id; 729 queryInfo.windowId = win.id;
716 730
717 chrome.tabs.query(queryInfo, tabs => 731 chrome.tabs.query(queryInfo, tabs =>
718 { 732 {
719 if (tabs.length > 0) 733 if (tabs && tabs.length > 0)
Manish Jethani 2017/08/16 00:44:44 Firefox returns null instead of an empty array.
720 { 734 {
721 let tab = tabs[0]; 735 let tab = tabs[0];
722 736
723 chrome.windows.update(tab.windowId, {focused: true}); 737 chrome.windows.update(tab.windowId, {focused: true});
724 chrome.tabs.update(tab.id, {active: true}); 738 chrome.tabs.update(tab.id, {active: true});
725 739
726 if (callback) 740 if (callback)
727 callback(new Page(tab)); 741 callback(new Page(tab));
728 } 742 }
729 else 743 else
730 { 744 {
731 ext.pages.open(optionsUrl, callback); 745 ext.pages.open(optionsUrl, callback);
732 } 746 }
733 }); 747 });
734 }); 748 });
735 }; 749 }
736 } 750 };
737 751
738 /* Windows */ 752 /* Windows */
739 ext.windows = { 753 ext.windows = {
740 create(createData, callback) 754 create(createData, callback)
741 { 755 {
742 chrome.windows.create(createData, createdWindow => 756 chrome.windows.create(createData, createdWindow =>
743 { 757 {
744 afterTabLoaded(callback)(createdWindow.tabs[0]); 758 afterTabLoaded(callback)(createdWindow.tabs[0]);
745 }); 759 });
746 } 760 }
747 }; 761 };
748 }()); 762 }());
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