Bug 1207785 - Telemetry probe for Youtube-related embed tags; r=cpeterson r=vladan
authorKyle Machulis <kyle@nonpolynomial.com>
Mon, 28 Sep 2015 16:06:31 -0700
changeset 264863 8a905fb2619eff29cbd2bbbf9f91dc517b0922ef
parent 264862 ef04c494e2edfb074a9033f3a2ad1cda5551567b
child 264864 b85067b9554f190e21c5e526f5a076a75241b713
push id29450
push usercbook@mozilla.com
push dateTue, 29 Sep 2015 10:00:39 +0000
treeherdermozilla-central@acdb22976ff8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpeterson, vladan
bugs1207785
milestone44.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 1207785 - Telemetry probe for Youtube-related embed tags; r=cpeterson r=vladan
dom/base/nsObjectLoadingContent.cpp
dom/base/nsObjectLoadingContent.h
toolkit/components/telemetry/Histograms.json
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -1469,16 +1469,47 @@ nsObjectLoadingContent::CheckJavaCodebas
          this));
     return false;
   }
 
   return true;
 }
 
 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)) {
+    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) {
+    NS_WARNING("Could not parse plugin domain!");
+    return false;
+  }
+  nsAutoCString domain("youtube.com");
+  if (StringEndsWith(domain, currentBaseDomain)) {
+    return true;
+  }
+  return false;
+}
+
+bool
 nsObjectLoadingContent::CheckLoadPolicy(int16_t *aContentPolicy)
 {
   if (!aContentPolicy || !mURI) {
     NS_NOTREACHED("Doing it wrong");
     return false;
   }
 
   nsCOMPtr<nsIContent> thisContent =
@@ -2117,16 +2148,21 @@ nsObjectLoadingContent::LoadObject(bool 
   } else if (mChannelLoaded && mChannel != aLoadingChannel) {
     // The only time we should have a loaded channel with a changed state is
     // when the channel has just opened -- in which case this call should
     // have originated from OnStartRequest
     NS_NOTREACHED("Loading with a channel, but state doesn't make sense");
     return NS_OK;
   }
 
+  // Check whether this is a youtube embed.
+  if (IsYoutubeEmbed()) {
+    Telemetry::Accumulate(Telemetry::YOUTUBE_EMBED_SEEN, 1);
+  }
+
   //
   // Security checks
   //
 
   if (mType != eType_Null) {
     bool allowLoad = true;
     if (IsJavaMIME(mContentType)) {
       allowLoad = CheckJavaCodebase();
--- a/dom/base/nsObjectLoadingContent.h
+++ b/dom/base/nsObjectLoadingContent.h
@@ -514,16 +514,18 @@ class nsObjectLoadingContent : public ns
     ObjectType GetTypeOfContent(const nsCString& aMIMEType);
 
     /**
      * Gets the frame that's associated with this content node.
      * Does not flush.
      */
     nsPluginFrame* GetExistingFrame();
 
+    bool IsYoutubeEmbed();
+
     // Helper class for SetupProtoChain
     class SetupProtoChainRunner final : public nsIRunnable
     {
       ~SetupProtoChainRunner();
     public:
       NS_DECL_ISUPPORTS
 
       explicit SetupProtoChainRunner(nsObjectLoadingContent* aContent);
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -9768,10 +9768,16 @@
     "description": "Attempt to notify ServiceWorker of push notification resubscription."
   },
   "PLUGIN_ACTIVATION_COUNT": {
     "alert_emails": ["cpeterson@mozilla.com"],
     "expires_in_version": "48",
     "kind": "count",
     "keyed": true,
     "description": "Counts number of times a certain plugin has been activated."
+  },
+  "YOUTUBE_EMBED_SEEN": {
+    "alert_emails": ["cpeterson@mozilla.com"],
+    "expires_in_version": "48",
+    "kind": "flag",
+    "description": "Flag activated whenever a youtube flash embed is seen during a session."
   }
 }