| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/html/AutoplayUmaHelper.h" | 5 #include "core/html/AutoplayUmaHelper.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/ElementVisibilityObserver.h" | 8 #include "core/dom/ElementVisibilityObserver.h" |
| 9 #include "core/events/Event.h" | 9 #include "core/events/Event.h" |
| 10 #include "core/frame/LocalDOMWindow.h" | 10 #include "core/frame/LocalDOMWindow.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 autoplayUnmuteHistogram.count(static_cast<int>(status)); | 91 autoplayUnmuteHistogram.count(static_cast<int>(status)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void AutoplayUmaHelper::didMoveToNewDocument(Document& oldDocument) | 94 void AutoplayUmaHelper::didMoveToNewDocument(Document& oldDocument) |
| 95 { | 95 { |
| 96 if (!shouldListenToUnloadEvent()) | 96 if (!shouldListenToUnloadEvent()) |
| 97 return; | 97 return; |
| 98 | 98 |
| 99 if (oldDocument.domWindow()) | 99 if (oldDocument.domWindow()) |
| 100 oldDocument.domWindow()->removeEventListener(EventTypeNames::unload, thi
s, false); | 100 oldDocument.domWindow()->removeEventListener(EventTypeNames::unload, thi
s, false); |
| 101 if (m_element && m_element->document().domWindow()) | 101 if (m_element->document().domWindow()) |
| 102 m_element->document().domWindow()->addEventListener(EventTypeNames::unlo
ad, this, false); | 102 m_element->document().domWindow()->addEventListener(EventTypeNames::unlo
ad, this, false); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void AutoplayUmaHelper::onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(
bool isVisible) | 105 void AutoplayUmaHelper::onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(
bool isVisible) |
| 106 { | 106 { |
| 107 if (!isVisible || !m_mutedVideoPlayMethodVisibilityObserver) | 107 if (!isVisible || !m_mutedVideoPlayMethodVisibilityObserver) |
| 108 return; | 108 return; |
| 109 | 109 |
| 110 maybeStopRecordingMutedVideoPlayMethodBecomeVisible(true); | 110 maybeStopRecordingMutedVideoPlayMethodBecomeVisible(true); |
| 111 } | 111 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 213 } |
| 214 m_mutedVideoOffscreenDurationVisibilityObserver->stop(); | 214 m_mutedVideoOffscreenDurationVisibilityObserver->stop(); |
| 215 m_mutedVideoOffscreenDurationVisibilityObserver = nullptr; | 215 m_mutedVideoOffscreenDurationVisibilityObserver = nullptr; |
| 216 m_mutedVideoAutoplayOffscreenDurationMS = 0; | 216 m_mutedVideoAutoplayOffscreenDurationMS = 0; |
| 217 m_element->removeEventListener(EventTypeNames::pause, this, false); | 217 m_element->removeEventListener(EventTypeNames::pause, this, false); |
| 218 maybeUnregisterUnloadListener(); | 218 maybeUnregisterUnloadListener(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void AutoplayUmaHelper::maybeUnregisterUnloadListener() | 221 void AutoplayUmaHelper::maybeUnregisterUnloadListener() |
| 222 { | 222 { |
| 223 if (!shouldListenToUnloadEvent() && m_element && m_element->document().domWi
ndow()) | 223 if (!shouldListenToUnloadEvent() && m_element->document().domWindow()) |
| 224 m_element->document().domWindow()->removeEventListener(EventTypeNames::u
nload, this, false); | 224 m_element->document().domWindow()->removeEventListener(EventTypeNames::u
nload, this, false); |
| 225 } | 225 } |
| 226 | 226 |
| 227 bool AutoplayUmaHelper::shouldListenToUnloadEvent() const | 227 bool AutoplayUmaHelper::shouldListenToUnloadEvent() const |
| 228 { | 228 { |
| 229 return m_mutedVideoPlayMethodVisibilityObserver || m_mutedVideoOffscreenDura
tionVisibilityObserver; | 229 return m_mutedVideoPlayMethodVisibilityObserver || m_mutedVideoOffscreenDura
tionVisibilityObserver; |
| 230 } | 230 } |
| 231 | 231 |
| 232 DEFINE_TRACE(AutoplayUmaHelper) | 232 DEFINE_TRACE(AutoplayUmaHelper) |
| 233 { | 233 { |
| 234 EventListener::trace(visitor); | 234 EventListener::trace(visitor); |
| 235 visitor->trace(m_element); | 235 visitor->trace(m_element); |
| 236 visitor->trace(m_mutedVideoPlayMethodVisibilityObserver); | 236 visitor->trace(m_mutedVideoPlayMethodVisibilityObserver); |
| 237 visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver); | 237 visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver); |
| 238 } | 238 } |
| 239 | 239 |
| 240 } // namespace blink | 240 } // namespace blink |
| OLD | NEW |