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: Created Sept. 6, 2017, 1:05 a.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 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.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 });
351 });
352 }
353
354 let BrowserAction = function(tabId) 320 let BrowserAction = function(tabId)
355 { 321 {
356 this._tabId = tabId; 322 this._tabId = tabId;
357 this._changes = null; 323 this._changes = null;
358 }; 324 };
359 BrowserAction.prototype = { 325 BrowserAction.prototype = {
360 _applyChanges() 326 _applyChanges()
361 { 327 {
362 if ("iconPath" in this._changes) 328 if ("iconPath" in this._changes)
363 { 329 {
364 // 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
365 // 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
366 // the future. 332 // the future.
367 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746 333 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746
368 if ("setIcon" in chrome.browserAction) 334 if ("setIcon" in chrome.browserAction)
369 { 335 {
370 chrome.browserAction.setIcon({ 336 let path = {
371 tabId: this._tabId, 337 16: this._changes.iconPath.replace("$size", "16"),
372 path: { 338 19: this._changes.iconPath.replace("$size", "19"),
373 16: this._changes.iconPath.replace("$size", "16"), 339 20: this._changes.iconPath.replace("$size", "20"),
374 19: this._changes.iconPath.replace("$size", "19"), 340 32: this._changes.iconPath.replace("$size", "32"),
375 20: this._changes.iconPath.replace("$size", "20"), 341 38: this._changes.iconPath.replace("$size", "38"),
376 32: this._changes.iconPath.replace("$size", "32"), 342 40: this._changes.iconPath.replace("$size", "40")
377 38: this._changes.iconPath.replace("$size", "38"), 343 };
378 40: this._changes.iconPath.replace("$size", "40") 344 try
379 } 345 {
380 }); 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 }
381 } 355 }
382 } 356 }
383 357
384 if ("badgeText" in this._changes) 358 if ("badgeText" in this._changes)
385 { 359 {
386 // 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
387 // simply a menu item. 361 // simply a menu item.
388 if ("setBadgeText" in chrome.browserAction) 362 if ("setBadgeText" in chrome.browserAction)
389 { 363 {
390 chrome.browserAction.setBadgeText({ 364 chrome.browserAction.setBadgeText({
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 items[key] = value; 686 items[key] = value;
713 chrome.storage.local.set(items, callback); 687 chrome.storage.local.set(items, callback);
714 }, 688 },
715 remove(key, callback) 689 remove(key, callback)
716 { 690 {
717 chrome.storage.local.remove(key, callback); 691 chrome.storage.local.remove(key, callback);
718 }, 692 },
719 onChanged: chrome.storage.onChanged 693 onChanged: chrome.storage.onChanged
720 }; 694 };
721 695
722 /* Options */
723
724 ext.showOptions = callback =>
725 {
726 let info = require("info");
727
728 if ("openOptionsPage" in chrome.runtime &&
729 // We don't use runtime.openOptionsPage on Firefox for Android because
730 // we have a different options page for mobile.
731 info.application != "fennec")
732 {
733 if (!callback)
734 {
735 chrome.runtime.openOptionsPage();
736 }
737 else
738 {
739 chrome.runtime.openOptionsPage(() =>
740 {
741 if (chrome.runtime.lastError)
742 return;
743
744 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
745 {
746 if (tabs.length > 0)
747 {
748 if (tabs[0].status == "complete")
749 callback(new Page(tabs[0]));
750 else
751 afterTabLoaded(callback)(tabs[0]);
752 }
753 });
754 });
755 }
756 }
757 else
758 {
759 // Edge does not yet support runtime.openOptionsPage (tested version 38)
760 let optionsUrl = "options.html";
761
762 // Firefox for Android has its own options page.
763 if (info.application == "fennec")
764 optionsUrl = "mobile-options.html";
765
766 chrome.tabs.query({}, tabs =>
767 {
768 // We find a tab ourselves because Edge has a bug when quering tabs
769 // with extension URL protocol:
770 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8094141/
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);
775 let tab = tabs.find(element => element.url == fullOptionsUrl);
776 if (tab)
777 {
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
783 chrome.tabs.update(tab.id, {active: true});
784
785 if (callback)
786 callback(new Page(tab));
787 }
788 else
789 {
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.
791 }
792 });
793 }
794 };
795
796 /* Windows */ 696 /* Windows */
797 ext.windows = { 697 ext.windows = {
798 create(createData, callback) 698 create(createData, callback)
799 { 699 {
800 chrome.windows.create(createData, createdWindow => 700 chrome.windows.create(createData, createdWindow =>
801 { 701 {
802 afterTabLoaded(callback)(createdWindow.tabs[0]); 702 afterTabLoaded(callback)(createdWindow.tabs[0]);
803 }); 703 });
804 } 704 }
805 }; 705 };
806 }()); 706 }());
LEFTRIGHT

Powered by Google App Engine
This is Rietveld