Bug 1155898 - Use fetch instead of XHR for IdP
authorMartin Thomson <martin.thomson@gmail.com>
Tue, 21 Apr 2015 11:11:40 -0700
changeset 265198 4d63ef04b3db5758889a5f780069cfbfd28f7603
parent 265197 39d75574a70eddb0466555e1c1c6b49ccfc8dbe0
child 550977 0bc7b05c9aa76914cc27e7cf9d13f102b7117ec5
push id2102
push usermartin.thomson@gmail.com
push dateMon, 18 May 2015 17:35:37 +0000
bugs1155898
milestone41.0a1
Bug 1155898 - Use fetch instead of XHR for IdP
dom/media/IdpSandbox.jsm
dom/media/tests/mochitest/identity/idp.js
--- 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({