Backed out 2 changesets (bug 1443942) for mda assertion failures in /build/build/src/dom/media/ChannelMediaResource.cpp
authorMargareta Eliza Balazs <ebalazs@mozilla.com>
Tue, 13 Mar 2018 07:14:32 +0200
changeset 766822 ce0bde354931425a042449771d1d81f54fa316b9
parent 766821 be7993b626921feeda9076ebba9ec0384805a969
child 766823 4660a81a0228d6d9b3c6063256cd4348ad1c142b
push id102399
push userbmo:mratcliffe@mozilla.com
push dateTue, 13 Mar 2018 10:12:19 +0000
bugs1443942
milestone61.0a1
backs oute2f69088b1d7074deeda9acd0b912d520de6b4ff
446bfe8412cb963b62c51e90349a3a33ebc32467
Backed out 2 changesets (bug 1443942) for mda assertion failures in /build/build/src/dom/media/ChannelMediaResource.cpp Backed out changeset e2f69088b1d7 (bug 1443942) Backed out changeset 446bfe8412cb (bug 1443942)
dom/media/ChannelMediaDecoder.cpp
dom/media/DecoderTraits.cpp
dom/media/DecoderTraits.h
dom/media/MediaPrefs.h
dom/media/test/midflight-redirect.sjs
dom/media/test/mochitest.ini
dom/media/test/test_midflight_redirect_blocked.html
--- a/dom/media/ChannelMediaDecoder.cpp
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -162,19 +162,19 @@ ChannelMediaDecoder::NotifyPrincipalChan
     // We'll receive one notification when the channel's initial principal
     // is known, after all HTTP redirects have resolved. This isn't really a
     // principal change, so return here to avoid the mSameOriginMedia check
     // below.
     mInitialChannelPrincipalKnown = true;
     return;
   }
   if (!mSameOriginMedia &&
-      Preferences::GetBool("media.block-midflight-redirects", true)) {
-    // Block mid-flight redirects to non CORS same origin destinations.
-    // See bugs 1441153, 1443942.
+      DecoderTraits::CrossOriginRedirectsProhibited(ContainerType())) {
+    // For some content types we block mid-flight channel redirects to cross
+    // origin destinations due to security constraints. See bug 1441153.
     LOG("ChannnelMediaDecoder prohibited cross origin redirect blocked.");
     NetworkError(MediaResult(NS_ERROR_DOM_BAD_URI,
                              "Prohibited cross origin redirect blocked"));
   }
 }
 
 void
 ChannelMediaDecoder::ResourceCallback::NotifySuspendedStatusChanged(
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -320,9 +320,16 @@ bool DecoderTraits::IsSupportedInVideoDo
     ADTSDecoder::IsSupportedType(*type) ||
     FlacDecoder::IsSupportedType(*type) ||
 #ifdef MOZ_ANDROID_HLS_SUPPORT
     HLSDecoder::IsSupportedType(*type) ||
 #endif
     false;
 }
 
+/* static */
+bool
+DecoderTraits::CrossOriginRedirectsProhibited(const MediaContainerType& aType)
+{
+  return WaveDecoder::IsSupportedType(aType);
+}
+
 } // namespace mozilla
--- a/dom/media/DecoderTraits.h
+++ b/dom/media/DecoderTraits.h
@@ -52,14 +52,18 @@ public:
 
   // Returns true if aType is MIME type of hls.
   static bool IsHttpLiveStreamingType(const MediaContainerType& aType);
 
   // Returns true if aType is matroska type.
   static bool IsMatroskaType(const MediaContainerType& aType);
 
   static bool IsSupportedType(const MediaContainerType& aType);
+
+  // For some content types we block channel redirects to cross origin
+  // destinations due to security constraints. See bug 1441153.
+  static bool CrossOriginRedirectsProhibited(const MediaContainerType& aType);
 };
 
 } // namespace mozilla
 
 #endif
 
