ServiceWorkerRegistrationDescriptor.h (3559B)
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 #ifndef _mozilla_dom_ServiceWorkerRegistrationDescriptor_h 7 #define _mozilla_dom_ServiceWorkerRegistrationDescriptor_h 8 9 #include "mozilla/Maybe.h" 10 #include "mozilla/UniquePtr.h" 11 #include "mozilla/dom/ServiceWorkerDescriptor.h" 12 #include "mozilla/dom/WorkerBinding.h" 13 14 namespace mozilla { 15 16 namespace ipc { 17 class PrincipalInfo; 18 } // namespace ipc 19 20 namespace dom { 21 22 class IPCServiceWorkerRegistrationDescriptor; 23 class ServiceWorkerInfo; 24 enum class ServiceWorkerUpdateViaCache : uint8_t; 25 26 // This class represents a snapshot of a particular 27 // ServiceWorkerRegistrationInfo object. It is threadsafe and can be 28 // transferred across processes. 29 class ServiceWorkerRegistrationDescriptor final { 30 // This class is largely a wrapper wround an IPDL generated struct. We 31 // need the wrapper class since IPDL generated code includes windows.h 32 // which is in turn incompatible with bindings code. 33 UniquePtr<IPCServiceWorkerRegistrationDescriptor> mData; 34 35 Maybe<IPCServiceWorkerDescriptor> NewestInternal() const; 36 37 public: 38 ServiceWorkerRegistrationDescriptor( 39 uint64_t aId, uint64_t aVersion, nsIPrincipal* aPrincipal, 40 const nsACString& aScope, WorkerType aType, 41 ServiceWorkerUpdateViaCache aUpdateViaCache); 42 43 ServiceWorkerRegistrationDescriptor( 44 uint64_t aId, uint64_t aVersion, 45 const mozilla::ipc::PrincipalInfo& aPrincipalInfo, 46 const nsACString& aScope, WorkerType aType, 47 ServiceWorkerUpdateViaCache aUpdateViaCache); 48 49 explicit ServiceWorkerRegistrationDescriptor( 50 const IPCServiceWorkerRegistrationDescriptor& aDescriptor); 51 52 ServiceWorkerRegistrationDescriptor( 53 const ServiceWorkerRegistrationDescriptor& aRight); 54 55 ServiceWorkerRegistrationDescriptor& operator=( 56 const ServiceWorkerRegistrationDescriptor& aRight); 57 58 ServiceWorkerRegistrationDescriptor( 59 ServiceWorkerRegistrationDescriptor&& aRight); 60 61 ServiceWorkerRegistrationDescriptor& operator=( 62 ServiceWorkerRegistrationDescriptor&& aRight); 63 64 ~ServiceWorkerRegistrationDescriptor(); 65 66 bool operator==(const ServiceWorkerRegistrationDescriptor& aRight) const; 67 68 uint64_t Id() const; 69 70 uint64_t Version() const; 71 72 ServiceWorkerUpdateViaCache UpdateViaCache() const; 73 74 const mozilla::ipc::PrincipalInfo& PrincipalInfo() const; 75 76 Result<nsCOMPtr<nsIPrincipal>, nsresult> GetPrincipal() const; 77 78 const nsCString& Scope() const; 79 80 WorkerType Type() const; 81 82 Maybe<ServiceWorkerDescriptor> GetInstalling() const; 83 84 Maybe<ServiceWorkerDescriptor> GetWaiting() const; 85 86 Maybe<ServiceWorkerDescriptor> GetActive() const; 87 88 Maybe<ServiceWorkerDescriptor> Newest() const; 89 90 bool HasWorker(const ServiceWorkerDescriptor& aDescriptor) const; 91 92 bool IsValid() const; 93 94 void SetUpdateViaCache(ServiceWorkerUpdateViaCache aUpdateViaCache); 95 96 void SetWorkerType(WorkerType aType); 97 98 void SetWorkers(ServiceWorkerInfo* aInstalling, ServiceWorkerInfo* aWaiting, 99 ServiceWorkerInfo* aActive); 100 101 void SetVersion(uint64_t aVersion); 102 103 // Expose the underlying IPC type so that it can be passed via IPC. 104 const IPCServiceWorkerRegistrationDescriptor& ToIPC() const; 105 }; 106 107 } // namespace dom 108 } // namespace mozilla 109 110 #endif // _mozilla_dom_ServiceWorkerRegistrationDescriptor_h