Changeset 166443 in webkit


Ignore:
Timestamp:
Mar 28, 2014, 6:15:49 PM (11 years ago)
Author:
Stephanie Lewis
Message:

Source/WebCore: Rename pluginDidEvaluate to better represent when it’s called.
Part of <rdar://problem/16061257> PluginProcess should AppNap when no plugins on active tab.

Reviewed by Anders Carlsson.

No new test because it’s just a name change.

  • page/PageThrottler.h:

(WebCore::PageThrottler::pluginDidEvaluateWhileAudioIsPlaying):

Source/WebKit2: Stop waking up the web process in the background because of plugin activity.
Part of <rdar://problem/16061257> PluginProcess should AppNap when no plugins on active tab.

Reviewed by Anders Carlsson.

Plugin activity in the background can constantly wake up web processes. This is only
necessary when audio is playing to support web apps like Pandora and youtube playing
in the background. Use a new api in CoreAudio to see if there is audio playing in
the PluginProcess.

  • PluginProcess/PluginProcess.cpp:

(WebKit::PluginProcess::PluginProcess): Add a AudioHardwareListener
(WebKit::PluginProcess::createWebProcessConnection): tell web process current state
(WebKit::PluginProcess::audioHardwareDidBecomeActive): respond to audio hardware notifications
(WebKit::PluginProcess::audioHardwareDidBecomeInactive):

  • PluginProcess/PluginProcess.h:
  • PluginProcess/WebProcessConnection.cpp: tell WebProcess when audio state in PluginProcess

changes.

(WebKit::WebProcessConnection::audioHardwareDidBecomeActive):
(WebKit::WebProcessConnection::audioHardwareDidBecomeInactive):

  • PluginProcess/WebProcessConnection.h:
  • WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:

Only invoke pageThrottler activity when playing audio

(WebKit::NPRuntimeObjectMap::evaluate):

  • WebProcess/Plugins/Plugin.h: add function to get audio state

(WebKit::Plugin::audioIsPlayingInPluginProcess):

  • WebProcess/Plugins/PluginProcessConnection.cpp: store audio state

(WebKit::PluginProcessConnection::PluginProcessConnection):
(WebKit::PluginProcessConnection::didReceiveMessage):
(WebKit::PluginProcessConnection::audioHardwareDidBecomeActive):
(WebKit::PluginProcessConnection::audioHardwareDidBecomeInactive):

  • WebProcess/Plugins/PluginProcessConnection.h:

(WebKit::PluginProcessConnection::audioIsPlaying):

  • WebProcess/Plugins/PluginProcessConnection.messages.in:
  • WebProcess/Plugins/PluginProxy.cpp:

(WebKit::PluginProxy::audioIsPlayingInPluginProcess):

  • WebProcess/Plugins/PluginProxy.h:
  • WebProcess/Plugins/PluginView.cpp:

(WebKit::PluginView::audioIsPlayingInPluginProcess):

  • WebProcess/Plugins/PluginView.h:
