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

Delta Between Two Patch Sets: ext/background.js

Issue 29536764: Issue 5587, 5748 - Use mobile options page on Firefox for Android (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Use runtime.openOptionsPage on Firefox 57+ Created Sept. 12, 2017, 12:37 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « desktop-options.js ('k') | lib/notificationHelper.js » ('j') | options.js » ('J')
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-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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 _applyChanges() 326 _applyChanges()
327 { 327 {
328 if ("iconPath" in this._changes) 328 if ("iconPath" in this._changes)
329 { 329 {
330 // Firefox for Android displays the browser action not as an icon but 330 // Firefox for Android displays the browser action not as an icon but
331 // as a menu item. There is no icon, but such an option may be added in 331 // as a menu item. There is no icon, but such an option may be added in
332 // the future. 332 // the future.
333 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746 333 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746
334 if ("setIcon" in chrome.browserAction) 334 if ("setIcon" in chrome.browserAction)
335 { 335 {
336 chrome.browserAction.setIcon({ 336 let path = {
337 tabId: this._tabId, 337 16: this._changes.iconPath.replace("$size", "16"),
338 path: { 338 19: this._changes.iconPath.replace("$size", "19"),
339 16: this._changes.iconPath.replace("$size", "16"), 339 20: this._changes.iconPath.replace("$size", "20"),
340 19: this._changes.iconPath.replace("$size", "19"), 340 32: this._changes.iconPath.replace("$size", "32"),
341 20: this._changes.iconPath.replace("$size", "20"), 341 38: this._changes.iconPath.replace("$size", "38"),
342 32: this._changes.iconPath.replace("$size", "32"), 342 40: this._changes.iconPath.replace("$size", "40")
343 38: this._changes.iconPath.replace("$size", "38"), 343 };
344 40: this._changes.iconPath.replace("$size", "40") 344 try
345 } 345 {
346 }); 346 chrome.browserAction.setIcon({tabId: this._tabId, path});
347 }
348 catch (e)
349 {
350 // Edge throws if passed icon sizes different than 19,20,38,40px.
351 delete path[16];
352 delete path[32];
353 chrome.browserAction.setIcon({tabId: this._tabId, path});
354 }
347 } 355 }
348 } 356 }
349 357
350 if ("badgeText" in this._changes) 358 if ("badgeText" in this._changes)
351 { 359 {
352 // There is no badge on Firefox for Android; the browser action is 360 // There is no badge on Firefox for Android; the browser action is
353 // simply a menu item. 361 // simply a menu item.
354 if ("setBadgeText" in chrome.browserAction) 362 if ("setBadgeText" in chrome.browserAction)
355 { 363 {
356 chrome.browserAction.setBadgeText({ 364 chrome.browserAction.setBadgeText({
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 items[key] = value; 686 items[key] = value;
679 chrome.storage.local.set(items, callback); 687 chrome.storage.local.set(items, callback);
680 }, 688 },
681 remove(key, callback) 689 remove(key, callback)
682 { 690 {
683 chrome.storage.local.remove(key, callback); 691 chrome.storage.local.remove(key, callback);
684 }, 692 },
685 onChanged: chrome.storage.onChanged 693 onChanged: chrome.storage.onChanged
686 }; 694 };
687 695
688 /* Options */
689
690 ext.showOptions = callback =>
691 {
692 let info = require("info");
693
694 if ("openOptionsPage" in chrome.runtime &&
695 // Some versions of Firefox for Android before version 57 do have a
696 // runtime.openOptionsPage but it doesn't do anything.
697 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945
698 (info.application != "fennec" ||
699 parseInt(info.applicationVersion, 10) >= 57))
700 {
701 if (!callback)
702 {
703 chrome.runtime.openOptionsPage();
704 }
705 else
706 {
707 chrome.runtime.openOptionsPage(() =>
708 {
709 if (chrome.runtime.lastError)
710 return;
711
712 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
713 {
714 if (tabs.length > 0)
715 {
716 if (tabs[0].status == "complete")
717 callback(new Page(tabs[0]));
718 else
719 afterTabLoaded(callback)(tabs[0]);
720 }
721 });
722 });
723 }
724 }
725 else if ("windows" in chrome)
726 {
727 // Edge does not yet support runtime.openOptionsPage (tested version 38)
728 // and so this workaround needs to stay for now.
729 let optionsUrl = "options.html";
730
731 chrome.tabs.query({}, tabs =>
732 {
733 // We find a tab ourselves because Edge has a bug when quering tabs
734 // with extension URL protocol:
735 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8094141/
736 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8604703/
737 let fullOptionsUrl = ext.getURL(optionsUrl);
738 let tab = tabs.find(element => element.url == fullOptionsUrl);
739 if (tab)
740 {
741 chrome.windows.update(tab.windowId, {focused: true});
742 chrome.tabs.update(tab.id, {active: true});
743
744 if (callback)
745 callback(new Page(tab));
746 }
747 else
748 {
749 // We don't use fullOptionsUrl here because of this Edge issue:
750 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issue s/10276332
751 ext.pages.open(optionsUrl, callback);
752 }
753 });
754 }
755 else
756 {
757 // Firefox for Android before version 57 does not support
758 // runtime.openOptionsPage, nor does it support the windows API. Since
759 // there is effectively only one window on the mobile browser, there's no
760 // need to bring it into focus.
761 ext.pages.open("options.html", callback);
762 }
763 };
764
765 /* Windows */ 696 /* Windows */
766 ext.windows = { 697 ext.windows = {
767 create(createData, callback) 698 create(createData, callback)
768 { 699 {
769 chrome.windows.create(createData, createdWindow => 700 chrome.windows.create(createData, createdWindow =>
770 { 701 {
771 afterTabLoaded(callback)(createdWindow.tabs[0]); 702 afterTabLoaded(callback)(createdWindow.tabs[0]);
772 }); 703 });
773 } 704 }
774 }; 705 };
775 }()); 706 }());
LEFTRIGHT

Powered by Google App Engine
This is Rietveld