Changeset 244899 in webkit


Ignore:
Timestamp:
May 2, 2019 9:28:13 PM (5 years ago)
Author:
youenn@apple.com
Message:

Make AudioContext::scriptExecutionContext() private
https://bugs.webkit.org/show_bug.cgi?id=197512

Reviewed by Eric Carlson.

Refactor code to make audio nodes not rely on AudioContext::scriptExecutionContext.
Instead, let AudioContext provide the necessary API for its nodes.
Covered by existing tests.

  • Modules/webaudio/AudioBufferSourceNode.cpp:

(WebCore::AudioBufferSourceNode::looping):
(WebCore::AudioBufferSourceNode::setLooping):

  • Modules/webaudio/AudioContext.cpp:

(WebCore::AudioContext::postTask):
(WebCore::AudioContext::origin const):
(WebCore::AudioContext::addConsoleMessage):

  • Modules/webaudio/AudioContext.h:

(WebCore::AudioContext::isStopped const):

  • Modules/webaudio/AudioNode.cpp:

(WebCore::AudioNode::scriptExecutionContext const):

  • Modules/webaudio/AudioNode.h:
  • Modules/webaudio/AudioScheduledSourceNode.cpp:

(WebCore::AudioScheduledSourceNode::finish):

  • Modules/webaudio/DefaultAudioDestinationNode.cpp:

(WebCore::DefaultAudioDestinationNode::resume):
(WebCore::DefaultAudioDestinationNode::suspend):
(WebCore::DefaultAudioDestinationNode::close):

  • Modules/webaudio/MediaElementAudioSourceNode.cpp:

(WebCore::MediaElementAudioSourceNode::wouldTaintOrigin):

  • Modules/webaudio/MediaStreamAudioDestinationNode.cpp:

(WebCore::MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode):

  • Modules/webaudio/ScriptProcessorNode.cpp:

