Skip to content

Commit 34ef05a

Browse files
committed
next try on postponedActions
1 parent 29d91b1 commit 34ef05a

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

src/main/java/org/htmlunit/html/DomElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ public <P extends Page> P click(final boolean shiftKey, final boolean ctrlKey, f
10411041
AbstractJavaScriptEngine.PostponedActionsBlocker blocker = null;
10421042
final AbstractJavaScriptEngine<?> jsEngine = webClient.getJavaScriptEngine();
10431043
if (webClient.isJavaScriptEnabled()) {
1044-
blocker = jsEngine.blockPostponedActions();
1044+
blocker = jsEngine.blockPostponedActions(page);
10451045
}
10461046
try {
10471047
if (handleFocus) {

src/main/java/org/htmlunit/javascript/AbstractJavaScriptEngine.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ public interface AbstractJavaScriptEngine<SCRIPT> {
108108
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
109109
* Indicates that no postponed action should be executed.
110110
*
111+
* @param page only block actions for this page
111112
* @return {@link PostponedActionsBlocker}
112113
*/
113-
PostponedActionsBlocker blockPostponedActions();
114+
PostponedActionsBlocker blockPostponedActions(Page page);
114115

115116
/**
116117
* Compiles the specified JavaScript code in the context of a given scope.
@@ -159,6 +160,7 @@ Object execute(HtmlPage page,
159160
* Helper for blocking the execution of postponed actions for some time.
160161
*/
161162
interface PostponedActionsBlocker {
163+
boolean blocks(PostponedAction postponedAction);
162164
void release();
163165
}
164166
}

src/main/java/org/htmlunit/javascript/JavaScriptEngine.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,13 @@ private void doProcessPostponedActions() {
945945

946946
// verify that the page that registered this PostponedAction is still alive
947947
if (action.isStillAlive()) {
948-
action.execute();
948+
if (postponedActionsBlocker_ == null
949+
|| !postponedActionsBlocker_.blocks(action)) {
950+
action.execute();
951+
}
952+
else {
953+
addPostponedAction(action);
954+
}
949955
}
950956
}
951957
}
@@ -1033,13 +1039,13 @@ protected void handleJavaScriptTimeoutError(final HtmlPage page, final TimeoutEr
10331039
* {@inheritDoc}
10341040
*/
10351041
@Override
1036-
public PostponedActionsBlocker blockPostponedActions() {
1042+
public PostponedActionsBlocker blockPostponedActions(final Page page) {
10371043
if (postponedActionsBlocker_ == null) {
1038-
postponedActionsBlocker_ = new RootPostponedActionsBlocker(this);
1044+
postponedActionsBlocker_ = new RootPostponedActionsBlocker(this, page);
10391045
return postponedActionsBlocker_;
10401046
}
10411047

1042-
return new ChildPostponedActionsBlocker();
1048+
return new ChildPostponedActionsBlocker(postponedActionsBlocker_);
10431049
}
10441050

10451051
/**
@@ -1048,9 +1054,7 @@ public PostponedActionsBlocker blockPostponedActions() {
10481054
*/
10491055
@Override
10501056
public void processPostponedActions() {
1051-
if (postponedActionsBlocker_ == null) {
1052-
doProcessPostponedActions();
1053-
}
1057+
doProcessPostponedActions();
10541058
}
10551059

10561060
/**
@@ -1396,9 +1400,16 @@ public static String evaluateProxyAutoConfig(final BrowserVersion browserVersion
13961400
*/
13971401
private final class RootPostponedActionsBlocker implements PostponedActionsBlocker {
13981402
private final JavaScriptEngine jsEngine_;
1403+
private final Page owningPage_;
13991404

1400-
private RootPostponedActionsBlocker(final JavaScriptEngine jsEngine) {
1405+
private RootPostponedActionsBlocker(final JavaScriptEngine jsEngine, final Page owningPage) {
14011406
jsEngine_ = jsEngine;
1407+
owningPage_ = owningPage;
1408+
}
1409+
1410+
@Override
1411+
public boolean blocks(final PostponedAction postponedAction) {
1412+
return owningPage_ == postponedAction.getOwningPage();
14021413
}
14031414

14041415
@Override
@@ -1412,9 +1423,16 @@ public void release() {
14121423
* {@link PostponedActionsBlocker} - noop blocker.
14131424
*/
14141425
private final class ChildPostponedActionsBlocker implements PostponedActionsBlocker {
1426+
private final RootPostponedActionsBlocker root_;
14151427

1416-
private ChildPostponedActionsBlocker() {
1428+
private ChildPostponedActionsBlocker(final RootPostponedActionsBlocker root) {
14171429
super();
1430+
root_ = root;
1431+
}
1432+
1433+
@Override
1434+
public boolean blocks(final PostponedAction postponedAction) {
1435+
return root_.blocks(postponedAction);
14181436
}
14191437

14201438
@Override

0 commit comments

Comments
 (0)