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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« dependencies ('K') | « dependencies ('k') | metadata.gecko-webext » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ext/background.js
===================================================================
--- a/ext/background.js
+++ b/ext/background.js
@@ -318,17 +318,41 @@
/* Browser actions */
// On Firefox for Android, open the options page directly when the browser
// action is clicked.
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
{
chrome.browserAction.onClicked.addListener(() =>
{
- ext.showOptions();
+ ext.pages.query({active: true, lastFocusedWindow: true}, pages =>
+ {
+ let currentPage = pages[0];
+
+ ext.showOptions(optionsPage =>
+ {
+ if (!currentPage.url ||
+ 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.
+ {
+ return;
+ }
+
+ optionsPage.sendMessage({
+ type: "app.respond",
+ action: "showPageOptions",
+ args: [
+ {
+ host: currentPage.url.hostname,
+ 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.
+ .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
+ }
+ ]
+ });
+ });
+ });
});
}
let BrowserAction = function(tabId)
{
this._tabId = tabId;
this._changes = null;
};
@@ -697,21 +721,19 @@
/* Options */
ext.showOptions = callback =>
{
let info = require("info");
if ("openOptionsPage" in chrome.runtime &&
- // Some versions of Firefox for Android before version 57 do have a
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
- // runtime.openOptionsPage but it doesn't do anything.
- // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945
- (info.application != "fennec" ||
- parseInt(info.applicationVersion, 10) >= 57))
+ // We don't use runtime.openOptionsPage on Firefox for Android because
+ // we have a different options page for mobile.
+ info.application != "fennec")
{
if (!callback)
{
chrome.runtime.openOptionsPage();
}
else
{
chrome.runtime.openOptionsPage(() =>
@@ -727,55 +749,53 @@
callback(new Page(tabs[0]));
else
afterTabLoaded(callback)(tabs[0]);
}
});
});
}
}
- else if ("windows" in chrome)
Manish Jethani 2017/09/06 01:12:12 Now this code is used for Firefox for Android as w
+ else
{
// Edge does not yet support runtime.openOptionsPage (tested version 38)
- // 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
- // We are not using extension.getURL to get the absolute path here
- // because of the Edge issue:
- // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10276332/
let optionsUrl = "options.html";
- let fullOptionsUrl = ext.getURL(optionsUrl);
+
+ // Firefox for Android has its own options page.
+ if (info.application == "fennec")
+ optionsUrl = "mobile-options.html";
chrome.tabs.query({}, tabs =>
{
// We find a tab ourselves because Edge has a bug when quering tabs
// with extension URL protocol:
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8094141/
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8604703/
+ // 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.
+ // https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Match_patterns
+ let fullOptionsUrl = ext.getURL(optionsUrl);
let tab = tabs.find(element => element.url == fullOptionsUrl);
if (tab)
{
- chrome.windows.update(tab.windowId, {focused: true});
+ // Firefox for Android doesn't support the windows API, and the
+ // mobile browser has only one window anyway.
+ if ("windows" in chrome)
+ chrome.windows.update(tab.windowId, {focused: true});
+
chrome.tabs.update(tab.id, {active: true});
if (callback)
callback(new Page(tab));
}
else
{
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.
}
});
}
- else
- {
- // Firefox for Android before version 57 does not support
- // runtime.openOptionsPage, nor does it support the windows API. Since
- // there is effectively only one window on the mobile browser, there's no
- // need to bring it into focus.
- ext.pages.open("options.html", callback);
- }
};
/* Windows */
ext.windows = {
create(createData, callback)
{
chrome.windows.create(createData, createdWindow =>
{
« dependencies ('K') | « dependencies ('k') | metadata.gecko-webext » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld