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

Unified Diff: ext/background.js

Issue 29516684: Issue 5347 - Open options page on Firefox for Android when browser action is clicked (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Check specifically for "fennec" Created Aug. 18, 2017, 2:20 p.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
« no previous file with comments | « no previous file | no next file » | 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
@@ -312,16 +312,26 @@
chrome.tabs.onActivated.addListener(details =>
{
ext.pages.onActivated._dispatch(new Page({id: details.tabId}));
});
/* Browser actions */
+ // On Firefox for Android, open the options page directly when the browser
+ // action is clicked.
+ if (!("getPopup" in chrome.browserAction))
+ {
+ chrome.browserAction.onClicked.addListener(() =>
+ {
+ ext.showOptions();
+ });
+ }
+
let BrowserAction = function(tabId)
{
this._tabId = tabId;
this._changes = null;
};
BrowserAction.prototype = {
_applyChanges()
{
@@ -660,19 +670,24 @@
{
chrome.storage.local.remove(key, callback);
},
onChanged: chrome.storage.onChanged
};
/* Options */
- if ("openOptionsPage" in chrome.runtime)
+ ext.showOptions = callback =>
{
- ext.showOptions = callback =>
+ let {application} = require("info");
Sebastian Noack 2017/08/18 17:46:24 The temporary variable is redundant now, you could
Manish Jethani 2017/08/19 03:43:41 Done.
+
+ if ("openOptionsPage" in chrome.runtime &&
+ // Firefox for Android does have a runtime.openOptionsPage but it
+ // doesn't do anything.
+ application != "fennec")
{
if (!callback)
{
chrome.runtime.openOptionsPage();
}
else
{
chrome.runtime.openOptionsPage(() =>
@@ -687,58 +702,56 @@
if (tabs[0].status == "complete")
callback(new Page(tabs[0]));
else
afterTabLoaded(callback)(tabs[0]);
}
});
});
}
- };
- }
- else
- {
- // Edge does not yet support runtime.openOptionsPage (tested version 38)
- // and so this workaround needs to stay for now.
- // 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/
- ext.showOptions = callback =>
+ }
+ else
{
+ // Edge does not yet support runtime.openOptionsPage (tested version 38)
+ // nor does Firefox for Android,
+ // and so this workaround needs to stay for now.
+ // 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/
chrome.windows.getLastFocused(win =>
{
let optionsUrl = "options.html";
let queryInfo = {url: optionsUrl};
// extension pages can't be accessed in incognito windows. In order to
// correctly mimic the way in which Chrome opens extension options,
// we have to focus the options page in any other window.
if (!win.incognito)
queryInfo.windowId = win.id;
chrome.tabs.query(queryInfo, tabs =>
{
- if (tabs.length > 0)
+ if (tabs && tabs.length > 0)
{
let tab = tabs[0];
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);
}
});
});
- };
- }
+ }
+ };
/* Windows */
ext.windows = {
create(createData, callback)
{
chrome.windows.create(createData, createdWindow =>
{
afterTabLoaded(callback)(createdWindow.tabs[0]);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld