1 /*
2 * Copyright (c) 2002-2026 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.javascript.host.performance;
16
17 import org.htmlunit.corejs.javascript.Scriptable;
18 import org.htmlunit.javascript.HtmlUnitScriptable;
19 import org.htmlunit.javascript.JavaScriptEngine;
20 import org.htmlunit.javascript.configuration.JsxClass;
21 import org.htmlunit.javascript.configuration.JsxConstant;
22 import org.htmlunit.javascript.configuration.JsxConstructor;
23 import org.htmlunit.javascript.configuration.JsxFunction;
24 import org.htmlunit.javascript.configuration.JsxGetter;
25
26 /**
27 * A JavaScript object for {@code PerformanceNavigation}.
28 *
29 * @author Ahmed Ashour
30 * @author Ronald Brill
31 */
32 @JsxClass
33 public class PerformanceNavigation extends HtmlUnitScriptable {
34
35 // private static final Log LOG = LogFactory.getLog(PerformanceNavigation.class);
36
37 /** Navigate. */
38 @JsxConstant
39 public static final int TYPE_NAVIGATE = 0;
40
41 /** Reload. */
42 @JsxConstant
43 public static final int TYPE_RELOAD = 1;
44
45 /** Back forward. */
46 @JsxConstant
47 public static final int TYPE_BACK_FORWARD = 2;
48
49 /** Reserved. */
50 @JsxConstant
51 public static final int TYPE_RESERVED = 255;
52
53 /**
54 * JavaScript constructor.
55 */
56 @JsxConstructor
57 public void jsConstructor() {
58 // nothing to do
59 }
60
61 /**
62 * Returns the {@code type} property.
63 * @return the {@code type} property
64 */
65 @JsxGetter
66 public int getType() {
67 return TYPE_NAVIGATE;
68 }
69
70 /**
71 * Returns the {@code redirectCount} property.
72 * @return the {@code redirectCount} property
73 */
74 @JsxGetter
75 public int getRedirectCount() {
76 return 0;
77 }
78
79 /**
80 * The {@code toJSON} function.
81 * @return the {@code toJSON} object
82 */
83 @JsxFunction
84 public Scriptable toJSON() {
85 final Scriptable json = JavaScriptEngine.newObject(getParentScope());
86 json.put("type", json, getType());
87 json.put("redirectCount", json, getRedirectCount());
88
89 return json;
90 }
91
92 }