Bug 1333289. Part 1 - add a function to the webidl to retrieve debugging data in an asynchronous way. r?bz draft
authorJW Wang <jwwang@mozilla.com>
Wed, 18 Jan 2017 16:14:57 +0800
changeset 465929 074da83deb1e89d2e212f00713ac975e2bb24467
parent 465532 1826b1433b859d584f2023a694e9a123ca0aa526
child 465930 3109853b14a4aac1d4cb6ad2d2f307c3713b0bee
push id42752
push userjwwang@mozilla.com
push dateWed, 25 Jan 2017 01:49:49 +0000
reviewersbz
bugs1333289
milestone54.0a1
Bug 1333289. Part 1 - add a function to the webidl to retrieve debugging data in an asynchronous way. r?bz MozReview-Commit-ID: AXTpOYaq56A
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
dom/webidl/HTMLMediaElement.webidl
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1466,16 +1466,31 @@ HTMLMediaElement::GetMozDebugReaderData(
 {
   if (mDecoder && !mSrcStream) {
     nsAutoCString result;
     mDecoder->GetMozDebugReaderData(result);
     aString = NS_ConvertUTF8toUTF16(result);
   }
 }
 
+already_AddRefed<Promise>
+HTMLMediaElement::MozRequestDebugInfo(ErrorResult& aRv)
+{
+  RefPtr<Promise> promise = CreateDOMPromise(aRv);
+  if (NS_WARN_IF(aRv.Failed())) {
+    return nullptr;
+  }
+
+  // TODO: collect data from MDSM which must be done off the main thread.
+  nsAutoString result;
+  GetMozDebugReaderData(result);
+  promise->MaybeResolve(result);
+  return promise.forget();
+}
+
 void
 HTMLMediaElement::MozDumpDebugInfo()
 {
   if (mDecoder) {
     mDecoder->DumpDebugInfo();
   }
 }
 
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -599,16 +599,20 @@ public:
     mIsCasting = aShow;
   }
 
   already_AddRefed<MediaSource> GetMozMediaSourceObject() const;
   // Returns a string describing the state of the media player internal
   // data. Used for debugging purposes.
   void GetMozDebugReaderData(nsAString& aString);
 
+  // Returns a promise which will be resolved after collecting debugging
+  // data from decoder/reader/MDSM. Used for debugging purposes.
+  already_AddRefed<Promise> MozRequestDebugInfo(ErrorResult& aRv);
+
   void MozDumpDebugInfo();
 
   void SetVisible(bool aVisible);
 
   already_AddRefed<DOMMediaStream> GetSrcObject() const;
   void SetSrcObject(DOMMediaStream& aValue);
   void SetSrcObject(DOMMediaStream* aValue);
 
--- a/dom/webidl/HTMLMediaElement.webidl
+++ b/dom/webidl/HTMLMediaElement.webidl
@@ -99,16 +99,18 @@ interface HTMLMediaElement : HTMLElement
 };
 
 // Mozilla extensions:
 partial interface HTMLMediaElement {
   [ChromeOnly]
   readonly attribute MediaSource? mozMediaSourceObject;
   [ChromeOnly]
   readonly attribute DOMString mozDebugReaderData;
+  [ChromeOnly, NewObject]
+  Promise<DOMString> mozRequestDebugInfo();
 
   [Pref="media.test.dumpDebugInfo"]
   void mozDumpDebugInfo();
 
   attribute MediaStream? srcObject;
   // TODO: remove prefixed version soon (1183495).
   attribute MediaStream? mozSrcObject;