Location:
trunk/Source
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r166442 r166443  
     12014-03-28  Stephanie Lewis  <slewis@apple.com>
     2
     3        Rename pluginDidEvaluate to better represent when it’s called.
     4        Part of <rdar://problem/16061257> PluginProcess should AppNap when no plugins on active tab.
     5
     6        Reviewed by Anders Carlsson.
     7
     8        No new test because it’s just a name change.
     9
     10        * page/PageThrottler.h:
     11        (WebCore::PageThrottler::pluginDidEvaluateWhileAudioIsPlaying):
     12
    1132014-03-28  Stephanie Lewis  <slewis@apple.com>
    214
  • trunk/Source/WebCore/page/PageThrottler.h

    r164948 r166443  
    4848
    4949    void didReceiveUserInput() { m_hysteresis.impulse(); }
    50     void pluginDidEvaluate() { m_hysteresis.impulse(); }
     50    void pluginDidEvaluateWhileAudioIsPlaying() { m_hysteresis.impulse(); }
    5151    std::unique_ptr<PageActivityAssertionToken> mediaActivityToken();
    5252    std::unique_ptr<PageActivityAssertionToken> pageLoadActivityToken();
  • trunk/Source/WebKit2/ChangeLog

    r166441 r166443  
     12014-03-28  Stephanie Lewis  <slewis@apple.com>
     2
     3        Stop waking up the web process in the background because of plugin activity.
     4        Part of <rdar://problem/16061257> PluginProcess should AppNap when no plugins on active tab.
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Plugin activity in the background can constantly wake up web processes.  This is only
     9        necessary when audio is playing to support web apps like Pandora and youtube playing
     10        in the background.  Use a new api in CoreAudio to see if there is audio playing in
     11        the PluginProcess.
     12
     13        * PluginProcess/PluginProcess.cpp:
     14        (WebKit::PluginProcess::PluginProcess): Add a AudioHardwareListener
     15        (WebKit::PluginProcess::createWebProcessConnection): tell web process current state
     16        (WebKit::PluginProcess::audioHardwareDidBecomeActive): respond to audio hardware notifications
     17        (WebKit::PluginProcess::audioHardwareDidBecomeInactive):
     18        * PluginProcess/PluginProcess.h:
     19        * PluginProcess/WebProcessConnection.cpp: tell WebProcess when audio state in PluginProcess
     20             changes.
     21        (WebKit::WebProcessConnection::audioHardwareDidBecomeActive):
     22        (WebKit::WebProcessConnection::audioHardwareDidBecomeInactive):
     23        * PluginProcess/WebProcessConnection.h:
     24        * WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:
     25             Only invoke pageThrottler activity when playing audio
     26        (WebKit::NPRuntimeObjectMap::evaluate):
     27        * WebProcess/Plugins/Plugin.h: add function to get audio state
     28        (WebKit::Plugin::audioIsPlayingInPluginProcess):
     29        * WebProcess/Plugins/PluginProcessConnection.cpp: store audio state
     30        (WebKit::PluginProcessConnection::PluginProcessConnection):
     31        (WebKit::PluginProcessConnection::didReceiveMessage):
     32        (WebKit::PluginProcessConnection::audioHardwareDidBecomeActive):
     33        (WebKit::PluginProcessConnection::audioHardwareDidBecomeInactive):
     34        * WebProcess/Plugins/PluginProcessConnection.h:
     35        (WebKit::PluginProcessConnection::audioIsPlaying):
     36        * WebProcess/Plugins/PluginProcessConnection.messages.in:
     37        * WebProcess/Plugins/PluginProxy.cpp:
     38        (WebKit::PluginProxy::audioIsPlayingInPluginProcess):
     39        * WebProcess/Plugins/PluginProxy.h:
     40        * WebProcess/Plugins/PluginView.cpp:
     41        (WebKit::PluginView::audioIsPlayingInPluginProcess):
     42        * WebProcess/Plugins/PluginView.h:
     43
    1442014-03-28  Stephanie Lewis  <slewis@apple.com>
    245
  • trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp

    r166441 r166443  
    6565{
    6666    NetscapePlugin::setSetExceptionFunction(WebProcessConnection::setGlobalException);
     67    m_audioHardwareListener = AudioHardwareListener::create(*this);
    6768}
    6869
     
    162163    // Create a listening connection.
    163164    RefPtr<WebProcessConnection> connection = WebProcessConnection::create(IPC::Connection::Identifier(listeningPort));
     165
     166    if (m_audioHardwareListener) {
     167        if (m_audioHardwareListener->hardwareActivity() == WebCore::AudioHardwareActivityType::IsActive)
     168            connection->audioHardwareDidBecomeActive();
     169        else if (m_audioHardwareListener->hardwareActivity() == WebCore::AudioHardwareActivityType::IsInactive)
     170            connection->audioHardwareDidBecomeInactive();
     171    }
     172
    164173    m_webProcessConnections.append(connection.release());
    165174
     
    247256    m_visiblePluginsActivity.decrement();
    248257}
     258   
     259void PluginProcess::audioHardwareDidBecomeActive()
     260{
     261    for (auto& connection : m_webProcessConnections)
     262        connection->audioHardwareDidBecomeActive();
     263}
     264   
     265void PluginProcess::audioHardwareDidBecomeInactive()
     266{
     267    for (auto& connection : m_webProcessConnections)
     268        connection->audioHardwareDidBecomeInactive();
     269}
    249270
    250271} // namespace WebKit
  • trunk/Source/WebKit2/PluginProcess/PluginProcess.h

    r166441 r166443  
    3131#include "ChildProcess.h"
    3232#include <WebCore/CountedUserActivity.h>
     33#include <WebCore/AudioHardwareListener.h>
    3334#include <wtf/Forward.h>
    3435#include <wtf/NeverDestroyed.h>
     
    4142struct PluginProcessCreationParameters;
    4243       
    43 class PluginProcess : public ChildProcess {
     44class PluginProcess : public ChildProcess, private WebCore::AudioHardwareListener::Client
     45{
    4446    WTF_MAKE_NONCOPYABLE(PluginProcess);
    4547    friend class NeverDestroyed<PluginProcess>;
     
    9698    void getSitesWithData(uint64_t callbackID);
    9799    void clearSiteData(const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID);
     100   
     101    // AudioHardwareListenerClient
     102    virtual void audioHardwareDidBecomeActive() override;
     103    virtual void audioHardwareDidBecomeInactive() override;
    98104
    99105    void platformInitializePluginProcess(const PluginProcessCreationParameters&);
     
    126132    CountedUserActivity m_connectionActivity;
    127133    CountedUserActivity m_visiblePluginsActivity;
     134   
     135    RefPtr<WebCore::AudioHardwareListener> m_audioHardwareListener;
    128136};
    129137
  • trunk/Source/WebKit2/PluginProcess/WebProcessConnection.cpp

    r166441 r166443  
    4040#include "PluginProxyMessages.h"
    4141#include "WebProcessConnectionMessages.h"
     42#include <WebCore/AudioHardwareListener.h>
    4243#include <unistd.h>
    4344#include <wtf/RunLoop.h>
     
    349350}
    350351   
     352void WebProcessConnection::audioHardwareDidBecomeActive()
     353{
     354    m_connection->send(Messages::PluginProcessConnection::AudioHardwareDidBecomeActive(), 0);
     355}
     356
     357void WebProcessConnection::audioHardwareDidBecomeInactive()
     358{
     359    m_connection->send(Messages::PluginProcessConnection::AudioHardwareDidBecomeInactive(), 0);
     360}
     361   
    351362} // namespace WebKit
    352363
  • trunk/Source/WebKit2/PluginProcess/WebProcessConnection.h

    r166441 r166443  
    5858    void pluginDidBecomeHidden(unsigned pluginInstanceID);
    5959
     60    void audioHardwareDidBecomeActive();
     61    void audioHardwareDidBecomeInactive();
     62
    6063private:
    6164    WebProcessConnection(IPC::Connection::Identifier);
  • trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp

    r163647 r166443  
    4040#include <JavaScriptCore/Strong.h>
    4141#include <JavaScriptCore/StrongInlines.h>
     42#include <WebCore/AudioHardwareListener.h>
    4243#include <WebCore/DOMWrapperWorld.h>
    4344#include <WebCore/Frame.h>
     
    191192
    192193    if (m_pluginView && !m_pluginView->isBeingDestroyed()) {
    193         if (Page* page = m_pluginView->frame()->page())
    194             page->pageThrottler().pluginDidEvaluate();
     194        if (Page* page = m_pluginView->frame()->page()) {
     195            if (m_pluginView->audioHardwareActivity() != WebCore::AudioHardwareActivityType::IsInactive)
     196                page->pageThrottler().pluginDidEvaluateWhileAudioIsPlaying();
     197        }
    195198    }
    196199
  • trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h

    r164192 r166443  
    2727#define Plugin_h
    2828
     29#include <WebCore/AudioHardwareListener.h>
    2930#include <WebCore/FindOptions.h>
    3031#include <WebCore/GraphicsLayer.h>
     
    277278
    278279    virtual String getSelectionString() const = 0;
     280   
     281    virtual WebCore::AudioHardwareActivityType audioHardwareActivity() const { return WebCore::AudioHardwareActivityType::Unknown; }
    279282
    280283protected:
  • trunk/Source/WebKit2/WebProcess/Plugins/PluginProcessConnection.cpp

    r161148 r166443  
    4747    , m_pluginProcessToken(pluginProcessToken)
    4848    , m_supportsAsynchronousPluginInitialization(supportsAsynchronousPluginInitialization)
     49    , m_audioHardwareActivity(WebCore::AudioHardwareActivityType::Unknown)
    4950{
    5051    m_connection = IPC::Connection::createClientConnection(connectionIdentifier, this, RunLoop::main());
     
    9192void PluginProcessConnection::didReceiveMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder)
    9293{
     94    if (!decoder.destinationID()) {
     95        didReceivePluginProcessConnectionMessage(connection, decoder);
     96        return;
     97    }
     98   
    9399    ASSERT(decoder.destinationID());
    94100
     
    139145    NPRuntimeObjectMap::setGlobalException(exceptionString);
    140146}
     147   
     148void PluginProcessConnection::audioHardwareDidBecomeActive()
     149{
     150    m_audioHardwareActivity = WebCore::AudioHardwareActivityType::IsActive;
     151}
     152
     153void PluginProcessConnection::audioHardwareDidBecomeInactive()
     154{
     155    m_audioHardwareActivity = WebCore::AudioHardwareActivityType::IsInactive;
     156}
    141157
    142158} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/Plugins/PluginProcessConnection.h

    r162139 r166443  
    5959
    6060    bool supportsAsynchronousPluginInitialization() const { return m_supportsAsynchronousPluginInitialization; }
    61 
     61    WebCore::AudioHardwareActivityType audioHardwareActivity() const { return m_audioHardwareActivity; }
     62   
    6263private:
    6364    PluginProcessConnection(PluginProcessConnectionManager*, uint64_t pluginProcessToken, IPC::Connection::Identifier connectionIdentifier, bool supportsAsynchronousInitialization);
     
    7071
    7172    // Message handlers.
     73    void didReceivePluginProcessConnectionMessage(IPC::Connection*, IPC::MessageDecoder&);
    7274    void didReceiveSyncPluginProcessConnectionMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&);
    7375    void setException(const String&);
     76    void audioHardwareDidBecomeActive();
     77    void audioHardwareDidBecomeInactive();
    7478
    7579    PluginProcessConnectionManager* m_pluginProcessConnectionManager;
     
    8589   
    8690    bool m_supportsAsynchronousPluginInitialization;
     91    WebCore::AudioHardwareActivityType m_audioHardwareActivity;
    8792};
    8893
  • trunk/Source/WebKit2/WebProcess/Plugins/PluginProcessConnection.messages.in

    r160022 r166443  
    2626    # Set a global JavaScript exception.
    2727    SetException(String exceptionString) -> ()
     28   
     29    # Plugin process audio hardware state changed
     30    AudioHardwareDidBecomeActive()
     31    AudioHardwareDidBecomeInactive()
    2832}
    2933
  • trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp

    r164192 r166443  
    710710    return 0;
    711711}
     712   
     713WebCore::AudioHardwareActivityType PluginProxy::audioHardwareActivity() const
     714{
     715    return m_connection->audioHardwareActivity();
     716}
    712717
    713718} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h

    r164192 r166443  
    139139
    140140    virtual String getSelectionString() const override { return String(); }
     141   
     142    virtual WebCore::AudioHardwareActivityType audioHardwareActivity() const override;
    141143
    142144    float contentsScaleFactor();
  • trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp

    r166262 r166443  
    545545    return true;
    546546}
    547 
     547   
     548WebCore::AudioHardwareActivityType PluginView::audioHardwareActivity() const
     549{
     550    return m_plugin->audioHardwareActivity();
     551}
     552   
    548553NSObject *PluginView::accessibilityObject() const
    549554{
  • trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h

    r164192 r166443  
    108108    PassRefPtr<WebCore::SharedBuffer> liveResourceData() const;
    109109    bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&);
     110    WebCore::AudioHardwareActivityType audioHardwareActivity() const;
    110111
    111112private:
Note: See TracChangeset for help on using the changeset viewer.