Bug 1347402 part 5 - create MediaElementGMPCrashHelper in HTMLMediaElement.cpp; r=cpearce,jwwang

Move the creation of MediaElementGMPCrashHelper out from MediaDecoder.cpp
which reduces the dependency of MediaDecoder to HTMLMediaElement.

MozReview-Commit-ID: E60aMfcFr7V

--HG--
extra : rebase_source : f50a8ee6f2fbec0bdf117eb1217066bc9c701745
extra : source : dd4e52da6d0d6205fe61d0caba44bbff008fd21a
This commit is contained in:
Kaku Kuo 2017-03-16 11:16:15 +08:00
parent b7fee84e84
commit 0d5f3a200f
5 changed files with 36 additions and 25 deletions

View File

@ -121,6 +121,8 @@ static mozilla::LazyLogModule gMediaElementEventsLog("nsMediaElementEvents");
#include "mozilla/dom/VideoPlaybackQuality.h"
#include "HTMLMediaElement.h"
#include "GMPCrashHelper.h"
using namespace mozilla::layers;
using mozilla::net::nsMediaFragmentURIParser;
@ -7462,6 +7464,32 @@ HTMLMediaElement::RemoveMediaTracks()
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,

View File

@ -780,6 +780,8 @@ public:
void RemoveMediaTracks() override;
already_AddRefed<GMPCrashHelper> CreateGMPCrashHelper() override;
protected:
virtual ~HTMLMediaElement();

View File

@ -32,7 +32,6 @@
#include "mozilla/dom/VideoTrackList.h"
#include "nsPrintfCString.h"
#include "mozilla/Telemetry.h"
#include "GMPCrashHelper.h"
#include "Layers.h"
#include "mozilla/layers/ShadowLayers.h"
@ -965,34 +964,11 @@ MediaDecoder::OwnerHasError() const
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

View File

@ -11,6 +11,7 @@
namespace mozilla {
class AbstractThread;
class GMPCrashHelper;
class VideoFrameContainer;
class MediaInfo;
class MediaResult;
@ -169,6 +170,9 @@ public:
// 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

View File

@ -57,6 +57,7 @@ public:
nsIDocument* GetDocument() const { return nullptr; }
void ConstructMediaTracks(const MediaInfo* aInfo) {}
void RemoveMediaTracks() {}
already_AddRefed<GMPCrashHelper> CreateGMPCrashHelper() { return nullptr; }
};
}