/src/mozilla-central/dom/clients/manager/ClientState.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | #include "ClientState.h" |
8 | | |
9 | | #include "mozilla/dom/ClientIPCTypes.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace dom { |
13 | | |
14 | | ClientWindowState::ClientWindowState(mozilla::dom::VisibilityState aVisibilityState, |
15 | | const TimeStamp& aLastFocusTime, |
16 | | nsContentUtils::StorageAccess aStorageAccess, |
17 | | bool aFocused) |
18 | | : mData(MakeUnique<IPCClientWindowState>(aVisibilityState, aLastFocusTime, |
19 | | aStorageAccess, aFocused)) |
20 | 0 | { |
21 | 0 | } |
22 | | |
23 | | ClientWindowState::ClientWindowState(const IPCClientWindowState& aData) |
24 | | : mData(MakeUnique<IPCClientWindowState>(aData)) |
25 | 0 | { |
26 | 0 | } |
27 | | |
28 | | ClientWindowState::ClientWindowState(const ClientWindowState& aRight) |
29 | 0 | { |
30 | 0 | operator=(aRight); |
31 | 0 | } |
32 | | |
33 | | ClientWindowState::ClientWindowState(ClientWindowState&& aRight) |
34 | | : mData(std::move(aRight.mData)) |
35 | 0 | { |
36 | 0 | } |
37 | | |
38 | | ClientWindowState& |
39 | | ClientWindowState::operator=(const ClientWindowState& aRight) |
40 | 0 | { |
41 | 0 | mData.reset(); |
42 | 0 | mData = MakeUnique<IPCClientWindowState>(*aRight.mData); |
43 | 0 | return *this; |
44 | 0 | } |
45 | | |
46 | | ClientWindowState& |
47 | | ClientWindowState::operator=(ClientWindowState&& aRight) |
48 | 0 | { |
49 | 0 | mData.reset(); |
50 | 0 | mData = std::move(aRight.mData); |
51 | 0 | return *this; |
52 | 0 | } |
53 | | |
54 | | ClientWindowState::~ClientWindowState() |
55 | 0 | { |
56 | 0 | } |
57 | | |
58 | | mozilla::dom::VisibilityState |
59 | | ClientWindowState::VisibilityState() const |
60 | 0 | { |
61 | 0 | return mData->visibilityState(); |
62 | 0 | } |
63 | | |
64 | | const TimeStamp& |
65 | | ClientWindowState::LastFocusTime() const |
66 | 0 | { |
67 | 0 | return mData->lastFocusTime(); |
68 | 0 | } |
69 | | |
70 | | bool |
71 | | ClientWindowState::Focused() const |
72 | 0 | { |
73 | 0 | return mData->focused(); |
74 | 0 | } |
75 | | |
76 | | nsContentUtils::StorageAccess |
77 | | ClientWindowState::GetStorageAccess() const |
78 | 0 | { |
79 | 0 | return mData->storageAccess(); |
80 | 0 | } |
81 | | |
82 | | const IPCClientWindowState& |
83 | | ClientWindowState::ToIPC() const |
84 | 0 | { |
85 | 0 | return *mData; |
86 | 0 | } |
87 | | |
88 | | ClientWorkerState::ClientWorkerState(nsContentUtils::StorageAccess aStorageAccess) |
89 | | : mData(MakeUnique<IPCClientWorkerState>(aStorageAccess)) |
90 | 0 | { |
91 | 0 | } |
92 | | |
93 | | ClientWorkerState::ClientWorkerState(const IPCClientWorkerState& aData) |
94 | | : mData(MakeUnique<IPCClientWorkerState>(aData)) |
95 | 0 | { |
96 | 0 | } |
97 | | |
98 | | ClientWorkerState::ClientWorkerState(ClientWorkerState&& aRight) |
99 | | : mData(std::move(aRight.mData)) |
100 | 0 | { |
101 | 0 | } |
102 | | |
103 | | ClientWorkerState::ClientWorkerState(const ClientWorkerState& aRight) |
104 | 0 | { |
105 | 0 | operator=(aRight); |
106 | 0 | } |
107 | | |
108 | | ClientWorkerState& |
109 | | ClientWorkerState::operator=(const ClientWorkerState& aRight) |
110 | 0 | { |
111 | 0 | mData.reset(); |
112 | 0 | mData = MakeUnique<IPCClientWorkerState>(*aRight.mData); |
113 | 0 | return *this; |
114 | 0 | } |
115 | | |
116 | | ClientWorkerState& |
117 | | ClientWorkerState::operator=(ClientWorkerState&& aRight) |
118 | 0 | { |
119 | 0 | mData.reset(); |
120 | 0 | mData = std::move(aRight.mData); |
121 | 0 | return *this; |
122 | 0 | } |
123 | | |
124 | | ClientWorkerState::~ClientWorkerState() |
125 | 0 | { |
126 | 0 | } |
127 | | |
128 | | nsContentUtils::StorageAccess |
129 | | ClientWorkerState::GetStorageAccess() const |
130 | 0 | { |
131 | 0 | return mData->storageAccess(); |
132 | 0 | } |
133 | | |
134 | | const IPCClientWorkerState& |
135 | | ClientWorkerState::ToIPC() const |
136 | 0 | { |
137 | 0 | return *mData; |
138 | 0 | } |
139 | | |
140 | | ClientState::ClientState() |
141 | 0 | { |
142 | 0 | } |
143 | | |
144 | | ClientState::ClientState(const ClientWindowState& aWindowState) |
145 | 0 | { |
146 | 0 | mData.emplace(AsVariant(aWindowState)); |
147 | 0 | } |
148 | | |
149 | | ClientState::ClientState(const ClientWorkerState& aWorkerState) |
150 | 0 | { |
151 | 0 | mData.emplace(AsVariant(aWorkerState)); |
152 | 0 | } |
153 | | |
154 | | ClientState::ClientState(const IPCClientWindowState& aData) |
155 | 0 | { |
156 | 0 | mData.emplace(AsVariant(ClientWindowState(aData))); |
157 | 0 | } |
158 | | |
159 | | ClientState::ClientState(const IPCClientWorkerState& aData) |
160 | 0 | { |
161 | 0 | mData.emplace(AsVariant(ClientWorkerState(aData))); |
162 | 0 | } |
163 | | |
164 | | ClientState::ClientState(ClientState&& aRight) |
165 | | : mData(std::move(aRight.mData)) |
166 | 0 | { |
167 | 0 | } |
168 | | |
169 | | ClientState& |
170 | | ClientState::operator=(ClientState&& aRight) |
171 | 0 | { |
172 | 0 | mData = std::move(aRight.mData); |
173 | 0 | return *this; |
174 | 0 | } |
175 | | |
176 | | ClientState::~ClientState() |
177 | 0 | { |
178 | 0 | } |
179 | | |
180 | | // static |
181 | | ClientState |
182 | | ClientState::FromIPC(const IPCClientState& aData) |
183 | 0 | { |
184 | 0 | switch(aData.type()) { |
185 | 0 | case IPCClientState::TIPCClientWindowState: |
186 | 0 | return ClientState(aData.get_IPCClientWindowState()); |
187 | 0 | case IPCClientState::TIPCClientWorkerState: |
188 | 0 | return ClientState(aData.get_IPCClientWorkerState()); |
189 | 0 | default: |
190 | 0 | MOZ_CRASH("unexpected IPCClientState type"); |
191 | 0 | } |
192 | 0 | } |
193 | | |
194 | | bool |
195 | | ClientState::IsWindowState() const |
196 | 0 | { |
197 | 0 | return mData.isSome() && mData.ref().is<ClientWindowState>(); |
198 | 0 | } |
199 | | |
200 | | const ClientWindowState& |
201 | | ClientState::AsWindowState() const |
202 | 0 | { |
203 | 0 | return mData.ref().as<ClientWindowState>(); |
204 | 0 | } |
205 | | |
206 | | bool |
207 | | ClientState::IsWorkerState() const |
208 | 0 | { |
209 | 0 | return mData.isSome() && mData.ref().is<ClientWorkerState>(); |
210 | 0 | } |
211 | | |
212 | | const ClientWorkerState& |
213 | | ClientState::AsWorkerState() const |
214 | 0 | { |
215 | 0 | return mData.ref().as<ClientWorkerState>(); |
216 | 0 | } |
217 | | |
218 | | nsContentUtils::StorageAccess |
219 | | ClientState::GetStorageAccess() const |
220 | 0 | { |
221 | 0 | if (IsWindowState()) { |
222 | 0 | return AsWindowState().GetStorageAccess(); |
223 | 0 | } |
224 | 0 | |
225 | 0 | return AsWorkerState().GetStorageAccess(); |
226 | 0 | } |
227 | | |
228 | | const IPCClientState |
229 | | ClientState::ToIPC() const |
230 | 0 | { |
231 | 0 | if (IsWindowState()) { |
232 | 0 | return IPCClientState(AsWindowState().ToIPC()); |
233 | 0 | } |
234 | 0 | |
235 | 0 | return IPCClientState(AsWorkerState().ToIPC()); |
236 | 0 | } |
237 | | |
238 | | } // namespace dom |
239 | | } // namespace mozilla |