(WebCore::ScriptProcessorNode::fireProcessEvent):

Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r244894 r244899  
     12019-05-02  Youenn Fablet  <youenn@apple.com>
     2
     3        Make AudioContext::scriptExecutionContext() private
     4        https://bugs.webkit.org/show_bug.cgi?id=197512
     5
     6        Reviewed by Eric Carlson.
     7
     8        Refactor code to make audio nodes not rely on AudioContext::scriptExecutionContext.
     9        Instead, let AudioContext provide the necessary API for its nodes.
     10        Covered by existing tests.
     11
     12        * Modules/webaudio/AudioBufferSourceNode.cpp:
     13        (WebCore::AudioBufferSourceNode::looping):
     14        (WebCore::AudioBufferSourceNode::setLooping):
     15        * Modules/webaudio/AudioContext.cpp:
     16        (WebCore::AudioContext::postTask):
     17        (WebCore::AudioContext::origin const):
     18        (WebCore::AudioContext::addConsoleMessage):
     19        * Modules/webaudio/AudioContext.h:
     20        (WebCore::AudioContext::isStopped const):
     21        * Modules/webaudio/AudioNode.cpp:
     22        (WebCore::AudioNode::scriptExecutionContext const):
     23        * Modules/webaudio/AudioNode.h:
     24        * Modules/webaudio/AudioScheduledSourceNode.cpp:
     25        (WebCore::AudioScheduledSourceNode::finish):
     26        * Modules/webaudio/DefaultAudioDestinationNode.cpp:
     27        (WebCore::DefaultAudioDestinationNode::resume):
     28        (WebCore::DefaultAudioDestinationNode::suspend):
     29        (WebCore::DefaultAudioDestinationNode::close):
     30        * Modules/webaudio/MediaElementAudioSourceNode.cpp:
     31        (WebCore::MediaElementAudioSourceNode::wouldTaintOrigin):
     32        * Modules/webaudio/MediaStreamAudioDestinationNode.cpp:
     33        (WebCore::MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode):
     34        * Modules/webaudio/ScriptProcessorNode.cpp:
     35        (WebCore::ScriptProcessorNode::fireProcessEvent):
     36
    1372019-05-02  Ryosuke Niwa  <rniwa@webkit.org>
    238
  • trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp

    r243887 r244899  
    534534{
    535535    static bool firstTime = true;
    536     if (firstTime && context().scriptExecutionContext()) {
    537         context().scriptExecutionContext()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "AudioBufferSourceNode 'looping' attribute is deprecated.  Use 'loop' instead."_s);
     536    if (firstTime) {
     537        context().addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "AudioBufferSourceNode 'looping' attribute is deprecated.  Use 'loop' instead."_s);
    538538        firstTime = false;
    539539    }
     
    545545{
    546546    static bool firstTime = true;
    547     if (firstTime && context().scriptExecutionContext()) {
    548         context().scriptExecutionContext()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "AudioBufferSourceNode 'looping' attribute is deprecated.  Use 'loop' instead."_s);
     547    if (firstTime) {
     548        context().addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "AudioBufferSourceNode 'looping' attribute is deprecated.  Use 'loop' instead."_s);
    549549        firstTime = false;
    550550    }
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp

    r244860 r244899  
    13211321}
    13221322
     1323void AudioContext::postTask(WTF::Function<void()>&& task)
     1324{
     1325    if (m_isStopScheduled)
     1326        return;
     1327
     1328    m_scriptExecutionContext->postTask(WTFMove(task));
     1329}
     1330
     1331const SecurityOrigin* AudioContext::origin() const
     1332{
     1333    return m_scriptExecutionContext ? m_scriptExecutionContext->securityOrigin() : nullptr;
     1334}
     1335
     1336void AudioContext::addConsoleMessage(MessageSource source, MessageLevel level, const String& message)
     1337{
     1338    if (m_scriptExecutionContext)
     1339        m_scriptExecutionContext->addConsoleMessage(source, level, message);
     1340}
     1341
    13231342#if !RELEASE_LOG_DISABLED
    13241343WTFLogChannel& AudioContext::logChannel() const
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.h

    r244825 r244899  
    3535#include "MediaProducer.h"
    3636#include "PlatformMediaSession.h"
     37#include "ScriptExecutionContext.h"
    3738#include "VisibilityChangeClient.h"
     39#include <JavaScriptCore/ConsoleTypes.h>
    3840#include <JavaScriptCore/Float32Array.h>
    3941#include <atomic>
     
    7375class PeriodicWave;
    7476class ScriptProcessorNode;
     77class SecurityOrigin;
    7578class WaveShaperNode;
    7679
     
    250253    // EventTarget
    251254    EventTargetInterface eventTargetInterface() const final { return AudioContextEventTargetInterfaceType; }
    252     ScriptExecutionContext* scriptExecutionContext() const final;
    253255
    254256    // Reconcile ref/deref which are defined both in ThreadSafeRefCounted and EventTarget.
     
    285287#endif
    286288
     289    void postTask(WTF::Function<void()>&&);
     290    bool isStopped() const { return m_isStopScheduled; }
     291    const SecurityOrigin* origin() const;
     292    void addConsoleMessage(MessageSource, MessageLevel, const String& message);
     293
    287294protected:
    288295    explicit AudioContext(Document&);
     
    310317
    311318    void mediaCanStart(Document&) override;
     319
     320    // EventTarget
     321    ScriptExecutionContext* scriptExecutionContext() const final;
    312322
    313323    // MediaProducer
  • trunk/Source/WebCore/Modules/webaudio/AudioNode.cpp

    r243887 r244899  
    360360ScriptExecutionContext* AudioNode::scriptExecutionContext() const
    361361{
    362     return const_cast<AudioNode*>(this)->context().scriptExecutionContext();
     362    return static_cast<ActiveDOMObject&>(const_cast<AudioNode*>(this)->context()).scriptExecutionContext();
    363363}
    364364
  • trunk/Source/WebCore/Modules/webaudio/AudioNode.h

    r243887 r244899  
    182182    AudioBus::ChannelInterpretation internalChannelInterpretation() const { return m_channelInterpretation; }
    183183
    184     // EventTarget
    185     EventTargetInterface eventTargetInterface() const override;
    186     ScriptExecutionContext* scriptExecutionContext() const final;
    187 
    188184protected:
    189185    // Inputs and outputs must be created before the AudioNode is initialized.
     
    207203
    208204private:
     205    // EventTarget
     206    EventTargetInterface eventTargetInterface() const override;
     207    ScriptExecutionContext* scriptExecutionContext() const final;
     208
    209209    volatile bool m_isInitialized;
    210210    NodeType m_nodeType;
  • trunk/Source/WebCore/Modules/webaudio/AudioScheduledSourceNode.cpp

    r243887 r244899  
    178178        return;
    179179
    180     auto* scriptExecutionContext = this->scriptExecutionContext();
    181     if (!scriptExecutionContext)
    182         return;
    183 
    184     scriptExecutionContext->postTask([this, protectedThis = makeRef(*this)] (auto&) {
    185         // Make sure ActiveDOMObjects have not been stopped after scheduling this task.
    186         if (!this->scriptExecutionContext())
     180    context().postTask([this, protectedThis = makeRef(*this)] {
     181        if (context().isStopped())
    187182            return;
    188 
    189183        this->dispatchEvent(Event::create(eventNames().endedEvent, Event::CanBubble::No, Event::IsCancelable::No));
    190184    });
  • trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.cpp

    r243887 r244899  
    119119    if (isInitialized())
    120120        m_destination->start();
    121     if (auto scriptExecutionContext = context().scriptExecutionContext())
    122         scriptExecutionContext->postTask(WTFMove(function));
     121    context().postTask(WTFMove(function));
    123122}
    124123
     
    128127    if (isInitialized())
    129128        m_destination->stop();
    130     if (auto scriptExecutionContext = context().scriptExecutionContext())
    131         scriptExecutionContext->postTask(WTFMove(function));
     129    context().postTask(WTFMove(function));
    132130}
    133131
     
    136134    ASSERT(isInitialized());
    137135    uninitialize();
    138     if (auto scriptExecutionContext = context().scriptExecutionContext())
    139         scriptExecutionContext->postTask(WTFMove(function));
     136    context().postTask(WTFMove(function));
    140137}
    141138
  • trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp

    r243887 r244899  
    114114        return false;
    115115
    116     if (auto* scriptExecutionContext = context().scriptExecutionContext()) {
    117         if (auto* origin = scriptExecutionContext->securityOrigin())
    118             return m_mediaElement->wouldTaintOrigin(*origin);
    119     }
     116    if (auto* origin = context().origin())
     117        return m_mediaElement->wouldTaintOrigin(*origin);
    120118
    121119    return true;
  • trunk/Source/WebCore/Modules/webaudio/MediaStreamAudioDestinationNode.cpp

    r243887 r244899  
    3030#include "AudioContext.h"
    3131#include "AudioNodeInput.h"
     32#include "Document.h"
    3233#include "MediaStream.h"
    3334#include "MediaStreamAudioSource.h"
     
    4748    : AudioBasicInspectorNode(context, context.sampleRate(), numberOfChannels)
    4849    , m_source(MediaStreamAudioSource::create(context.sampleRate()))
    49     , m_stream(MediaStream::create(*context.scriptExecutionContext(), MediaStreamPrivate::create(m_source.copyRef())))
     50    , m_stream(MediaStream::create(*context.document(), MediaStreamPrivate::create(m_source.copyRef())))
    5051{
    5152    setNodeType(NodeTypeMediaStreamAudioDestination);
  • trunk/Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp

    r243887 r244899  
    223223
    224224    // Avoid firing the event if the document has already gone away.
    225     if (context().scriptExecutionContext()) {
     225    if (!context().isStopped()) {
    226226        // Let the audio thread know we've gotten to the point where it's OK for it to make another request.
    227227        m_isRequestOutstanding = false;
Note: See TracChangeset for help on using the changeset viewer.