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