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: Remove unnecessary variable and add link to bug Created Aug. 19, 2017, 3:42 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))
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 =>
669 { 679 {
670 ext.showOptions = callback => 680 if ("openOptionsPage" in chrome.runtime &&
681 // Firefox for Android does have a runtime.openOptionsPage but it
682 // doesn't do anything.
683 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945
684 require("info").application != "fennec")
671 { 685 {
672 if (!callback) 686 if (!callback)
673 { 687 {
674 chrome.runtime.openOptionsPage(); 688 chrome.runtime.openOptionsPage();
675 } 689 }
676 else 690 else
677 { 691 {
678 chrome.runtime.openOptionsPage(() => 692 chrome.runtime.openOptionsPage(() =>
679 { 693 {
680 if (chrome.runtime.lastError) 694 if (chrome.runtime.lastError)
681 return; 695 return;
682 696
683 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => 697 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
684 { 698 {
685 if (tabs.length > 0) 699 if (tabs.length > 0)
686 { 700 {
687 if (tabs[0].status == "complete") 701 if (tabs[0].status == "complete")
688 callback(new Page(tabs[0])); 702 callback(new Page(tabs[0]));
689 else 703 else
690 afterTabLoaded(callback)(tabs[0]); 704 afterTabLoaded(callback)(tabs[0]);
691 } 705 }
692 }); 706 });
693 }); 707 });
694 } 708 }
695 }; 709 }
696 } 710 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 { 711 {
712 // Edge does not yet support runtime.openOptionsPage (tested version 38)
713 // nor does Firefox for Android,
714 // and so this workaround needs to stay for now.
715 // We are not using extension.getURL to get the absolute path here
716 // because of the Edge issue:
717 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10 276332/
706 chrome.windows.getLastFocused(win => 718 chrome.windows.getLastFocused(win =>
707 { 719 {
708 let optionsUrl = "options.html"; 720 let optionsUrl = "options.html";
709 let queryInfo = {url: optionsUrl}; 721 let queryInfo = {url: optionsUrl};
710 722
711 // extension pages can't be accessed in incognito windows. In order to 723 // extension pages can't be accessed in incognito windows. In order to
712 // correctly mimic the way in which Chrome opens extension options, 724 // correctly mimic the way in which Chrome opens extension options,
713 // we have to focus the options page in any other window. 725 // we have to focus the options page in any other window.
714 if (!win.incognito) 726 if (!win.incognito)
715 queryInfo.windowId = win.id; 727 queryInfo.windowId = win.id;
716 728
717 chrome.tabs.query(queryInfo, tabs => 729 chrome.tabs.query(queryInfo, tabs =>
718 { 730 {
719 if (tabs.length > 0) 731 if (tabs && tabs.length > 0)
720 { 732 {
721 let tab = tabs[0]; 733 let tab = tabs[0];
722 734
723 chrome.windows.update(tab.windowId, {focused: true}); 735 chrome.windows.update(tab.windowId, {focused: true});
724 chrome.tabs.update(tab.id, {active: true}); 736 chrome.tabs.update(tab.id, {active: true});
725 737
726 if (callback) 738 if (callback)
727 callback(new Page(tab)); 739 callback(new Page(tab));
728 } 740 }
729 else 741 else
730 { 742 {
731 ext.pages.open(optionsUrl, callback); 743 ext.pages.open(optionsUrl, callback);
732 } 744 }
733 }); 745 });
734 }); 746 });
735 }; 747 }
736 } 748 };
737 749
738 /* Windows */ 750 /* Windows */
739 ext.windows = { 751 ext.windows = {
740 create(createData, callback) 752 create(createData, callback)
741 { 753 {
742 chrome.windows.create(createData, createdWindow => 754 chrome.windows.create(createData, createdWindow =>
743 { 755 {
744 afterTabLoaded(callback)(createdWindow.tabs[0]); 756 afterTabLoaded(callback)(createdWindow.tabs[0]);
745 }); 757 });
746 } 758 }
747 }; 759 };
748 }()); 760 }());
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