Bug 1147668 - Correctly reflect video and track RequestContext values; r=smaug
☠☠ backed out by bbeaa22dfafe ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 15 Jun 2015 16:45:27 -0400
changeset 279980 f46a712edf7ee9088854b220661df6857453f69c
parent 279979 0086cb0ada91f77c6f0dcc115ca8b5051c2869ee
child 279981 1659c5b4e48dfa990bb9d04f39147691f48715f1
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1147668
milestone41.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 1147668 - Correctly reflect video and track RequestContext values; r=smaug
dom/fetch/InternalRequest.cpp
dom/fetch/InternalRequest.h
dom/html/HTMLMediaElement.cpp
dom/html/HTMLTrackElement.cpp
dom/media/MediaResource.cpp
dom/workers/test/serviceworkers/fetch/context/context_test.js
dom/workers/test/serviceworkers/fetch/context/index.html
--- a/dom/fetch/InternalRequest.cpp
+++ b/dom/fetch/InternalRequest.cpp
@@ -147,19 +147,25 @@ InternalRequest::MapContentPolicyTypeToR
     context = RequestContext::Plugin;
     break;
   case nsIContentPolicy::TYPE_DTD:
     context = RequestContext::Internal;
     break;
   case nsIContentPolicy::TYPE_FONT:
     context = RequestContext::Font;
     break;
-  case nsIContentPolicy::TYPE_MEDIA:
+  case nsIContentPolicy::TYPE_INTERNAL_AUDIO:
     context = RequestContext::Audio;
     break;
+  case nsIContentPolicy::TYPE_INTERNAL_VIDEO:
+    context = RequestContext::Video;
+    break;
+  case nsIContentPolicy::TYPE_INTERNAL_TRACK:
+    context = RequestContext::Track;
+    break;
   case nsIContentPolicy::TYPE_WEBSOCKET:
     context = RequestContext::Internal;
     break;
   case nsIContentPolicy::TYPE_CSP_REPORT:
     context = RequestContext::Cspreport;
     break;
   case nsIContentPolicy::TYPE_XSLT:
     context = RequestContext::Xslt;
