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

Unified Diff: lib/options.js

Issue 29570614: Issue 5028 - Use browser namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Rebase Created Oct. 13, 2017, 7:59 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
Index: lib/options.js
===================================================================
--- a/lib/options.js
+++ b/lib/options.js
@@ -23,26 +23,26 @@
const {checkWhitelisted} = require("whitelisting");
const {port} = require("messaging");
const info = require("info");
const optionsUrl = "options.html";
function findOptionsTab(callback)
{
- chrome.tabs.query({}, tabs =>
+ browser.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, though
// starting with Firefox 56 an extension can query for its own URLs:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1271354
- let fullOptionsUrl = chrome.extension.getURL(optionsUrl);
+ let fullOptionsUrl = browser.extension.getURL(optionsUrl);
callback(tabs.find(element => element.url == fullOptionsUrl));
});
}
function returnShowOptionsCall(optionsTab, callback)
{
if (!callback)
return;
@@ -82,58 +82,58 @@
*
* @param {function} callback
*/
exports.showOptions = callback =>
{
findOptionsTab(optionsTab =>
{
// Edge does not yet support runtime.openOptionsPage (tested version 38)
- if ("openOptionsPage" in chrome.runtime &&
+ if ("openOptionsPage" in browser.runtime &&
// Some versions of Firefox for Android before version 57 do have a
// 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))
{
- chrome.runtime.openOptionsPage(() =>
+ browser.runtime.openOptionsPage(() =>
{
returnShowOptionsCall(optionsTab, callback);
});
}
else if (optionsTab)
{
// 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.
- if ("windows" in chrome)
- chrome.windows.update(optionsTab.windowId, {focused: true});
+ if ("windows" in browser)
+ browser.windows.update(optionsTab.windowId, {focused: true});
- chrome.tabs.update(optionsTab.id, {active: true});
+ browser.tabs.update(optionsTab.id, {active: true});
returnShowOptionsCall(optionsTab, callback);
}
else
{
// We use a relative URL here because of this Edge issue:
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10276332
- chrome.tabs.create({url: optionsUrl}, () =>
+ browser.tabs.create({url: optionsUrl}, () =>
{
returnShowOptionsCall(optionsTab, callback);
});
}
});
};
// On Firefox for Android, open the options page directly when the browser
// action is clicked.
-chrome.browserAction.onClicked.addListener(() =>
+browser.browserAction.onClicked.addListener(() =>
{
- chrome.tabs.query({active: true, lastFocusedWindow: true}, ([tab]) =>
+ browser.tabs.query({active: true, lastFocusedWindow: true}, ([tab]) =>
{
let currentPage = new ext.Page(tab);
showOptions(optionsPage =>
{
if (!/^https?:$/.test(currentPage.url.protocol))
return;
« lib/notificationHelper.js ('K') | « lib/notificationHelper.js ('k') | lib/popupBlocker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld