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.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 */
31 public class DocumentProxy extends HtmlUnitScriptableProxy<Document> {
32
33 private final WebWindow webWindow_;
34
35 /**
36 * Construct a proxy for the {@link Document} of the {@link WebWindow}.
37 * @param webWindow the window
38 */
39 public DocumentProxy(final WebWindow webWindow) {
40 super();
41 webWindow_ = webWindow;
42 }
43
44 /**
45 * {@inheritDoc}
46 */
47 @Override
48 public Document getDelegee() {
49 final Window w = webWindow_.getScriptableObject();
50 return w.getDocument();
51 }
52
53 }