Bug 1208371 - Add an interface DecoderPrincipalChangeObserver to HTMLMediaElement. r?roc
MozReview-Commit-ID: DwDHDE7SLxY
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -4182,16 +4182,31 @@ void HTMLMediaElement::NotifyDecoderPrin
mDecoder->UpdateSameOriginStatus(!principal || IsCORSSameOrigin());
for (uint32_t i = 0; i < mOutputStreams.Length(); ++i) {
OutputMediaStream* ms = &mOutputStreams[i];
ms->mStream->SetCORSMode(mCORSMode);
ms->mStream->CombineWithPrincipal(principal);
}
+
+ for (DecoderPrincipalChangeObserver* observer :
+ mDecoderPrincipalChangeObservers) {
+ observer->NotifyDecoderPrincipalChanged();
+ }
+}
+
+void HTMLMediaElement::AddDecoderPrincipalChangeObserver(DecoderPrincipalChangeObserver* aObserver)
+{
+ mDecoderPrincipalChangeObservers.AppendElement(aObserver);
+}
+
+bool HTMLMediaElement::RemoveDecoderPrincipalChangeObserver(DecoderPrincipalChangeObserver* aObserver)
+{
+ return mDecoderPrincipalChangeObservers.RemoveElement(aObserver);
}
void HTMLMediaElement::UpdateMediaSize(const nsIntSize& aSize)
{
if (IsVideo() && mReadyState != HAVE_NOTHING &&
mMediaInfo.mVideo.mDisplay != aSize) {
DispatchAsyncEvent(NS_LITERAL_STRING("resize"));
}
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -260,17 +260,40 @@ public:
bool IsPlaybackEnded() const;
// principal of the currently playing resource. Anything accessing the contents
// of this element must have a principal that subsumes this principal.
// Returns null if nothing is playing.
already_AddRefed<nsIPrincipal> GetCurrentPrincipal();
// called to notify that the principal of the decoder's media resource has changed.
- virtual void NotifyDecoderPrincipalChanged() final override;
+ void NotifyDecoderPrincipalChanged() final override;
+
+ // An interface for observing principal changes on the media elements
+ // MediaDecoder.
+ class DecoderPrincipalChangeObserver
+ {
+ public:
+ virtual void NotifyDecoderPrincipalChanged() = 0;
+ };
+
+ /**
+ * Add a DecoderPrincipalChangeObserver to this media element.
+ *
+ * Ownership of the DecoderPrincipalChangeObserver remains with the caller,
+ * and it's the caller's responsibility to remove the observer before it dies.
+ */
+ void AddDecoderPrincipalChangeObserver(DecoderPrincipalChangeObserver* aObserver);
+
+ /**
+ * Remove an added DecoderPrincipalChangeObserver from this media element.
+ *
+ * Returns true if it was successfully removed.
+ */
+ bool RemoveDecoderPrincipalChangeObserver(DecoderPrincipalChangeObserver* aObserver);
// Update the visual size of the media. Called from the decoder on the
// main thread when/if the size changes.
void UpdateMediaSize(const nsIntSize& aSize);
// Like UpdateMediaSize, but only updates the size if no size has yet
// been set.
void UpdateInitialMediaSize(const nsIntSize& aSize);
@@ -1106,16 +1129,20 @@ protected:
using nsGenericHTMLElement::DispatchEvent;
// For nsAsyncEventRunner.
nsresult DispatchEvent(const nsAString& aName);
// The current decoder. Load() has been called on this decoder.
// At most one of mDecoder and mSrcStream can be non-null.
RefPtr<MediaDecoder> mDecoder;
+ // Observers listening to changes to the mDecoder principal.
+ // Used by streams captured from this element.
+ nsTArray<DecoderPrincipalChangeObserver*> mDecoderPrincipalChangeObservers;
+
// State-watching manager.
WatchManager<HTMLMediaElement> mWatchManager;
// A reference to the VideoFrameContainer which contains the current frame
// of video to display.
RefPtr<VideoFrameContainer> mVideoFrameContainer;
// Holds a reference to the DOM wrapper for the MediaStream that has been