Changeset 207699 in webkit


Ignore:
Timestamp:
Oct 21, 2016 4:20:11 PM (7 years ago)
Author:
barraclough@apple.com
Message:

WebPage should take UserActivity directly for user input
https://bugs.webkit.org/show_bug.cgi?id=163813

Reviewed by Anders Carlsson.

When we receive mouse/keyboard events in a page, we want to prevent AppNap. We currently do so
via the PageThrottler. This patch is to just make the WebPage drive the UserActivity directly.

Two reasons to do so: (1) to cleanup & simplify for further refactoring. (2) The current code
isn't really achieving the desired effect. The page setting the flag in the throttler to get
the activity to be set is now a less effective way of achieving this goal, since the
PageActivityState bounces back across to the UI process & then messages back to the WebContent
process to take the UserActivity. These extra hops defeat the purpose of making sure the boost
from the initial message isn't lost.

Source/WebCore:

  • page/PageThrottler.cpp:

(WebCore::PageThrottler::PageThrottler):
(WebCore::m_userInputHysteresis): Deleted.

  • page/PageThrottler.h:

(WebCore::PageThrottler::didReceiveUserInput): Deleted.

  • removed PageActivityState::UserInputActivity, didReceiveUserInput, m_userInputHysteresis.

Source/WebKit2:

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::m_userActivityHysteresis):

  • m_userActivityHysteresis triggers updateUserActivity.

(WebKit::WebPage::setPageSuppressed):

  • setPageSuppressed starts/stops m_userActivityHysteresis.

(WebKit::WebPage::updateUserActivity):

  • update UserActivity based on state of m_userActivityHysteresis.

