View Javadoc
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   * JavaScript host object for {@code PerformanceNavigation}.
28   *
29   * @author Ahmed Ashour
30   * @author Ronald Brill
31   *
32   * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigation">MDN Documentation</a>
33   */
34  @JsxClass
35  public class PerformanceNavigation extends HtmlUnitScriptable {
36  
37      // private static final Log LOG = LogFactory.getLog(PerformanceNavigation.class);
38  
39      /** Navigate. */
40      @JsxConstant
41      public static final int TYPE_NAVIGATE = 0;
42  
43      /** Reload. */
44      @JsxConstant
45      public static final int TYPE_RELOAD = 1;
46  
47      /** Back forward. */
48      @JsxConstant
49      public static final int TYPE_BACK_FORWARD = 2;
50  
51      /** Reserved. */
52      @JsxConstant
53      public static final int TYPE_RESERVED = 255;
54  
55      /**
56       * Creates an instance of this object.
57       */
58      @JsxConstructor
59      public void jsConstructor() {
60          // nothing to do
61      }
62  
63      /**
64       * Returns the {@code type} property.
65       *
66       * @return the {@code type} property
67       */
68      @JsxGetter
69      public int getType() {
70          return TYPE_NAVIGATE;
71      }
72  
73      /**
74       * Returns the {@code redirectCount} property.
75       *
76       * @return the {@code redirectCount} property
77       */
78      @JsxGetter
79      public int getRedirectCount() {
80          return 0;
81      }
82  
83      /**
84       * Serializes the object to a JSON representation.
85       *
86       * @return a JSON object containing the {@code type} and {@code redirectCount} properties
87       */
88      @JsxFunction
89      public Scriptable toJSON() {
90          final Scriptable json = JavaScriptEngine.newObject(getParentScope());
91          json.put("type", json, getType());
92          json.put("redirectCount", json, getRedirectCount());
93  
94          return json;
95      }
96  }