Changeset 251537 in webkit


Ignore:
Timestamp:
Oct 24, 2019, 7:39:09 AM (6 years ago)
Author:
Chris Dumez
Message:

AudioContext should not prevent entering the back/forward cache
https://bugs.webkit.org/show_bug.cgi?id=203102

Reviewed by Geoffrey Garen.

Source/WebCore:

Allow pages with AudioContexts that are rendering in the back/forward cache.
Upon entering the back/forward cache, we suspend rendering and update IsPlaying
state so that the browser no longer shows the "Audio Playing" icon. Upon restoring
from the back/forward cache, we resume rendering and update IsPlaying state again
so that the browser shows the "Audio Playing" icon again. I tested it on:

With regards to events dispatching, the AudioContext class is already using a
GenericEventQueue that properly delays event dispatching while in the back/forward
cache.

No new tests, updated existing test.

  • Modules/webaudio/AudioContext.cpp:

(WebCore::AudioContext::suspend):
(WebCore::AudioContext::resume):
(WebCore::AudioContext::suspendRendering):
(WebCore::AudioContext::resumeRendering):

  • Modules/webaudio/AudioContext.h:
  • Modules/webaudio/AudioContext.idl:

LayoutTests:

Update layout test coverage.

  • fast/history/page-cache-running-audiocontext-expected.txt:
  • fast/history/page-cache-running-audiocontext.html:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r251536 r251537  
     12019-10-24  Chris Dumez  <[email protected]>
     2
     3        AudioContext should not prevent entering the back/forward cache
     4        https://bugs.webkit.org/show_bug.cgi?id=203102
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Update layout test coverage.
     9
     10        * fast/history/page-cache-running-audiocontext-expected.txt:
     11        * fast/history/page-cache-running-audiocontext.html:
     12
    1132019-10-24  Antoine Quint  <[email protected]>
    214
  • trunk/LayoutTests/fast/history/page-cache-running-audiocontext-expected.txt

    r180934 r251537  
    1 Tests that a page with a running AudioContext does not go into the page cache.
     1Tests that a page with a running AudioContext goes into the back/forward cache.
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
     
    55
    66pageshow - not from cache
    7 PASS Page was not restored from page cache
     7pagehide - entering cache
     8pageshow - from cache
     9PASS Page did enter and was restored from the back/forward cache
    810PASS successfullyParsed is true
    911
  • trunk/LayoutTests/fast/history/page-cache-running-audiocontext.html

    r251220 r251537  
    33<html>
    44<body>
    5 <script src="../../resources/js-test-pre.js"></script>
     5<script src="../../resources/js-test.js"></script>
    66<script>
    7 description('Tests that a page with a running AudioContext does not go into the page cache.');
     7description('Tests that a page with a running AudioContext goes into the back/forward cache.');
    88window.jsTestIsAsync = true;
    99
     
    1111    debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache");
    1212
    13     if (!window.sessionStorage.page_cache_running_audiocontext_test_started)
    14         return;
    15 
    16     delete window.sessionStorage.page_cache_running_audiocontext_test_started;
    17 
    18     if (event.persisted)
    19         testFailed("Page did enter and was restored from the page cache");
    20     else
    21         testPassed("Page was not restored from page cache");
    22 
    23     finishJSTest();
     13    if (event.persisted) {
     14        testPassed("Page did enter and was restored from the back/forward cache");
     15        finishJSTest();
     16    }
    2417}, false);
    2518
    2619window.addEventListener("pagehide", function(event) {
    2720    debug("pagehide - " + (event.persisted ? "" : "not ") + "entering cache");
    28     if (event.persisted) {
    29         testFailed("Page entered the page cache.");
     21    if (!event.persisted) {
     22        testFailed("Page failed to enter the back/forward cache.");
    3023        finishJSTest();
    3124    }
     
    4336    setTimeout(function() {
    4437        // Force a back navigation back to this page.
    45         window.sessionStorage.page_cache_running_audiocontext_test_started = true;
    4638        window.location.href = "resources/page-cache-helper.html";
    4739    }, 0);
    4840}, false);
    49 
    5041</script>
    51 <script src="../../resources/js-test-post.js"></script>
    5242</body>
    5343</html>
  • trunk/Source/WebCore/ChangeLog

    r251532 r251537  
     12019-10-24  Chris Dumez  <[email protected]>
     2
     3        AudioContext should not prevent entering the back/forward cache
     4        https://bugs.webkit.org/show_bug.cgi?id=203102
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Allow pages with AudioContexts that are rendering in the back/forward cache.
     9        Upon entering the back/forward cache, we suspend rendering and update IsPlaying
     10        state so that the browser no longer shows the "Audio Playing" icon. Upon restoring
     11        from the back/forward cache, we resume rendering and update IsPlaying state again
     12        so that the browser shows the "Audio Playing" icon again. I tested it on:
     13        - http://webaudioplayground.appspot.com
     14
     15        With regards to events dispatching, the AudioContext class is already using a
     16        GenericEventQueue that properly delays event dispatching while in the back/forward
     17        cache.
     18
     19        No new tests, updated existing test.
     20
     21        * Modules/webaudio/AudioContext.cpp:
     22        (WebCore::AudioContext::suspend):
     23        (WebCore::AudioContext::resume):
     24        (WebCore::AudioContext::suspendRendering):
     25        (WebCore::AudioContext::resumeRendering):
     26        * Modules/webaudio/AudioContext.h:
     27        * Modules/webaudio/AudioContext.idl:
     28
    1292019-10-24  Antti Koivisto  <[email protected]>
    230
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp

    r251244 r251537  
    341341}
    342342
    343 bool AudioContext::shouldPreventEnteringBackForwardCache_DEPRECATED() const
    344 {
    345     // FIXME: We should be able to suspend while rendering as well with some more code.
    346     return m_state != State::Suspended && m_state != State::Closed;
     343void AudioContext::suspend(ReasonForSuspension)
     344{
     345    if (state() == State::Running) {
     346        m_mediaSession->beginInterruption(PlatformMediaSession::PlaybackSuspended);
     347        document()->updateIsPlayingMedia();
     348    }
     349}
     350
     351void AudioContext::resume()
     352{
     353    if (state() == State::Interrupted) {
     354        m_mediaSession->endInterruption(PlatformMediaSession::MayResumePlaying);
     355        document()->updateIsPlayingMedia();
     356    }
    347357}
    348358
     
    12301240}
    12311241
    1232 void AudioContext::suspend(DOMPromiseDeferred<void>&& promise)
     1242void AudioContext::suspendRendering(DOMPromiseDeferred<void>&& promise)
    12331243{
    12341244    if (isOfflineContext() || m_isStopScheduled) {
     
    12591269}
    12601270
    1261 void AudioContext::resume(DOMPromiseDeferred<void>&& promise)
     1271void AudioContext::resumeRendering(DOMPromiseDeferred<void>&& promise)
    12621272{
    12631273    if (isOfflineContext() || m_isStopScheduled) {
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.h

    r251244 r251537  
    127127    AudioListener* listener() { return m_listener.get(); }
    128128
    129     using ActiveDOMObject::suspend;
    130     using ActiveDOMObject::resume;
    131 
    132     void suspend(DOMPromiseDeferred<void>&&);
    133     void resume(DOMPromiseDeferred<void>&&);
     129    void suspendRendering(DOMPromiseDeferred<void>&&);
     130    void resumeRendering(DOMPromiseDeferred<void>&&);
    134131    void close(DOMPromiseDeferred<void>&&);
    135132
     
    339336
    340337    // ActiveDOMObject API.
     338    void suspend(ReasonForSuspension) final;
     339    void resume() final;
    341340    void stop() override;
    342     bool shouldPreventEnteringBackForwardCache_DEPRECATED() const override;
    343341    const char* activeDOMObjectName() const override;
    344342
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.idl

    r244825 r251537  
    5252    readonly attribute AudioListener listener;
    5353
    54     Promise<void> suspend();
    55     Promise<void> resume();
     54    [ImplementedAs=suspendRendering] Promise<void> suspend();
     55    [ImplementedAs=resumeRendering] Promise<void> resume();
    5656    Promise<void> close();
    5757
Note: See TracChangeset for help on using the changeset viewer.