Commit e125d147 authored by Thomas Greiner's avatar Thomas Greiner

Issue 7345 - Use the extension Promise API in release-2018-5

parent d709a168
......@@ -38,8 +38,7 @@ function addFilters()
browser.runtime.sendMessage({
type: "filters.importRaw",
text: document.getElementById("filters").value
},
errors =>
}).then((errors) =>
{
if (errors.length > 0)
alert(errors.join("\n"));
......
......@@ -130,12 +130,11 @@
if (!("tabs" in browser))
browser.tabs = {};
browser.tabs.captureVisibleTab = (tabId, options, callback) =>
browser.tabs.captureVisibleTab = (tabId, options) =>
{
log(`Take screenshot of tab with ID ${tabId || activeTab.id}`);
return fetch("../tests/image.base64.txt")
.then(body => body.text())
.then(callback);
.then(body => body.text());
};
browser.tabs.create = (options) =>
......@@ -162,10 +161,7 @@
return Promise.resolve(tab);
};
browser.tabs.getCurrent = (callback) =>
{
return Promise.resolve(activeTab).then(callback);
};
browser.tabs.getCurrent = () => Promise.resolve(activeTab);
browser.tabs.onUpdated = {
addListener() {}
......@@ -178,14 +174,14 @@
return Promise.resolve();
};
browser.tabs.update = (tabId, options, callback) =>
browser.tabs.update = (tabId, options) =>
{
if (options.active)
{
activeTab = tabs.get(tabId);
log(`Focused tab with ID ${activeTab.id}`);
}
return Promise.resolve().then(callback);
return Promise.resolve();
};
class MockXmlHttpRequest extends XMLHttpRequest
......
......@@ -953,7 +953,7 @@ function onDOMLoaded()
});
for (const key of customize)
{
getPref(key).then(value =>
getPref(key).then((value) =>
{
onPrefMessage(key, value, true);
});
......@@ -1131,7 +1131,7 @@ function setPrivacyConflict()
const acceptableAdsForm = $("#acceptable-ads");
if (hasPrivacyConflict())
{
getPref("ui_warn_tracking").then(showTrackingWarning =>
getPref("ui_warn_tracking").then((showTrackingWarning) =>
{
acceptableAdsForm.classList.toggle("show-warning", showTrackingWarning);
});
......@@ -1163,7 +1163,7 @@ function populateLists()
browser.runtime.sendMessage({
type: "subscriptions.get",
special: true
}).then(subscriptions =>
}).then((subscriptions) =>
{
const customFilterPromises = subscriptions.map(getSubscriptionFilters);
Promise.all(customFilterPromises).then((filters) =>
......@@ -1173,33 +1173,27 @@ function populateLists()
}).then(done);
});
browser.runtime.sendMessage({
type: "prefs.get",
key: "subscriptions_exceptionsurl"
}).then(url =>
{
acceptableAdsUrl = url;
return browser.runtime.sendMessage({
Promise.all([
browser.runtime.sendMessage({
type: "prefs.get",
key: "subscriptions_exceptionsurl"
}),
browser.runtime.sendMessage({
type: "prefs.get",
key: "subscriptions_exceptionsurl_privacy"
});
}).then(urlPrivacy =>
{
acceptableAdsPrivacyUrl = urlPrivacy;
return getPref("additional_subscriptions");
}).then(subscriptionUrls =>
{
additionalSubscriptions = subscriptionUrls;
// Load user subscriptions
return browser.runtime.sendMessage({
}),
getPref("additional_subscriptions"),
browser.runtime.sendMessage({
type: "subscriptions.get",
downloadable: true
});
}).then(subscriptions =>
})
])
.then(([url, privacyUrl, additionalSubscriptionUrls, subscriptions]) =>
{
acceptableAdsUrl = url;
acceptableAdsPrivacyUrl = privacyUrl;
additionalSubscriptions = additionalSubscriptionUrls;
for (const subscription of subscriptions)
onSubscriptionMessage("added", subscription);
......
......@@ -6,10 +6,11 @@ const activeTab = new Promise(
{
document.addEventListener("DOMContentLoaded", () =>
{
browser.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
{
resolve({id: tabs[0].id, url: tabs[0].url});
});
browser.tabs.query({active: true, lastFocusedWindow: true})
.then((tabs) =>
{
resolve({id: tabs[0].id, url: tabs[0].url});
});
}, {once: true});
}
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment