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.html;
16  
17  import org.htmlunit.WebWindow;
18  import org.htmlunit.javascript.HtmlUnitScriptableProxy;
19  import org.htmlunit.javascript.host.Window;
20  import org.htmlunit.javascript.host.dom.Document;
21  
22  /**
23   * Proxy for a {@link Document} script object. In theory, we could satisfy single-document requirements
24   * without a proxy, by reusing (with appropriate cleanup and re-initialization) a single {@link Document}
25   * instance across various pages. However, we allow users to keep references to old pages as they navigate
26   * across a series of pages, and all of these pages need to be usable -- so we can't just leave these old
27   * pages without a <code>window.document</code> object.
28   *
29   * @author Daniel Gredler
30   * @author Ronald Brill
31   */
32  public class DocumentProxy extends HtmlUnitScriptableProxy<Document> {
33  
34      private final WebWindow webWindow_;
35  
36      /**
37       * Construct a proxy for the {@link Document} of the {@link WebWindow}.
38       * @param webWindow the window
39       */
40      public DocumentProxy(final WebWindow webWindow) {
41          super();
42          webWindow_ = webWindow;
43      }
44  
45      /**
46       * {@inheritDoc}
47       */
48      @Override
49      public Document getDelegee() {
50          final Window w = webWindow_.getScriptableObject();
51          return w.getDocument();
52      }
53  
54  }