| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayUnmuteHistogram, ("Media.V
ideo.Autoplay.Muted.UnmuteAction", static_cast<int>(AutoplayUnmuteActionStatus::
NumberOfStatus))); | 66 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayUnmuteHistogram, ("Media.V
ideo.Autoplay.Muted.UnmuteAction", static_cast<int>(AutoplayUnmuteActionStatus::
NumberOfStatus))); |
| 67 | 67 |
| 68 autoplayUnmuteHistogram.count(static_cast<int>(status)); | 68 autoplayUnmuteHistogram.count(static_cast<int>(status)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void AutoplayUmaHelper::didMoveToNewDocument(Document& oldDocument) | 71 void AutoplayUmaHelper::didMoveToNewDocument(Document& oldDocument) |
| 72 { | 72 { |
| 73 if (!m_videoMutedPlayMethodVisibilityObserver) | 73 if (!m_videoMutedPlayMethodVisibilityObserver) |
| 74 return; | 74 return; |
| 75 | 75 |
| 76 oldDocument.domWindow()->removeEventListener(EventTypeNames::unload, this, f
alse); | 76 if (oldDocument.domWindow()) |
| 77 m_element->document().domWindow()->addEventListener(EventTypeNames::unload,
this, false); | 77 oldDocument.domWindow()->removeEventListener(EventTypeNames::unload, thi
s, false); |
| 78 if (m_element && m_element->document().domWindow()) |
| 79 m_element->document().domWindow()->addEventListener(EventTypeNames::unlo
ad, this, false); |
| 78 } | 80 } |
| 79 | 81 |
| 80 void AutoplayUmaHelper::onVisibilityChangedForVideoMutedPlayMethod(bool isVisibl
e) | 82 void AutoplayUmaHelper::onVisibilityChangedForVideoMutedPlayMethod(bool isVisibl
e) |
| 81 { | 83 { |
| 82 if (!isVisible) | 84 if (!isVisible) |
| 83 return; | 85 return; |
| 84 | 86 |
| 85 recordVideoAutoplayMutedPlayMethodBecomesVisibleUma(true); | 87 recordVideoAutoplayMutedPlayMethodBecomesVisibleUma(true); |
| 86 m_videoMutedPlayMethodVisibilityObserver->stop(); | 88 m_videoMutedPlayMethodVisibilityObserver->stop(); |
| 87 m_videoMutedPlayMethodVisibilityObserver = nullptr; | 89 m_videoMutedPlayMethodVisibilityObserver = nullptr; |
| 88 m_element->document().domWindow()->removeEventListener(EventTypeNames::unloa
d, this, false); | 90 if (m_element && m_element->document().domWindow()) |
| 91 m_element->document().domWindow()->removeEventListener(EventTypeNames::u
nload, this, false); |
| 89 } | 92 } |
| 90 | 93 |
| 91 void AutoplayUmaHelper::handleEvent(ExecutionContext* executionContext, Event* e
vent) | 94 void AutoplayUmaHelper::handleEvent(ExecutionContext* executionContext, Event* e
vent) |
| 92 { | 95 { |
| 93 if (event->type() == EventTypeNames::playing) | 96 if (event->type() == EventTypeNames::playing) |
| 94 handlePlayingEvent(); | 97 handlePlayingEvent(); |
| 95 else if (event->type() == EventTypeNames::unload) | 98 else if (event->type() == EventTypeNames::unload) |
| 96 handleUnloadEvent(); | 99 handleUnloadEvent(); |
| 97 else | 100 else |
| 98 NOTREACHED(); | 101 NOTREACHED(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 121 } | 124 } |
| 122 | 125 |
| 123 DEFINE_TRACE(AutoplayUmaHelper) | 126 DEFINE_TRACE(AutoplayUmaHelper) |
| 124 { | 127 { |
| 125 EventListener::trace(visitor); | 128 EventListener::trace(visitor); |
| 126 visitor->trace(m_element); | 129 visitor->trace(m_element); |
| 127 visitor->trace(m_videoMutedPlayMethodVisibilityObserver); | 130 visitor->trace(m_videoMutedPlayMethodVisibilityObserver); |
| 128 } | 131 } |
| 129 | 132 |
| 130 } // namespace blink | 133 } // namespace blink |
| OLD | NEW |