Source code

Revision control

Other Tools

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