Commit dba93b7d authored by Thomas Greiner's avatar Thomas Greiner

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

parent c7358bbe
Pipeline #52045665 passed with stages
in 8 minutes and 46 seconds
......@@ -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"));
......
......@@ -136,12 +136,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) =>
......@@ -168,10 +167,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() {}
......@@ -184,14 +180,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
......
......@@ -951,7 +951,7 @@ function onDOMLoaded()
});
for (const key of customize)
{
getPref(key, (value) =>
getPref(key).then((value) =>
{
onPrefMessage(key, value, true);
});
......@@ -1130,7 +1130,7 @@ function setPrivacyConflict()
const acceptableAdsForm = $("#acceptable-ads");
if (hasPrivacyConflict())
{
getPref("ui_warn_tracking", (showTrackingWarning) =>
getPref("ui_warn_tracking").then((showTrackingWarning) =>
{
acceptableAdsForm.classList.toggle("show-warning", showTrackingWarning);
});
......@@ -1161,8 +1161,7 @@ function populateLists()
browser.runtime.sendMessage({
type: "subscriptions.get",
special: true
},
(subscriptions) =>
}).then((subscriptions) =>
{
const customFilterPromises = subscriptions.map(getSubscriptionFilters);
Promise.all(customFilterPromises).then((filters) =>
......@@ -1171,41 +1170,33 @@ function populateLists()
isCustomFiltersLoaded = true;
}).then(done);
});
browser.runtime.sendMessage({
type: "prefs.get",
key: "subscriptions_exceptionsurl"
},
(url) =>
{
acceptableAdsUrl = url;
Promise.all([
browser.runtime.sendMessage({
type: "prefs.get",
key: "subscriptions_exceptionsurl"
}),
browser.runtime.sendMessage({
type: "prefs.get",
key: "subscriptions_exceptionsurl_privacy"
},
(urlPrivacy) =>
{
acceptableAdsPrivacyUrl = urlPrivacy;
}),
getPref("additional_subscriptions"),
browser.runtime.sendMessage({
type: "subscriptions.get",
downloadable: true
})
])
.then(([url, privacyUrl, additionalSubscriptionUrls, subscriptions]) =>
{
acceptableAdsUrl = url;
acceptableAdsPrivacyUrl = privacyUrl;
additionalSubscriptions = additionalSubscriptionUrls;
getPref("additional_subscriptions", (subscriptionUrls) =>
{
additionalSubscriptions = subscriptionUrls;
// Load user subscriptions
browser.runtime.sendMessage({
type: "subscriptions.get",
downloadable: true
},
(subscriptions) =>
{
for (const subscription of subscriptions)
onSubscriptionMessage("added", subscription);
for (const subscription of subscriptions)
onSubscriptionMessage("added", subscription);
setAcceptableAds();
done();
});
});
});
setAcceptableAds();
done();
});
});
}
......@@ -1380,12 +1371,12 @@ function getPrefElement(key)
return document.querySelector("[data-pref='" + key + "']");
}
function getPref(key, callback)
function getPref(key)
{
browser.runtime.sendMessage({
return browser.runtime.sendMessage({
type: "prefs.get",
key
}, callback);
});
}
function onPrefMessage(key, value, initial)
......
......@@ -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