ServiceWorkerRegistrationProxy.h (3064B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef moz_dom_ServiceWorkerRegistrationProxy_h 8 #define moz_dom_ServiceWorkerRegistrationProxy_h 9 10 #include "ServiceWorkerRegistrationDescriptor.h" 11 #include "ServiceWorkerRegistrationListener.h" 12 #include "ServiceWorkerUtils.h" 13 #include "mozilla/dom/ClientInfo.h" 14 #include "mozilla/dom/PServiceWorkerRegistrationParent.h" 15 #include "mozilla/dom/notification/NotificationUtils.h" 16 #include "nsProxyRelease.h" 17 18 namespace mozilla::dom { 19 20 class ServiceWorkerRegistrationInfo; 21 class ServiceWorkerRegistrationParent; 22 23 class ServiceWorkerRegistrationProxy final 24 : public ServiceWorkerRegistrationListener { 25 // Background thread only 26 RefPtr<ServiceWorkerRegistrationParent> mActor; 27 28 // Written on background thread and read on main thread 29 nsCOMPtr<nsISerialEventTarget> mEventTarget; 30 31 // Main thread only 32 ServiceWorkerRegistrationDescriptor mDescriptor; 33 ClientInfo mListeningClientInfo; 34 nsMainThreadPtrHandle<ServiceWorkerRegistrationInfo> mReg; 35 36 ~ServiceWorkerRegistrationProxy(); 37 38 // Background thread methods 39 void MaybeShutdownOnBGThread(); 40 41 void UpdateStateOnBGThread( 42 const ServiceWorkerRegistrationDescriptor& aDescriptor); 43 44 void FireUpdateFoundOnBGThread(); 45 46 // Main thread methods 47 void InitOnMainThread(); 48 49 void MaybeShutdownOnMainThread(); 50 51 void StopListeningOnMainThread(); 52 53 // The timer callback to perform the delayed update 54 class DelayedUpdate; 55 RefPtr<DelayedUpdate> mDelayedUpdate; 56 57 // ServiceWorkerRegistrationListener interface 58 void UpdateState( 59 const ServiceWorkerRegistrationDescriptor& aDescriptor) override; 60 61 void FireUpdateFound() override; 62 63 void RegistrationCleared() override; 64 65 void GetScope(nsAString& aScope) const override; 66 67 bool MatchesDescriptor( 68 const ServiceWorkerRegistrationDescriptor& aDescriptor) override; 69 70 public: 71 ServiceWorkerRegistrationProxy( 72 const ServiceWorkerRegistrationDescriptor& aDescriptor, 73 const ClientInfo& aForClient); 74 75 void Init(ServiceWorkerRegistrationParent* aActor); 76 77 void RevokeActor(ServiceWorkerRegistrationParent* aActor); 78 79 RefPtr<GenericPromise> Unregister(); 80 81 RefPtr<ServiceWorkerRegistrationPromise> Update( 82 const nsACString& aNewestWorkerScriptUrl); 83 84 RefPtr<GenericPromise> SetNavigationPreloadEnabled(const bool& aEnabled); 85 86 RefPtr<GenericPromise> SetNavigationPreloadHeader(const nsACString& aHeader); 87 88 RefPtr<NavigationPreloadStatePromise> GetNavigationPreloadState(); 89 90 RefPtr<notification::NotificationsPromise> GetNotifications( 91 const nsAString& aTag); 92 93 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServiceWorkerRegistrationProxy, 94 override); 95 }; 96 97 } // namespace mozilla::dom 98 99 #endif // moz_dom_ServiceWorkerRegistrationProxy_h