--- a/dom/media/MediaPrefs.h
+++ b/dom/media/MediaPrefs.h
@@ -200,17 +200,16 @@ private:
   DECL_MEDIA_PREF("media.resume-bkgnd-video-on-tabhover",     ResumeVideoDecodingOnTabHover, bool, false);
 
   // Enable sandboxing support for cubeb
   DECL_MEDIA_PREF("media.cubeb.sandbox",                      CubebSandbox, bool, false);
   DECL_MEDIA_PREF("media.videocontrols.lock-video-orientation",  VideoOrientationLockEnabled, bool, false);
 
   // Media Seamless Looping
   DECL_MEDIA_PREF("media.seamless-looping",                   SeamlessLooping, bool, true);
-
 public:
   // Manage the singleton:
   static MediaPrefs& GetSingleton();
   static bool SingletonExists();
 
 private:
   template<class T> friend class StaticAutoPtr;
   static StaticAutoPtr<MediaPrefs> sInstance;
deleted file mode 100644
--- a/dom/media/test/midflight-redirect.sjs
+++ /dev/null
@@ -1,71 +0,0 @@
-function parseQuery(query, key) {
-  for (let p of query.split('&')) {
-    if (p == key) {
-      return true;
-    }
-    if (p.startsWith(key + "=")) {
-      return p.substring(key.length + 1);
-    }
-  }
-}
-
-// Return the first few bytes in a short byte range response. When Firefox
-// requests subsequent bytes in a second range request, respond with a
-// redirect. Requests after the first redirected are serviced as expected.
-function handleRequest(request, response)
-{
-  var query = request.queryString;
-  var resource = parseQuery(query, "resource");
-  var redirected = parseQuery(query, "redirected") || false;
-  var useCors = parseQuery(query, "cors") || false;
-
-  var file = Components.classes["@mozilla.org/file/directory_service;1"].
-                        getService(Components.interfaces.nsIProperties).
-                        get("CurWorkD", Components.interfaces.nsIFile);
-  var fis  = Components.classes['@mozilla.org/network/file-input-stream;1'].
-                        createInstance(Components.interfaces.nsIFileInputStream);
-  var bis  = Components.classes["@mozilla.org/binaryinputstream;1"].
-                        createInstance(Components.interfaces.nsIBinaryInputStream);
-  var paths = "tests/dom/media/test/" + resource;
-  var split = paths.split("/");
-  for (var i = 0; i < split.length; ++i) {
-    file.append(split[i]);
-  }
-  fis.init(file, -1, -1, false);
-
-  bis.setInputStream(fis);
-  var bytes = bis.readBytes(bis.available());
-  let [from, to] = request.getHeader("range").split("=")[1].split("-").map(s => parseInt(s));
-
-  if (!redirected && from > 0) {
-    var origin = request.host == "mochi.test" ? "example.org" : "mochi.test:8888";
-    response.setStatusLine(request.httpVersion, 303, "See Other");
-    let url = "http://" + origin +
-              "/tests/dom/media/test/midflight-redirect.sjs?redirected&" + query;
-    response.setHeader("Location", url);
-    response.setHeader("Content-Type", "text/html");
-    return;
-  }
-
-  if (from == 0 && !redirected) {
-    to = Math.min(bytes.length / 4, 200);
-  } else {
-    to = to || Math.max(from, bytes.length - 1);
-  }
-
-  byterange = bytes.substring(from, to + 1);
-
-  let contentRange = "bytes "+ from +"-"+ to +"/"+ bytes.length;
-  let contentLength = (to - from + 1).toString();
-
-  response.setStatusLine(request.httpVersion, 206, "Partial Content");
-  response.setHeader("Content-Range", contentRange);
-  response.setHeader("Content-Length", contentLength, false);
-  response.setHeader("Content-Type", "video/ogg", false);
-  response.setHeader("Accept-Ranges", "bytes", false);
-  if (redirected && useCors) {
-    response.setHeader("Access-Control-Allow-Origin", "*");
-  }
-  response.write(byterange, byterange.length);
-  bis.close();
-}
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -489,17 +489,16 @@ support-files =
   invalid-m2c1.opus
   invalid-m2c1.opus^headers^
   invalid-neg_discard.webm
   invalid-neg_discard.webm^headers^
   invalid-preskip.webm
   invalid-preskip.webm^headers^
   long.vtt
   manifest.js
-  midflight-redirect.sjs
   multiple-bos.ogg
   multiple-bos.ogg^headers^
   multiple-bos-more-header-fileds.ogg
   multiple-bos-more-header-fileds.ogg^headers^
   no-cues.webm
   no-cues.webm^headers^
   notags.mp3
   notags.mp3^headers^
