| 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/AutoplayExperimentHelper.h" | 5 #include "core/html/AutoplayExperimentHelper.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/frame/Settings.h" | 8 #include "core/frame/Settings.h" |
| 9 #include "core/html/HTMLMediaElement.h" | 9 #include "core/html/HTMLMediaElement.h" |
| 10 #include "core/layout/LayoutBox.h" | 10 #include "core/layout/LayoutBox.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 { | 39 { |
| 40 m_mode = fromString(this->client().autoplayExperimentMode()); | 40 m_mode = fromString(this->client().autoplayExperimentMode()); |
| 41 | 41 |
| 42 DVLOG_IF(3, isExperimentEnabled()) << "autoplay experiment set to " << m_mod
e; | 42 DVLOG_IF(3, isExperimentEnabled()) << "autoplay experiment set to " << m_mod
e; |
| 43 } | 43 } |
| 44 | 44 |
| 45 AutoplayExperimentHelper::~AutoplayExperimentHelper() | 45 AutoplayExperimentHelper::~AutoplayExperimentHelper() |
| 46 { | 46 { |
| 47 } | 47 } |
| 48 | 48 |
| 49 void AutoplayExperimentHelper::dispose() | |
| 50 { | |
| 51 // Do any cleanup that requires the client. | |
| 52 unregisterForPositionUpdatesIfNeeded(); | |
| 53 } | |
| 54 | |
| 55 void AutoplayExperimentHelper::becameReadyToPlay() | 49 void AutoplayExperimentHelper::becameReadyToPlay() |
| 56 { | 50 { |
| 57 // Assuming that we're eligible to override the user gesture requirement, | 51 // Assuming that we're eligible to override the user gesture requirement, |
| 58 // either play if we meet the visibility checks, or install a listener | 52 // either play if we meet the visibility checks, or install a listener |
| 59 // to wait for them to pass. We do not actually start playback; our | 53 // to wait for them to pass. We do not actually start playback; our |
| 60 // caller must do that. | 54 // caller must do that. |
| 61 autoplayMediaEncountered(); | 55 autoplayMediaEncountered(); |
| 62 | 56 |
| 63 if (isEligible()) { | 57 if (isEligible()) { |
| 64 if (meetsVisibilityRequirements()) | 58 if (meetsVisibilityRequirements()) |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 | 401 |
| 408 // Don't bother to call autoplayMediaEncountered, since whoever initiates | 402 // Don't bother to call autoplayMediaEncountered, since whoever initiates |
| 409 // playback has do it anyway, in case we don't allow autoplay. | 403 // playback has do it anyway, in case we don't allow autoplay. |
| 410 | 404 |
| 411 unregisterForPositionUpdatesIfNeeded(); | 405 unregisterForPositionUpdatesIfNeeded(); |
| 412 muteIfNeeded(); | 406 muteIfNeeded(); |
| 413 | 407 |
| 414 // Do not actually start playback here. | 408 // Do not actually start playback here. |
| 415 } | 409 } |
| 416 | 410 |
| 417 AutoplayExperimentHelper::Client& AutoplayExperimentHelper::client() const | |
| 418 { | |
| 419 return *m_client; | |
| 420 } | |
| 421 | |
| 422 AutoplayExperimentHelper::Mode AutoplayExperimentHelper::fromString(const String
& mode) | 411 AutoplayExperimentHelper::Mode AutoplayExperimentHelper::fromString(const String
& mode) |
| 423 { | 412 { |
| 424 Mode value = ExperimentOff; | 413 Mode value = ExperimentOff; |
| 425 if (mode.contains("-forvideo")) | 414 if (mode.contains("-forvideo")) |
| 426 value |= ForVideo; | 415 value |= ForVideo; |
| 427 if (mode.contains("-foraudio")) | 416 if (mode.contains("-foraudio")) |
| 428 value |= ForAudio; | 417 value |= ForAudio; |
| 429 if (mode.contains("-ifpagevisible")) | 418 if (mode.contains("-ifpagevisible")) |
| 430 value |= IfPageVisible; | 419 value |= IfPageVisible; |
| 431 if (mode.contains("-ifviewport")) | 420 if (mode.contains("-ifviewport")) |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 { | 535 { |
| 547 return client().isHTMLVideoElement() && (enabled(IfViewport) || enabled(IfPa
rtialViewport)); | 536 return client().isHTMLVideoElement() && (enabled(IfViewport) || enabled(IfPa
rtialViewport)); |
| 548 } | 537 } |
| 549 | 538 |
| 550 bool AutoplayExperimentHelper::isExperimentEnabled() | 539 bool AutoplayExperimentHelper::isExperimentEnabled() |
| 551 { | 540 { |
| 552 return m_mode != Mode::ExperimentOff; | 541 return m_mode != Mode::ExperimentOff; |
| 553 } | 542 } |
| 554 | 543 |
| 555 } // namespace blink | 544 } // namespace blink |
| OLD | NEW |