Bug 1347402 part 5 - create MediaElementGMPCrashHelper in HTMLMediaElement.cpp; r?jwwang, cpearce
Move the creation of MediaElementGMPCrashHelper out from MediaDecoder.cpp
which reduces the dependency of MediaDecoder to HTMLMediaElement.
MozReview-Commit-ID: E60aMfcFr7V
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -116,16 +116,18 @@ static mozilla::LazyLogModule gMediaElem
#include "nsDocShell.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/dom/HTMLVideoElement.h"
#include "mozilla/dom/VideoPlaybackQuality.h"
#include "HTMLMediaElement.h"
+#include "GMPCrashHelper.h"
+
using namespace mozilla::layers;
using mozilla::net::nsMediaFragmentURIParser;
namespace mozilla {
namespace dom {
// Number of milliseconds between progress events as defined by spec
static const uint32_t PROGRESS_MS = 350;
@@ -7456,16 +7458,42 @@ HTMLMediaElement::RemoveMediaTracks()
VideoTrackList* videoList = VideoTracks();
if (videoList) {
videoList->RemoveTracks();
}
mMediaTracksConstructed = false;
}
+class MediaElementGMPCrashHelper : public GMPCrashHelper
+{
+public:
+ explicit MediaElementGMPCrashHelper(HTMLMediaElement* aElement)
+ : mElement(aElement)
+ {
+ MOZ_ASSERT(NS_IsMainThread()); // WeakPtr isn't thread safe.
+ }
+ already_AddRefed<nsPIDOMWindowInner> GetPluginCrashedEventTarget() override
+ {
+ MOZ_ASSERT(NS_IsMainThread()); // WeakPtr isn't thread safe.
+ if (!mElement) {
+ return nullptr;
+ }
+ return do_AddRef(mElement->OwnerDoc()->GetInnerWindow());
+ }
+private:
+ WeakPtr<HTMLMediaElement> mElement;
+};
+
+already_AddRefed<GMPCrashHelper>
+HTMLMediaElement::CreateGMPCrashHelper()
+{
+ return MakeAndAddRef<MediaElementGMPCrashHelper>(this);
+}
+
bool HasDebuggerPrivilege(JSContext* aCx, JSObject* aObj)
{
return nsContentUtils::CallerHasPermission(aCx,
NS_LITERAL_STRING("debugger"));
}
} // namespace dom
} // namespace mozilla
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -775,16 +775,18 @@ public:
void MarkAsContentSource(CallerAPI aAPI);
nsIDocument* GetDocument() const override;
void ConstructMediaTracks(const MediaInfo* aInfo) override;
void RemoveMediaTracks() override;
+ already_AddRefed<GMPCrashHelper> CreateGMPCrashHelper() override;
+
protected:
virtual ~HTMLMediaElement();
class AudioChannelAgentCallback;
class ChannelLoader;
class ErrorSink;
class MediaLoadListener;
class MediaStreamTracksAvailableCallback;
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -27,17 +27,16 @@
#include "mozilla/dom/AudioTrack.h"
#include "mozilla/dom/AudioTrackList.h"
#include "mozilla/dom/HTMLMediaElement.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/VideoTrack.h"
#include "mozilla/dom/VideoTrackList.h"
#include "nsPrintfCString.h"
#include "mozilla/Telemetry.h"
-#include "GMPCrashHelper.h"
#include "Layers.h"
#include "mozilla/layers/ShadowLayers.h"
#ifdef MOZ_ANDROID_OMX
#include "AndroidBridge.h"
#endif
using namespace mozilla::dom;
@@ -960,44 +959,21 @@ MediaDecoder::IsSeeking() const
bool
MediaDecoder::OwnerHasError() const
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
return GetOwner()->HasError();
}
-class MediaElementGMPCrashHelper : public GMPCrashHelper
-{
-public:
- explicit MediaElementGMPCrashHelper(HTMLMediaElement* aElement)
- : mElement(aElement)
- {
- MOZ_ASSERT(NS_IsMainThread()); // WeakPtr isn't thread safe.
- }
- already_AddRefed<nsPIDOMWindowInner> GetPluginCrashedEventTarget() override
- {
- MOZ_ASSERT(NS_IsMainThread()); // WeakPtr isn't thread safe.
- if (!mElement) {
- return nullptr;
- }
- return do_AddRef(mElement->OwnerDoc()->GetInnerWindow());
- }
-private:
- WeakPtr<HTMLMediaElement> mElement;
-};
-
already_AddRefed<GMPCrashHelper>
MediaDecoder::GetCrashHelper()
{
MOZ_ASSERT(NS_IsMainThread());
- return GetOwner()->GetMediaElement()
- ? MakeAndAddRef<MediaElementGMPCrashHelper>(
- GetOwner()->GetMediaElement())
- : nullptr;
+ return GetOwner()->CreateGMPCrashHelper();
}
bool
MediaDecoder::IsEnded() const
{
MOZ_ASSERT(NS_IsMainThread());
return mPlayState == PLAY_STATE_ENDED;
}
--- a/dom/media/MediaDecoderOwner.h
+++ b/dom/media/MediaDecoderOwner.h
@@ -6,16 +6,17 @@
#ifndef MediaDecoderOwner_h_
#define MediaDecoderOwner_h_
#include "AbstractMediaDecoder.h"
#include "nsAutoPtr.h"
namespace mozilla {
class AbstractThread;
+class GMPCrashHelper;
class VideoFrameContainer;
class MediaInfo;
class MediaResult;
namespace dom {
class HTMLMediaElement;
} // namespace dom
@@ -164,14 +165,17 @@ public:
// Called by the media decoder to create audio/video tracks and add to its
// owner's track list.
virtual void ConstructMediaTracks(const MediaInfo* aInfo) = 0;
// Called by the media decoder to removes all audio/video tracks from its
// owner's track list.
virtual void RemoveMediaTracks() = 0;
+
+ // Called by the media decoder to create a GMPCrashHelper.
+ virtual already_AddRefed<GMPCrashHelper> CreateGMPCrashHelper() = 0;
};
} // namespace mozilla
#endif
--- a/dom/media/gtest/MockMediaDecoderOwner.h
+++ b/dom/media/gtest/MockMediaDecoderOwner.h
@@ -52,12 +52,13 @@ public:
AbstractThread* AbstractMainThread() const override
{
// Non-DocGroup version for Mock.
return AbstractThread::MainThread();
}
nsIDocument* GetDocument() const { return nullptr; }
void ConstructMediaTracks(const MediaInfo* aInfo) {}
void RemoveMediaTracks() {}
+ already_AddRefed<GMPCrashHelper> CreateGMPCrashHelper() { return nullptr; }
};
}
#endif