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

Side by Side Diff: ext/background.js

Issue 29536764: Issue 5587, 5748 - Use mobile options page on Firefox for Android (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Remove workaround for FOUC issue and update adblockplusui dependency Created Oct. 5, 2017, 1:24 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
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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
330 let BrowserAction = function(tabId) 320 let BrowserAction = function(tabId)
331 { 321 {
332 this._tabId = tabId; 322 this._tabId = tabId;
333 this._changes = null; 323 this._changes = null;
334 }; 324 };
335 BrowserAction.prototype = { 325 BrowserAction.prototype = {
336 _applyChanges() 326 _applyChanges()
337 { 327 {
338 if ("iconPath" in this._changes) 328 if ("iconPath" in this._changes)
339 { 329 {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 items[key] = value; 686 items[key] = value;
697 chrome.storage.local.set(items, callback); 687 chrome.storage.local.set(items, callback);
698 }, 688 },
699 remove(key, callback) 689 remove(key, callback)
700 { 690 {
701 chrome.storage.local.remove(key, callback); 691 chrome.storage.local.remove(key, callback);
702 }, 692 },
703 onChanged: chrome.storage.onChanged 693 onChanged: chrome.storage.onChanged
704 }; 694 };
705 695
706 /* Options */
707
708 ext.showOptions = callback =>
709 {
710 let info = require("info");
711
712 if ("openOptionsPage" in chrome.runtime &&
713 // Some versions of Firefox for Android before version 57 do have a
714 // runtime.openOptionsPage but it doesn't do anything.
715 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945
716 (info.application != "fennec" ||
717 parseInt(info.applicationVersion, 10) >= 57))
718 {
719 if (!callback)
720 {
721 chrome.runtime.openOptionsPage();
722 }
723 else
724 {
725 chrome.runtime.openOptionsPage(() =>
726 {
727 if (chrome.runtime.lastError)
728 return;
729
730 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
731 {
732 if (tabs.length > 0)
733 {
734 if (tabs[0].status == "complete")
735 callback(new Page(tabs[0]));
736 else
737 afterTabLoaded(callback)(tabs[0]);
738 }
739 });
740 });
741 }
742 }
743 else if ("windows" in chrome)
744 {
745 // Edge does not yet support runtime.openOptionsPage (tested version 38)
746 // and so this workaround needs to stay for now.
747 // We are not using extension.getURL to get the absolute path here
748 // because of the Edge issue:
749 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10 276332/
750 let optionsUrl = "options.html";
751 let fullOptionsUrl = ext.getURL(optionsUrl);
752
753 chrome.tabs.query({}, tabs =>
754 {
755 // We find a tab ourselves because Edge has a bug when quering tabs
756 // with extension URL protocol:
757 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8094141/
758 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8604703/
759 let tab = tabs.find(element => element.url == fullOptionsUrl);
760 if (tab)
761 {
762 chrome.windows.update(tab.windowId, {focused: true});
763 chrome.tabs.update(tab.id, {active: true});
764
765 if (callback)
766 callback(new Page(tab));
767 }
768 else
769 {
770 ext.pages.open(optionsUrl, callback);
771 }
772 });
773 }
774 else
775 {
776 // Firefox for Android before version 57 does not support
777 // runtime.openOptionsPage, nor does it support the windows API. Since
778 // there is effectively only one window on the mobile browser, there's no
779 // need to bring it into focus.
780 ext.pages.open("options.html", callback);
781 }
782 };
783
784 /* Windows */ 696 /* Windows */
785 ext.windows = { 697 ext.windows = {
786 create(createData, callback) 698 create(createData, callback)
787 { 699 {
788 chrome.windows.create(createData, createdWindow => 700 chrome.windows.create(createData, createdWindow =>
789 { 701 {
790 afterTabLoaded(callback)(createdWindow.tabs[0]); 702 afterTabLoaded(callback)(createdWindow.tabs[0]);
791 }); 703 });
792 } 704 }
793 }; 705 };
794 }()); 706 }());
OLDNEW
« no previous file with comments | « desktop-options.js ('k') | lib/notificationHelper.js » ('j') | options.js » ('J')

Powered by Google App Engine
This is Rietveld