ClientState.h (4240B)
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 _mozilla_dom_ClientState_h 8 #define _mozilla_dom_ClientState_h 9 10 #include "mozilla/Maybe.h" 11 #include "mozilla/TimeStamp.h" 12 #include "mozilla/UniquePtr.h" 13 #include "mozilla/Variant.h" 14 #include "nsContentUtils.h" 15 16 namespace mozilla { 17 // We forward-declare this because including StorageAccess.h causes cbindgen to 18 // have problems due to StorageAccess.h's include of BrowsingContext.h which 19 // includes SyncedContext.h. 20 enum class StorageAccess; 21 } // namespace mozilla 22 23 namespace mozilla::dom { 24 25 // We forward-declare this because otherwise we get an include cycle through 26 // DocumentBinding.h including ShadowRoot.h including DOMEventTargetHelper.h 27 // including GlobalTeardownObserver.h including nsIGlobalObject.h which needs 28 // to include this file. 29 enum class VisibilityState : uint8_t; 30 31 class IPCClientState; 32 class IPCClientWindowState; 33 class IPCClientWorkerState; 34 35 // This class defines the mutable nsGlobalWindow state we support querying 36 // through the ClientManagerService. It is a snapshot of the state and 37 // is not live updated. 38 class ClientWindowState final { 39 UniquePtr<IPCClientWindowState> mData; 40 41 public: 42 ClientWindowState(mozilla::dom::VisibilityState aVisibilityState, 43 const TimeStamp& aLastFocusTime, 44 StorageAccess aStorageAccess, bool aFocused); 45 46 explicit ClientWindowState(const IPCClientWindowState& aData); 47 48 ClientWindowState(const ClientWindowState& aRight); 49 ClientWindowState(ClientWindowState&& aRight); 50 51 ClientWindowState& operator=(const ClientWindowState& aRight); 52 53 ClientWindowState& operator=(ClientWindowState&& aRight); 54 55 ~ClientWindowState(); 56 57 mozilla::dom::VisibilityState VisibilityState() const; 58 59 const TimeStamp& LastFocusTime() const; 60 61 bool Focused() const; 62 63 StorageAccess GetStorageAccess() const; 64 65 const IPCClientWindowState& ToIPC() const; 66 }; 67 68 // This class defines the mutable worker state we support querying 69 // through the ClientManagerService. It is a snapshot of the state and 70 // is not live updated. Right now, we don't actually providate any 71 // worker specific state values, but we may in the future. This 72 // class also services as a placeholder that the state is referring 73 // to a worker in ClientState. 74 class ClientWorkerState final { 75 UniquePtr<IPCClientWorkerState> mData; 76 77 public: 78 explicit ClientWorkerState(StorageAccess aStorageAccess); 79 80 explicit ClientWorkerState(const IPCClientWorkerState& aData); 81 82 ClientWorkerState(const ClientWorkerState& aRight); 83 ClientWorkerState(ClientWorkerState&& aRight); 84 85 ClientWorkerState& operator=(const ClientWorkerState& aRight); 86 87 ClientWorkerState& operator=(ClientWorkerState&& aRight); 88 89 ~ClientWorkerState(); 90 91 StorageAccess GetStorageAccess() const; 92 93 const IPCClientWorkerState& ToIPC() const; 94 }; 95 96 // This is a union of the various types of mutable state we support 97 // querying in ClientManagerService. Right now it can contain either 98 // window or worker states. 99 class ClientState final { 100 Maybe<Variant<ClientWindowState, ClientWorkerState>> mData; 101 102 public: 103 ClientState(); 104 105 explicit ClientState(const ClientWindowState& aWindowState); 106 explicit ClientState(const ClientWorkerState& aWorkerState); 107 explicit ClientState(const IPCClientWindowState& aData); 108 explicit ClientState(const IPCClientWorkerState& aData); 109 110 ClientState(const ClientState& aRight) = default; 111 ClientState(ClientState&& aRight); 112 113 ClientState& operator=(const ClientState& aRight) = default; 114 115 ClientState& operator=(ClientState&& aRight); 116 117 ~ClientState(); 118 119 static ClientState FromIPC(const IPCClientState& aData); 120 121 bool IsWindowState() const; 122 123 const ClientWindowState& AsWindowState() const; 124 125 bool IsWorkerState() const; 126 127 const ClientWorkerState& AsWorkerState() const; 128 129 StorageAccess GetStorageAccess() const; 130 131 const IPCClientState ToIPC() const; 132 }; 133 134 } // namespace mozilla::dom 135 136 #endif // _mozilla_dom_ClientState_h