Coverage Report

Created: 2025-03-04 07:22

/src/serenity/Userland/Libraries/LibWeb/ServiceWorker/Registration.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/Optional.h>
10
#include <AK/Time.h>
11
#include <AK/Traits.h>
12
#include <LibURL/URL.h>
13
#include <LibWeb/Bindings/ServiceWorkerRegistrationPrototype.h>
14
#include <LibWeb/ServiceWorker/ServiceWorker.h>
15
#include <LibWeb/StorageAPI/StorageKey.h>
16
17
namespace Web::ServiceWorker {
18
19
// https://w3c.github.io/ServiceWorker/#dfn-service-worker-registration
20
// This class corresponds to "service worker registration", not "ServiceWorkerRegistration"
21
// FIXME: This object needs to live at the user-agent level, in LibWebView, not in LibWeb
22
//        .. And it will need some way to synchronize updates to each 'client' (aka process aka ESO)
23
class Registration {
24
    AK_MAKE_NONCOPYABLE(Registration);
25
    AK_MAKE_DEFAULT_MOVABLE(Registration);
26
27
public:
28
    // https://w3c.github.io/ServiceWorker/#get-registration-algorithm
29
    static Optional<Registration&> get(StorageAPI::StorageKey const&, Optional<URL::URL> scope);
30
31
    // https://w3c.github.io/ServiceWorker/#set-registration-algorithm
32
    static Registration& set(StorageAPI::StorageKey const&, URL::URL const&, Bindings::ServiceWorkerUpdateViaCache);
33
34
    static void remove(StorageAPI::StorageKey const&, URL::URL const&);
35
36
    bool is_unregistered();
37
38
0
    StorageAPI::StorageKey const& storage_key() const { return m_storage_key; }
39
0
    URL::URL const& scope_url() const { return m_scope_url; }
40
0
    Bindings::ServiceWorkerUpdateViaCache update_via_cache() const { return m_update_via_cache_mode; }
41
42
0
    void set_last_update_check_time(MonotonicTime time) { m_last_update_check_time = time; }
43
44
    ServiceWorker* newest_worker() const;
45
    bool is_stale() const;
46
47
private:
48
    Registration(StorageAPI::StorageKey, URL::URL, Bindings::ServiceWorkerUpdateViaCache);
49
50
    StorageAPI::StorageKey m_storage_key; // https://w3c.github.io/ServiceWorker/#service-worker-registration-storage-key
51
    URL::URL m_scope_url;                 // https://w3c.github.io/ServiceWorker/#dfn-scope-url
52
53
    // NOTE: These are "service workers", not "HTML::ServiceWorker"s
54
    ServiceWorker* m_installing_worker { nullptr }; // https://w3c.github.io/ServiceWorker/#dfn-installing-worker
55
    ServiceWorker* m_waiting_worker { nullptr };    // https://w3c.github.io/ServiceWorker/#dfn-waiting-worker
56
    ServiceWorker* m_active_worker { nullptr };     // https://w3c.github.io/ServiceWorker/#dfn-active-worker
57
58
    Optional<MonotonicTime> m_last_update_check_time;                                                               // https://w3c.github.io/ServiceWorker/#dfn-last-update-check-time
59
    Bindings::ServiceWorkerUpdateViaCache m_update_via_cache_mode = Bindings::ServiceWorkerUpdateViaCache::Imports; // https://w3c.github.io/ServiceWorker/#dfn-update-via-cache
60
    // FIXME: A service worker registration has one or more task queues... https://w3c.github.io/ServiceWorker/#dfn-service-worker-registration-task-queue
61
    // FIXME: Spec bug: A service worker registration has an associated NavigationPreloadManager object.
62
    //        This can't possibly be true. The association is the other way around.
63
64
    bool m_navigation_preload_enabled = { false }; // https://w3c.github.io/ServiceWorker/#service-worker-registration-navigation-preload-enabled-flag
65
    ByteString m_navigation_preload_header_value;  // https://w3c.github.io/ServiceWorker/#service-worker-registration-navigation-preload-header-value
66
};
67
68
}