Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing all Shells and the Display when browsertab is closed #239

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,12 @@ public void eventLoopException(Throwable exception) {
advisor.eventLoopIdle(display);
}
} catch (ThreadDeath th) {

for (Shell shell : display.getShells()) {
shell.close();
}
display.close();

throw th;
} catch (Exception ex) {
handle(ex, advisor);
Expand Down
24 changes: 15 additions & 9 deletions bundles/org.eclipse.rap.rwt/js/rwt/widgets/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ rwt.qx.Class.define( "rwt.widgets.Browser", {
try {
result = this._parseEvalResult( this._eval( script ) );
} catch( ex ) {
console.log(ex);
success = false;
}
var connection = rwt.remote.Connection.getInstance();
Expand Down Expand Up @@ -198,7 +199,7 @@ rwt.qx.Class.define( "rwt.widgets.Browser", {
// not accessible when it appears it should be
// => user navigated to external site.
this._throwSecurityException( true );
}
}
}
},

Expand All @@ -215,21 +216,26 @@ rwt.qx.Class.define( "rwt.widgets.Browser", {
},

_eval : function( script ) {
var win = this.getContentWindow();
if( !win[ "eval" ] && win[ "execScript" ] ) {
// Workaround for IE bug, see: http://www.thismuchiknow.co.uk/?p=25
win.execScript( "null;", "JScript" );
}
return win[ "eval" ]( script );
var win = this.getContentWindow();

if (win !== null) {
if( !win[ "eval" ] && win[ "execScript" ] ) {
// Workaround for IE bug, see: http://www.thismuchiknow.co.uk/?p=25
win.execScript( "null;", "JScript" );
}
return win[ "eval" ]( script );
} else {
console.error("Window is null, can not execute scipts:\n" + script);
}
},

_parseEvalResult : function( value ) {
var result = null;
var win = this.getContentWindow();
// NOTE: This mimics the behavior of the evaluate method in SWT:
if( value instanceof win.Function || value instanceof Function ) {
if( (win !== null && value instanceof win.Function) || value instanceof Function ) {
result = this.toJSON( [ [] ] );
} else if( value instanceof win.Array || value instanceof Array ) {
} else if( (win !== null && value instanceof win.Array) || value instanceof Array ) {
result = this.toJSON( [ value ] );
} else if( typeof value !== "object" && typeof value !== "function" ) {
// above: some browser say regular expressions of the type "function"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TypedListener;


Expand Down Expand Up @@ -80,6 +81,7 @@ public class Browser extends Composite {
private BrowserCallback browserCallback;
private transient IBrowserAdapter browserAdapter;
private final List<BrowserFunction> functions;
private boolean clientInited = false;

/**
* Constructs a new instance of this class given its parent
Expand Down Expand Up @@ -258,6 +260,33 @@ public boolean execute( String script ) {
if( executeScript != null ) {
throw new IllegalStateException( "Another script is already pending" );
}

boolean showedShell = false;
Shell shell = getShell();

try {
// Show the shell, so that the browser is created in the browser
if (!clientInited && shell != null && !shell.getVisible()) {
showedShell = true;
//shell.setMinimized(true);
shell.setVisible(true);
internalExecute( "" );
}

internalExecute( script );
} finally {
// if we showed it, we have to hide it again
if (showedShell) {
//shell.setMinimized(false);
shell.setVisible(false);
internalExecute( "" );
}
clientInited = true;
}
return executeResult.booleanValue();
}

protected void internalExecute( String script ) {
executeScript = script;
executeResult = null;
while( executeResult == null ) {
Expand All @@ -268,7 +297,6 @@ public boolean execute( String script ) {
}
executeScript = null;
executePending = false;
return executeResult.booleanValue();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.rap.rwt.testfixture.TestContext;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.internal.browser.browserkit.BrowserLCA;
import org.eclipse.swt.internal.events.EventTypes;
import org.eclipse.swt.internal.widgets.IBrowserAdapter;
Expand Down Expand Up @@ -356,9 +357,12 @@ public void run() {
}
} );

boolean result = browser.execute( "var x = 2;" );

assertFalse( result );
try {
boolean result = browser.execute( "var x = 2;" );
fail();
} catch( SWTException expected ) {
assertEquals( "Widget is disposed", expected.getMessage() );
}
}

@Test
Expand Down