⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 245299 in webkit


Ignore:
Timestamp:
May 14, 2019, 12:48:51 PM (7 years ago)
Author:
youenn@apple.com
Message:

A service worker process should app nap when all its clients app nap
https://bugs.webkit.org/show_bug.cgi?id=185626
<rdar://problem/46785908>

Reviewed by Alex Christensen.

Source/WebCore:

Update RegistrableDomain to work with SecurityOriginData.
Add internal API to enable accessing to service worker process throttle state.

Test: http/wpt/service-workers/mac/processSuppression.https.html

  • platform/RegistrableDomain.h:

(WebCore::RegistrableDomain::RegistrableDomain):
(WebCore::RegistrableDomain::matches const):
(WebCore::RegistrableDomain::registrableDomainFromHost):

  • testing/ServiceWorkerInternals.cpp:

(WebCore::ServiceWorkerInternals::isThrottleable const):

  • testing/ServiceWorkerInternals.h:
  • testing/ServiceWorkerInternals.idl:
  • workers/service/SWClientConnection.h:
  • workers/service/context/SWContextManager.cpp:
  • workers/service/context/SWContextManager.h:
  • workers/service/server/SWServer.cpp:

(WebCore::SWServer::serverToContextConnectionCreated):

  • workers/service/server/SWServer.h:

(WebCore::SWServer::Connection::server const):
(WebCore::SWServer::connections const):

  • workers/service/server/SWServerToContextConnection.h:

Source/WebKit:

Compute whether a given web process can be throttled on every page throttling change.
Send that information to network process which stores that information in WebSWServerConnection.
Every WebSWServerToContextConnection throttle state is then computed based on all WebSWServerConnection
that have a client that matches the registrable domain of the context connection.

  • NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:

(WebKit::WebSWServerConnection::registerServiceWorkerClient):
(WebKit::WebSWServerConnection::unregisterServiceWorkerClient):
(WebKit::WebSWServerConnection::hasMatchingClient const):
(WebKit::WebSWServerConnection::computeThrottleState const):
(WebKit::WebSWServerConnection::setThrottleState):
(WebKit::WebSWServerConnection::updateThrottleState):
(WebKit::WebSWServerConnection::serverToContextConnectionCreated):

  • NetworkProcess/ServiceWorker/WebSWServerConnection.h:

(WebKit::WebSWServerConnection::isThrottleable const):

  • NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in:
  • NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:

(WebKit::WebSWServerToContextConnection::setThrottleState):

  • NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:

(WebKit::WebSWServerToContextConnection::isThrottleable const):

  • UIProcess/ServiceWorkerProcessProxy.cpp:
  • UIProcess/ServiceWorkerProcessProxy.h:
  • WebProcess/Storage/WebSWClientConnection.cpp:

(WebKit::WebSWClientConnection::WebSWClientConnection):
(WebKit::WebSWClientConnection::updateThrottleState):

  • WebProcess/Storage/WebSWClientConnection.h:
  • WebProcess/Storage/WebSWContextManagerConnection.cpp:

(WebKit::WebSWContextManagerConnection::setThrottleState):
(WebKit::WebSWContextManagerConnection::isThrottleable const):

  • WebProcess/Storage/WebSWContextManagerConnection.h:
  • WebProcess/Storage/WebSWContextManagerConnection.messages.in:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::updateUserActivity):
(WebKit::WebPage::isThrottleable const):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::arePagesThrottleable const):

  • WebProcess/WebProcess.h:

Tools:

Allow to enable app nap through test header.

  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::resetPreferencesToConsistentValues):
(WTR::updateTestOptionsFromTestHeader):

  • WebKitTestRunner/TestOptions.h:

(WTR::TestOptions::hasSameInitializationOptions const):

LayoutTests:

  • http/wpt/service-workers/mac/throttleable-worker.js: Added.
  • http/wpt/service-workers/mac/throttleable.https-expected.txt: Added.
  • http/wpt/service-workers/mac/throttleable.https.html: Added.
  • platform/ios-wk2/TestExpectations:
