Bug 1267918 - Add GMPCrashHelper for WebAudio buffer decoder. r=karlt
authorChris Pearce <cpearce@mozilla.com>
Wed, 29 Jun 2016 11:42:10 +1200
changeset 303380 86d9f7174e213b464f179eb5effd5c61a7ffa85d
parent 303379 e0ad41829d68ff2a46d21b65bb6a23dab97fb61c
child 303381 7c72118d085a5cd547f83371435aad8fc7a96335
push id30388
push usercbook@mozilla.com
push dateSat, 02 Jul 2016 09:15:23 +0000
treeherdermozilla-central@39dffbba7642 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1267918
milestone50.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 1267918 - Add GMPCrashHelper for WebAudio buffer decoder. r=karlt This means if WebAudio is using the Adobe GMP for decoding and it crashes, we'll get a crash report for the GMP. MozReview-Commit-ID: FOZoPxvUwq5
dom/media/webaudio/BufferDecoder.cpp
dom/media/webaudio/BufferDecoder.h
dom/media/webaudio/MediaBufferDecoder.cpp
--- a/dom/media/webaudio/BufferDecoder.cpp
+++ b/dom/media/webaudio/BufferDecoder.cpp
@@ -3,23 +3,25 @@
 /* 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/. */
 
 #include "BufferDecoder.h"
 
 #include "nsISupports.h"
 #include "MediaResource.h"
+#include "GMPService.h"
 
 namespace mozilla {
 
 NS_IMPL_ISUPPORTS0(BufferDecoder)
 
-BufferDecoder::BufferDecoder(MediaResource* aResource)
+BufferDecoder::BufferDecoder(MediaResource* aResource, GMPCrashHelper* aCrashHelper)
   : mResource(aResource)
+  , mCrashHelper(aCrashHelper)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_COUNT_CTOR(BufferDecoder);
 }
 
 BufferDecoder::~BufferDecoder()
 {
   // The dtor may run on any thread, we cannot be sure.
@@ -62,9 +64,15 @@ BufferDecoder::GetImageContainer()
 
 MediaDecoderOwner*
 BufferDecoder::GetOwner()
 {
   // unknown
   return nullptr;
 }
 
+already_AddRefed<GMPCrashHelper>
+BufferDecoder::GetCrashHelper()
+{
+  return do_AddRef(mCrashHelper);
+}
+
 } // namespace mozilla
--- a/dom/media/webaudio/BufferDecoder.h
+++ b/dom/media/webaudio/BufferDecoder.h
@@ -19,34 +19,37 @@ namespace mozilla {
  * This class provides a decoder object which decodes a media file that lives in
  * a memory buffer.
  */
 class BufferDecoder final : public AbstractMediaDecoder
 {
 public:
   // This class holds a weak pointer to MediaResource.  It's the responsibility
   // of the caller to manage the memory of the MediaResource object.
-  explicit BufferDecoder(MediaResource* aResource);
+  explicit BufferDecoder(MediaResource* aResource, GMPCrashHelper* aCrashHelper);
 
   NS_DECL_THREADSAFE_ISUPPORTS
 
   // This has to be called before decoding begins
   void BeginDecoding(TaskQueue* aTaskQueueIdentity);
 
   MediaResource* GetResource() const final override;
 
   void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded,
                            uint32_t aDropped) final override;
 
   VideoFrameContainer* GetVideoFrameContainer() final override;
   layers::ImageContainer* GetImageContainer() final override;
 
   MediaDecoderOwner* GetOwner() final override;
 
+  already_AddRefed<GMPCrashHelper> GetCrashHelper() override;
+
 private:
   virtual ~BufferDecoder();
   RefPtr<TaskQueue> mTaskQueueIdentity;
   RefPtr<MediaResource> mResource;
+  RefPtr<GMPCrashHelper> mCrashHelper;
 };
 
 } // namespace mozilla
 
 #endif /* BUFFER_DECODER_H_ */
--- a/dom/media/webaudio/MediaBufferDecoder.cpp
+++ b/dom/media/webaudio/MediaBufferDecoder.cpp
@@ -20,16 +20,17 @@
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIScriptError.h"
 #include "nsMimeTypes.h"
 #include "VideoUtils.h"
 #include "WebAudioUtils.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/Telemetry.h"
 #include "nsPrintfCString.h"
+#include "GMPService.h"
 
 namespace mozilla {
 
 extern LazyLogModule gMediaDecoderLog;
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(WebAudioDecodeJob)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WebAudioDecodeJob)
@@ -176,16 +177,34 @@ MediaDecodeTask::Run()
     break;
   case PhaseEnum::Done:
     break;
   }
 
   return NS_OK;
 }
 
+class BufferDecoderGMPCrashHelper : public GMPCrashHelper
+{
+public:
+  explicit BufferDecoderGMPCrashHelper(nsPIDOMWindowInner* aParent)
+    : mParent(do_GetWeakReference(aParent))
+  {
+    MOZ_ASSERT(NS_IsMainThread());
+  }
+  already_AddRefed<nsPIDOMWindowInner> GetPluginCrashedEventTarget() override
+  {
+    MOZ_ASSERT(NS_IsMainThread());
+    nsCOMPtr<nsPIDOMWindowInner> window = do_QueryReferent(mParent);
+    return window.forget();
+  }
+private:
+  nsWeakPtr mParent;
+};
+
 bool
 MediaDecodeTask::CreateReader()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
 
   nsCOMPtr<nsIPrincipal> principal;
   nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(mDecodeJob.mContext->GetParentObject());
@@ -193,17 +212,18 @@ MediaDecodeTask::CreateReader()
     principal = sop->GetPrincipal();
   }
 
   RefPtr<BufferMediaResource> resource =
     new BufferMediaResource(static_cast<uint8_t*> (mBuffer),
                             mLength, principal, mContentType);
 
   MOZ_ASSERT(!mBufferDecoder);
-  mBufferDecoder = new BufferDecoder(resource);
+  mBufferDecoder = new BufferDecoder(resource,
+    new BufferDecoderGMPCrashHelper(mDecodeJob.mContext->GetParentObject()));
 
   // If you change this list to add support for new decoders, please consider
   // updating HTMLMediaElement::CreateDecoder as well.
 
   mDecoderReader = DecoderTraits::CreateReader(mContentType, mBufferDecoder);
 
   if (!mDecoderReader) {
     return false;