Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/MediaControlsOrientationLockDelegate.cpp

Issue 2725873002: Media: fix memory leak because of the document holding on an EventListener. (Closed)
Patch Set: event-based Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "MediaControlsOrientationLockDelegate.h" 5 #include "MediaControlsOrientationLockDelegate.h"
6 6
7 #include "core/events/Event.h" 7 #include "core/events/Event.h"
8 #include "core/frame/ScreenOrientationController.h" 8 #include "core/frame/ScreenOrientationController.h"
9 #include "core/html/HTMLVideoElement.h" 9 #include "core/html/HTMLVideoElement.h"
10 #include "core/page/ChromeClient.h" 10 #include "core/page/ChromeClient.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 public: 57 public:
58 void onSuccess() override {} 58 void onSuccess() override {}
59 void onError(WebLockOrientationError) override {} 59 void onError(WebLockOrientationError) override {}
60 }; 60 };
61 61
62 } // anonymous namespace 62 } // anonymous namespace
63 63
64 MediaControlsOrientationLockDelegate::MediaControlsOrientationLockDelegate( 64 MediaControlsOrientationLockDelegate::MediaControlsOrientationLockDelegate(
65 HTMLVideoElement& video) 65 HTMLVideoElement& video)
66 : EventListener(CPPEventListenerType), m_videoElement(video) { 66 : EventListener(CPPEventListenerType), m_videoElement(video) {
67 if (videoElement().isConnected())
68 attach();
69 }
70
71 void MediaControlsOrientationLockDelegate::attach() {
67 document().addEventListener(EventTypeNames::fullscreenchange, this, true); 72 document().addEventListener(EventTypeNames::fullscreenchange, this, true);
68 videoElement().addEventListener(EventTypeNames::webkitfullscreenchange, this, 73 videoElement().addEventListener(EventTypeNames::webkitfullscreenchange, this,
69 true); 74 true);
70 videoElement().addEventListener(EventTypeNames::loadedmetadata, this, true); 75 videoElement().addEventListener(EventTypeNames::loadedmetadata, this, true);
71 } 76 }
72 77
78 void MediaControlsOrientationLockDelegate::detach() {
79 document().removeEventListener(EventTypeNames::fullscreenchange, this, true);
80 videoElement().removeEventListener(EventTypeNames::webkitfullscreenchange,
81 this, true);
82 videoElement().removeEventListener(EventTypeNames::loadedmetadata, this,
83 true);
84 }
85
73 bool MediaControlsOrientationLockDelegate::operator==( 86 bool MediaControlsOrientationLockDelegate::operator==(
74 const EventListener& other) const { 87 const EventListener& other) const {
75 return this == &other; 88 return this == &other;
76 } 89 }
77 90
78 void MediaControlsOrientationLockDelegate::maybeLockOrientation() { 91 void MediaControlsOrientationLockDelegate::maybeLockOrientation() {
79 DCHECK(m_state != State::MaybeLockedFullscreen); 92 DCHECK(m_state != State::MaybeLockedFullscreen);
80 93
81 if (videoElement().getReadyState() == HTMLMediaElement::kHaveNothing) { 94 if (videoElement().getReadyState() == HTMLMediaElement::kHaveNothing) {
82 recordMetadataAvailability(MetadataAvailabilityMetrics::Missing); 95 recordMetadataAvailability(MetadataAvailabilityMetrics::Missing);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 NOTREACHED(); 205 NOTREACHED();
193 return WebScreenOrientationLockLandscape; 206 return WebScreenOrientationLockLandscape;
194 } 207 }
195 208
196 DEFINE_TRACE(MediaControlsOrientationLockDelegate) { 209 DEFINE_TRACE(MediaControlsOrientationLockDelegate) {
197 EventListener::trace(visitor); 210 EventListener::trace(visitor);
198 visitor->trace(m_videoElement); 211 visitor->trace(m_videoElement);
199 } 212 }
200 213
201 } // namespace blink 214 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698