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.background;
16
17 import org.htmlunit.WebWindow;
18 import org.htmlunit.html.HtmlPage;
19
20 /**
21 * A {@link JavaScriptJob} created from a string of code.
22 * @author Brad Clarke
23 */
24 class JavaScriptStringJob extends JavaScriptExecutionJob {
25
26 /** The JavaScript code to execute. */
27 private final String script_;
28
29 /**
30 * Creates a new JavaScript execution job, where the JavaScript code to execute is a string.
31 * @param initialDelay the initial amount of time to wait before executing this job
32 * @param period the amount of time to wait between executions of this job (may be {@code null})
33 * @param label the label for the job
34 * @param window the window to which the job belongs
35 * @param script the JavaScript code to execute
36 */
37 JavaScriptStringJob(final int initialDelay, final Integer period, final String label,
38 final WebWindow window, final String script) {
39 super(initialDelay, period, label, window);
40 script_ = script;
41 }
42
43 /** {@inheritDoc} */
44 @Override
45 protected void runJavaScript(final HtmlPage page) {
46 if (script_ == null) {
47 return;
48 }
49 page.executeJavaScript(script_, "JavaScriptStringJob", 1);
50 }
51
52 }