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