(WebKit::WebPage::mouseEvent):
(WebKit::WebPage::wheelEvent):
(WebKit::WebPage::keyEvent):

  • input events impulse m_userActivityHysteresis.
  • WebProcess/WebPage/WebPage.h:
Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207698 r207699  
     12016-10-21  Gavin Barraclough  <barraclough@apple.com>
     2
     3        WebPage should take UserActivity directly for user input
     4        https://bugs.webkit.org/show_bug.cgi?id=163813
     5
     6        Reviewed by Anders Carlsson.
     7
     8        When we receive mouse/keyboard events in a page, we want to prevent AppNap. We currently do so
     9        via the PageThrottler. This patch is to just make the WebPage drive the UserActivity directly.
     10
     11        Two reasons to do so: (1) to cleanup & simplify for further refactoring. (2) The current code
     12        isn't really achieving the desired effect. The page setting the flag in the throttler to get
     13        the activity to be set is now a less effective way of achieving this goal, since the
     14        PageActivityState bounces back across to the UI process & then messages back to the WebContent
     15        process to take the UserActivity. These extra hops defeat the purpose of making sure the boost
     16        from the initial message isn't lost.
     17
     18        * page/PageThrottler.cpp:
     19        (WebCore::PageThrottler::PageThrottler):
     20        (WebCore::m_userInputHysteresis): Deleted.
     21        * page/PageThrottler.h:
     22        (WebCore::PageThrottler::didReceiveUserInput): Deleted.
     23            - removed PageActivityState::UserInputActivity, didReceiveUserInput, m_userInputHysteresis.
     24
    1252016-10-21  Wenson Hsieh  <wenson_hsieh@apple.com>
    226
  • trunk/Source/WebCore/page/PageThrottler.cpp

    r200625 r207699  
    3535PageThrottler::PageThrottler(Page& page)
    3636    : m_page(page)
    37     , m_userInputHysteresis([this](HysteresisState state) { setActivityFlag(PageActivityState::UserInputActivity, state == HysteresisState::Started); })
    3837    , m_mediaActivityHysteresis([this](HysteresisState state) { setActivityFlag(PageActivityState::MediaActivity, state == HysteresisState::Started); })
    3938    , m_pageLoadActivityHysteresis([this](HysteresisState state) { setActivityFlag(PageActivityState::PageLoadActivity, state == HysteresisState::Started); }, PageLoadHysteresisSeconds)
  • trunk/Source/WebCore/page/PageThrottler.h

    r200625 r207699  
    4343struct PageActivityState {
    4444    enum {
    45         UserInputActivity = 1 << 0,
    46         MediaActivity = 1 << 1,
    47         PageLoadActivity = 1 << 2,
     45        MediaActivity = 1 << 0,
     46        PageLoadActivity = 1 << 1,
    4847    };
    4948
     
    5150
    5251    static const Flags NoFlags = 0;
    53     static const Flags AllFlags = UserInputActivity | MediaActivity | PageLoadActivity;
     52    static const Flags AllFlags = MediaActivity | PageLoadActivity;
    5453};
    5554
     
    5958    PageThrottler(Page&);
    6059
    61     void didReceiveUserInput() { m_userInputHysteresis.impulse(); }
    6260    PageActivityState::Flags activityState() { return m_activityState; }
    6361    void pluginDidEvaluateWhileAudioIsPlaying() { m_mediaActivityHysteresis.impulse(); }
     
    7270    Page& m_page;
    7371    PageActivityState::Flags m_activityState { PageActivityState::NoFlags };
    74     HysteresisActivity m_userInputHysteresis;
    7572    HysteresisActivity m_mediaActivityHysteresis;
    7673    HysteresisActivity m_pageLoadActivityHysteresis;
  • trunk/Source/WebKit2/ChangeLog

    r207698 r207699  
     12016-10-21  Gavin Barraclough  <barraclough@apple.com>
     2
     3        WebPage should take UserActivity directly for user input
     4        https://bugs.webkit.org/show_bug.cgi?id=163813
     5
     6        Reviewed by Anders Carlsson.
     7
     8        When we receive mouse/keyboard events in a page, we want to prevent AppNap. We currently do so
     9        via the PageThrottler. This patch is to just make the WebPage drive the UserActivity directly.
     10
     11        Two reasons to do so: (1) to cleanup & simplify for further refactoring. (2) The current code
     12        isn't really achieving the desired effect. The page setting the flag in the throttler to get
     13        the activity to be set is now a less effective way of achieving this goal, since the
     14        PageActivityState bounces back across to the UI process & then messages back to the WebContent
     15        process to take the UserActivity. These extra hops defeat the purpose of making sure the boost
     16        from the initial message isn't lost.
     17
     18        * WebProcess/WebPage/WebPage.cpp:
     19        (WebKit::m_userActivityHysteresis):
     20            - m_userActivityHysteresis triggers updateUserActivity.
     21        (WebKit::WebPage::setPageSuppressed):
     22            - setPageSuppressed starts/stops m_userActivityHysteresis.
     23        (WebKit::WebPage::updateUserActivity):
     24            - update UserActivity based on state of m_userActivityHysteresis.
     25        (WebKit::WebPage::mouseEvent):
     26        (WebKit::WebPage::wheelEvent):
     27        (WebKit::WebPage::keyEvent):
     28            - input events impulse m_userActivityHysteresis.
     29        * WebProcess/WebPage/WebPage.h:
     30
    1312016-10-21  Wenson Hsieh  <wenson_hsieh@apple.com>
    232
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r207689 r207699  
    379379    , m_viewState(parameters.viewState)
    380380    , m_userActivity("Process suppression disabled for page.")
     381    , m_userActivityHysteresis([this](HysteresisState) { updateUserActivity(); })
    381382    , m_pendingNavigationID(0)
    382383#if ENABLE(WEBGL)
     
    591592    // If the page should not be supressed, start it.
    592593    if (pageSuppressed)
     594        m_userActivityHysteresis.stop();
     595    else
     596        m_userActivityHysteresis.start();
     597}
     598
     599void WebPage::updateUserActivity()
     600{
     601    if (m_userActivityHysteresis.state() == HysteresisState::Started)
     602        m_userActivity.start();
     603    else
    593604        m_userActivity.stop();
    594     else
    595         m_userActivity.start();
    596605}
    597606
     
    22392248    TemporaryChange<bool> userIsInteractingChange { m_userIsInteracting, true };
    22402249
    2241     m_page->pageThrottler().didReceiveUserInput();
     2250    m_userActivityHysteresis.impulse();
    22422251
    22432252    bool shouldHandleEvent = true;
     
    22942303void WebPage::wheelEvent(const WebWheelEvent& wheelEvent)
    22952304{
    2296     m_page->pageThrottler().didReceiveUserInput();
     2305    m_userActivityHysteresis.impulse();
    22972306
    22982307    CurrentEvent currentEvent(wheelEvent);
     
    23172326    TemporaryChange<bool> userIsInteractingChange { m_userIsInteracting, true };
    23182327
    2319     m_page->pageThrottler().didReceiveUserInput();
     2328    m_userActivityHysteresis.impulse();
    23202329
    23212330    CurrentEvent currentEvent(keyboardEvent);
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r207689 r207699  
    972972    WebPage(uint64_t pageID, const WebPageCreationParameters&);
    973973
     974    void updateUserActivity();
     975
    974976    // IPC::MessageSender
    975977    IPC::Connection* messageSenderConnection() override;
     
    14871489
    14881490    UserActivity m_userActivity;
     1491    WebCore::HysteresisActivity m_userActivityHysteresis;
    14891492
    14901493    uint64_t m_pendingNavigationID;
Note: See TracChangeset for help on using the changeset viewer.