Changeset 291888 in webkit


Ignore:
Timestamp:
Mar 25, 2022 2:19:35 PM (4 months ago)
Author:
youenn@apple.com
Message:

Add support for focused and visible ServiceWorkerWindowClient states
https://bugs.webkit.org/show_bug.cgi?id=238372

Reviewed by Brady Eidson.

LayoutTests/imported/w3c:

  • web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/extendable-message-event.https-expected.txt:
  • web-platform-tests/service-workers/service-worker/clients-get.https-expected.txt:
  • web-platform-tests/service-workers/service-worker/clients-matchall-client-types.https-expected.txt:
  • web-platform-tests/service-workers/service-worker/clients-matchall-exact-controller.https-expected.txt:
  • web-platform-tests/service-workers/service-worker/clients-matchall.https-expected.txt:

Source/WebCore:

Add visible and focused to ServiceWorkerClientData.
In case document visibility or focused state changes, we push the corresponding ServiceWorkerClientData to network process.

Test: http/wpt/service-workers/client-properties.https.html

  • dom/Document.cpp:
  • dom/Document.h:
  • page/FocusController.cpp:
  • workers/service/ServiceWorkerClient.h:
  • workers/service/ServiceWorkerClientData.cpp:
  • workers/service/ServiceWorkerClientData.h:
  • workers/service/ServiceWorkerClients.cpp:
  • workers/service/ServiceWorkerWindowClient.cpp:
  • workers/service/ServiceWorkerWindowClient.h:

LayoutTests:

  • http/wpt/service-workers/client-properties-worker.js: Added.
  • http/wpt/service-workers/client-properties.https-expected.txt: Added.
  • http/wpt/service-workers/client-properties.https.html: Added.
