View Javadoc
1   /*
2    * Copyright (c) 2002-2025 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.apache.commons.logging.Log;
18  import org.apache.commons.logging.LogFactory;
19  import org.htmlunit.corejs.javascript.Scriptable;
20  import org.htmlunit.javascript.HtmlUnitScriptable;
21  import org.htmlunit.javascript.JavaScriptEngine;
22  import org.htmlunit.javascript.configuration.JsxClass;
23  import org.htmlunit.javascript.configuration.JsxConstant;
24  import org.htmlunit.javascript.configuration.JsxConstructor;
25  import org.htmlunit.javascript.configuration.JsxFunction;
26  import org.htmlunit.javascript.configuration.JsxGetter;
27  
28  /**
29   * A JavaScript object for {@code PerformanceNavigation}.
30   *
31   * @author Ahmed Ashour
32   * @author Ronald Brill
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       * JavaScript constructor.
57       */
58      @JsxConstructor
59      public void jsConstructor() {
60          // nothing to do
61      }
62  
63      /**
64       * Returns the {@code type} property.
65       * @return the {@code type} property
66       */
67      @JsxGetter
68      public int getType() {
69          return TYPE_NAVIGATE;
70      }
71  
72      /**
73       * Returns the {@code redirectCount} property.
74       * @return the {@code redirectCount} property
75       */
76      @JsxGetter
77      public int getRedirectCount() {
78          return 0;
79      }
80  
81      /**
82       * The {@code toJSON} function.
83       * @return the {@code toJSON} object
84       */
85      @JsxFunction
86      public Scriptable toJSON() {
87          final Scriptable json = JavaScriptEngine.newObject(getParentScope());
88          json.put("type", json, getType());
89          json.put("redirectCount", json, getRedirectCount());
90  
91          return json;
92      }
93  
94  }