--- a/dom/fetch/InternalRequest.h
+++ b/dom/fetch/InternalRequest.h
@@ -25,17 +25,17 @@ namespace dom {
 
 /*
  * The mapping of RequestContext and nsContentPolicyType is currently as the
  * following.  Note that this mapping is not perfect yet (see the TODO comments
  * below for examples).
  *
  * RequestContext    | nsContentPolicyType
  * ------------------+--------------------
- * audio             | TYPE_MEDIA
+ * audio             | TYPE_INTERNAL_AUDIO
  * beacon            | TYPE_BEACON
  * cspreport         | TYPE_CSP_REPORT
  * download          |
  * embed             | TYPE_OBJECT
  * eventsource       |
  * favicon           |
  * fetch             | TYPE_FETCH
  * font              | TYPE_FONT
@@ -52,25 +52,24 @@ namespace dom {
  * object            | TYPE_OBJECT
  * ping              | TYPE_PING
  * plugin            | TYPE_OBJECT_SUBREQUEST
  * prefetch          |
  * script            | TYPE_SCRIPT
  * sharedworker      |
  * subresource       | Not supported by Gecko
  * style             | TYPE_STYLESHEET
- * track             | TYPE_MEDIA
- * video             | TYPE_MEDIA
+ * track             | TYPE_INTERNAL_TRACK
+ * video             | TYPE_INTERNAL_VIDEO
  * worker            |
  * xmlhttprequest    | TYPE_XMLHTTPREQUEST
  * xslt              | TYPE_XSLT
  *
  * TODO: Figure out if TYPE_REFRESH maps to anything useful
  * TODO: Figure out if TYPE_DTD maps to anything useful
- * TODO: Split TYPE_MEDIA into TYPE_AUDIO, TYPE_VIDEO and TYPE_TRACK
  * TODO: Split TYPE_XMLHTTPREQUEST and TYPE_DATAREQUEST for EventSource
  * TODO: Figure out if TYPE_WEBSOCKET maps to anything useful
  * TODO: Differentiate between frame and iframe
  * TODO: Add content types for different kinds of workers
  * TODO: Add a content type for prefetch
  * TODO: Use the content type for manifest when it becomes available
  * TODO: Add a content type for location
  * TODO: Add a content type for hyperlink
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1145,18 +1145,22 @@ nsresult HTMLMediaElement::LoadResource(
   }
 
   // Check if media is allowed for the docshell.
   nsCOMPtr<nsIDocShell> docShell = OwnerDoc()->GetDocShell();
   if (docShell && !docShell->GetAllowMedia()) {
     return NS_ERROR_FAILURE;
   }
 
+  MOZ_ASSERT(IsAnyOfHTMLElements(nsGkAtoms::audio, nsGkAtoms::video));
+  nsContentPolicyType contentPolicyType = IsHTMLElement(nsGkAtoms::audio) ?
+    nsIContentPolicy::TYPE_INTERNAL_AUDIO : nsIContentPolicy::TYPE_INTERNAL_VIDEO;
+
   int16_t shouldLoad = nsIContentPolicy::ACCEPT;
-  nsresult rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_MEDIA,
+  nsresult rv = NS_CheckContentLoadPolicy(contentPolicyType,
                                           mLoadingSrc,
                                           NodePrincipal(),
                                           static_cast<Element*>(this),
                                           EmptyCString(), // mime type
                                           nullptr, // extra
                                           &shouldLoad,
                                           nsContentUtils::GetContentPolicy(),
                                           nsContentUtils::GetSecurityManager());
@@ -1224,17 +1228,17 @@ nsresult HTMLMediaElement::LoadResource(
   }
 
   nsCOMPtr<nsILoadGroup> loadGroup = GetDocumentLoadGroup();
   nsCOMPtr<nsIChannel> channel;
   rv = NS_NewChannel(getter_AddRefs(channel),
                      mLoadingSrc,
                      static_cast<Element*>(this),
                      securityFlags,
-                     nsIContentPolicy::TYPE_MEDIA,
+                     contentPolicyType,
                      loadGroup,
                      nullptr,   // aCallbacks
                      nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE_IF_BUSY |
                      nsIChannel::LOAD_MEDIA_SNIFFER_OVERRIDES_CONTENT_TYPE |
                      nsIChannel::LOAD_CALL_CONTENT_SNIFFERS);
 
   NS_ENSURE_SUCCESS(rv,rv);
 
--- a/dom/html/HTMLTrackElement.cpp
+++ b/dom/html/HTMLTrackElement.cpp
@@ -204,17 +204,17 @@ HTMLTrackElement::LoadResource()
   }
 
   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_MEDIA,
+  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());
@@ -231,17 +231,17 @@ HTMLTrackElement::LoadResource()
   }
 
   nsCOMPtr<nsIChannel> channel;
   nsCOMPtr<nsILoadGroup> loadGroup = OwnerDoc()->GetDocumentLoadGroup();
   rv = NS_NewChannel(getter_AddRefs(channel),
                      uri,
                      static_cast<Element*>(this),
                      nsILoadInfo::SEC_NORMAL,
-                     nsIContentPolicy::TYPE_MEDIA,
+                     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);
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -886,21 +886,25 @@ ChannelMediaResource::RecreateChannel()
   if (nsContentUtils::ChannelShouldInheritPrincipal(element->NodePrincipal(),
                                                     mURI,
                                                     false, // aInheritForAboutBlank
                                                     false // aForceInherit
                                                     )) {
     securityFlags = nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
   }
 
+  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,
                               securityFlags,
-                              nsIContentPolicy::TYPE_MEDIA,
+                              contentPolicyType,
                               loadGroup,
                               nullptr,  // aCallbacks
                               loadFlags);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // We have cached the Content-Type, which should not change. Give a hint to
   // the channel to avoid a sniffing failure, which would be expected because we
   // are probably seeking in the middle of the bitstream, and sniffing relies
@@ -1413,23 +1417,27 @@ already_AddRefed<MediaResource> FileMedi
   if (nsContentUtils::ChannelShouldInheritPrincipal(element->NodePrincipal(),
                                                     mURI,
                                                     false, // aInheritForAboutBlank
                                                     false // aForceInherit
                                                     )) {
     securityFlags = nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
   }
 
+  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),
                   mURI,
                   element,
                   securityFlags,
-                  nsIContentPolicy::TYPE_MEDIA,
+                  contentPolicyType,
                   loadGroup);
 
   if (NS_FAILED(rv))
     return nullptr;
 
   nsRefPtr<MediaResource> resource(new FileMediaResource(aDecoder, channel, mURI, GetContentType()));
   return resource.forget();
 }
--- a/dom/workers/test/serviceworkers/fetch/context/context_test.js
+++ b/dom/workers/test/serviceworkers/fetch/context/context_test.js
@@ -19,18 +19,17 @@ self.addEventListener("fetch", function(
     if (event.request.context == "imageset") {
       event.respondWith(fetch("realimg.jpg"));
     }
   } else if (event.request.url.indexOf("audio.ogg") >= 0) {
     if (event.request.context == "audio") {
       event.respondWith(fetch("realaudio.ogg"));
     }
   } else if (event.request.url.indexOf("video.ogg") >= 0) {
-    // FIXME: Bug 1147668: This should be "video".
-    if (event.request.context == "audio") {
+    if (event.request.context == "video") {
       event.respondWith(fetch("realaudio.ogg"));
     }
   } else if (event.request.url.indexOf("beacon.sjs") >= 0) {
     if (event.request.url.indexOf("queryContext") == -1) {
       event.respondWith(fetch("beacon.sjs?" + event.request.context));
     } else {
       event.respondWith(fetch(event.request));
     }
--- a/dom/workers/test/serviceworkers/fetch/context/index.html
+++ b/dom/workers/test/serviceworkers/fetch/context/index.html
@@ -298,18 +298,17 @@
     return new Promise(function(resolve, reject) {
       var video = document.createElement("video");
       var track = document.createElement("track");
       track.src = "track";
       video.appendChild(track);
       document.documentElement.appendChild(video);
       navigator.serviceWorker.addEventListener("message", function onMessage(e) {
         if (e.data.data == "track") {
-          // FIXME: Bug 1147668: This should be "track".
-          is(e.data.context, "audio", "Expected the audio context on a request coming from a track");
+          is(e.data.context, "track", "Expected the track context on a request coming from a track");
           navigator.serviceWorker.removeEventListener("message", onMessage);
           resolve();
         }
       }, false);
     });
   }
 
   function testXHR() {