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

Unified Diff: third_party/WebKit/Source/core/html/MediaCustomControlsFullscreenDetector.cpp

Issue 2758233003: Fix the conditions when fullscreen detector listeners are registered (Closed)
Patch Set: addressed mlamouri's comments 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/MediaCustomControlsFullscreenDetector.cpp
diff --git a/third_party/WebKit/Source/core/html/MediaCustomControlsFullscreenDetector.cpp b/third_party/WebKit/Source/core/html/MediaCustomControlsFullscreenDetector.cpp
index 39e9ee874369b1bcf003372bed0d6f83a6eba6a0..773adc5c85e49f4c2c131a068e5ba5d7ef603b63 100644
--- a/third_party/WebKit/Source/core/html/MediaCustomControlsFullscreenDetector.cpp
+++ b/third_party/WebKit/Source/core/html/MediaCustomControlsFullscreenDetector.cpp
@@ -29,12 +29,8 @@ MediaCustomControlsFullscreenDetector::MediaCustomControlsFullscreenDetector(
this,
&MediaCustomControlsFullscreenDetector::
onCheckViewportIntersectionTimerFired) {
- videoElement().addEventListener(EventTypeNames::DOMNodeInsertedIntoDocument,
- this, false);
- videoElement().addEventListener(EventTypeNames::DOMNodeRemovedFromDocument,
- this, false);
-
- videoElement().addEventListener(EventTypeNames::loadedmetadata, this, true);
+ if (videoElement().isConnected())
+ attach();
}
bool MediaCustomControlsFullscreenDetector::operator==(
@@ -43,6 +39,7 @@ bool MediaCustomControlsFullscreenDetector::operator==(
}
void MediaCustomControlsFullscreenDetector::attach() {
+ videoElement().addEventListener(EventTypeNames::loadedmetadata, this, true);
videoElement().document().addEventListener(
EventTypeNames::webkitfullscreenchange, this, true);
videoElement().document().addEventListener(EventTypeNames::fullscreenchange,
@@ -50,6 +47,8 @@ void MediaCustomControlsFullscreenDetector::attach() {
}
void MediaCustomControlsFullscreenDetector::detach() {
+ videoElement().removeEventListener(EventTypeNames::loadedmetadata, this,
+ true);
videoElement().document().removeEventListener(
EventTypeNames::webkitfullscreenchange, this, true);
videoElement().document().removeEventListener(
@@ -99,20 +98,10 @@ bool MediaCustomControlsFullscreenDetector::computeIsDominantVideoForTests(
void MediaCustomControlsFullscreenDetector::handleEvent(
ExecutionContext* context,
Event* event) {
- DCHECK(event->type() == EventTypeNames::DOMNodeInsertedIntoDocument ||
- event->type() == EventTypeNames::DOMNodeRemovedFromDocument ||
- event->type() == EventTypeNames::loadedmetadata ||
+ DCHECK(event->type() == EventTypeNames::loadedmetadata ||
event->type() == EventTypeNames::webkitfullscreenchange ||
event->type() == EventTypeNames::fullscreenchange);
- // Don't early return when the video is inserted into/removed from the
- // document, as the document might already be in fullscreen.
- if (event->type() == EventTypeNames::DOMNodeInsertedIntoDocument) {
- attach();
- } else if (event->type() == EventTypeNames::DOMNodeRemovedFromDocument) {
- detach();
- }
-
// Video is not loaded yet.
if (videoElement().getReadyState() < HTMLMediaElement::kHaveMetadata)
return;

Powered by Google App Engine
This is Rietveld 408576698