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: Created Sept. 6, 2017, 1:05 a.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 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))
Sebastian Noack 2017/09/06 03:17:12 Is this check still correct? We don't want the pop
Manish Jethani 2017/09/06 10:32:22 You're right, this check is not correct. We don't
323 { 323 {
324 chrome.browserAction.onClicked.addListener(() => 324 chrome.browserAction.onClicked.addListener(() =>
325 { 325 {
326 ext.showOptions(); 326 ext.pages.query({active: true, lastFocusedWindow: true}, pages =>
327 {
328 let currentPage = pages[0];
329
330 ext.showOptions(optionsPage =>
331 {
332 if (!currentPage.url ||
333 currentPage.url.toString() == optionsPage.url.toString())
Manish Jethani 2017/09/06 01:12:12 Do nothing if the options page is opened from the
Sebastian Noack 2017/09/06 03:17:12 I wonder whether this should rather be handled by
Manish Jethani 2017/09/06 10:32:22 Perhaps that's a better idea.
Manish Jethani 2017/09/07 11:04:16 Done.
334 {
335 return;
336 }
337
338 optionsPage.sendMessage({
339 type: "app.respond",
340 action: "showPageOptions",
341 args: [
342 {
343 host: currentPage.url.hostname,
344 whitelisted: require("whitelisting")
Manish Jethani 2017/09/06 01:12:12 require is not available at the time of initializa
Sebastian Noack 2017/09/06 03:17:12 Which raises the question, why is this code inside
Manish Jethani 2017/09/06 10:32:22 Makes sense. Do you think this should be a new mo
Sebastian Noack 2017/09/07 02:53:38 No strong opinion. Though, another option would be
Manish Jethani 2017/09/07 11:04:16 Done. I've moved it to lib/browserAction.js now.
345 .checkWhitelisted(currentPage)
Thomas Greiner 2017/09/06 12:40:03 Looking at the desktop equivalent of this feature
Thomas Greiner 2017/09/06 13:06:34 FYI: I've created a spec ticket to get the Product
Manish Jethani 2017/09/07 11:12:55 I'm not sure I understand. The difference between
Thomas Greiner 2017/09/13 14:56:29 It checks whether the page is whitelisted, not the
346 }
347 ]
348 });
349 });
350 });
327 }); 351 });
328 } 352 }
329 353
330 let BrowserAction = function(tabId) 354 let BrowserAction = function(tabId)
331 { 355 {
332 this._tabId = tabId; 356 this._tabId = tabId;
333 this._changes = null; 357 this._changes = null;
334 }; 358 };
335 BrowserAction.prototype = { 359 BrowserAction.prototype = {
336 _applyChanges() 360 _applyChanges()
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 onChanged: chrome.storage.onChanged 719 onChanged: chrome.storage.onChanged
696 }; 720 };
697 721
698 /* Options */ 722 /* Options */
699 723
700 ext.showOptions = callback => 724 ext.showOptions = callback =>
701 { 725 {
702 let info = require("info"); 726 let info = require("info");
703 727
704 if ("openOptionsPage" in chrome.runtime && 728 if ("openOptionsPage" in chrome.runtime &&
705 // Some versions of Firefox for Android before version 57 do have a 729 // We don't use runtime.openOptionsPage on Firefox for Android because
Manish Jethani 2017/09/06 01:12:12 There's no longer any need to mention this stuff a
Sebastian Noack 2017/09/06 03:17:12 Hmm, the "options_ui.page" given in manifest.json,
Manish Jethani 2017/09/06 10:32:22 This is a difficult one. Our options are to have a
Thomas Greiner 2017/09/06 12:40:02 I've been wondering about that too but couldn't co
Sebastian Noack 2017/09/07 02:53:38 How about having the default options page embed th
Sebastian Noack 2017/09/07 16:36:45 What about this? I would be open for other suggest
706 // runtime.openOptionsPage but it doesn't do anything. 730 // we have a different options page for mobile.
707 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945 731 info.application != "fennec")
708 (info.application != "fennec" ||
709 parseInt(info.applicationVersion, 10) >= 57))
710 { 732 {
711 if (!callback) 733 if (!callback)
712 { 734 {
713 chrome.runtime.openOptionsPage(); 735 chrome.runtime.openOptionsPage();
714 } 736 }
715 else 737 else
716 { 738 {
717 chrome.runtime.openOptionsPage(() => 739 chrome.runtime.openOptionsPage(() =>
718 { 740 {
719 if (chrome.runtime.lastError) 741 if (chrome.runtime.lastError)
720 return; 742 return;
721 743
722 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => 744 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
723 { 745 {
724 if (tabs.length > 0) 746 if (tabs.length > 0)
725 { 747 {
726 if (tabs[0].status == "complete") 748 if (tabs[0].status == "complete")
727 callback(new Page(tabs[0])); 749 callback(new Page(tabs[0]));
728 else 750 else
729 afterTabLoaded(callback)(tabs[0]); 751 afterTabLoaded(callback)(tabs[0]);
730 } 752 }
731 }); 753 });
732 }); 754 });
733 } 755 }
734 } 756 }
735 else if ("windows" in chrome) 757 else
Manish Jethani 2017/09/06 01:12:12 Now this code is used for Firefox for Android as w
736 { 758 {
737 // Edge does not yet support runtime.openOptionsPage (tested version 38) 759 // Edge does not yet support runtime.openOptionsPage (tested version 38)
738 // and so this workaround needs to stay for now.
Manish Jethani 2017/09/06 01:12:12 Removed this part of the comment since this is no
739 // We are not using extension.getURL to get the absolute path here
740 // because of the Edge issue:
741 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10 276332/
742 let optionsUrl = "options.html"; 760 let optionsUrl = "options.html";
743 let fullOptionsUrl = ext.getURL(optionsUrl); 761
762 // Firefox for Android has its own options page.
763 if (info.application == "fennec")
764 optionsUrl = "mobile-options.html";
744 765
745 chrome.tabs.query({}, tabs => 766 chrome.tabs.query({}, tabs =>
746 { 767 {
747 // We find a tab ourselves because Edge has a bug when quering tabs 768 // We find a tab ourselves because Edge has a bug when quering tabs
748 // with extension URL protocol: 769 // with extension URL protocol:
749 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8094141/ 770 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8094141/
750 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8604703/ 771 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8604703/
772 // Firefox won't let us query for moz-extension:// pages either:
Thomas Greiner 2017/09/06 12:40:02 Detail: It's worth mentioning that this has been f
Manish Jethani 2017/09/07 11:04:16 Done.
773 // https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Match_patte rns
774 let fullOptionsUrl = ext.getURL(optionsUrl);
751 let tab = tabs.find(element => element.url == fullOptionsUrl); 775 let tab = tabs.find(element => element.url == fullOptionsUrl);
752 if (tab) 776 if (tab)
753 { 777 {
754 chrome.windows.update(tab.windowId, {focused: true}); 778 // Firefox for Android doesn't support the windows API, and the
779 // mobile browser has only one window anyway.
780 if ("windows" in chrome)
781 chrome.windows.update(tab.windowId, {focused: true});
782
755 chrome.tabs.update(tab.id, {active: true}); 783 chrome.tabs.update(tab.id, {active: true});
756 784
757 if (callback) 785 if (callback)
758 callback(new Page(tab)); 786 callback(new Page(tab));
759 } 787 }
760 else 788 else
761 { 789 {
762 ext.pages.open(optionsUrl, callback); 790 ext.pages.open(optionsUrl, callback);
Oleksandr 2017/09/06 02:51:58 Maybe add a comment above this line why we are not
Manish Jethani 2017/09/06 10:32:22 Acknowledged.
Manish Jethani 2017/09/07 11:04:16 Done.
763 } 791 }
764 }); 792 });
765 } 793 }
766 else
767 {
768 // Firefox for Android before version 57 does not support
769 // runtime.openOptionsPage, nor does it support the windows API. Since
770 // there is effectively only one window on the mobile browser, there's no
771 // need to bring it into focus.
772 ext.pages.open("options.html", callback);
773 }
774 }; 794 };
775 795
776 /* Windows */ 796 /* Windows */
777 ext.windows = { 797 ext.windows = {
778 create(createData, callback) 798 create(createData, callback)
779 { 799 {
780 chrome.windows.create(createData, createdWindow => 800 chrome.windows.create(createData, createdWindow =>
781 { 801 {
782 afterTabLoaded(callback)(createdWindow.tabs[0]); 802 afterTabLoaded(callback)(createdWindow.tabs[0]);
783 }); 803 });
784 } 804 }
785 }; 805 };
786 }()); 806 }());
OLDNEW
« dependencies ('K') | « dependencies ('k') | metadata.gecko-webext » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld