Bug 1353629 - PBlob refactoring - part 15 - FileMediaResource is used for in-process blobURL, r=jwwang
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 24 Apr 2017 12:09:41 +0200
changeset 354630 6e18a14aa213774f5c80ca72e0667b87654c7b80
parent 354629 b93b33542bcf7baa6029df8e0bc7a822412fe0cc
child 354631 dec83a85f824c2afb541ecbda08dab6aa1abcff0
push id31707
push userkwierso@gmail.com
push dateMon, 24 Apr 2017 22:53:41 +0000
treeherdermozilla-central@abdcc8dfc283 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1353629
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1353629 - PBlob refactoring - part 15 - FileMediaResource is used for in-process blobURL, r=jwwang
dom/media/MediaResource.cpp
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -1513,24 +1513,45 @@ MediaResource::Create(MediaResourceCallb
 
   nsAutoCString contentTypeString;
   aChannel->GetContentType(contentTypeString);
   Maybe<MediaContainerType> containerType = MakeMediaContainerType(contentTypeString);
   if (!containerType) {
     return nullptr;
   }
 
+  RefPtr<MediaResource> resource;
+
+  // Let's try to create a FileMediaResource in case the channel is a nsIFile
   nsCOMPtr<nsIFileChannel> fc = do_QueryInterface(aChannel);
-  RefPtr<MediaResource> resource;
-  if (fc || (IsBlobURI(uri) && XRE_IsParentProcess())) {
+  if (fc) {
     resource = new FileMediaResource(aCallback, aChannel, uri, *containerType);
-  } else {
-    resource = new ChannelMediaResource(
-      aCallback, aChannel, uri, *containerType, aIsPrivateBrowsing);
   }
+
+  // If the URL is blobURL with a seekable inputStream, we can still use a
+  // FileMediaResource. This basically means that the blobURL and its Blob have
+  // been created in the current process.
+
+  if (!resource) {
+    nsCOMPtr<nsIInputStream> stream;
+    nsCOMPtr<nsISeekableStream> seekableStream;
+    if (IsBlobURI(uri) &&
+        NS_SUCCEEDED(NS_GetStreamForBlobURI(uri, getter_AddRefs(stream))) &&
+        (seekableStream = do_QueryInterface(stream))) {
+      resource =
+        new FileMediaResource(aCallback, aChannel, uri, *containerType);
+    }
+  }
+
+  if (!resource) {
+    resource =
+      new ChannelMediaResource(aCallback, aChannel, uri, *containerType,
+                               aIsPrivateBrowsing);
+  }
+
   return resource.forget();
 }
 
 void BaseMediaResource::SetLoadInBackground(bool aLoadInBackground) {
   if (aLoadInBackground == mLoadInBackground) {
     return;
   }
   mLoadInBackground = aLoadInBackground;