Location:
trunk
Files:
4 added
32 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r245295 r245299  
     12019-05-14  Youenn Fablet  <youenn@apple.com>
     2
     3        A service worker process should app nap when all its clients app nap
     4        https://bugs.webkit.org/show_bug.cgi?id=185626
     5        <rdar://problem/46785908>
     6
     7        Reviewed by Alex Christensen.
     8
     9        * http/wpt/service-workers/mac/throttleable-worker.js: Added.
     10        * http/wpt/service-workers/mac/throttleable.https-expected.txt: Added.
     11        * http/wpt/service-workers/mac/throttleable.https.html: Added.
     12        * platform/ios-wk2/TestExpectations:
     13
    1142019-05-14  Oriol Brufau  <obrufau@igalia.com>
    215
  • trunk/LayoutTests/platform/ios-wk2/TestExpectations

    r245242 r245299  
    368368http/tests/xmlhttprequest/cross-origin-authorization-with-embedder.html
    369369
     370http/wpt/service-workers/mac/ [ Skip ]
     371
    370372# HTTP tests that are flaky:
    371373http/tests/navigation/forward-and-cancel.html [ Failure Pass ]
  • trunk/Source/WebCore/ChangeLog

    r245296 r245299  
     12019-05-14  Youenn Fablet  <youenn@apple.com>
     2
     3        A service worker process should app nap when all its clients app nap
     4        https://bugs.webkit.org/show_bug.cgi?id=185626
     5        <rdar://problem/46785908>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Update RegistrableDomain to work with SecurityOriginData.
     10        Add internal API to enable accessing to service worker process throttle state.
     11
     12        Test: http/wpt/service-workers/mac/processSuppression.https.html
     13
     14        * platform/RegistrableDomain.h:
     15        (WebCore::RegistrableDomain::RegistrableDomain):
     16        (WebCore::RegistrableDomain::matches const):
     17        (WebCore::RegistrableDomain::registrableDomainFromHost):
     18        * testing/ServiceWorkerInternals.cpp:
     19        (WebCore::ServiceWorkerInternals::isThrottleable const):
     20        * testing/ServiceWorkerInternals.h:
     21        * testing/ServiceWorkerInternals.idl:
     22        * workers/service/SWClientConnection.h:
     23        * workers/service/context/SWContextManager.cpp:
     24        * workers/service/context/SWContextManager.h:
     25        * workers/service/server/SWServer.cpp:
     26        (WebCore::SWServer::serverToContextConnectionCreated):
     27        * workers/service/server/SWServer.h:
     28        (WebCore::SWServer::Connection::server const):
     29        (WebCore::SWServer::connections const):
     30        * workers/service/server/SWServerToContextConnection.h:
     31
    1322019-05-14  Youenn Fablet  <youenn@apple.com>
    233
  • trunk/Source/WebCore/platform/RegistrableDomain.h

    r242899 r245299  
    2727
    2828#include "PublicSuffix.h"
     29#include "SecurityOriginData.h"
    2930#include <wtf/HashTraits.h>
    3031#include <wtf/URL.h>
     
    3738public:
    3839    RegistrableDomain() = default;
     40
    3941    explicit RegistrableDomain(const URL& url)
    40 #if ENABLE(PUBLIC_SUFFIX_LIST)
    41         : m_registrableDomain { topPrivatelyControlledDomain(url.host().toString()) }
    42 #else
    43         : m_registrableDomain { url.host().toString() }
    44 #endif
     42        : RegistrableDomain(registrableDomainFromHost(url.host().toString()))
    4543    {
    46         auto hostString = url.host().toString();
    47         if (hostString.isEmpty())
    48             m_registrableDomain = "nullOrigin"_s;
    49         else if (m_registrableDomain.isEmpty())
    50             m_registrableDomain = hostString;
     44    }
     45
     46    explicit RegistrableDomain(const SecurityOriginData& origin)
     47        : RegistrableDomain(registrableDomainFromHost(origin.host))
     48    {
    5149    }
    5250
     
    5957    bool matches(const URL& url) const
    6058    {
    61         auto host = url.host();
    62         if (host.isEmpty() && m_registrableDomain == "nullOrigin"_s)
    63             return true;
    64         if (!host.endsWith(m_registrableDomain))
    65             return false;
    66         if (host.length() == m_registrableDomain.length())
    67             return true;
    68         return host[host.length() - m_registrableDomain.length() - 1] == '.';
     59        return matches(url.host());
     60    }
     61
     62    bool matches(const SecurityOriginData& origin) const
     63    {
     64        return matches(origin.host);
    6965    }
    7066
     
    110106    }
    111107
     108    bool matches(StringView host) const
     109    {
     110        if (host.isEmpty() && m_registrableDomain == "nullOrigin"_s)
     111            return true;
     112        if (!host.endsWith(m_registrableDomain))
     113            return false;
     114        if (host.length() == m_registrableDomain.length())
     115            return true;
     116        return host[host.length() - m_registrableDomain.length() - 1] == '.';
     117    }
     118
     119    static inline String registrableDomainFromHost(const String& host)
     120    {
     121#if ENABLE(PUBLIC_SUFFIX_LIST)
     122        auto domain = topPrivatelyControlledDomain(host);
     123#else
     124        auto domain = host;
     125#endif
     126        if (host.isEmpty())
     127            domain = "nullOrigin"_s;
     128        else if (domain.isEmpty())
     129            domain = host;
     130        return domain;
     131    }
     132
    112133    String m_registrableDomain;
    113134};
  • trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp

    r244054 r245299  
    9797#endif
    9898
     99bool ServiceWorkerInternals::isThrottleable() const
     100{
     101    auto* connection = SWContextManager::singleton().connection();
     102    return connection ? connection->isThrottleable() : true;
     103}
     104
    99105} // namespace WebCore
    100106
  • trunk/Source/WebCore/testing/ServiceWorkerInternals.h

    r244054 r245299  
    5252    String processName() const;
    5353
     54    bool isThrottleable() const;
     55
    5456private:
    5557    explicit ServiceWorkerInternals(ServiceWorkerIdentifier);
  • trunk/Source/WebCore/testing/ServiceWorkerInternals.idl

    r244054 r245299  
    3838
    3939    readonly attribute DOMString processName;
     40    readonly attribute boolean isThrottleable;
    4041};
  • trunk/Source/WebCore/workers/service/SWClientConnection.h

    r244160 r245299  
    8686    virtual void finishFetchingScriptInServer(const ServiceWorkerFetchResult&) = 0;
    8787
     88    virtual bool isThrottleable() const = 0;
     89    virtual void updateThrottleState() = 0;
     90
    8891protected:
    8992    WEBCORE_EXPORT SWClientConnection();
  • trunk/Source/WebCore/workers/service/context/SWContextManager.h

    r242279 r245299  
    6363        virtual void matchAll(ServiceWorkerIdentifier, const ServiceWorkerClientQueryOptions&, ServiceWorkerClientsMatchAllCallback&&) = 0;
    6464        virtual void claim(ServiceWorkerIdentifier, CompletionHandler<void()>&&) = 0;
     65
     66        virtual bool isThrottleable() const = 0;
    6567    };
    6668
  • trunk/Source/WebCore/workers/service/server/SWServer.cpp

    r245200 r245299  
    545545void SWServer::serverToContextConnectionCreated(SWServerToContextConnection& contextConnection)
    546546{
     547    for (auto& connection : m_connections.values())
     548        connection->serverToContextConnectionCreated(contextConnection);
     549
    547550    auto pendingContextDatas = m_pendingContextDatas.take(contextConnection.registrableDomain());
    548551    for (auto& data : pendingContextDatas)
  • trunk/Source/WebCore/workers/service/server/SWServer.h

    r244097 r245299  
    8888        virtual void registrationReady(uint64_t registrationReadyRequestIdentifier, ServiceWorkerRegistrationData&&) = 0;
    8989
     90        virtual void serverToContextConnectionCreated(SWServerToContextConnection&) = 0;
     91
    9092        SWServer& server() { return m_server; }
     93        const SWServer& server() const { return m_server; }
    9194
    9295    protected:
     
    153156    WEBCORE_EXPORT void removeConnection(SWServerConnectionIdentifier);
    154157    Connection* connection(SWServerConnectionIdentifier identifier) const { return m_connections.get(identifier); }
     158
     159    const HashMap<SWServerConnectionIdentifier, std::unique_ptr<Connection>>& connections() const { return m_connections; }
    155160
    156161    SWOriginStore& originStore() { return m_originStore; }
  • trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h

    r242905 r245299  
    7777    WEBCORE_EXPORT void setScriptResource(ServiceWorkerIdentifier, URL&& scriptURL, String&& script, URL&& responseURL, String&& mimeType);
    7878
    79     static SWServerToContextConnection* connectionForRegistrableDomain(const RegistrableDomain&);
     79    WEBCORE_EXPORT static SWServerToContextConnection* connectionForRegistrableDomain(const RegistrableDomain&);
    8080
    8181    const RegistrableDomain& registrableDomain() const { return m_registrableDomain; }
  • trunk/Source/WebKit/ChangeLog

    r245298 r245299  
     12019-05-14  Youenn Fablet  <youenn@apple.com>
     2
     3        A service worker process should app nap when all its clients app nap
     4        https://bugs.webkit.org/show_bug.cgi?id=185626
     5        <rdar://problem/46785908>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Compute whether a given web process can be throttled on every page throttling change.
     10        Send that information to network process which stores that information in WebSWServerConnection.
     11        Every WebSWServerToContextConnection throttle state is then computed based on all WebSWServerConnection
     12        that have a client that matches the registrable domain of the context connection.
     13
     14        * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
     15        (WebKit::WebSWServerConnection::registerServiceWorkerClient):
     16        (WebKit::WebSWServerConnection::unregisterServiceWorkerClient):
     17        (WebKit::WebSWServerConnection::hasMatchingClient const):
     18        (WebKit::WebSWServerConnection::computeThrottleState const):
     19        (WebKit::WebSWServerConnection::setThrottleState):
     20        (WebKit::WebSWServerConnection::updateThrottleState):
     21        (WebKit::WebSWServerConnection::serverToContextConnectionCreated):
     22        * NetworkProcess/ServiceWorker/WebSWServerConnection.h:
     23        (WebKit::WebSWServerConnection::isThrottleable const):
     24        * NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in:
     25        * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
     26        (WebKit::WebSWServerToContextConnection::setThrottleState):
     27        * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
     28        (WebKit::WebSWServerToContextConnection::isThrottleable const):
     29        * UIProcess/ServiceWorkerProcessProxy.cpp:
     30        * UIProcess/ServiceWorkerProcessProxy.h:
     31        * WebProcess/Storage/WebSWClientConnection.cpp:
     32        (WebKit::WebSWClientConnection::WebSWClientConnection):
     33        (WebKit::WebSWClientConnection::updateThrottleState):
     34        * WebProcess/Storage/WebSWClientConnection.h:
     35        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
     36        (WebKit::WebSWContextManagerConnection::setThrottleState):
     37        (WebKit::WebSWContextManagerConnection::isThrottleable const):
     38        * WebProcess/Storage/WebSWContextManagerConnection.h:
     39        * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
     40        * WebProcess/WebPage/WebPage.cpp:
     41        (WebKit::WebPage::updateUserActivity):
     42        (WebKit::WebPage::isThrottleable const):
     43        * WebProcess/WebPage/WebPage.h:
     44        * WebProcess/WebProcess.cpp:
     45        (WebKit::WebProcess::arePagesThrottleable const):
     46        * WebProcess/WebProcess.h:
     47
    1482019-05-14  Chris Dumez  <cdumez@apple.com>
    249
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp

    r243345 r245299  
    5252#include <WebCore/ServiceWorkerJobData.h>
    5353#include <WebCore/ServiceWorkerUpdateViaCache.h>
     54#include <wtf/Algorithms.h>
    5455#include <wtf/MainThread.h>
    5556
     
    279280    m_clientOrigins.add(data.identifier, clientOrigin);
    280281    server().registerServiceWorkerClient(WTFMove(clientOrigin), WTFMove(data), controllingServiceWorkerRegistrationIdentifier, WTFMove(userAgent));
     282
     283    if (!m_isThrottleable)
     284        updateThrottleState();
    281285}
    282286
     
    289293    server().unregisterServiceWorkerClient(iterator->value, clientIdentifier);
    290294    m_clientOrigins.remove(iterator);
     295
     296    if (!m_isThrottleable)
     297        updateThrottleState();
     298}
     299
     300bool WebSWServerConnection::hasMatchingClient(const RegistrableDomain& domain) const
     301{
     302    return WTF::anyOf(m_clientOrigins.values(), [&domain](auto& origin) {
     303        return domain.matches(origin.clientOrigin);
     304    });
     305}
     306
     307bool WebSWServerConnection::computeThrottleState(const RegistrableDomain& domain) const
     308{
     309    return WTF::allOf(server().connections().values(), [&domain](auto& serverConnection) {
     310        auto& connection = static_cast<WebSWServerConnection&>(*serverConnection);
     311        return connection.isThrottleable() || !connection.hasMatchingClient(domain);
     312    });
     313}
     314
     315void WebSWServerConnection::setThrottleState(bool isThrottleable)
     316{
     317    m_isThrottleable = isThrottleable;
     318    updateThrottleState();
     319}
     320
     321void WebSWServerConnection::updateThrottleState()
     322{
     323    HashSet<SecurityOriginData> origins;
     324    for (auto& origin : m_clientOrigins.values())
     325        origins.add(origin.clientOrigin);
     326
     327    for (auto& origin : origins) {
     328        if (auto* contextConnection = SWServerToContextConnection::connectionForRegistrableDomain(RegistrableDomain { origin })) {
     329            auto& connection = static_cast<WebSWServerToContextConnection&>(*contextConnection);
     330
     331            if (connection.isThrottleable() == m_isThrottleable)
     332                continue;
     333            bool newThrottleState = computeThrottleState(connection.registrableDomain());
     334            if (connection.isThrottleable() == newThrottleState)
     335                continue;
     336            connection.setThrottleState(newThrottleState);
     337        }
     338    }
     339}
     340
     341void WebSWServerConnection::serverToContextConnectionCreated(WebCore::SWServerToContextConnection& contextConnection)
     342{
     343    auto& connection =  static_cast<WebSWServerToContextConnection&>(contextConnection);
     344    connection.setThrottleState(computeThrottleState(connection.registrableDomain()));
    291345}
    292346
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h

    r243345 r245299  
    9595    void syncTerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier&&, CompletionHandler<void()>&&);
    9696
     97    void serverToContextConnectionCreated(WebCore::SWServerToContextConnection&) final;
     98
     99    bool isThrottleable() const { return m_isThrottleable; }
     100    bool hasMatchingClient(const WebCore::RegistrableDomain&) const;
     101    bool computeThrottleState(const WebCore::RegistrableDomain&) const;
     102    void setThrottleState(bool isThrottleable);
     103    void updateThrottleState();
     104
    97105    IPC::Connection* messageSenderConnection() const final { return m_contentConnection.ptr(); }
    98106    uint64_t messageSenderDestinationID() const final { return identifier().toUInt64(); }
     
    104112    Ref<NetworkProcess> m_networkProcess;
    105113    HashMap<WebCore::ServiceWorkerClientIdentifier, WebCore::ClientOrigin> m_clientOrigins;
     114    bool m_isThrottleable { true };
    106115};
    107116
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in

    r243345 r245299  
    4545
    4646    SyncTerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier workerIdentifier) -> () Synchronous
     47
     48    SetThrottleState(bool isThrottleable)
    4749}
    4850
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp

    r242905 r245299  
    116116}
    117117
     118void WebSWServerToContextConnection::setThrottleState(bool isThrottleable)
     119{
     120    m_isThrottleable = isThrottleable;
     121    send(Messages::WebSWContextManagerConnection::SetThrottleState { isThrottleable });
     122}
     123
    118124void WebSWServerToContextConnection::terminate()
    119125{
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h

    r242905 r245299  
    7272    void didReceiveFetchTaskMessage(IPC::Connection&, IPC::Decoder&);
    7373
     74    void setThrottleState(bool isThrottleable);
     75    bool isThrottleable() const { return m_isThrottleable; }
     76
    7477private:
    7578    WebSWServerToContextConnection(NetworkProcess&, const WebCore::RegistrableDomain&, Ref<IPC::Connection>&&);
     
    98101    HashMap<ServiceWorkerFetchTask::Identifier, WebCore::FetchIdentifier> m_ongoingFetchIdentifiers;
    99102    HashMap<WebCore::FetchIdentifier, Ref<ServiceWorkerFetchTask>> m_ongoingFetches;
     103    bool m_isThrottleable { true };
    100104}; // class WebSWServerToContextConnection
    101105
  • trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp

    r243384 r245299  
    107107}
    108108
    109 void ServiceWorkerProcessProxy::didFinishLaunching(ProcessLauncher* launcher, IPC::Connection::Identifier connectionIdentifier)
    110 {
    111     WebProcessProxy::didFinishLaunching(launcher, connectionIdentifier);
    112 
    113     // Prevent App Nap for Service Worker processes.
    114     // FIXME: Ideally, the Service Worker process would app nap when all its clients app nap (http://webkit.org/b/185626).
    115     setProcessSuppressionEnabled(false);
    116 }
    117 
    118109} // namespace WebKit
    119110
  • trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h

    r242905 r245299  
    5555    void getLaunchOptions(ProcessLauncher::LaunchOptions&) final;
    5656
    57     // ProcessLauncher::Client
    58     void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) final;
    59 
    6057    bool isServiceWorkerProcess() const final { return true; }
    6158
  • trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp

    r244160 r245299  
    6161
    6262    ASSERT_UNUSED(result, result);
     63    updateThrottleState();
    6364}
    6465
     
    232233}
    233234
     235void WebSWClientConnection::updateThrottleState()
     236{
     237    m_isThrottleable = WebProcess::singleton().areAllPagesThrottleable();
     238    send(Messages::WebSWServerConnection::SetThrottleState { m_isThrottleable });
     239}
     240
    234241} // namespace WebKit
    235242
  • trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h

    r244160 r245299  
    8888
    8989    void didResolveRegistrationPromise(const WebCore::ServiceWorkerRegistrationKey&) final;
     90    void updateThrottleState() final;
     91    bool isThrottleable() const final { return m_isThrottleable; }
    9092
    9193    void scheduleStorageJob(const WebCore::ServiceWorkerJobData&);
     
    110112    HashMap<uint64_t, WhenRegistrationReadyCallback> m_ongoingRegistrationReadyTasks;
    111113    Deque<WTF::Function<void()>> m_tasksPendingOriginImport;
    112 
     114    bool m_isThrottleable { true };
    113115}; // class WebSWServerConnection
    114116
  • trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp

    r242503 r245299  
    365365}
    366366
     367void WebSWContextManagerConnection::setThrottleState(bool isThrottleable)
     368{
     369    RELEASE_LOG(ServiceWorker, "Service worker throttleable state is set to %d", isThrottleable);
     370    m_isThrottleable = isThrottleable;
     371    WebProcess::singleton().setProcessSuppressionEnabled(isThrottleable);
     372}
     373
     374bool WebSWContextManagerConnection::isThrottleable() const
     375{
     376    return m_isThrottleable;
     377}
     378
    367379} // namespace WebCore
    368380
  • trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h

    r242279 r245299  
    7474    void skipWaiting(WebCore::ServiceWorkerIdentifier, Function<void()>&&) final;
    7575    void setScriptResource(WebCore::ServiceWorkerIdentifier, const URL&, const WebCore::ServiceWorkerContextData::ImportedScript&) final;
     76    bool isThrottleable() const final;
    7677
    7778    // IPC messages.
     
    9293    void setUserAgent(String&& userAgent);
    9394    NO_RETURN void terminateProcess();
     95    void setThrottleState(bool isThrottleable);
    9496
    9597    Ref<IPC::Connection> m_connectionToNetworkProcess;
     
    107109    uint64_t m_previousRequestIdentifier { 0 };
    108110    String m_userAgent;
     111    bool m_isThrottleable { true };
    109112};
    110113
  • trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in

    r243345 r245299  
    4040    UpdatePreferencesStore(struct WebKit::WebPreferencesStore store)
    4141    TerminateProcess()
     42    SetThrottleState(bool isThrottleable)
    4243}
    4344
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r245196 r245299  
    214214#include <WebCore/ResourceResponse.h>
    215215#include <WebCore/RuntimeEnabledFeatures.h>
     216#include <WebCore/SWClientConnection.h>
    216217#include <WebCore/SchemeRegistry.h>
    217218#include <WebCore/ScriptController.h>
     
    766767void WebPage::updateThrottleState()
    767768{
    768     bool isActive = m_activityState.containsAny({ ActivityState::IsLoading, ActivityState::IsAudible, ActivityState::IsCapturingMedia, ActivityState::WindowIsActive });
    769     bool isVisuallyIdle = m_activityState.contains(ActivityState::IsVisuallyIdle);
    770 
    771     bool shouldAllowAppNap = m_isAppNapEnabled && !isActive && isVisuallyIdle;
     769    bool isThrottleable = this->isThrottleable();
    772770
    773771    // The UserActivity prevents App Nap. So if we want to allow App Nap of the page, stop the activity.
    774772    // If the page should not be app nap'd, start it.
    775     if (shouldAllowAppNap)
     773    if (isThrottleable)
    776774        m_userActivity.stop();
    777775    else
    778776        m_userActivity.start();
     777
     778#if ENABLE(SERVICE_WORKER)
     779    if (auto* connection = ServiceWorkerProvider::singleton().existingServiceWorkerConnectionForSession(sessionID())) {
     780        if (isThrottleable != connection->isThrottleable())
     781            connection->updateThrottleState();
     782    }
     783#endif
     784}
     785
     786bool WebPage::isThrottleable() const
     787{
     788    bool isActive = m_activityState.containsAny({ ActivityState::IsLoading, ActivityState::IsAudible, ActivityState::IsCapturingMedia, ActivityState::WindowIsActive });
     789    bool isVisuallyIdle = m_activityState.contains(ActivityState::IsVisuallyIdle);
     790
     791    return m_isAppNapEnabled && !isActive && isVisuallyIdle;
    779792}
    780793
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r245183 r245299  
    11921192    void updateIntrinsicContentSizeIfNeeded(const WebCore::IntSize&);
    11931193    void scheduleFullEditorStateUpdate();
     1194    bool isThrottleable() const;
    11941195
    11951196private:
  • trunk/Source/WebKit/WebProcess/WebProcess.cpp

    r245069 r245299  
    118118#include <WebCore/Settings.h>
    119119#include <WebCore/UserGestureIndicator.h>
     120#include <wtf/Algorithms.h>
    120121#include <wtf/Language.h>
    121122#include <wtf/ProcessPrivilege.h>
     
    19081909#endif
    19091910
     1911bool WebProcess::areAllPagesThrottleable() const
     1912{
     1913    return WTF::allOf(m_pageMap.values(), [](auto& page) {
     1914        return page->isThrottleable();
     1915    });
     1916}
     1917
    19101918} // namespace WebKit
  • trunk/Source/WebKit/WebProcess/WebProcess.h

    r245069 r245299  
    270270#endif
    271271
     272    bool areAllPagesThrottleable() const;
     273
    272274private:
    273275    WebProcess();
  • trunk/Tools/ChangeLog

    r245290 r245299  
     12019-05-14  Youenn Fablet  <youenn@apple.com>
     2
     3        A service worker process should app nap when all its clients app nap
     4        https://bugs.webkit.org/show_bug.cgi?id=185626
     5        <rdar://problem/46785908>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Allow to enable app nap through test header.
     10
     11        * WebKitTestRunner/TestController.cpp:
     12        (WTR::TestController::resetPreferencesToConsistentValues):
     13        (WTR::updateTestOptionsFromTestHeader):
     14        * WebKitTestRunner/TestOptions.h:
     15        (WTR::TestOptions::hasSameInitializationOptions const):
     16
    1172019-05-14  Commit Queue  <commit-queue@webkit.org>
    218
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r245280 r245299  
    785785
    786786    WKPreferencesSetProcessSwapOnNavigationEnabled(preferences, options.contextOptions.shouldEnableProcessSwapOnNavigation());
    787     WKPreferencesSetPageVisibilityBasedProcessSuppressionEnabled(preferences, false);
     787    WKPreferencesSetPageVisibilityBasedProcessSuppressionEnabled(preferences, options.enableAppNap);
    788788    WKPreferencesSetOfflineWebApplicationCacheEnabled(preferences, true);
    789789    WKPreferencesSetSubpixelAntialiasedLayerTextEnabled(preferences, false);
     
    13981398        else if (key == "shouldUseModernCompatibilityMode")
    13991399            testOptions.shouldUseModernCompatibilityMode = parseBooleanTestHeaderValue(value);
     1400        else if (key == "enableAppNap")
     1401            testOptions.enableAppNap = parseBooleanTestHeaderValue(value);
    14001402        pairStart = pairEnd + 1;
    14011403    }
  • trunk/Tools/WebKitTestRunner/TestOptions.h

    r245280 r245299  
    9393    bool shouldPresentPopovers { true };
    9494    bool shouldUseModernCompatibilityMode { false };
     95    bool enableAppNap { false };
    9596
    9697    double contentInsetTop { 0 };
     
    145146            || shouldPresentPopovers != options.shouldPresentPopovers
    146147            || contentInsetTop != options.contentInsetTop
    147             || shouldUseModernCompatibilityMode != options.shouldUseModernCompatibilityMode)
     148            || shouldUseModernCompatibilityMode != options.shouldUseModernCompatibilityMode
     149            || enableAppNap != options.enableAppNap)
    148150            return false;
    149151
Note: See TracChangeset for help on using the changeset viewer.