Bug 1112424 - Part 4: Add an about:media page to show debug information about active HTML media elements. r=gavin, a=sledru
authorChris Double <chris.double@double.co.nz>
Wed, 28 Jan 2015 18:35:00 -0500
changeset 243639 23b7a843e75d
parent 243638 68c3b8df1065
child 243640 dbb452162854
push id4421
push userryanvm@gmail.com
push date2015-02-02 19:52 +0000
treeherdermozilla-beta@08a02585bc60 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin, sledru
bugs1112424
milestone36.0
Bug 1112424 - Part 4: Add an about:media page to show debug information about active HTML media elements. r=gavin, a=sledru Adds about:media which shows internal debug data for HTMLMediaElement and MediaSource in particular. The intent is for this to be used by Gecko developers to help debug video playback and to be able to provide data to be copy/pasted by testers when problems arise. It calls internal JS APIs which are implemented in Part 1 and Part 2 of the patch.
browser/base/content/content.js
docshell/base/nsAboutRedirector.cpp
docshell/build/nsDocShellModule.cpp
toolkit/components/aboutmedia/content/aboutMedia.js
toolkit/components/aboutmedia/content/aboutMedia.xhtml
toolkit/components/aboutmedia/jar.mn
toolkit/components/aboutmedia/moz.build
toolkit/components/moz.build
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -940,8 +940,33 @@ addMessageListener("ContextMenu:SaveVide
   canvas.height = video.videoHeight;
 
   let ctxDraw = canvas.getContext("2d");
   ctxDraw.drawImage(video, 0, 0);
   sendAsyncMessage("ContextMenu:SaveVideoFrameAsImage:Result", {
     dataURL: canvas.toDataURL("image/jpeg", ""),
   });
 });
+
+addMessageListener("AboutMedia:CollectData", (mesage) => {
+  let text = "";
+  let media = content.document.getElementsByTagName('video');
+  if (media.length > 0) {
+    text += content.document.documentURI + "\n";
+  }
+  for (let mediaEl of media) {
+    text += "\t" + mediaEl.currentSrc + "\n";
+    text += "\t" + "currentTime: " + mediaEl.currentTime + "\n";
+    let ms = mediaEl.mozMediaSourceObject;
+    if (ms) {
+      for (let k = 0; k < ms.sourceBuffers.length; ++k) {
+        let sb = ms.sourceBuffers[k];
+        text += "\t\tSourceBuffer " + k + "\n";
+        for (let l = 0; l < sb.buffered.length; ++l) {
+          text += "\t\t\tstart=" + sb.buffered.start(l) + " end=" + sb.buffered.end(l) + "\n";
+        }
+      }
+      text += "\tInternal Data:\n";
+      text += ms.mozDebugReaderData.split("\n").map(line => { return "\t" + line + "\n"; }).join("");
+     }
+  }
+  sendAsyncMessage("AboutMedia:DataCollected", { text: text });
+});
--- a/docshell/base/nsAboutRedirector.cpp
+++ b/docshell/base/nsAboutRedirector.cpp
@@ -64,16 +64,18 @@ static RedirEntry kRedirMap[] = {
     { "support", "chrome://global/content/aboutSupport.xhtml",
       nsIAboutModule::ALLOW_SCRIPT },
     { "telemetry", "chrome://global/content/aboutTelemetry.xhtml",
       nsIAboutModule::ALLOW_SCRIPT },
     { "networking", "chrome://global/content/aboutNetworking.xhtml",
        nsIAboutModule::ALLOW_SCRIPT },
     { "webrtc", "chrome://global/content/aboutwebrtc/aboutWebrtc.xhtml",
        nsIAboutModule::ALLOW_SCRIPT },
+    { "media", "chrome://global/content/aboutMedia.xhtml",
+       nsIAboutModule::ALLOW_SCRIPT },
     // about:srcdoc is unresolvable by specification.  It is included here
     // because the security manager would disallow srcdoc iframes otherwise.
     { "srcdoc", "about:blank",
       nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
       nsIAboutModule::HIDE_FROM_ABOUTABOUT }
 };
 static const int kRedirTotal = mozilla::ArrayLength(kRedirMap);
 
