Bug 1155898 - Use fetch instead of XHR for IdP
--- a/dom/media/IdpSandbox.jsm
+++ b/dom/media/IdpSandbox.jsm
@@ -202,17 +202,17 @@ IdpSandbox.prototype = {
this.sandbox = Cu.Sandbox(principal, {
sandboxName: 'IdP-' + this.source.host,
wantComponents: false,
wantExportHelpers: false,
wantGlobalProperties: [
'indexedDB', 'XMLHttpRequest', 'TextEncoder', 'TextDecoder',
'URL', 'URLSearchParams', 'atob', 'btoa', 'Blob', 'crypto',
- 'rtcIdentityProvider'
+ 'rtcIdentityProvider', 'fetch'
]
});
let registrar = this.sandbox.rtcIdentityProvider;
if (!Cu.isXrayWrapper(registrar)) {
throw new Error('IdP setup failed');
}
// have to use the ultimate URI, not the starting one to avoid
--- a/dom/media/tests/mochitest/identity/idp.js
+++ b/dom/media/tests/mochitest/identity/idp.js
@@ -16,22 +16,18 @@
var path = global.location.pathname;
this.protocol =
path.substring(path.lastIndexOf('/') + 1) + global.location.hash;
this.id = crypto.getRandomValues(new Uint8Array(10)).join('.');
}
IDPJS.prototype = {
getLogin: function() {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', 'https://example.com/.well-known/idp-proxy/idp.sjs?' + this.id);
- return new Promise(resolve => {
- xhr.onload = e => resolve(xhr.status === 200);
- xhr.send();
- });
+ return fetch('https://example.com/.well-known/idp-proxy/idp.sjs?' + this.id)
+ .then(response => response.status === 200);
},
checkLogin: function(result) {
return this.getLogin()
.then(loggedIn => {
if (loggedIn) {
return result;
}
return Promise.reject({