Bug 1473362 [wpt PR 11778] - Update wpt metadata, a=testonly
[gecko.git] / docshell / base / nsDocShellLoadTypes.h
blobe2dd2115f72d8c162aeb47ca2bed9b67c25e45d9
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 nsDocShellLoadTypes_h_
8 #define nsDocShellLoadTypes_h_
10 #ifdef MOZILLA_INTERNAL_API
12 #include "nsDOMNavigationTiming.h"
13 #include "nsIDocShell.h"
14 #include "nsIDocShellLoadInfo.h"
15 #include "nsIWebNavigation.h"
17 /**
18 * Load flag for error pages. This uses one of the reserved flag
19 * values from nsIWebNavigation.
21 #define LOAD_FLAGS_ERROR_PAGE 0x0001U
23 #define MAKE_LOAD_TYPE(type, flags) ((type) | ((flags) << 16))
24 #define LOAD_TYPE_HAS_FLAGS(type, flags) ((type) & ((flags) << 16))
26 /**
27 * These are flags that confuse ConvertLoadTypeToDocShellLoadInfo and should
28 * not be passed to MAKE_LOAD_TYPE. In particular this includes all flags
29 * above 0xffff (e.g. LOAD_FLAGS_BYPASS_CLASSIFIER), since MAKE_LOAD_TYPE would
30 * just shift them out anyway.
32 #define EXTRA_LOAD_FLAGS (LOAD_FLAGS_FIRST_LOAD | \
33 LOAD_FLAGS_ALLOW_POPUPS | \
34 0xffff0000)
36 /* load types are legal combinations of load commands and flags
38 * NOTE:
39 * Remember to update the IsValidLoadType function below if you change this
40 * enum to ensure bad flag combinations will be rejected.
42 enum LoadType
44 LOAD_NORMAL = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_NONE),
45 LOAD_NORMAL_REPLACE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY),
46 LOAD_NORMAL_EXTERNAL = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_FROM_EXTERNAL),
47 LOAD_HISTORY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_HISTORY, nsIWebNavigation::LOAD_FLAGS_NONE),
48 LOAD_NORMAL_BYPASS_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE),
49 LOAD_NORMAL_BYPASS_PROXY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY),
50 LOAD_NORMAL_BYPASS_PROXY_AND_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY),
51 LOAD_NORMAL_ALLOW_MIXED_CONTENT = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_ALLOW_MIXED_CONTENT | nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE),
52 LOAD_RELOAD_NORMAL = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_NONE),
53 LOAD_RELOAD_BYPASS_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE),
54 LOAD_RELOAD_BYPASS_PROXY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY),
55 LOAD_RELOAD_ALLOW_MIXED_CONTENT = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_ALLOW_MIXED_CONTENT | nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE),
56 LOAD_RELOAD_BYPASS_PROXY_AND_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY),
57 LOAD_LINK = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_IS_LINK),
58 LOAD_REFRESH = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_IS_REFRESH),
59 LOAD_RELOAD_CHARSET_CHANGE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_CHARSET_CHANGE),
60 LOAD_RELOAD_CHARSET_CHANGE_BYPASS_PROXY_AND_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_CHARSET_CHANGE | nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY),
61 LOAD_RELOAD_CHARSET_CHANGE_BYPASS_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_CHARSET_CHANGE | nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE),
62 LOAD_BYPASS_HISTORY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY),
63 LOAD_STOP_CONTENT = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_STOP_CONTENT),
64 LOAD_STOP_CONTENT_AND_REPLACE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_STOP_CONTENT | nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY),
65 LOAD_PUSHSTATE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_PUSHSTATE, nsIWebNavigation::LOAD_FLAGS_NONE),
66 LOAD_REPLACE_BYPASS_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY | nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE),
67 /**
68 * Load type for an error page. These loads are never triggered by users of
69 * Docshell. Instead, Docshell triggers the load itself when a
70 * consumer-triggered load failed.
72 LOAD_ERROR_PAGE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL,
73 LOAD_FLAGS_ERROR_PAGE)
75 // NOTE: Adding a new value? Remember to update IsValidLoadType!
78 static inline bool
79 IsValidLoadType(uint32_t aLoadType)
81 switch (aLoadType) {
82 case LOAD_NORMAL:
83 case LOAD_NORMAL_REPLACE:
84 case LOAD_NORMAL_EXTERNAL:
85 case LOAD_NORMAL_BYPASS_CACHE:
86 case LOAD_NORMAL_BYPASS_PROXY:
87 case LOAD_NORMAL_BYPASS_PROXY_AND_CACHE:
88 case LOAD_NORMAL_ALLOW_MIXED_CONTENT:
89 case LOAD_HISTORY:
90 case LOAD_RELOAD_NORMAL:
91 case LOAD_RELOAD_BYPASS_CACHE:
92 case LOAD_RELOAD_BYPASS_PROXY:
93 case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE:
94 case LOAD_RELOAD_ALLOW_MIXED_CONTENT:
95 case LOAD_LINK:
96 case LOAD_REFRESH:
97 case LOAD_RELOAD_CHARSET_CHANGE:
98 case LOAD_RELOAD_CHARSET_CHANGE_BYPASS_PROXY_AND_CACHE:
99 case LOAD_RELOAD_CHARSET_CHANGE_BYPASS_CACHE:
100 case LOAD_BYPASS_HISTORY:
101 case LOAD_STOP_CONTENT:
102 case LOAD_STOP_CONTENT_AND_REPLACE:
103 case LOAD_PUSHSTATE:
104 case LOAD_REPLACE_BYPASS_CACHE:
105 case LOAD_ERROR_PAGE:
106 return true;
108 return false;
111 static inline bool
112 IsForceReloadType(uint32_t aLoadType) {
113 switch (aLoadType) {
114 case LOAD_RELOAD_BYPASS_CACHE:
115 case LOAD_RELOAD_BYPASS_PROXY:
116 case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE:
117 case LOAD_RELOAD_ALLOW_MIXED_CONTENT:
118 return true;
120 return false;
123 static inline nsDocShellInfoLoadType
124 ConvertLoadTypeToDocShellInfoLoadType(uint32_t aLoadType)
126 nsDocShellInfoLoadType docShellLoadType = nsIDocShellLoadInfo::loadNormal;
127 switch (aLoadType) {
128 case LOAD_NORMAL:
129 docShellLoadType = nsIDocShellLoadInfo::loadNormal;
130 break;
131 case LOAD_NORMAL_REPLACE:
132 docShellLoadType = nsIDocShellLoadInfo::loadNormalReplace;
133 break;
134 case LOAD_NORMAL_EXTERNAL:
135 docShellLoadType = nsIDocShellLoadInfo::loadNormalExternal;
136 break;
137 case LOAD_NORMAL_BYPASS_CACHE:
138 docShellLoadType = nsIDocShellLoadInfo::loadNormalBypassCache;
139 break;
140 case LOAD_NORMAL_BYPASS_PROXY:
141 docShellLoadType = nsIDocShellLoadInfo::loadNormalBypassProxy;
142 break;
143 case LOAD_NORMAL_BYPASS_PROXY_AND_CACHE:
144 docShellLoadType = nsIDocShellLoadInfo::loadNormalBypassProxyAndCache;
145 break;
146 case LOAD_NORMAL_ALLOW_MIXED_CONTENT:
147 docShellLoadType = nsIDocShellLoadInfo::loadNormalAllowMixedContent;
148 break;
149 case LOAD_HISTORY:
150 docShellLoadType = nsIDocShellLoadInfo::loadHistory;
151 break;
152 case LOAD_RELOAD_NORMAL:
153 docShellLoadType = nsIDocShellLoadInfo::loadReloadNormal;
154 break;
155 case LOAD_RELOAD_CHARSET_CHANGE:
156 docShellLoadType = nsIDocShellLoadInfo::loadReloadCharsetChange;
157 break;
158 case LOAD_RELOAD_CHARSET_CHANGE_BYPASS_CACHE:
159 docShellLoadType = nsIDocShellLoadInfo::loadReloadCharsetChangeBypassCache;
160 break;
161 case LOAD_RELOAD_CHARSET_CHANGE_BYPASS_PROXY_AND_CACHE:
162 docShellLoadType = nsIDocShellLoadInfo::loadReloadCharsetChangeBypassProxyAndCache;
163 break;
164 case LOAD_RELOAD_BYPASS_CACHE:
165 docShellLoadType = nsIDocShellLoadInfo::loadReloadBypassCache;
166 break;
167 case LOAD_RELOAD_BYPASS_PROXY:
168 docShellLoadType = nsIDocShellLoadInfo::loadReloadBypassProxy;
169 break;
170 case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE:
171 docShellLoadType = nsIDocShellLoadInfo::loadReloadBypassProxyAndCache;
172 break;
173 case LOAD_LINK:
174 docShellLoadType = nsIDocShellLoadInfo::loadLink;
175 break;
176 case LOAD_REFRESH:
177 docShellLoadType = nsIDocShellLoadInfo::loadRefresh;
178 break;
179 case LOAD_BYPASS_HISTORY:
180 case LOAD_ERROR_PAGE:
181 docShellLoadType = nsIDocShellLoadInfo::loadBypassHistory;
182 break;
183 case LOAD_STOP_CONTENT:
184 docShellLoadType = nsIDocShellLoadInfo::loadStopContent;
185 break;
186 case LOAD_STOP_CONTENT_AND_REPLACE:
187 docShellLoadType = nsIDocShellLoadInfo::loadStopContentAndReplace;
188 break;
189 case LOAD_PUSHSTATE:
190 docShellLoadType = nsIDocShellLoadInfo::loadPushState;
191 break;
192 case LOAD_REPLACE_BYPASS_CACHE:
193 docShellLoadType = nsIDocShellLoadInfo::loadReplaceBypassCache;
194 break;
195 case LOAD_RELOAD_ALLOW_MIXED_CONTENT:
196 docShellLoadType = nsIDocShellLoadInfo::loadReloadMixedContent;
197 break;
198 default:
199 MOZ_ASSERT_UNREACHABLE("Unexpected load type value");
202 return docShellLoadType;
205 static inline uint32_t
206 ConvertDocShellInfoLoadTypeToLoadType(nsDocShellInfoLoadType aDocShellLoadType)
208 uint32_t loadType = LOAD_NORMAL;
210 switch (aDocShellLoadType) {
211 case nsIDocShellLoadInfo::loadNormal:
212 loadType = LOAD_NORMAL;
213 break;
214 case nsIDocShellLoadInfo::loadNormalReplace:
215 loadType = LOAD_NORMAL_REPLACE;
216 break;
217 case nsIDocShellLoadInfo::loadNormalExternal:
218 loadType = LOAD_NORMAL_EXTERNAL;
219 break;
220 case nsIDocShellLoadInfo::loadHistory:
221 loadType = LOAD_HISTORY;
222 break;
223 case nsIDocShellLoadInfo::loadNormalBypassCache:
224 loadType = LOAD_NORMAL_BYPASS_CACHE;
225 break;
226 case nsIDocShellLoadInfo::loadNormalBypassProxy:
227 loadType = LOAD_NORMAL_BYPASS_PROXY;
228 break;
229 case nsIDocShellLoadInfo::loadNormalBypassProxyAndCache:
230 loadType = LOAD_NORMAL_BYPASS_PROXY_AND_CACHE;
231 break;
232 case nsIDocShellLoadInfo::loadNormalAllowMixedContent:
233 loadType = LOAD_NORMAL_ALLOW_MIXED_CONTENT;
234 break;
235 case nsIDocShellLoadInfo::loadReloadNormal:
236 loadType = LOAD_RELOAD_NORMAL;
237 break;
238 case nsIDocShellLoadInfo::loadReloadCharsetChange:
239 loadType = LOAD_RELOAD_CHARSET_CHANGE;
240 break;
241 case nsIDocShellLoadInfo::loadReloadCharsetChangeBypassCache:
242 loadType = LOAD_RELOAD_CHARSET_CHANGE_BYPASS_CACHE;
243 break;
244 case nsIDocShellLoadInfo::loadReloadCharsetChangeBypassProxyAndCache:
245 loadType = LOAD_RELOAD_CHARSET_CHANGE_BYPASS_PROXY_AND_CACHE;
246 break;
247 case nsIDocShellLoadInfo::loadReloadBypassCache:
248 loadType = LOAD_RELOAD_BYPASS_CACHE;
249 break;
250 case nsIDocShellLoadInfo::loadReloadBypassProxy:
251 loadType = LOAD_RELOAD_BYPASS_PROXY;
252 break;
253 case nsIDocShellLoadInfo::loadReloadBypassProxyAndCache:
254 loadType = LOAD_RELOAD_BYPASS_PROXY_AND_CACHE;
255 break;
256 case nsIDocShellLoadInfo::loadLink:
257 loadType = LOAD_LINK;
258 break;
259 case nsIDocShellLoadInfo::loadRefresh:
260 loadType = LOAD_REFRESH;
261 break;
262 case nsIDocShellLoadInfo::loadBypassHistory:
263 loadType = LOAD_BYPASS_HISTORY;
264 break;
265 case nsIDocShellLoadInfo::loadStopContent:
266 loadType = LOAD_STOP_CONTENT;
267 break;
268 case nsIDocShellLoadInfo::loadStopContentAndReplace:
269 loadType = LOAD_STOP_CONTENT_AND_REPLACE;
270 break;
271 case nsIDocShellLoadInfo::loadPushState:
272 loadType = LOAD_PUSHSTATE;
273 break;
274 case nsIDocShellLoadInfo::loadReplaceBypassCache:
275 loadType = LOAD_REPLACE_BYPASS_CACHE;
276 break;
277 case nsIDocShellLoadInfo::loadReloadMixedContent:
278 loadType = LOAD_RELOAD_ALLOW_MIXED_CONTENT;
279 break;
280 default:
281 MOZ_ASSERT_UNREACHABLE("Unexpected nsDocShellInfoLoadType value");
284 return loadType;
287 static inline nsDOMNavigationTiming::Type
288 ConvertLoadTypeToNavigationType(uint32_t aLoadType)
290 // Not initialized, assume it's normal load.
291 if (aLoadType == 0) {
292 aLoadType = LOAD_NORMAL;
295 auto result = nsDOMNavigationTiming::TYPE_RESERVED;
296 switch (aLoadType) {
297 case LOAD_NORMAL:
298 case LOAD_NORMAL_EXTERNAL:
299 case LOAD_NORMAL_BYPASS_CACHE:
300 case LOAD_NORMAL_BYPASS_PROXY:
301 case LOAD_NORMAL_BYPASS_PROXY_AND_CACHE:
302 case LOAD_NORMAL_REPLACE:
303 case LOAD_NORMAL_ALLOW_MIXED_CONTENT:
304 case LOAD_LINK:
305 case LOAD_STOP_CONTENT:
306 case LOAD_REPLACE_BYPASS_CACHE:
307 result = nsDOMNavigationTiming::TYPE_NAVIGATE;
308 break;
309 case LOAD_HISTORY:
310 result = nsDOMNavigationTiming::TYPE_BACK_FORWARD;
311 break;
312 case LOAD_RELOAD_NORMAL:
313 case LOAD_RELOAD_CHARSET_CHANGE:
314 case LOAD_RELOAD_CHARSET_CHANGE_BYPASS_PROXY_AND_CACHE:
315 case LOAD_RELOAD_CHARSET_CHANGE_BYPASS_CACHE:
316 case LOAD_RELOAD_BYPASS_CACHE:
317 case LOAD_RELOAD_BYPASS_PROXY:
318 case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE:
319 case LOAD_RELOAD_ALLOW_MIXED_CONTENT:
320 result = nsDOMNavigationTiming::TYPE_RELOAD;
321 break;
322 case LOAD_STOP_CONTENT_AND_REPLACE:
323 case LOAD_REFRESH:
324 case LOAD_BYPASS_HISTORY:
325 case LOAD_ERROR_PAGE:
326 case LOAD_PUSHSTATE:
327 result = nsDOMNavigationTiming::TYPE_RESERVED;
328 break;
329 default:
330 result = nsDOMNavigationTiming::TYPE_RESERVED;
331 break;
334 return result;
337 #endif // MOZILLA_INTERNAL_API
338 #endif