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/. */
7 #ifndef _mozilla_dom_ClientState_h
8 #define _mozilla_dom_ClientState_h
10 #include "mozilla/dom/DocumentBinding.h"
11 #include "mozilla/Maybe.h"
12 #include "mozilla/StorageAccess.h"
13 #include "mozilla/TimeStamp.h"
14 #include "mozilla/UniquePtr.h"
15 #include "mozilla/Variant.h"
16 #include "nsContentUtils.h"
18 namespace mozilla::dom
{
21 class IPCClientWindowState
;
22 class IPCClientWorkerState
;
24 // This class defines the mutable nsGlobalWindow state we support querying
25 // through the ClientManagerService. It is a snapshot of the state and
26 // is not live updated.
27 class ClientWindowState final
{
28 UniquePtr
<IPCClientWindowState
> mData
;
31 ClientWindowState(mozilla::dom::VisibilityState aVisibilityState
,
32 const TimeStamp
& aLastFocusTime
,
33 StorageAccess aStorageAccess
, bool aFocused
);
35 explicit ClientWindowState(const IPCClientWindowState
& aData
);
37 ClientWindowState(const ClientWindowState
& aRight
);
38 ClientWindowState(ClientWindowState
&& aRight
);
40 ClientWindowState
& operator=(const ClientWindowState
& aRight
);
42 ClientWindowState
& operator=(ClientWindowState
&& aRight
);
46 mozilla::dom::VisibilityState
VisibilityState() const;
48 const TimeStamp
& LastFocusTime() const;
52 StorageAccess
GetStorageAccess() const;
54 const IPCClientWindowState
& ToIPC() const;
57 // This class defines the mutable worker state we support querying
58 // through the ClientManagerService. It is a snapshot of the state and
59 // is not live updated. Right now, we don't actually providate any
60 // worker specific state values, but we may in the future. This
61 // class also services as a placeholder that the state is referring
62 // to a worker in ClientState.
63 class ClientWorkerState final
{
64 UniquePtr
<IPCClientWorkerState
> mData
;
67 explicit ClientWorkerState(StorageAccess aStorageAccess
);
69 explicit ClientWorkerState(const IPCClientWorkerState
& aData
);
71 ClientWorkerState(const ClientWorkerState
& aRight
);
72 ClientWorkerState(ClientWorkerState
&& aRight
);
74 ClientWorkerState
& operator=(const ClientWorkerState
& aRight
);
76 ClientWorkerState
& operator=(ClientWorkerState
&& aRight
);
80 StorageAccess
GetStorageAccess() const;
82 const IPCClientWorkerState
& ToIPC() const;
85 // This is a union of the various types of mutable state we support
86 // querying in ClientManagerService. Right now it can contain either
87 // window or worker states.
88 class ClientState final
{
89 Maybe
<Variant
<ClientWindowState
, ClientWorkerState
>> mData
;
94 explicit ClientState(const ClientWindowState
& aWindowState
);
95 explicit ClientState(const ClientWorkerState
& aWorkerState
);
96 explicit ClientState(const IPCClientWindowState
& aData
);
97 explicit ClientState(const IPCClientWorkerState
& aData
);
99 ClientState(const ClientState
& aRight
) = default;
100 ClientState(ClientState
&& aRight
);
102 ClientState
& operator=(const ClientState
& aRight
) = default;
104 ClientState
& operator=(ClientState
&& aRight
);
108 static ClientState
FromIPC(const IPCClientState
& aData
);
110 bool IsWindowState() const;
112 const ClientWindowState
& AsWindowState() const;
114 bool IsWorkerState() const;
116 const ClientWorkerState
& AsWorkerState() const;
118 StorageAccess
GetStorageAccess() const;
120 const IPCClientState
ToIPC() const;
123 } // namespace mozilla::dom
125 #endif // _mozilla_dom_ClientState_h