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

Delta Between Two Patch Sets: 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/
Left Patch Set: Created Aug. 16, 2017, 12:38 a.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 320 // On Firefox for Android, open the options page directly when the browser
321 // action is clicked. 321 // action is clicked.
322 if (!("getPopup" in chrome.browserAction)) 322 if (!("getPopup" in chrome.browserAction))
Manish Jethani 2017/08/16 00:44:45 We're checking for browserAction.getPopup, i.e. wh
323 { 323 {
324 chrome.browserAction.onClicked.addListener(() => 324 chrome.browserAction.onClicked.addListener(() =>
325 { 325 {
326 ext.showOptions(); 326 ext.showOptions();
327 }); 327 });
328 } 328 }
329 329
330 let BrowserAction = function(tabId) 330 let BrowserAction = function(tabId)
331 { 331 {
332 this._tabId = tabId; 332 this._tabId = tabId;
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 }, 668 },
669 remove(key, callback) 669 remove(key, callback)
670 { 670 {
671 chrome.storage.local.remove(key, callback); 671 chrome.storage.local.remove(key, callback);
672 }, 672 },
673 onChanged: chrome.storage.onChanged 673 onChanged: chrome.storage.onChanged
674 }; 674 };
675 675
676 /* Options */ 676 /* Options */
677 677
678 ext.showOptions = callback => 678 ext.showOptions = callback =>
Manish Jethani 2017/08/16 00:44:44 Note that now it's one function with the if...else
679 { 679 {
680 let {application} = require("info");
681
682 if ("openOptionsPage" in chrome.runtime && 680 if ("openOptionsPage" in chrome.runtime &&
683 // Firefox for Android does have a runtime.openOptionsPage but it 681 // Firefox for Android does have a runtime.openOptionsPage but it
684 // doesn't do anything. 682 // doesn't do anything.
685 application && application != "unknown" && 683 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945
686 application != "fennec") 684 require("info").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
687 { 685 {
688 if (!callback) 686 if (!callback)
689 { 687 {
690 chrome.runtime.openOptionsPage(); 688 chrome.runtime.openOptionsPage();
691 } 689 }
692 else 690 else
693 { 691 {
694 chrome.runtime.openOptionsPage(() => 692 chrome.runtime.openOptionsPage(() =>
695 { 693 {
696 if (chrome.runtime.lastError) 694 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
697 return; 695 return;
698 696
699 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => 697 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
700 { 698 {
701 if (tabs.length > 0) 699 if (tabs.length > 0)
702 { 700 {
703 if (tabs[0].status == "complete") 701 if (tabs[0].status == "complete")
704 callback(new Page(tabs[0])); 702 callback(new Page(tabs[0]));
705 else 703 else
706 afterTabLoaded(callback)(tabs[0]); 704 afterTabLoaded(callback)(tabs[0]);
(...skipping 16 matching lines...) Expand all
723 let queryInfo = {url: optionsUrl}; 721 let queryInfo = {url: optionsUrl};
724 722
725 // 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
726 // correctly mimic the way in which Chrome opens extension options, 724 // correctly mimic the way in which Chrome opens extension options,
727 // we have to focus the options page in any other window. 725 // we have to focus the options page in any other window.
728 if (!win.incognito) 726 if (!win.incognito)
729 queryInfo.windowId = win.id; 727 queryInfo.windowId = win.id;
730 728
731 chrome.tabs.query(queryInfo, tabs => 729 chrome.tabs.query(queryInfo, tabs =>
732 { 730 {
733 if (tabs && tabs.length > 0) 731 if (tabs && tabs.length > 0)
Manish Jethani 2017/08/16 00:44:44 Firefox returns null instead of an empty array.
734 { 732 {
735 let tab = tabs[0]; 733 let tab = tabs[0];
736 734
737 chrome.windows.update(tab.windowId, {focused: true}); 735 chrome.windows.update(tab.windowId, {focused: true});
738 chrome.tabs.update(tab.id, {active: true}); 736 chrome.tabs.update(tab.id, {active: true});
739 737
740 if (callback) 738 if (callback)
741 callback(new Page(tab)); 739 callback(new Page(tab));
742 } 740 }
743 else 741 else
744 { 742 {
745 ext.pages.open(optionsUrl, callback); 743 ext.pages.open(optionsUrl, callback);
746 } 744 }
747 }); 745 });
748 }); 746 });
749 } 747 }
750 }; 748 };
751 749
752 /* Windows */ 750 /* Windows */
753 ext.windows = { 751 ext.windows = {
754 create(createData, callback) 752 create(createData, callback)
755 { 753 {
756 chrome.windows.create(createData, createdWindow => 754 chrome.windows.create(createData, createdWindow =>
757 { 755 {
758 afterTabLoaded(callback)(createdWindow.tabs[0]); 756 afterTabLoaded(callback)(createdWindow.tabs[0]);
759 }); 757 });
760 } 758 }
761 }; 759 };
762 }()); 760 }());
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld