Bug 1194524 - Use channel->ascynOpen2 in dom/media/MediaResource.cpp (r=sicking)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Sat, 12 Sep 2015 12:59:08 -0700
changeset 262210 f737c4a017525cb3522e1326e5b63e6ee13d94fb
parent 262209 bdb5b24b1f4e39412022f62354e6de3911cb34eb
child 262211 7af4eae9a68f9f7aa72cace2454f6ac1de8b3110
push id29366
push userphilringnalda@gmail.com
push dateSun, 13 Sep 2015 18:58:26 +0000
treeherdermozilla-central@9ed17db42e3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs1194524
milestone43.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 1194524 - Use channel->ascynOpen2 in dom/media/MediaResource.cpp (r=sicking)
dom/media/MediaResource.cpp
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -557,47 +557,26 @@ nsresult ChannelMediaResource::OpenChann
 
   if (aStreamListener) {
     *aStreamListener = mListener;
     NS_ADDREF(*aStreamListener);
   } else {
     nsresult rv = mChannel->SetNotificationCallbacks(mListener.get());
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsCOMPtr<nsIStreamListener> listener = mListener.get();
+    rv = SetupChannelHeaders();
+    NS_ENSURE_SUCCESS(rv, rv);
 
-    // Ensure that if we're loading cross domain, that the server is sending
-    // an authorizing Access-Control header.
+    rv = mChannel->AsyncOpen2(mListener);
+    NS_ENSURE_SUCCESS(rv, rv);
+    
+    // Tell the media element that we are fetching data from a channel.
     MediaDecoderOwner* owner = mDecoder->GetMediaOwner();
     NS_ENSURE_TRUE(owner, NS_ERROR_FAILURE);
     dom::HTMLMediaElement* element = owner->GetMediaElement();
-    NS_ENSURE_TRUE(element, NS_ERROR_FAILURE);
-    if (element->ShouldCheckAllowOrigin()) {
-      nsRefPtr<nsCORSListenerProxy> crossSiteListener =
-        new nsCORSListenerProxy(mListener,
-                                element->NodePrincipal(),
-                                false);
-      NS_ENSURE_TRUE(crossSiteListener, NS_ERROR_OUT_OF_MEMORY);
-      rv = crossSiteListener->Init(mChannel, DataURIHandling::Allow);
-      NS_ENSURE_SUCCESS(rv, rv);
-      listener = crossSiteListener;
-    } else {
-      rv = nsContentUtils::GetSecurityManager()->
-        CheckLoadURIWithPrincipal(element->NodePrincipal(),
-                                  mURI,
-                                  nsIScriptSecurityManager::STANDARD);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-
-    rv = SetupChannelHeaders();
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    rv = mChannel->AsyncOpen(listener, nullptr);
-    NS_ENSURE_SUCCESS(rv, rv);
-    // Tell the media element that we are fetching data from a channel.
     element->DownloadResumed(true);
   }
 
   return NS_OK;
 }
 
 nsresult ChannelMediaResource::SetupChannelHeaders()
 {
@@ -864,24 +843,19 @@ ChannelMediaResource::RecreateChannel()
   dom::HTMLMediaElement* element = owner->GetMediaElement();
   if (!element) {
     // The decoder is being shut down, so don't bother opening a new channel
     return NS_OK;
   }
   nsCOMPtr<nsILoadGroup> loadGroup = element->GetDocumentLoadGroup();
   NS_ENSURE_TRUE(loadGroup, NS_ERROR_NULL_POINTER);
 
-  nsSecurityFlags securityFlags = nsILoadInfo::SEC_NORMAL;
-  if (nsContentUtils::ChannelShouldInheritPrincipal(element->NodePrincipal(),
-                                                    mURI,
-                                                    false, // aInheritForAboutBlank
-                                                    false // aForceInherit
-                                                    )) {
-    securityFlags = nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
-  }
+  nsSecurityFlags securityFlags = element->ShouldCheckAllowOrigin()
+                                  ? nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS
+                                  : nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS;
 
   MOZ_ASSERT(element->IsAnyOfHTMLElements(nsGkAtoms::audio, nsGkAtoms::video));
   nsContentPolicyType contentPolicyType = element->IsHTMLElement(nsGkAtoms::audio) ?
     nsIContentPolicy::TYPE_INTERNAL_AUDIO : nsIContentPolicy::TYPE_INTERNAL_VIDEO;
 
   nsresult rv = NS_NewChannel(getter_AddRefs(mChannel),
                               mURI,
                               element,
@@ -1369,30 +1343,26 @@ nsresult FileMediaResource::Open(nsIStre
       NS_ENSURE_SUCCESS(rv, rv);
 
       rv = NS_NewLocalFileInputStream(
         getter_AddRefs(mInput), file, -1, -1, nsIFileInputStream::SHARE_DELETE);
     } else if (IsBlobURI(mURI)) {
       rv = NS_GetStreamForBlobURI(mURI, getter_AddRefs(mInput));
     }
   } else {
-    // Ensure that we never load a local file from some page on a
-    // web server.
-    MediaDecoderOwner* owner = mDecoder->GetMediaOwner();
-    NS_ENSURE_TRUE(owner, NS_ERROR_FAILURE);
-    dom::HTMLMediaElement* element = owner->GetMediaElement();
-    NS_ENSURE_TRUE(element, NS_ERROR_FAILURE);
 
-    rv = nsContentUtils::GetSecurityManager()->
-           CheckLoadURIWithPrincipal(element->NodePrincipal(),
-                                     mURI,
-                                     nsIScriptSecurityManager::STANDARD);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    rv = mChannel->Open(getter_AddRefs(mInput));
+#ifdef DEBUG
+    {
+      nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
+      MOZ_ASSERT((loadInfo->GetSecurityMode() &
+                 nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS) == 0,
+                 "can not enforce CORS when calling Open2()");
+    }
+#endif
+    rv = mChannel->Open2(getter_AddRefs(mInput));
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   mSeekable = do_QueryInterface(mInput);
   if (!mSeekable) {
     // XXX The file may just be a .url or similar
     // shortcut that points to a Web site. We need to fix this by
     // doing an async open and waiting until we locate the real resource,
@@ -1446,24 +1416,19 @@ already_AddRefed<MediaResource> FileMedi
   dom::HTMLMediaElement* element = owner->GetMediaElement();
   if (!element) {
     // The decoder is being shut down, so we can't clone
     return nullptr;
   }
   nsCOMPtr<nsILoadGroup> loadGroup = element->GetDocumentLoadGroup();
   NS_ENSURE_TRUE(loadGroup, nullptr);
 
-  nsSecurityFlags securityFlags = nsILoadInfo::SEC_NORMAL;
-  if (nsContentUtils::ChannelShouldInheritPrincipal(element->NodePrincipal(),
-                                                    mURI,
-                                                    false, // aInheritForAboutBlank
-                                                    false // aForceInherit
-                                                    )) {
-    securityFlags = nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
-  }
+  nsSecurityFlags securityFlags = element->ShouldCheckAllowOrigin()
+                                  ? nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS
+                                  : nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS;
 
   MOZ_ASSERT(element->IsAnyOfHTMLElements(nsGkAtoms::audio, nsGkAtoms::video));
   nsContentPolicyType contentPolicyType = element->IsHTMLElement(nsGkAtoms::audio) ?
     nsIContentPolicy::TYPE_INTERNAL_AUDIO : nsIContentPolicy::TYPE_INTERNAL_VIDEO;
 
   nsCOMPtr<nsIChannel> channel;
   nsresult rv =
     NS_NewChannel(getter_AddRefs(channel),