--- a/docshell/build/nsDocShellModule.cpp
+++ b/docshell/build/nsDocShellModule.cpp
@@ -170,16 +170,17 @@ const mozilla::Module::ContractIDEntry k
   { NS_ABOUT_MODULE_CONTRACTID_PREFIX "compartments", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
   { NS_ABOUT_MODULE_CONTRACTID_PREFIX "memory", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
   { NS_ABOUT_MODULE_CONTRACTID_PREFIX "addons", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
   { NS_ABOUT_MODULE_CONTRACTID_PREFIX "newaddon", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
   { NS_ABOUT_MODULE_CONTRACTID_PREFIX "support", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
   { NS_ABOUT_MODULE_CONTRACTID_PREFIX "telemetry", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
   { NS_ABOUT_MODULE_CONTRACTID_PREFIX "networking", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
   { NS_ABOUT_MODULE_CONTRACTID_PREFIX "webrtc", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
+  { NS_ABOUT_MODULE_CONTRACTID_PREFIX "media", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
   { NS_ABOUT_MODULE_CONTRACTID_PREFIX "srcdoc", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
   { NS_URI_LOADER_CONTRACTID, &kNS_URI_LOADER_CID },
   { NS_DOCUMENTLOADER_SERVICE_CONTRACTID, &kNS_DOCUMENTLOADER_SERVICE_CID },
   { NS_EXTERNALHELPERAPPSERVICE_CONTRACTID, &kNS_EXTERNALHELPERAPPSERVICE_CID },
   { NS_EXTERNALPROTOCOLSERVICE_CONTRACTID, &kNS_EXTERNALHELPERAPPSERVICE_CID },
   { NS_MIMESERVICE_CONTRACTID, &kNS_EXTERNALHELPERAPPSERVICE_CID },
   { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"default", &kNS_EXTERNALPROTOCOLHANDLER_CID },
   { NS_PREFETCHSERVICE_CONTRACTID, &kNS_PREFETCHSERVICE_CID },
new file mode 100644
--- /dev/null
+++ b/toolkit/components/aboutmedia/content/aboutMedia.js
@@ -0,0 +1,22 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+let Cc = Components.classes;
+let Ci = Components.interfaces;
+
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+let listener = {
+  receiveMessage: function (msg) {
+    let text = msg.json.text;
+    document.getElementById('data').innerHTML += text;
+  },
+  QueryInterface: XPCOMUtils.generateQI(["nsISupportsWeakReference"])
+};
+
+function getData() {
+  let globalMM = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
+  globalMM.addWeakMessageListener("AboutMedia:DataCollected", listener);
+  globalMM.broadcastAsyncMessage("AboutMedia:CollectData");
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/aboutmedia/content/aboutMedia.xhtml
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <title>about:media</title>
+    <script type="application/javascript;version=1.8" src="chrome://global/content/aboutMedia.js"></script>
+  </head>
+  <body onload="getData()"><h1>HTMLMediaElement debug data</h1><pre id='data'></pre></body>
+</html>
new file mode 100644
--- /dev/null
+++ b/toolkit/components/aboutmedia/jar.mn
@@ -0,0 +1,7 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+toolkit.jar:
+  content/global/aboutMedia.xhtml                     (content/aboutMedia.xhtml)
+  content/global/aboutMedia.js                        (content/aboutMedia.js)
new file mode 100644
--- /dev/null
+++ b/toolkit/components/aboutmedia/moz.build
@@ -0,0 +1,7 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+JAR_MANIFESTS += ['jar.mn']
--- a/toolkit/components/moz.build
+++ b/toolkit/components/moz.build
@@ -5,16 +5,17 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # These component dirs are built for all apps (including suite)
 if CONFIG['MOZ_ENABLE_XREMOTE']:
     DIRS += ['remote']
 
 DIRS += [
     'aboutcache',
+    'aboutmedia',
     'aboutmemory',
     'addoncompat',
     'alerts',
     'apppicker',
     'asyncshutdown',
     'commandlines',
     'console',
     'contentprefs',