@@ -943,17 +942,16 @@ skip-if = android_version == '17' # andr
 tags=msg
 [test_mediatrack_events.html]
 skip-if = android_version == '17' # android(bug 1232305)
 [test_mediatrack_parsing_ogg.html]
 skip-if = android_version == '17' # android(bug 1232305)
 [test_mediatrack_replay_from_end.html]
 skip-if = toolkit == 'android' # android(bug 1232305)
 [test_metadata.html]
-[test_midflight_redirect_blocked.html]
 [test_mixed_principals.html]
 skip-if = toolkit == 'android' # bug 1309814, android(bug 1232305)
 [test_mozHasAudio.html]
 skip-if = toolkit == 'android' # android(bug 1232305)
 [test_multiple_mediastreamtracks.html]
 skip-if = android_version == '17' # android(bug 1232305)
 [test_networkState.html]
 skip-if = android_version == '17' # android(bug 1232305)
deleted file mode 100644
--- a/dom/media/test/test_midflight_redirect_blocked.html
+++ /dev/null
@@ -1,95 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-  <head>
-    <title>Test mid-flight cross site redirects are blocked</title>
-    <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
-    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-    <script type="text/javascript" src="manifest.js"></script>
-  </head>
-  <body>
-    <pre id='test'>
-    <script class="testbody" type='application/javascript'>
-
-      function testIfLoadsToMetadata(test, useCors) {
-        return new Promise(function(resolve, reject) {
-          var elemType = getMajorMimeType(test.type);
-          var element = document.createElement(elemType);
-
-          if (useCors) {
-            element.crossOrigin = "anonymous";
-          }
-
-          // Log events for debugging.
-          [
-            "suspend", "play", "canplay", "canplaythrough", "loadstart",
-            "loadedmetadata", "loadeddata", "playing", "ended", "error",
-            "stalled", "emptied", "abort", "waiting", "pause"
-          ].forEach((eventName) => {
-            element.addEventListener(eventName, (event)=> {
-              info(test.name + " " + event.type);
-            });
-          });
-
-          element.addEventListener("loadedmetadata", ()=>{
-            resolve(true);
-            removeNodeAndSource(element);
-          }, false);
-
-          element.addEventListener("error", ()=>{
-            resolve(false);
-            removeNodeAndSource(element);
-          }, false);
-
-          let suffix = useCors ? "&cors" : "";
-          element.src = "midflight-redirect.sjs?resource=" + test.name + suffix;
-          element.preload = "metadata";
-          document.body.appendChild(element);
-          element.load()
-        });
-      }
-
-      let v = document.createElement("video");
-      const testCases = gSmallTests.filter(t => v.canPlayType(t.type));
-
-      function testMediaLoad(expectedToLoad, message, useCors) {
-        return new Promise(async function(resolve, reject) {
-          for (let test of testCases) {
-            let loaded = await testIfLoadsToMetadata(test, useCors);
-            is(loaded, expectedToLoad, test.name + " " + message);
-          }
-          resolve();
-        });
-      }
-
-      async function runTest() {
-        try {
-          SimpleTest.info("Allowing midflight redirects...");
-          await SpecialPowers.pushPrefEnv({'set': [["media.block-midflight-redirects", false]]});
-
-          SimpleTest.info("Test that all media plays...");
-          await testMediaLoad(true, "expected to load", false);
-
-          SimpleTest.info("Blocking midflight redirects...");
-          await SpecialPowers.pushPrefEnv({'set': [["media.block-midflight-redirects", true]]});
-
-          SimpleTest.info("Test that all media no longer play...");
-          await testMediaLoad(false, "expected to be blocked", false);
-
-          SimpleTest.info("Test that all media play if CORS used...");
-          await testMediaLoad(true, "expected to play with CORS", true);
-        } catch (e) {
-          info("Exception " + e.message);
-          ok(false, "Threw exception " + e.message);
-        }
-        SimpleTest.finish();
-      }
-
-      SimpleTest.waitForExplicitFinish();
-
-      addLoadEvent(runTest);
-
-    </script>
-    </pre>
-  </body>
-</html>