Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| index db78202be84776c2d54247c0cb3323b16f52b7f8..af1292d0c04b7dea17053b6988e2fbf65253eb35 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| @@ -437,6 +437,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, |
| m_fragmentEndTime(std::numeric_limits<double>::quiet_NaN()), |
| m_pendingActionFlags(0), |
| m_lockedPendingUserGesture(false), |
| + m_lockedPendingUserGestureIfCrossOriginExperimentEnabled(true), |
| m_playing(false), |
| m_shouldDelayLoadEvent(false), |
| m_haveFiredLoadedData(false), |
| @@ -467,6 +468,8 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, |
| BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")"; |
| m_lockedPendingUserGesture = computeLockedPendingUserGesture(document); |
| + m_lockedPendingUserGestureIfCrossOriginExperimentEnabled = |
| + isDocumentCrossOrigin(document); |
| LocalFrame* frame = document.frame(); |
| if (frame) { |
| @@ -513,9 +516,8 @@ void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument) { |
| computeLockedPendingUserGesture(oldDocument); |
| bool newDocumentRequiresUserGesture = |
| computeLockedPendingUserGesture(document()); |
| - if (newDocumentRequiresUserGesture && !oldDocumentRequiresUserGesture) { |
| + if (newDocumentRequiresUserGesture && !oldDocumentRequiresUserGesture) |
| m_lockedPendingUserGesture = true; |
| - } |
| if (m_shouldDelayLoadEvent) { |
| document().incrementLoadEventDelayCount(); |
| @@ -528,6 +530,9 @@ void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument) { |
| oldDocument.incrementLoadEventDelayCount(); |
| } |
| + if (isDocumentCrossOrigin(document()) && !isDocumentCrossOrigin(oldDocument)) |
| + m_lockedPendingUserGestureIfCrossOriginExperimentEnabled = true; |
|
whywhat
2016/11/29 21:42:04
should you make it false in the case the new docum
Zhiqiang Zhang (Slow)
2016/11/30 17:30:52
Please see the other reply.
|
| + |
| removeElementFromDocumentMap(this, &oldDocument); |
| addElementToDocumentMap(this, &document()); |
| @@ -1371,6 +1376,10 @@ bool HTMLMediaElement::isMediaDataCORSSameOrigin(SecurityOrigin* origin) const { |
| !origin->taintsCanvas(currentSrc())); |
| } |
| +bool HTMLMediaElement::isCrossOrigin() const { |
| + return isDocumentCrossOrigin(document()); |
| +} |
| + |
| void HTMLMediaElement::startProgressEventTimer() { |
| if (m_progressEventTimer.isActive()) |
| return; |
| @@ -1736,6 +1745,13 @@ void HTMLMediaElement::setReadyState(ReadyState state) { |
| m_autoplayHelper->becameReadyToPlay(); |
| if (!isGestureNeededForPlayback()) { |
| + if (isGestureNeededForPlaybackIfCrossOriginExperimentEnabled()) { |
| + m_autoplayUmaHelper->recordCrossOriginExperimentMetric( |
| + AutoplayCrossOriginExperimentMetric::AutoplayBlocked); |
| + } else { |
| + m_autoplayUmaHelper->recordCrossOriginExperimentMetric( |
| + AutoplayCrossOriginExperimentMetric::AutoplayAllowed); |
| + } |
| if (isHTMLVideoElement() && muted() && |
| RuntimeEnabledFeatures::autoplayMutedVideosEnabled()) { |
| // We might end up in a situation where the previous |
| @@ -1754,6 +1770,9 @@ void HTMLMediaElement::setReadyState(ReadyState state) { |
| scheduleNotifyPlaying(); |
| m_autoplaying = false; |
| } |
| + } else { |
| + m_autoplayUmaHelper->recordCrossOriginExperimentMetric( |
| + AutoplayCrossOriginExperimentMetric::AutoplayBlocked); |
| } |
| } |
| @@ -2246,6 +2265,8 @@ Nullable<ExceptionCode> HTMLMediaElement::play() { |
| return nullptr; |
| } |
| + m_autoplayUmaHelper->recordCrossOriginExperimentMetric( |
| + AutoplayCrossOriginExperimentMetric::AutoplayBlocked); |
| recordAutoplayMetric(PlayMethodFailed); |
| String message = ExceptionMessages::failedToExecute( |
| "play", "HTMLMediaElement", |
| @@ -2253,8 +2274,18 @@ Nullable<ExceptionCode> HTMLMediaElement::play() { |
| document().addConsoleMessage(ConsoleMessage::create( |
| JSMessageSource, WarningMessageLevel, message)); |
| return NotAllowedError; |
| + } else { |
| + if (isGestureNeededForPlaybackIfCrossOriginExperimentEnabled()) { |
| + m_autoplayUmaHelper->recordCrossOriginExperimentMetric( |
| + AutoplayCrossOriginExperimentMetric::AutoplayBlocked); |
| + } else { |
| + m_autoplayUmaHelper->recordCrossOriginExperimentMetric( |
|
whywhat
2016/11/29 21:42:04
seems like we'll record some metrics when the expe
Zhiqiang Zhang (Slow)
2016/11/30 17:30:52
Yes :)
Since the experiment might break many sites
|
| + AutoplayCrossOriginExperimentMetric::AutoplayAllowed); |
| + } |
| } |
| } else { |
| + m_autoplayUmaHelper->recordCrossOriginExperimentMetric( |
| + AutoplayCrossOriginExperimentMetric::PlayedWithGesture); |
| UserGestureIndicator::utilizeUserGesture(); |
| // We ask the helper to remove the gesture requirement for us, so that |
| // it can record the reason. |
| @@ -3904,6 +3935,7 @@ bool HTMLMediaElement::isLockedPendingUserGesture() const { |
| void HTMLMediaElement::unlockUserGesture() { |
| m_lockedPendingUserGesture = false; |
| + m_lockedPendingUserGestureIfCrossOriginExperimentEnabled = false; |
| } |
| bool HTMLMediaElement::isGestureNeededForPlayback() const { |
| @@ -3933,6 +3965,23 @@ bool HTMLMediaElement::isGestureNeededForPlayback() const { |
| return true; |
| } |
| +bool HTMLMediaElement:: |
|
whywhat
2016/11/29 21:42:04
how is this different from the isGestureNeededForP
Zhiqiang Zhang (Slow)
2016/11/30 17:30:52
Done. Added the missing checks.
|
| + isGestureNeededForPlaybackIfCrossOriginExperimentEnabled() const { |
| + if (!m_lockedPendingUserGestureIfCrossOriginExperimentEnabled) |
| + return false; |
| + |
| + if (isHTMLVideoElement() && muted() && |
| + RuntimeEnabledFeatures::autoplayMutedVideosEnabled() && |
| + !(document().settings() && document().settings()->dataSaverEnabled()) && |
| + !(document().settings() && |
| + document().settings()->forcePreloadNoneForMediaElements()) && |
| + isAutoplayAllowedPerSettings()) { |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| bool HTMLMediaElement::isAutoplayAllowedPerSettings() const { |
| LocalFrame* frame = document().frame(); |
| if (!frame) |