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