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: Pass boolean instead of object Created Sept. 8, 2017, 12:50 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 // We don't use runtime.openOptionsPage on Firefox for Android because
696 // we have a different options page for mobile.
697 info.application != "fennec")
Sebastian Noack 2017/09/11 22:40:02 Does this change still make sense? We open options
Manish Jethani 2017/09/12 12:39:18 You're right, now we can just use runtime.openOpti
698 {
699 if (!callback)
700 {
701 chrome.runtime.openOptionsPage();
702 }
703 else
704 {
705 chrome.runtime.openOptionsPage(() =>
706 {
707 if (chrome.runtime.lastError)
708 return;
709
710 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
711 {
712 if (tabs.length > 0)
713 {
714 if (tabs[0].status == "complete")
715 callback(new Page(tabs[0]));
716 else
717 afterTabLoaded(callback)(tabs[0]);
718 }
719 });
720 });
721 }
722 }
723 else
724 {
725 // Edge does not yet support runtime.openOptionsPage (tested version 38)
726 let optionsUrl = "options.html";
727
728 chrome.tabs.query({}, tabs =>
729 {
730 // We find a tab ourselves because Edge has a bug when quering tabs
731 // with extension URL protocol:
732 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8094141/
733 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8604703/
734 // Firefox won't let us query for moz-extension:// pages either, though
735 // starting with Firefox 56 an extension can query for its own URLs:
736 // https://bugzilla.mozilla.org/show_bug.cgi?id=1271354
737 let fullOptionsUrl = ext.getURL(optionsUrl);
738 let tab = tabs.find(element => element.url == fullOptionsUrl);
739 if (tab)
740 {
741 // Firefox for Android doesn't support the windows API, and the
742 // mobile browser has only one window anyway.
743 if ("windows" in chrome)
744 chrome.windows.update(tab.windowId, {focused: true});
745
746 chrome.tabs.update(tab.id, {active: true});
747
748 if (callback)
749 callback(new Page(tab));
750 }
751 else
752 {
753 // We don't use fullOptionsUrl here because of this Edge issue:
754 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issue s/10276332
755 ext.pages.open(optionsUrl, callback);
756 }
757 });
758 }
759 };
760
761 /* Windows */ 696 /* Windows */
762 ext.windows = { 697 ext.windows = {
763 create(createData, callback) 698 create(createData, callback)
764 { 699 {
765 chrome.windows.create(createData, createdWindow => 700 chrome.windows.create(createData, createdWindow =>
766 { 701 {
767 afterTabLoaded(callback)(createdWindow.tabs[0]); 702 afterTabLoaded(callback)(createdWindow.tabs[0]);
768 }); 703 });
769 } 704 }
770 }; 705 };
771 }()); 706 }());
LEFTRIGHT

Powered by Google App Engine
This is Rietveld