Bug 1218952 - Add support for object tags to youtube telemetry tracking; r=cpeterson, a=sylvestre
authorKyle Machulis <kyle@nonpolynomial.com>
Fri, 30 Oct 2015 16:03:00 +0100
changeset 296659 be9dcc3b97b3
parent 296658 89e3c373b3a4
child 296660 9eb17d1e915c
push id5276
push usercbook@mozilla.com
push date2015-11-09 10:31 +0000
treeherdermozilla-beta@be9dcc3b97b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpeterson, sylvestre
bugs1218952
milestone43.0
Bug 1218952 - Add support for object tags to youtube telemetry tracking; r=cpeterson, a=sylvestre
dom/base/nsObjectLoadingContent.cpp
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -1474,38 +1474,46 @@ nsObjectLoadingContent::CheckJavaCodebas
 
 bool
 nsObjectLoadingContent::IsYoutubeEmbed()
 {
   nsCOMPtr<nsIContent> thisContent =
     do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
   NS_ASSERTION(thisContent, "Must be an instance of content");
 
-  // We're only interested in switching out embed tags
-  if (!thisContent->NodeInfo()->Equals(nsGkAtoms::embed)) {
+  // We're only interested in switching out embed and object tags
+  if (!thisContent->NodeInfo()->Equals(nsGkAtoms::embed) &&
+      !thisContent->NodeInfo()->Equals(nsGkAtoms::object)) {
     return false;
   }
   nsCOMPtr<nsIEffectiveTLDService> tldService =
     do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
   // If we can't analyze the URL, just pass on through.
   if(!tldService) {
     NS_WARNING("Could not get TLD service!");
     return false;
   }
   nsAutoCString currentBaseDomain;
   bool ok = NS_SUCCEEDED(tldService->GetBaseDomain(mURI, 0, currentBaseDomain));
   if (!ok) {
     // Data URIs won't parse correctly, so just fail silently here.
     return false;
   }
+  // See if URL is referencing youtube
   nsAutoCString domain("youtube.com");
-  if (StringEndsWith(domain, currentBaseDomain)) {
-    return true;
+  if (!StringEndsWith(domain, currentBaseDomain)) {
+    return false;
   }
-  return false;
+  // See if requester is planning on using the JS API.
+  nsAutoCString uri;
+  mURI->GetSpec(uri);
+  if (uri.Find("enablejsapi=1", true, 0, -1) == kNotFound) {
+    return false;
+  }
+  return true;
 }
 
 bool
 nsObjectLoadingContent::CheckLoadPolicy(int16_t *aContentPolicy)
 {
   if (!aContentPolicy || !mURI) {
     NS_NOTREACHED("Doing it wrong");
     return false;