Bug 1182540 - Use channel->ascynOpen2 in dom/html/HTMLTrackElement.cpp (r=sicking)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Sat, 25 Jul 2015 10:29:22 -0700
changeset 254643 7f458c4bd2713cfaea02eddcb48470d535c9b815
parent 254642 e78c69d59b604c50d19bee733a18a7c48e01f000
child 254644 32b4e6d96e248c10bb8e51215ecfc285f64f9c33
push id14246
push userryanvm@gmail.com
push dateMon, 27 Jul 2015 14:44:11 +0000
treeherderfx-team@c2e8b03c28bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs1182540
milestone42.0a1
Bug 1182540 - Use channel->ascynOpen2 in dom/html/HTMLTrackElement.cpp (r=sicking)
dom/html/HTMLTrackElement.cpp
dom/security/nsContentSecurityManager.cpp
--- a/dom/html/HTMLTrackElement.cpp
+++ b/dom/html/HTMLTrackElement.cpp
@@ -198,61 +198,41 @@ HTMLTrackElement::LoadResource()
   LOG(LogLevel::Info, ("%p Trying to load from src=%s", this,
       NS_ConvertUTF16toUTF8(src).get()));
 
   if (mChannel) {
     mChannel->Cancel(NS_BINDING_ABORTED);
     mChannel = nullptr;
   }
 
-  rv = nsContentUtils::GetSecurityManager()->
-    CheckLoadURIWithPrincipal(NodePrincipal(), uri,
-                              nsIScriptSecurityManager::STANDARD);
-  NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
-
-  int16_t shouldLoad = nsIContentPolicy::ACCEPT;
-  rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_INTERNAL_TRACK,
-                                 uri,
-                                 NodePrincipal(),
-                                 static_cast<Element*>(this),
-                                 NS_LITERAL_CSTRING("text/vtt"), // mime type
-                                 nullptr, // extra
-                                 &shouldLoad,
-                                 nsContentUtils::GetContentPolicy(),
-                                 nsContentUtils::GetSecurityManager());
-  NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
-  if (NS_CP_REJECTED(shouldLoad)) {
-    return;
-  }
-
   // We may already have a TextTrack at this point if GetTrack() has already
   // been called. This happens, for instance, if script tries to get the
   // TextTrack before its mTrackElement has been bound to the DOM tree.
   if (!mTrack) {
     CreateTextTrack();
   }
 
   nsCOMPtr<nsIChannel> channel;
   nsCOMPtr<nsILoadGroup> loadGroup = OwnerDoc()->GetDocumentLoadGroup();
   rv = NS_NewChannel(getter_AddRefs(channel),
                      uri,
                      static_cast<Element*>(this),
-                     nsILoadInfo::SEC_NORMAL,
+                     nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS,
                      nsIContentPolicy::TYPE_INTERNAL_TRACK,
                      loadGroup);
 
   NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
 
   mListener = new WebVTTListener(this);
   rv = mListener->LoadResource();
   NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
   channel->SetNotificationCallbacks(mListener);
 
   LOG(LogLevel::Debug, ("opening webvtt channel"));
-  rv = channel->AsyncOpen(mListener, nullptr);
+  rv = channel->AsyncOpen2(mListener);
   NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
 
   mChannel = channel;
 }
 
 nsresult
 HTMLTrackElement::BindToTree(nsIDocument* aDocument,
                              nsIContent* aParent,
--- a/dom/security/nsContentSecurityManager.cpp
+++ b/dom/security/nsContentSecurityManager.cpp
@@ -110,57 +110,64 @@ DoCORSChecks(nsIChannel* aChannel, nsILo
   return NS_OK;
 }
 
 nsresult
 DoContentSecurityChecks(nsIURI* aURI, nsILoadInfo* aLoadInfo)
 {
   nsContentPolicyType contentPolicyType = aLoadInfo->GetContentPolicyType();
   nsCString mimeTypeGuess;
-  nsCOMPtr<nsISupports> requestingContext = nullptr;
+  nsCOMPtr<nsINode> requestingContext = nullptr;
 
   switch(contentPolicyType) {
     case nsIContentPolicy::TYPE_OTHER:
     case nsIContentPolicy::TYPE_SCRIPT:
     case nsIContentPolicy::TYPE_IMAGE:
     case nsIContentPolicy::TYPE_STYLESHEET:
     case nsIContentPolicy::TYPE_OBJECT:
     case nsIContentPolicy::TYPE_DOCUMENT:
     case nsIContentPolicy::TYPE_SUBDOCUMENT:
     case nsIContentPolicy::TYPE_REFRESH:
     case nsIContentPolicy::TYPE_XBL:
     case nsIContentPolicy::TYPE_PING:
     case nsIContentPolicy::TYPE_XMLHTTPREQUEST:
     // alias nsIContentPolicy::TYPE_DATAREQUEST:
     case nsIContentPolicy::TYPE_OBJECT_SUBREQUEST:
     case nsIContentPolicy::TYPE_DTD:
-    case nsIContentPolicy::TYPE_FONT:
+    case nsIContentPolicy::TYPE_FONT: {
       MOZ_ASSERT(false, "contentPolicyType not supported yet");
       break;
+    }
 
-    case nsIContentPolicy::TYPE_MEDIA:
-      mimeTypeGuess = EmptyCString();
+    case nsIContentPolicy::TYPE_MEDIA: {
+      nsContentPolicyType internalContentPolicyType =
+        aLoadInfo->InternalContentPolicyType();
+
+      if (internalContentPolicyType == nsIContentPolicy::TYPE_INTERNAL_TRACK) {
+        mimeTypeGuess = NS_LITERAL_CSTRING("text/vtt");
+      }
+      else {
+        mimeTypeGuess = EmptyCString();
+      }
       requestingContext = aLoadInfo->LoadingNode();
-#ifdef DEBUG
-      {
-        nsCOMPtr<mozilla::dom::Element> element = do_QueryInterface(requestingContext);
-        NS_ASSERTION(element != nullptr,
-                     "type_media requires requestingContext of type Element");
-      }
-#endif
+      MOZ_ASSERT(!requestingContext ||
+                 requestingContext->NodeType() == nsIDOMNode::ELEMENT_NODE,
+                 "type_media requires requestingContext of type Element");
       break;
+    }
 
     case nsIContentPolicy::TYPE_WEBSOCKET:
     case nsIContentPolicy::TYPE_CSP_REPORT:
     case nsIContentPolicy::TYPE_XSLT:
     case nsIContentPolicy::TYPE_BEACON:
     case nsIContentPolicy::TYPE_FETCH:
-    case nsIContentPolicy::TYPE_IMAGESET:
+    case nsIContentPolicy::TYPE_IMAGESET: {
       MOZ_ASSERT(false, "contentPolicyType not supported yet");
       break;
+    }
 
     default:
       // nsIContentPolicy::TYPE_INVALID
       MOZ_ASSERT(false, "can not perform security check without a valid contentType");
   }
 
   int16_t shouldLoad = nsIContentPolicy::ACCEPT;
   nsresult rv = NS_CheckContentLoadPolicy(contentPolicyType,