Commit bdef306f authored by zqzhang's avatar zqzhang Committed by Commit bot

[Autoplay] Add more rappor metrics for autoplay in cross-origin iframes

This CL adds rappor metrics for recording the eTLD+1 of the top-level
frame and cross-origin iframe when the user pauses an autoplaying video.

BUG=672526

Review-Url: https://codereview.chromium.org/2563723002
Cr-Commit-Position: refs/heads/master@{#437976}
parent b64f718b
...@@ -210,6 +210,7 @@ void AutoplayUmaHelper::handlePlayingEvent() { ...@@ -210,6 +210,7 @@ void AutoplayUmaHelper::handlePlayingEvent() {
void AutoplayUmaHelper::handlePauseEvent() { void AutoplayUmaHelper::handlePauseEvent() {
maybeStopRecordingMutedVideoOffscreenDuration(); maybeStopRecordingMutedVideoOffscreenDuration();
maybeRecordUserPausedAutoplayingCrossOriginVideo();
} }
void AutoplayUmaHelper::contextDestroyed() { void AutoplayUmaHelper::contextDestroyed() {
...@@ -299,21 +300,55 @@ void AutoplayUmaHelper::maybeStopRecordingMutedVideoOffscreenDuration() { ...@@ -299,21 +300,55 @@ void AutoplayUmaHelper::maybeStopRecordingMutedVideoOffscreenDuration() {
m_mutedVideoOffscreenDurationVisibilityObserver->stop(); m_mutedVideoOffscreenDurationVisibilityObserver->stop();
m_mutedVideoOffscreenDurationVisibilityObserver = nullptr; m_mutedVideoOffscreenDurationVisibilityObserver = nullptr;
m_mutedVideoAutoplayOffscreenDurationMS = 0; m_mutedVideoAutoplayOffscreenDurationMS = 0;
m_element->removeEventListener(EventTypeNames::pause, this, false); maybeUnregisterMediaElementPauseListener();
maybeUnregisterContextDestroyedObserver(); maybeUnregisterContextDestroyedObserver();
} }
void AutoplayUmaHelper::maybeRecordUserPausedAutoplayingCrossOriginVideo() {
if (!shouldRecordUserPausedAutoplayingCrossOriginVideo())
return;
if (m_element->ended() || m_element->seeking())
return;
Platform::current()->recordRapporURL(
"Media.Autoplay.CrossOrigin.UserPausedAutoplayingVideo.ChildFrame",
m_element->document().url());
Platform::current()->recordRapporURL(
"Media.Autoplay.CrossOrigin.UserPausedAutoplayingVideo."
"TopLevelFrame",
m_element->document().topDocument().url());
m_hasRecordedUserPausedAutoplayingCrossOriginVideo = true;
maybeUnregisterMediaElementPauseListener();
}
void AutoplayUmaHelper::maybeUnregisterContextDestroyedObserver() { void AutoplayUmaHelper::maybeUnregisterContextDestroyedObserver() {
if (!shouldListenToContextDestroyed()) { if (!shouldListenToContextDestroyed()) {
setContext(nullptr); setContext(nullptr);
} }
} }
void AutoplayUmaHelper::maybeUnregisterMediaElementPauseListener() {
if (m_mutedVideoOffscreenDurationVisibilityObserver)
return;
if (shouldRecordUserPausedAutoplayingCrossOriginVideo())
return;
m_element->removeEventListener(EventTypeNames::pause, this, false);
}
bool AutoplayUmaHelper::shouldListenToContextDestroyed() const { bool AutoplayUmaHelper::shouldListenToContextDestroyed() const {
return m_mutedVideoPlayMethodVisibilityObserver || return m_mutedVideoPlayMethodVisibilityObserver ||
m_mutedVideoOffscreenDurationVisibilityObserver; m_mutedVideoOffscreenDurationVisibilityObserver;
} }
bool AutoplayUmaHelper::shouldRecordUserPausedAutoplayingCrossOriginVideo()
const {
return m_element->isInCrossOriginFrame() && m_element->isHTMLVideoElement() &&
m_source != AutoplaySource::NumberOfSources &&
!m_hasRecordedUserPausedAutoplayingCrossOriginVideo;
}
DEFINE_TRACE(AutoplayUmaHelper) { DEFINE_TRACE(AutoplayUmaHelper) {
EventListener::trace(visitor); EventListener::trace(visitor);
ContextLifecycleObserver::trace(visitor); ContextLifecycleObserver::trace(visitor);
......
...@@ -86,6 +86,7 @@ class CORE_EXPORT AutoplayUmaHelper : public EventListener, ...@@ -86,6 +86,7 @@ class CORE_EXPORT AutoplayUmaHelper : public EventListener,
virtual void handleContextDestroyed(); // Make virtual for testing. virtual void handleContextDestroyed(); // Make virtual for testing.
void maybeUnregisterContextDestroyedObserver(); void maybeUnregisterContextDestroyedObserver();
void maybeUnregisterMediaElementPauseListener();
void maybeStartRecordingMutedVideoPlayMethodBecomeVisible(); void maybeStartRecordingMutedVideoPlayMethodBecomeVisible();
void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible); void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible);
...@@ -93,10 +94,13 @@ class CORE_EXPORT AutoplayUmaHelper : public EventListener, ...@@ -93,10 +94,13 @@ class CORE_EXPORT AutoplayUmaHelper : public EventListener,
void maybeStartRecordingMutedVideoOffscreenDuration(); void maybeStartRecordingMutedVideoOffscreenDuration();
void maybeStopRecordingMutedVideoOffscreenDuration(); void maybeStopRecordingMutedVideoOffscreenDuration();
void maybeRecordUserPausedAutoplayingCrossOriginVideo();
void onVisibilityChangedForMutedVideoOffscreenDuration(bool isVisibile); void onVisibilityChangedForMutedVideoOffscreenDuration(bool isVisibile);
void onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool isVisible); void onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool isVisible);
bool shouldListenToContextDestroyed() const; bool shouldListenToContextDestroyed() const;
bool shouldRecordUserPausedAutoplayingCrossOriginVideo() const;
// The autoplay source. Use AutoplaySource::NumberOfSources for invalid // The autoplay source. Use AutoplaySource::NumberOfSources for invalid
// source. // source.
...@@ -126,6 +130,9 @@ class CORE_EXPORT AutoplayUmaHelper : public EventListener, ...@@ -126,6 +130,9 @@ class CORE_EXPORT AutoplayUmaHelper : public EventListener,
std::set<CrossOriginAutoplayResult> m_recordedCrossOriginAutoplayResults; std::set<CrossOriginAutoplayResult> m_recordedCrossOriginAutoplayResults;
// Whether the UMA helper has recorded user pausing a cross-origin video.
bool m_hasRecordedUserPausedAutoplayingCrossOriginVideo;
// The observer is used to observer an autoplaying muted video changing it's // The observer is used to observer an autoplaying muted video changing it's
// visibility, which is used for offscreen duration UMA. The UMA is pending // visibility, which is used for offscreen duration UMA. The UMA is pending
// for recording as long as this observer is non-null. // for recording as long as this observer is non-null.
......
...@@ -1063,6 +1063,30 @@ components/rappor/rappor_parameters.h. ...@@ -1063,6 +1063,30 @@ components/rappor/rappor_parameters.h.
</summary> </summary>
</rappor-metric> </rappor-metric>
<rappor-metric
name="Media.Autoplay.CrossOrigin.UserPausedAutoplayingVideo.ChildFrame"
type="ETLD_PLUS_ONE">
<owner>avayvod@chromium.org</owner>
<owner>mlamouri@chromium.org</owner>
<owner>zqzhang@chromium.org</owner>
<summary>
The eTLD+1 of a cross-origin iframe URL containing an autoplaying video but
the user actively paused it.
</summary>
</rappor-metric>
<rappor-metric
name="Media.Autoplay.CrossOrigin.UserPausedAutoplayingVideo.TopLevelFrame"
type="ETLD_PLUS_ONE">
<owner>avayvod@chromium.org</owner>
<owner>mlamouri@chromium.org</owner>
<owner>zqzhang@chromium.org</owner>
<summary>
The eTLD+1 of the top-level frame URL that has a cross-origin iframe
containing an autoplaying video but the user actively paused it.
</summary>
</rappor-metric>
<rappor-metric name="Media.OriginUrl.EME" type="ETLD_PLUS_ONE"> <rappor-metric name="Media.OriginUrl.EME" type="ETLD_PLUS_ONE">
<owner>xhwang@chromium.org</owner> <owner>xhwang@chromium.org</owner>
<summary> <summary>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment