Bug 1494896 - Make hybrid content telemetry init reject on older versions of Frefox. r=chutten

This patch enables the HCT init promise to reject even for Firefox
versions (before 63) that do not have the required chrome code
to communicate back to the library the lack of privileges or that
HCT is disabled. It introduces a timeout that rejects the promise
after 3 seconds.

Differential Revision: https://phabricator.services.mozilla.com/D7693

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alessio Placitelli 2018-10-05 18:48:24 +00:00
Родитель f495f7a26f
Коммит 42d97bbaad
1 изменённых файлов: 14 добавлений и 1 удалений

Просмотреть файл

@ -50,7 +50,7 @@ if (typeof Mozilla == "undefined") {
*/
function _registerInternalPolicyHandler() {
// Create a promise to wait on for HCT to be completely initialized.
_initPromise = new Promise(function(resolveInit, rejectInit) {
var setupPromise = new Promise(function(resolveInit, rejectInit) {
// Register the handler that will update the policy boolean.
function policyChangeHandler(updatedPref) {
if (!("detail" in updatedPref) ||
@ -69,6 +69,19 @@ if (typeof Mozilla == "undefined") {
{once: true});
});
// In bug 1490284 we introduced a mechanism for which the HCT library rejects if the
// requesting website has not enough privileges or telemetry is disabled. Unfortunately,
// this required a change in chrome JSMs and is not available to Firefox versions
// before 63. To reject on these versions as well, a fallback timeout is provided that
// automatically rejects the init promise after 3 seconds.
var timeoutPromise = new Promise((resolve, reject) => {
setTimeout(reject, 3000);
});
// Resolves or rejects as soon as one of the promises resolves or rejects: the
// rejection timeout has no effect if |setupPromise| resolves before it.
_initPromise = Promise.race([setupPromise, timeoutPromise]);
// Make sure the chrome is initialized.
_sendMessageToChrome("init");
}