Location:
trunk
Files:
3 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r291886 r291888  
     12022-03-25  Youenn Fablet  <youenn@apple.com>
     2
     3        Add support for focused and visible ServiceWorkerWindowClient states
     4        https://bugs.webkit.org/show_bug.cgi?id=238372
     5
     6        Reviewed by Brady Eidson.
     7
     8        * http/wpt/service-workers/client-properties-worker.js: Added.
     9        * http/wpt/service-workers/client-properties.https-expected.txt: Added.
     10        * http/wpt/service-workers/client-properties.https.html: Added.
     11
    1122022-03-25  Devin Rousso  <drousso@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r291886 r291888  
     12022-03-25  Youenn Fablet  <youenn@apple.com>
     2
     3        Add support for focused and visible ServiceWorkerWindowClient states
     4        https://bugs.webkit.org/show_bug.cgi?id=238372
     5
     6        Reviewed by Brady Eidson.
     7
     8        * web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/extendable-message-event.https-expected.txt:
     9        * web-platform-tests/service-workers/service-worker/clients-get.https-expected.txt:
     10        * web-platform-tests/service-workers/service-worker/clients-matchall-client-types.https-expected.txt:
     11        * web-platform-tests/service-workers/service-worker/clients-matchall-exact-controller.https-expected.txt:
     12        * web-platform-tests/service-workers/service-worker/clients-matchall.https-expected.txt:
     13
    1142022-03-25  Devin Rousso  <drousso@apple.com>
    215
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/extendable-message-event.https-expected.txt

    r267647 r291888  
    11
    22PASS Post an extendable message from a top-level client
    3 FAIL Post an extendable message from a nested client assert_equals: event `source` property `focused` expected false but got true
     3PASS Post an extendable message from a nested client
    44PASS Post loopback extendable messages
    55PASS Post extendable messages among service workers
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-get.https-expected.txt

    r288201 r291888  
    11
    2 FAIL Test Clients.get() assert_array_equals: expected property 1 to be false but got true (expected array ["visible", false, "https://localhost:9443/service-workers/service-worker/resources/clients-get-frame.html#2", "window", "nested"] got ["visible", true, "https://localhost:9443/service-workers/service-worker/resources/clients-get-frame.html#2", "window", "nested"])
     2PASS Test Clients.get()
    33PASS Test successful Clients.get(FetchEvent.resultingClientId)
    44PASS Test unsuccessful Clients.get(FetchEvent.resultingClientId)
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-matchall-exact-controller.https-expected.txt

    r262254 r291888  
    11
     2PASS Test Clients.matchAll() with exact controller
    23
    3 FAIL Test Clients.matchAll() with exact controller assert_array_equals: expected property 1 to be false but got true (expected array ["visible", false, "https://localhost:9443/service-workers/service-worker/resources/blank.html?clients-matchAll#2", "window", "nested"] got ["visible", true, "https://localhost:9443/service-workers/service-worker/resources/blank.html?clients-matchAll#2", "window", "nested"])
    4 
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-matchall.https-expected.txt

    r262254 r291888  
    11
     2PASS Test Clients.matchAll()
    23
    3 FAIL Test Clients.matchAll() assert_array_equals: expected property 1 to be false but got true (expected array ["visible", false, "https://localhost:9443/service-workers/service-worker/resources/blank.html?clients-matchAll#2", "window", "nested"] got ["visible", true, "https://localhost:9443/service-workers/service-worker/resources/blank.html?clients-matchAll#2", "window", "nested"])
    4 
  • trunk/Source/WebCore/ChangeLog

    r291886 r291888  
     12022-03-25  Youenn Fablet  <youenn@apple.com>
     2
     3        Add support for focused and visible ServiceWorkerWindowClient states
     4        https://bugs.webkit.org/show_bug.cgi?id=238372
     5
     6        Reviewed by Brady Eidson.
     7
     8        Add visible and focused to ServiceWorkerClientData.
     9        In case document visibility or focused state changes, we push the corresponding ServiceWorkerClientData to network process.
     10
     11        Test: http/wpt/service-workers/client-properties.https.html
     12
     13        * dom/Document.cpp:
     14        * dom/Document.h:
     15        * page/FocusController.cpp:
     16        * workers/service/ServiceWorkerClient.h:
     17        * workers/service/ServiceWorkerClientData.cpp:
     18        * workers/service/ServiceWorkerClientData.h:
     19        * workers/service/ServiceWorkerClients.cpp:
     20        * workers/service/ServiceWorkerWindowClient.cpp:
     21        * workers/service/ServiceWorkerWindowClient.h:
     22
    1232022-03-25  Devin Rousso  <drousso@apple.com>
    224
  • trunk/Source/WebCore/dom/Document.cpp

    r291741 r291888  
    563563    , m_quirks(makeUniqueRef<Quirks>(*this))
    564564    , m_cachedResourceLoader(createCachedResourceLoader(frame))
     565    , m_creationURL(url)
    565566    , m_domTreeVersion(++s_globalTreeVersion)
    566567    , m_styleScope(makeUnique<Style::Scope>(*this))
     
    18641865            callback();
    18651866    }
     1867#if ENABLE(SERVICE_WORKER)
     1868    updateServiceWorkerClientData();
     1869#endif
    18661870}
    18671871
     
    87678771
    87688772    m_serviceWorkerConnection = serviceWorkerConnection;
    8769 
     8773    updateServiceWorkerClientData();
     8774}
     8775
     8776void Document::updateServiceWorkerClientData()
     8777{
    87708778    if (!m_serviceWorkerConnection)
    87718779        return;
  • trunk/Source/WebCore/dom/Document.h

    r291741 r291888  
    709709    const URL& urlForBindings() const { return m_url.isEmpty() ? aboutBlankURL() : m_url; }
    710710
     711    const URL& creationURL() const { return m_creationURL; }
     712
    711713    // To understand how these concepts relate to one another, please see the
    712714    // comments surrounding their declaration.
     
    15661568#if ENABLE(SERVICE_WORKER)
    15671569    void setServiceWorkerConnection(SWClientConnection*);
     1570    void updateServiceWorkerClientData();
    15681571#endif
    15691572
     
    18171820    // Document URLs.
    18181821    URL m_url; // Document.URL: The URL from which this document was retrieved.
     1822    URL m_creationURL; // https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-creation-url.
    18191823    URL m_baseURL; // Node.baseURI: The URL to use when resolving relative URLs.
    18201824    URL m_baseURLOverride; // An alternative base URL that takes precedence over m_baseURL (but not m_baseElementURL).
  • trunk/Source/WebCore/page/FocusController.cpp

    r291044 r291888  
    364364        oldFrame->selection().setFocused(false);
    365365        oldFrame->document()->dispatchWindowEvent(Event::create(eventNames().blurEvent, Event::CanBubble::No, Event::IsCancelable::No));
     366#if ENABLE(SERVICE_WORKER)
     367        auto* frame = oldFrame.get();
     368        do {
     369            frame->document()->updateServiceWorkerClientData();
     370            frame = frame->tree().parent();
     371        } while (frame);
     372#endif
    366373    }
    367374
     
    369376        newFrame->selection().setFocused(true);
    370377        newFrame->document()->dispatchWindowEvent(Event::create(eventNames().focusEvent, Event::CanBubble::No, Event::IsCancelable::No));
     378#if ENABLE(SERVICE_WORKER)
     379        auto* frame = newFrame.get();
     380        do {
     381            frame->document()->updateServiceWorkerClientData();
     382            frame = frame->tree().parent();
     383        } while (frame);
     384#endif
    371385    }
    372386
  • trunk/Source/WebCore/workers/service/ServiceWorkerClient.cpp

    r281808 r291888  
    4242Ref<ServiceWorkerClient> ServiceWorkerClient::getOrCreate(ServiceWorkerGlobalScope& context, ServiceWorkerClientData&& data)
    4343{
    44     if (auto* client = context.serviceWorkerClient(data.identifier))
     44    if (auto* client = context.serviceWorkerClient(data.identifier)) {
     45        // Temporary fix until we remove reusing of same ServiceWorkerClient objects.
     46        client->m_data = WTFMove(data);
    4547        return *client;
     48    }
    4649
    4750    if (data.type == ServiceWorkerClientType::Window)
  • trunk/Source/WebCore/workers/service/ServiceWorkerClient.h

    r286012 r291888  
    6666    ExceptionOr<void> postMessage(JSC::JSGlobalObject&, JSC::JSValue message, StructuredSerializeOptions&&);
    6767
     68    const ServiceWorkerClientData& data() const { return m_data; }
     69
    6870protected:
    6971    ServiceWorkerClient(ServiceWorkerGlobalScope&, ServiceWorkerClientData&&);
    7072
     73private:
    7174    ServiceWorkerClientData m_data;
    7275};
  • trunk/Source/WebCore/workers/service/ServiceWorkerClientData.cpp

    r291123 r291888  
    5959ServiceWorkerClientData ServiceWorkerClientData::isolatedCopy() const &
    6060{
    61     return { identifier, type, frameType, url.isolatedCopy(), lastNavigationWasAppInitiated };
     61    return { identifier, type, frameType, url.isolatedCopy(), lastNavigationWasAppInitiated, isVisible, isFocused, focusOrder };
    6262}
    6363
    6464ServiceWorkerClientData ServiceWorkerClientData::isolatedCopy() &&
    6565{
    66     return { identifier, type, frameType, WTFMove(url).isolatedCopy(), lastNavigationWasAppInitiated };
     66    return { identifier, type, frameType, WTFMove(url).isolatedCopy(), lastNavigationWasAppInitiated, isVisible, isFocused, focusOrder };
    6767}
    6868
     
    7979        isDocument ? ServiceWorkerClientType::Window : ServiceWorkerClientType::Worker,
    8080        toServiceWorkerClientFrameType(context),
    81         context.url(), lastNavigationWasAppInitiated
     81        document.creationURL(), lastNavigationWasAppInitiated,
     82        !document.hidden(),
     83        document.hasFocus(),
     84        0
    8285    };
    8386}
  • trunk/Source/WebCore/workers/service/ServiceWorkerClientData.h

    r291123 r291888  
    4747    URL url;
    4848    LastNavigationWasAppInitiated lastNavigationWasAppInitiated;
     49    bool isVisible { false };
     50    bool isFocused { false };
     51    uint64_t focusOrder { 0 };
    4952
    5053    ServiceWorkerClientData isolatedCopy() const &;
     
    6063void ServiceWorkerClientData::encode(Encoder& encoder) const
    6164{
    62     encoder << identifier << type << frameType << url << lastNavigationWasAppInitiated;
     65    encoder << identifier << type << frameType << url << lastNavigationWasAppInitiated << isVisible << isFocused << focusOrder;
    6366}
    6467
     
    9194        return std::nullopt;
    9295
    93     return { { WTFMove(*identifier), WTFMove(*type), WTFMove(*frameType), WTFMove(*url), WTFMove(*lastNavigationWasAppInitiated) } };
     96    std::optional<bool> isVisible;
     97    decoder >> isVisible;
     98    if (!isVisible)
     99        return std::nullopt;
     100
     101    std::optional<bool> isFocused;
     102    decoder >> isFocused;
     103    if (!isFocused)
     104        return std::nullopt;
     105
     106    std::optional<uint64_t> focusOrder;
     107    decoder >> focusOrder;
     108    if (!focusOrder)
     109        return std::nullopt;
     110
     111    return { { WTFMove(*identifier), WTFMove(*type), WTFMove(*frameType), WTFMove(*url), WTFMove(*lastNavigationWasAppInitiated), WTFMove(*isVisible), WTFMove(*isFocused), WTFMove(*focusOrder) } };
    94112}
    95113
  • trunk/Source/WebCore/workers/service/ServiceWorkerClients.cpp

    r291003 r291888  
    7373        return ServiceWorkerClient::getOrCreate(scope, WTFMove(clientData));
    7474    });
     75    std::sort(clients.begin(), clients.end(), [&] (auto& a, auto& b) {
     76        return a->data().focusOrder > b->data().focusOrder;
     77    });
    7578    promise.resolve<IDLSequence<IDLInterface<ServiceWorkerClient>>>(WTFMove(clients));
    7679}
  • trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp

    r233122 r291888  
    3838}
    3939
    40 VisibilityState ServiceWorkerWindowClient::visibilityState() const
    41 {
    42     return VisibilityState::Visible;
    43 }
    44 
    45 bool ServiceWorkerWindowClient::isFocused() const
    46 {
    47     return true;
    48 }
    49 
    5040void ServiceWorkerWindowClient::focus(Ref<DeferredPromise>&& promise)
    5141{
  • trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.h

    r225760 r291888  
    4343    }
    4444
    45     VisibilityState visibilityState() const;
    46     bool isFocused() const;
     45    VisibilityState visibilityState() const { return data().isVisible ? VisibilityState::Visible : VisibilityState::Hidden; }
     46    bool isFocused() const { return data().isFocused; }
    4747
    4848    void focus(Ref<DeferredPromise>&&);
  • trunk/Source/WebCore/workers/service/server/SWServer.cpp

    r291467 r291888  
    966966        ASSERT(m_visibleClientIdToInternalClientIdMap.get(data.identifier.object().toString()) == clientIdentifier);
    967967        ASSERT(m_clientsById.contains(clientIdentifier));
     968        if (data.isFocused)
     969            data.focusOrder = ++m_focusOrder;
    968970        m_clientsById.set(clientIdentifier, WTFMove(data));
    969971        return;
  • trunk/Source/WebCore/workers/service/server/SWServer.h

    r291467 r291888  
    306306    bool m_hasReceivedAppBoundDomains { false };
    307307    unsigned m_uniqueRegistrationCount { 0 };
     308    uint64_t m_focusOrder { 0 };
    308309};
    309310
Note: See TracChangeset for help on using the changeset viewer.