Registration.h 3.2 KB

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