Changeset 150935 in webkit


Ignore:
Timestamp:
May 29, 2013 4:17:59 PM (11 years ago)
Author:
oliver@apple.com
Message:

Add more accurate activity state tracking
https://bugs.webkit.org/show_bug.cgi?id=116893

Reviewed by Gavin Barraclough.

Source/WebCore:

Add a hysteresis to Page activity throttling. We do this
through a PageThrottler class that now handles entering and
exiting throttling state, and adds a hysteresis to we can
limit the amount of on/off bouncing on the throttle.

Media elements now make use of this to disable timer throttling
while they are playing, and plugins use it to momentarily bounce
from throttled to unthrottled state.

  • CMakeLists.txt:
  • GNUmakefile.list.am:
  • Target.pri:
  • WebCore.exp.in:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.vcxproj/WebCore.vcxproj:
  • WebCore.vcxproj/WebCore.vcxproj.filters:
  • WebCore.xcodeproj/project.pbxproj:
  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::~HTMLMediaElement):
(WebCore::HTMLMediaElement::pageThrottlerIfPossible):
(WebCore):
(WebCore::HTMLMediaElement::playInternal):
(WebCore::HTMLMediaElement::pauseInternal):

  • html/HTMLMediaElement.h:

(WebCore):

  • html/MediaController.cpp:

(MediaController::unpause):

  • page/ChromeClient.h:

(WebCore::ChromeClient::incrementActivePageCount):
(WebCore::ChromeClient::decrementActivePageCount):
(ChromeClient):

  • page/Page.cpp:

(WebCore::Page::Page):
(WebCore::Page::~Page):
(WebCore::Page::setThrottled):

  • page/Page.h:

(WebCore):
(Page):
(WebCore::Page::pageThrottler):

  • page/PageThrottleState.h: Added.
  • page/PageThrottler.cpp: Added.

(WebCore):
(WebCore::PageThrottler::PageThrottler):
(WebCore::PageThrottler::~PageThrottler):
(WebCore::PageThrottler::clearPage):
(WebCore::PageThrottler::throttlePage):
(WebCore::PageThrottler::unthrottlePage):
(WebCore::PageThrottler::setThrottled):
(WebCore::PageThrottler::preventThrottling):
(WebCore::PageThrottler::allowThrottling):
(WebCore::PageThrottler::stopThrottleHysteresisTimer):
(WebCore::PageThrottler::reportInterestingEvent):
(WebCore::PageThrottler::startThrottleHysteresisTimer):
(WebCore::PageThrottler::throttleHysteresisTimerFired):

  • page/PageThrottler.h: Added.

(WebCore):
(PageThrottler):
(WebCore::PageThrottler::create):
(WebCore::PageThrottler::shouldThrottleAnimations):
(WebCore::PageThrottler::shouldThrottleTimers):

Source/WebKit2:

This extends the logic in WebCore from a Page to Process
granularity, so we will avoid lowering the child process
priority if there is active content. This also plumbs in
the logic to allow plugins to report that they have done
something "interesting". Currently this is somewhat conservative
but even this is sufficient to fix some stuttering issues
that we've seen.

  • Shared/ChildProcess.cpp:

(WebKit::ChildProcess::ChildProcess):

  • Shared/ChildProcess.h:

(ChildProcess):
(WebKit::ChildProcess::processSuppressionEnabled):
(WebKit::ChildProcess::incrementActiveTaskCount):
(WebKit::ChildProcess::decrementActiveTaskCount):

  • Shared/mac/ChildProcessMac.mm:

(WebKit):
(WebKit::ChildProcess::setProcessSuppressionEnabledInternal):
(WebKit::ChildProcess::setProcessSuppressionEnabled):
(WebKit::ChildProcess::incrementActiveTaskCount):
(WebKit::ChildProcess::decrementActiveTaskCount):
(WebKit::ChildProcess::suspensionHysteresisTimerFired):

  • WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:

(WebKit::NPRuntimeObjectMap::NPRuntimeObjectMap):
(WebKit::NPRuntimeObjectMap::evaluate):

  • WebProcess/Plugins/Netscape/NPRuntimeObjectMap.h:

(WebCore):
(NPRuntimeObjectMap):

  • WebProcess/Plugins/PluginView.cpp:

(WebKit::PluginView::PluginView):

  • WebProcess/WebCoreSupport/WebChromeClient.cpp:

(WebKit::WebChromeClient::incrementActivePageCount):
(WebKit):
(WebKit::WebChromeClient::decrementActivePageCount):

  • WebProcess/WebCoreSupport/WebChromeClient.h:

(WebChromeClient):

Location:
trunk/Source
Files:
2 added
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r150924 r150935  
    17581758    page/PageGroupLoadDeferrer.cpp
    17591759    page/PageSerializer.cpp
     1760    page/PageThrottler.cpp
    17601761    page/PageVisibilityState.cpp
    17611762    page/Performance.cpp
  • trunk/Source/WebCore/ChangeLog

    r150934 r150935  
     12013-05-28  Oliver Hunt  <oliver@apple.com>
     2
     3        Add more accurate activity state tracking
     4        https://bugs.webkit.org/show_bug.cgi?id=116893
     5
     6        Reviewed by Gavin Barraclough.
     7
     8        Add a hysteresis to Page activity throttling.  We do this
     9        through a PageThrottler class that now handles entering and
     10        exiting throttling state, and adds a hysteresis to we can
     11        limit the amount of on/off bouncing on the throttle.
     12
     13        Media elements now make use of this to disable timer throttling
     14        while they are playing, and plugins use it to momentarily bounce
     15        from throttled to unthrottled state.
     16
     17        * CMakeLists.txt:
     18        * GNUmakefile.list.am:
     19        * Target.pri:
     20        * WebCore.exp.in:
     21        * WebCore.vcproj/WebCore.vcproj:
     22        * WebCore.vcxproj/WebCore.vcxproj:
     23        * WebCore.vcxproj/WebCore.vcxproj.filters:
     24        * WebCore.xcodeproj/project.pbxproj:
     25        * html/HTMLMediaElement.cpp:
     26        (WebCore::HTMLMediaElement::~HTMLMediaElement):
     27        (WebCore::HTMLMediaElement::pageThrottlerIfPossible):
     28        (WebCore):
     29        (WebCore::HTMLMediaElement::playInternal):
     30        (WebCore::HTMLMediaElement::pauseInternal):
     31        * html/HTMLMediaElement.h:
     32        (WebCore):
     33        * html/MediaController.cpp:
     34        (MediaController::unpause):
     35        * page/ChromeClient.h:
     36        (WebCore::ChromeClient::incrementActivePageCount):
     37        (WebCore::ChromeClient::decrementActivePageCount):
     38        (ChromeClient):
     39        * page/Page.cpp:
     40        (WebCore::Page::Page):
     41        (WebCore::Page::~Page):
     42        (WebCore::Page::setThrottled):
     43        * page/Page.h:
     44        (WebCore):
     45        (Page):
     46        (WebCore::Page::pageThrottler):
     47        * page/PageThrottleState.h: Added.
     48        * page/PageThrottler.cpp: Added.
     49        (WebCore):
     50        (WebCore::PageThrottler::PageThrottler):
     51        (WebCore::PageThrottler::~PageThrottler):
     52        (WebCore::PageThrottler::clearPage):
     53        (WebCore::PageThrottler::throttlePage):
     54        (WebCore::PageThrottler::unthrottlePage):
     55        (WebCore::PageThrottler::setThrottled):
     56        (WebCore::PageThrottler::preventThrottling):
     57        (WebCore::PageThrottler::allowThrottling):
     58        (WebCore::PageThrottler::stopThrottleHysteresisTimer):
     59        (WebCore::PageThrottler::reportInterestingEvent):
     60        (WebCore::PageThrottler::startThrottleHysteresisTimer):
     61        (WebCore::PageThrottler::throttleHysteresisTimerFired):
     62        * page/PageThrottler.h: Added.
     63        (WebCore):
     64        (PageThrottler):
     65        (WebCore::PageThrottler::create):
     66        (WebCore::PageThrottler::shouldThrottleAnimations):
     67        (WebCore::PageThrottler::shouldThrottleTimers):
     68
    1692013-05-29  Kent Tamura  <tkent@chromium.org>
    270
  • trunk/Source/WebCore/GNUmakefile.list.am

    r150924 r150935  
    42604260        Source/WebCore/page/PageSerializer.cpp \
    42614261        Source/WebCore/page/PageSerializer.h \
     4262        Source/WebCore/page/PageThrottler.cpp \
     4263        Source/WebCore/page/PageThrottler.h \
    42624264        Source/WebCore/page/PageVisibilityState.cpp \
    42634265        Source/WebCore/page/PageVisibilityState.h \
  • trunk/Source/WebCore/Target.pri

    r150924 r150935  
    935935    page/PageGroup.cpp \
    936936    page/PageGroupLoadDeferrer.cpp \
     937    page/PageThrottler.cpp \
    937938    page/PageVisibilityState.cpp \
    938939    page/Performance.cpp \
     
    21002101    page/Page.h \
    21012102    page/PageConsole.h \
     2103    page/PageThrottler.h \
    21022104    page/PageVisibilityState.h \
    21032105    page/PlugInClient.h \
  • trunk/Source/WebCore/WebCore.exp.in

    r150873 r150935  
    278278__ZN7WebCore13NodeTraversal19nextAncestorSiblingEPKNS_4NodeE
    279279__ZN7WebCore13NodeTraversal8previousEPKNS_4NodeES3_
     280__ZN7WebCore13PageThrottler22reportInterestingEventEv
     281__ZN7WebCore13PageThrottlerD1Ev
    280282__ZN7WebCore13QualifiedNameD1Ev
    281283__ZN7WebCore13ResourceErrorC1EP7NSError
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r150876 r150935  
    2757927579                                >
    2758027580                        </File>
    27581                         <File
     27581             <File
    2758227582                                RelativePath="..\page\PageConsole.cpp"
    2758327583                                >
     
    2760927609                        <File
    2761027610                                RelativePath="..\page\PageSerializer.h"
     27611                                >
     27612                        </File>
     27613                        <File
     27614                                RelativePath="..\page\PageThrottler.cpp"
     27615                                >
     27616                        </File>
     27617                        <File
     27618                                RelativePath="..\page\PageThrottler.h"
    2761127619                                >
    2761227620                        </File>
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

    r150907 r150935  
    39383938    <ClCompile Include="..\page\PageGroupLoadDeferrer.cpp" />
    39393939    <ClCompile Include="..\page\PageSerializer.cpp" />
     3940    <ClCompile Include="..\page\PageThrottler.cpp" />
    39403941    <ClCompile Include="..\page\PageVisibilityState.cpp" />
    39413942    <ClCompile Include="..\page\Performance.cpp" />
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters

    r150907 r150935  
    52335233      <Filter>page</Filter>
    52345234    </ClCompile>
     5235    <ClCompile Include="..\page\PageThrottler.cpp">
     5236      <Filter>page</Filter>
     5237    </ClCompile>
    52355238    <ClCompile Include="..\page\PageVisibilityState.cpp">
    52365239      <Filter>page</Filter>
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r150924 r150935  
    33963396                A718760E0B2A120100A16ECE /* DragActions.h in Headers */ = {isa = PBXBuildFile; fileRef = A718760D0B2A120100A16ECE /* DragActions.h */; settings = {ATTRIBUTES = (Private, ); }; };
    33973397                A71878900B2D04AC00A16ECE /* DragControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A718788F0B2D04AC00A16ECE /* DragControllerMac.mm */; };
     3398                A7197F24175689C4007B9442 /* PageThrottler.h in Headers */ = {isa = PBXBuildFile; fileRef = A7197F23175689C4007B9442 /* PageThrottler.h */; settings = {ATTRIBUTES = (Private, ); }; };
     3399                A7197F2617568AE5007B9442 /* PageThrottler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7197F2517568AE5007B9442 /* PageThrottler.cpp */; };
    33983400                A723F77B1484CA4C008C6DBE /* PlatformExportMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = A723F77A1484CA4C008C6DBE /* PlatformExportMacros.h */; settings = {ATTRIBUTES = (Private, ); }; };
    33993401                A72763BF16689BFB002FCACB /* UserActionElementSet.h in Headers */ = {isa = PBXBuildFile; fileRef = A72763BE16689BFB002FCACB /* UserActionElementSet.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    98529854                A718760D0B2A120100A16ECE /* DragActions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragActions.h; sourceTree = "<group>"; };
    98539855                A718788F0B2D04AC00A16ECE /* DragControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragControllerMac.mm; sourceTree = "<group>"; };
     9856                A7197F23175689C4007B9442 /* PageThrottler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PageThrottler.h; sourceTree = "<group>"; };
     9857                A7197F2517568AE5007B9442 /* PageThrottler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageThrottler.cpp; sourceTree = "<group>"; };
    98549858                A71A70C911AFB02000989D6D /* HTMLMeterElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HTMLMeterElement.idl; sourceTree = "<group>"; };
    98559859                A7211F231678A54200957444 /* NodeRenderingTraversal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NodeRenderingTraversal.cpp; sourceTree = "<group>"; };
     
    1474814752                                371E65CD13661EED00BEEDB0 /* PageSerializer.cpp */,
    1474914753                                371E65CB13661EDC00BEEDB0 /* PageSerializer.h */,
     14754                                A7197F23175689C4007B9442 /* PageThrottler.h */,
     14755                                A7197F2517568AE5007B9442 /* PageThrottler.cpp */,
    1475014756                                FFD5B977135CC97800D5E92A /* PageVisibilityState.cpp */,
    1475114757                                FFD5B978135CC97800D5E92A /* PageVisibilityState.h */,
     
    2284222848                                979F43D41075E44A0000F83B /* NavigationScheduler.h in Headers */,
    2284322849                                A9C6E5A60D746458006442E9 /* Navigator.h in Headers */,
     22850                                A7197F24175689C4007B9442 /* PageThrottler.h in Headers */,
    2284422851                                E12719C70EEEC16800F61213 /* NavigatorBase.h in Headers */,
    2284522852                                9711460414EF009A00674FD9 /* NavigatorGeolocation.h in Headers */,
     
    2586825875                                77EF62F312F9DB7400C77BD2 /* JSWebGLVertexArrayObjectOES.cpp in Sources */,
    2586925876                                31C0FF3D0E4CEFAC007D6FE5 /* JSWebKitAnimationEvent.cpp in Sources */,
     25877                                A7197F2617568AE5007B9442 /* PageThrottler.cpp in Sources */,
    2587025878                                A2E8AE3716A49840006BB3AA /* JSWebKitCSSFilterRule.cpp in Sources */,
    2587125879                                310603741432819C00ABF4BA /* JSWebKitCSSFilterValue.cpp in Sources */,
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r150651 r150935  
    7171#include "Page.h"
    7272#include "PageGroup.h"
     73#include "PageThrottler.h"
    7374#include "RenderVideo.h"
    7475#include "RenderView.h"
     
    345346{
    346347    LOG(Media, "HTMLMediaElement::~HTMLMediaElement");
     348
     349    if (!m_paused && m_pageThrottler) {
     350        m_pageThrottler->allowThrottling();
     351        m_pageThrottler.clear();
     352    }
    347353    if (m_isWaitingUntilMediaCanStart)
    348354        document()->removeMediaCanStartListener(this);
     
    24782484}
    24792485
     2486PageThrottler* HTMLMediaElement::pageThrottlerIfPossible()
     2487{
     2488    if (m_pageThrottler)
     2489        return m_pageThrottler.get();
     2490
     2491    if (!document())
     2492        return 0;
     2493
     2494    if (Page* page = document()->page())
     2495        m_pageThrottler = page->pageThrottler();
     2496   
     2497    return m_pageThrottler.get();
     2498}
     2499
    24802500void HTMLMediaElement::playInternal()
    24812501{
     
    24932513
    24942514    if (m_paused) {
     2515        if (PageThrottler* throttler = pageThrottlerIfPossible())
     2516            throttler->preventThrottling();
    24952517        m_paused = false;
    24962518        invalidateCachedTime();
     
    25032525    }
    25042526    m_autoplaying = false;
    2505 
    25062527    updatePlayState();
    25072528    updateMediaController();
     
    25302551
    25312552    if (!m_paused) {
     2553        if (PageThrottler* throttler = m_pageThrottler.get())
     2554            throttler->preventThrottling();
    25322555        m_paused = true;
    25332556        scheduleTimeupdateEvent(false);
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r150710 r150935  
    6060class HTMLSourceElement;
    6161class HTMLTrackElement;
     62class KURL;
    6263class MediaController;
    6364class MediaControls;
    6465class MediaError;
    65 class KURL;
     66class PageThrottler;
    6667class TimeRanges;
    6768#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
     
    756757    RefPtr<MediaController> m_mediaController;
    757758
     759    PageThrottler* pageThrottlerIfPossible();
     760    RefPtr<PageThrottler> m_pageThrottler;
     761
    758762#if PLATFORM(MAC)
    759763    OwnPtr<DisplaySleepDisabler> m_sleepDisabler;
  • trunk/Source/WebCore/html/MediaController.cpp

    r148099 r150935  
    184184    if (!m_paused)
    185185        return;
    186 
    187186    // the user agent must change the MediaController into a playing media controller,
    188187    m_paused = false;
  • trunk/Source/WebCore/page/ChromeClient.h

    r150876 r150935  
    363363    virtual void didAddFooterLayer(GraphicsLayer*) { }
    364364
     365    // These methods are used to report pages that are performing
     366    // some task that we consider to be "active", and so the user
     367    // would likely want the page to remain running uninterrupted.
     368    virtual void incrementActivePageCount() { }
     369    virtual void decrementActivePageCount() { }
     370
    365371protected:
    366372    virtual ~ChromeClient() { }
  • trunk/Source/WebCore/page/Page.cpp

    r150695 r150935  
    6060#include "PageConsole.h"
    6161#include "PageGroup.h"
     62#include "PageThrottler.h"
    6263#include "PlugInClient.h"
    6364#include "PluginData.h"
     
    185186    , m_alternativeTextClient(pageClients.alternativeTextClient)
    186187    , m_scriptedAnimationsSuspended(false)
     188    , m_pageThrottler(PageThrottler::create(this))
    187189    , m_console(PageConsole::create(this))
    188190{
     
    232234    pageCounter.decrement();
    233235#endif
     236    m_pageThrottler->clearPage();
    234237
    235238}
     
    958961}
    959962
    960 void Page::setThrottled(bool isThrottled)
    961 {
    962     for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) {
    963         if (frame->document())
    964             frame->document()->scriptedAnimationControllerSetThrottled(isThrottled);
    965     }
     963void Page::setThrottled(bool throttled)
     964{
     965    m_pageThrottler->setThrottled(throttled);
    966966}
    967967
  • trunk/Source/WebCore/page/Page.h

    r150633 r150935  
    3737#include <wtf/HashSet.h>
    3838#include <wtf/Noncopyable.h>
     39#include <wtf/RefCounted.h>
    3940#include <wtf/text/WTFString.h>
    4041
     
    7778class PageConsole;
    7879class PageGroup;
     80class PageThrottler;
    7981class PlugInClient;
    8082class PluginData;
     
    111113    WTF_MAKE_NONCOPYABLE(Page);
    112114    friend class Settings;
     115    friend class PageThrottler;
     116
    113117public:
    114118    static void updateStyleForAllPagesAfterGlobalChangeInEnvironment();
     
    390394    void resetSeenMediaEngines();
    391395
     396    PageThrottler* pageThrottler() { return m_pageThrottler.get(); }
     397
    392398    PageConsole* console() { return m_console.get(); }
    393399
     
    528534
    529535    bool m_scriptedAnimationsSuspended;
     536    RefPtr<PageThrottler> m_pageThrottler;
     537
    530538    OwnPtr<PageConsole> m_console;
    531539
  • trunk/Source/WebKit2/ChangeLog

    r150925 r150935  
     12013-05-28  Oliver Hunt  <oliver@apple.com>
     2
     3        Add more accurate activity state tracking
     4        https://bugs.webkit.org/show_bug.cgi?id=116893
     5
     6        Reviewed by Gavin Barraclough.
     7
     8        This extends the logic in WebCore from a Page to Process
     9        granularity, so we will avoid lowering the child process
     10        priority if there is active content.  This also plumbs in
     11        the logic to allow plugins to report that they have done
     12        something "interesting".  Currently this is somewhat conservative
     13        but even this is sufficient to fix some stuttering issues
     14        that we've seen.
     15
     16        * Shared/ChildProcess.cpp:
     17        (WebKit::ChildProcess::ChildProcess):
     18        * Shared/ChildProcess.h:
     19        (ChildProcess):
     20        (WebKit::ChildProcess::processSuppressionEnabled):
     21        (WebKit::ChildProcess::incrementActiveTaskCount):
     22        (WebKit::ChildProcess::decrementActiveTaskCount):
     23        * Shared/mac/ChildProcessMac.mm:
     24        (WebKit):
     25        (WebKit::ChildProcess::setProcessSuppressionEnabledInternal):
     26        (WebKit::ChildProcess::setProcessSuppressionEnabled):
     27        (WebKit::ChildProcess::incrementActiveTaskCount):
     28        (WebKit::ChildProcess::decrementActiveTaskCount):
     29        (WebKit::ChildProcess::suspensionHysteresisTimerFired):
     30        * WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:
     31        (WebKit::NPRuntimeObjectMap::NPRuntimeObjectMap):
     32        (WebKit::NPRuntimeObjectMap::evaluate):
     33        * WebProcess/Plugins/Netscape/NPRuntimeObjectMap.h:
     34        (WebCore):
     35        (NPRuntimeObjectMap):
     36        * WebProcess/Plugins/PluginView.cpp:
     37        (WebKit::PluginView::PluginView):
     38        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
     39        (WebKit::WebChromeClient::incrementActivePageCount):
     40        (WebKit):
     41        (WebKit::WebChromeClient::decrementActivePageCount):
     42        * WebProcess/WebCoreSupport/WebChromeClient.h:
     43        (WebChromeClient):
     44
    1452013-05-29  Anders Carlsson  <andersca@apple.com>
    246
  • trunk/Source/WebKit2/Shared/ChildProcess.cpp

    r150669 r150935  
    4141    , m_terminationCounter(0)
    4242    , m_terminationTimer(RunLoop::main(), this, &ChildProcess::terminationTimerFired)
     43#if PLATFORM(MAC)
     44    , m_activeTaskCount(0)
     45    , m_shouldSuspend(false)
     46    , m_suspensionHysteresisTimer(RunLoop::main(), this, &ChildProcess::suspensionHysteresisTimerFired)
     47#endif
    4348{
    4449}
  • trunk/Source/WebKit2/Shared/ChildProcess.h

    r150669 r150935  
    6363
    6464#if PLATFORM(MAC)
     65    void setProcessSuppressionEnabled(bool);
    6566    bool processSuppressionEnabled() const { return !m_processSuppressionAssertion; }
    66     void setProcessSuppressionEnabled(bool);
     67    void incrementActiveTaskCount();
     68    void decrementActiveTaskCount();
    6769
    6870    void setApplicationIsDaemon();
     71#else
     72    void incrementActiveTaskCount() { }
     73    void decrementActiveTaskCount() { }
    6974#endif
    7075
     
    110115
    111116#if PLATFORM(MAC)
     117    void suspensionHysteresisTimerFired();
     118    void setProcessSuppressionEnabledInternal(bool);
     119    size_t m_activeTaskCount;
     120    bool m_shouldSuspend;
     121    WebCore::RunLoop::Timer<ChildProcess> m_suspensionHysteresisTimer;
    112122    RetainPtr<id> m_processSuppressionAssertion;
    113123#endif
  • trunk/Source/WebKit2/Shared/mac/ChildProcessMac.mm

    r150495 r150935  
    6060namespace WebKit {
    6161
    62 void ChildProcess::setProcessSuppressionEnabled(bool processSuppressionEnabled)
     62static const double kSuspensionHysteresisSeconds = 5.0;
     63
     64void ChildProcess::setProcessSuppressionEnabledInternal(bool processSuppressionEnabled)
    6365{
    6466#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
     
    6769
    6870    if (processSuppressionEnabled) {
     71        ASSERT(!m_activeTaskCount);
    6972        [[NSProcessInfo processInfo] endActivity:m_processSuppressionAssertion.get()];
    7073        m_processSuppressionAssertion.clear();
     
    7679    UNUSED_PARAM(processSuppressionEnabled);
    7780#endif
     81}
     82
     83void ChildProcess::setProcessSuppressionEnabled(bool processSuppressionEnabled)
     84{
     85    if (this->processSuppressionEnabled() == processSuppressionEnabled)
     86        return;
     87    if (m_shouldSuspend == processSuppressionEnabled)
     88        return;
     89    m_shouldSuspend = processSuppressionEnabled;
     90    if (m_shouldSuspend) {
     91        if (!m_activeTaskCount)
     92            m_suspensionHysteresisTimer.startOneShot(kSuspensionHysteresisSeconds);
     93        return;
     94    }
     95    setProcessSuppressionEnabledInternal(false);
     96}
     97
     98void ChildProcess::incrementActiveTaskCount()
     99{
     100    m_activeTaskCount++;
     101    if (m_suspensionHysteresisTimer.isActive())
     102        m_suspensionHysteresisTimer.stop();
     103    if (m_activeTaskCount)
     104        setProcessSuppressionEnabledInternal(false);
     105}
     106
     107void ChildProcess::decrementActiveTaskCount()
     108{
     109    ASSERT(m_activeTaskCount);
     110    m_activeTaskCount--;
     111    if (m_activeTaskCount)
     112        return;
     113    if (m_shouldSuspend)
     114        m_suspensionHysteresisTimer.startOneShot(kSuspensionHysteresisSeconds);
     115}
     116
     117void ChildProcess::suspensionHysteresisTimerFired()
     118{
     119    ASSERT(!m_activeTaskCount);
     120    ASSERT(m_shouldSuspend);
     121    setProcessSuppressionEnabledInternal(true);
    78122}
    79123
  • trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp

    r149848 r150935  
    4242#include <WebCore/DOMWrapperWorld.h>
    4343#include <WebCore/Frame.h>
     44#include <WebCore/Page.h>
     45#include <WebCore/PageThrottler.h>
    4446#include <WebCore/ScriptController.h>
    4547
     
    5052
    5153
    52 NPRuntimeObjectMap::NPRuntimeObjectMap(PluginView* pluginView)
     54NPRuntimeObjectMap::NPRuntimeObjectMap(PluginView* pluginView, PageThrottler* pageThrottler)
    5355    : m_pluginView(pluginView)
     56    , m_pageThrottler(pageThrottler)
    5457    , m_finalizationTimer(RunLoop::main(), this, &NPRuntimeObjectMap::invalidateQueuedObjects)
    5558{
     
    183186bool NPRuntimeObjectMap::evaluate(NPObject* npObject, const String& scriptString, NPVariant* result)
    184187{
     188    m_pageThrottler->reportInterestingEvent();
    185189    Strong<JSGlobalObject> globalObject(this->globalObject()->vm(), this->globalObject());
    186190    if (!globalObject)
  • trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeObjectMap.h

    r149848 r150935  
    4646}
    4747
     48namespace WebCore {
     49    class PageThrottler;
     50}
     51
    4852namespace WebKit {
    4953
     
    5559class NPRuntimeObjectMap : private JSC::WeakHandleOwner {
    5660public:
    57     explicit NPRuntimeObjectMap(PluginView*);
     61    explicit NPRuntimeObjectMap(PluginView*, WebCore::PageThrottler*);
    5862
    5963    class PluginProtector {
     
    96100
    97101    PluginView* m_pluginView;
    98 
     102    RefPtr<WebCore::PageThrottler> m_pageThrottler;
    99103    HashMap<JSC::JSObject*, NPJSObject*> m_npJSObjects;
    100104    HashMap<NPObject*, JSC::Weak<JSNPObject>> m_jsNPObjects;
  • trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp

    r150796 r150935  
    5757#include <WebCore/NetworkingContext.h>
    5858#include <WebCore/Page.h>
     59#include <WebCore/PageThrottler.h>
    5960#include <WebCore/PlatformMouseEvent.h>
    6061#include <WebCore/ProtectionSpace.h>
     
    278279    , m_pendingURLRequestsTimer(RunLoop::main(), this, &PluginView::pendingURLRequestsTimerFired)
    279280#if ENABLE(NETSCAPE_PLUGIN_API)
    280     , m_npRuntimeObjectMap(this)
     281    , m_npRuntimeObjectMap(this, m_webPage->corePage()->pageThrottler())
    281282#endif
    282283    , m_manualStreamState(StreamStateInitial)
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r150669 r150935  
    901901}
    902902
     903void WebChromeClient::incrementActivePageCount()
     904{
     905    WebProcess::shared().incrementActiveTaskCount();
     906}
     907
     908void WebChromeClient::decrementActivePageCount()
     909{
     910    WebProcess::shared().decrementActiveTaskCount();
     911}
     912
    903913} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h

    r150441 r150935  
    234234    virtual void didAddFooterLayer(WebCore::GraphicsLayer*) OVERRIDE;
    235235
     236    virtual void incrementActivePageCount() OVERRIDE;
     237    virtual void decrementActivePageCount() OVERRIDE;
     238
    236239    String m_cachedToolTip;
    237240    mutable RefPtr<WebFrame> m_cachedFrameSetLargestFrame;
Note: See TracChangeset for help on using the changeset viewer.