Bug 1299718 part 2 - implement the MarkAsContentSource() API; r?gerald,kamidphish
MozReview-Commit-ID: 5ABZTv1iR6K
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2920,17 +2920,18 @@ HTMLMediaElement::HTMLMediaElement(alrea
mAudioChannelVolume(1.0),
mPlayingThroughTheAudioChannel(false),
mDisableVideo(false),
mElementInTreeState(ELEMENT_NOT_INTREE),
mHasUserInteraction(false),
mFirstFrameLoaded(false),
mDefaultPlaybackStartPosition(0.0),
mIsAudioTrackAudible(false),
- mAudible(IsAudible())
+ mAudible(IsAudible()),
+ mVisibilityState(Visibility::NONVISIBLE)
{
ErrorResult rv;
double defaultVolume = Preferences::GetFloat("media.default_volume", 1.0);
SetVolume(defaultVolume, rv);
mAudioChannel = AudioChannelService::GetDefaultAudioChannel();
@@ -6489,16 +6490,18 @@ static const char* VisibilityString(Visi
// direction and the video might be IN_DISPLAYPORT soon.
void
HTMLMediaElement::OnVisibilityChange(Visibility aOldVisibility,
Visibility aNewVisibility)
{
LOG(LogLevel::Debug, ("OnVisibilityChange(): %s -> %s\n",
VisibilityString(aOldVisibility),VisibilityString(aNewVisibility)));
+ mVisibilityState = aNewVisibility;
+
if (!mDecoder) {
return;
}
switch (aNewVisibility) {
case Visibility::UNTRACKED: {
MOZ_ASSERT_UNREACHABLE("Shouldn't notify for untracked visibility");
break;
@@ -6612,10 +6615,71 @@ HTMLMediaElement::NotifyCueDisplayStates
{
if (!mTextTrackManager) {
return;
}
mTextTrackManager->DispatchUpdateCueDisplay();
}
+void
+HTMLMediaElement::MarkAsContentSource(CallerAPI aAPI)
+{
+ const bool isVisible = mVisibilityState != Visibility::NONVISIBLE;
+
+ if (isVisible) {
+ // 0 = ALL_VISIBLE
+ Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 0);
+ } else {
+ // 1 = ALL_INVISIBLE
+ Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 1);
+ }
+
+ switch (aAPI) {
+ case CallerAPI::DRAW_IMAGE: {
+ if (isVisible) {
+ // 2 = drawImage_VISIBLE
+ Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 2);
+ } else {
+ // 3 = drawImage_INVISIBLE
+ Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 3);
+ }
+ break;
+ }
+ case CallerAPI::CREATE_PATTERN: {
+ if (isVisible) {
+ // 4 = createPattern_VISIBLE
+ Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 4);
+ } else {
+ // 5 = createPattern_INVISIBLE
+ Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 5);
+ }
+ break;
+ }
+ case CallerAPI::CREATE_IMAGEBITMAP: {
+ if (isVisible) {
+ // 6 = createImageBitmap_VISIBLE
+ Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 6);
+ } else {
+ // 7 = createImageBitmap_INVISIBLE
+ Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 7);
+ }
+ break;
+ }
+ case CallerAPI::CAPTURE_STREAM: {
+ if (isVisible) {
+ // 8 = captureStream_VISIBLE
+ Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 8);
+ } else {
+ // 9 = captureStream_INVISIBLE
+ Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 9);
+ }
+ break;
+ }
+ }
+
+ LOG(LogLevel::Debug,
+ ("%p Log VIDEO_AS_CONTENT_SOURCE: visibility = %u, API: '%d' and 'All'",
+ this, isVisible, aAPI));
+}
+
} // namespace dom
} // namespace mozilla
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -734,16 +734,27 @@ public:
// These are used for testing only
float ComputedVolume() const;
bool ComputedMuted() const;
nsSuspendedTypes ComputedSuspended() const;
void SetMediaInfo(const MediaInfo& aInfo);
+ // Telemetry: to record the usage of a {visible / invisible} video element as
+ // the source of {drawImage(), createPattern(), createImageBitmap() and
+ // captureStream()} APIs.
+ enum class CallerAPI {
+ DRAW_IMAGE,
+ CREATE_PATTERN,
+ CREATE_IMAGEBITMAP,
+ CAPTURE_STREAM,
+ };
+ void MarkAsContentSource(CallerAPI aAPI);
+
protected:
virtual ~HTMLMediaElement();
class ChannelLoader;
class MediaLoadListener;
class MediaStreamTracksAvailableCallback;
class MediaStreamTrackListener;
class StreamListener;
@@ -1710,14 +1721,16 @@ private:
// be seeked even before the media is loaded.
double mDefaultPlaybackStartPosition;
// True if the audio track is not silent.
bool mIsAudioTrackAudible;
// True if media element is audible for users.
bool mAudible;
+
+ Visibility mVisibilityState;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_HTMLMediaElement_h