@ -16,15 +16,14 @@ import com.teamdev.jxbrowser.engine.Engine;
import com.teamdev.jxbrowser.engine.EngineOptions ;
import com.teamdev.jxbrowser.engine.RenderingMode ;
import com.teamdev.jxbrowser.js.JsObject ;
import com.teamdev.jxbrowser.net.Network ;
import com.teamdev.jxbrowser.net.callback.InterceptRequestCallback ;
import com.teamdev.jxbrowser.net.Scheme ;
import com.teamdev.jxbrowser.view.swing.BrowserView ;
import java.awt.BorderLayout ;
import java.awt.Dimension ;
import java.util.Map ;
import java.util.Optional ;
import javax.swing.JDialog ;
import javax.swing.SwingUtilities ;
import javax.swing.WindowConstants ;
@ -43,6 +42,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
private String namespace = "Pool" ;
private String variable = "data" ;
private String expression = "update()" ;
private Scheme scheme ;
private NxInterceptRequestCallback requestCallback ;
private NewModernUIPane ( ) {
super ( ) ;
@ -96,7 +97,13 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
}
private void initializeBrowser ( ) {
Engine engine = Engine . newInstance ( EngineOptions . newBuilder ( RenderingMode . HARDWARE_ACCELERATED ) . addSwitch ( "--disable-google-traffic" ) . build ( ) ) ;
EngineOptions options ;
if ( scheme ! = null & & requestCallback ! = null ) {
options = EngineOptions . newBuilder ( RenderingMode . HARDWARE_ACCELERATED ) . addSwitch ( "--disable-google-traffic" ) . addScheme ( scheme , requestCallback ) . build ( ) ;
} else {
options = EngineOptions . newBuilder ( RenderingMode . HARDWARE_ACCELERATED ) . addSwitch ( "--disable-google-traffic" ) . build ( ) ;
}
Engine engine = Engine . newInstance ( options ) ;
browser = engine . newBrowser ( ) ;
// 初始化的时候,就把命名空间对象初始化好,确保window.a.b.c("a.b.c"为命名空间)对象都是初始化过的
@ -124,8 +131,9 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
@Override
public void redirect ( String url , Map < String , String > map ) {
Network network = browser . engine ( ) . network ( ) ;
network . set ( InterceptRequestCallback . class , new NxInterceptRequestCallback ( network , map ) ) ;
if ( requestCallback ! = null ) {
requestCallback . setMap ( map ) ;
}
browser . navigation ( ) . loadUrl ( url ) ;
}
@ -169,8 +177,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
@Override
public NewModernUIPane . Builder < T > withEMB ( final String path ) {
Network network = pane . browser . engine ( ) . network ( ) ;
network . set ( InterceptRequestCallback . class , new NxComplexInterceptRequestCallback ( network , null ) ) ;
pane . scheme = Scheme . of ( "emb" ) ;
pane . requestCallback = new NxComplexInterceptRequestCallback ( null ) ;
pane . browser . navigation ( ) . loadUrl ( "emb:" + path ) ;
return this ;
}
@ -182,8 +190,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
@Override
public NewModernUIPane . Builder < T > withURL ( final String url ) {
Network network = pane . browser . engine ( ) . network ( ) ;
network . set ( InterceptRequestCallback . class , new NxInterceptRequestCallback ( network ) ) ;
pane . scheme = Scheme . of ( "file" ) ;
pane . requestCallback = new NxComplexInterceptRequestCallback ( null ) ;
pane . browser . navigation ( ) . loadUrl ( url ) ;
return this ;
}
@ -195,8 +203,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
@Override
public NewModernUIPane . Builder < T > withURL ( final String url , Map < String , String > map ) {
Network network = pane . browser . engine ( ) . network ( ) ;
network . set ( InterceptRequestCallback . class , new NxInterceptRequestCallback ( network , map ) ) ;
pane . scheme = Scheme . of ( "file" ) ;
pane . requestCallback = new NxInterceptRequestCallback ( map ) ;
pane . browser . navigation ( ) . loadUrl ( url ) ;
return this ;
}
@ -208,8 +216,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
@Override
public NewModernUIPane . Builder < T > withComponent ( AssembleComponent component ) {
Network network = pane . browser . engine ( ) . network ( ) ;
network . set ( InterceptRequestCallback . class , new NxComplexInterceptRequestCallback ( network , component ) ) ;
pane . scheme = Scheme . of ( "emb" ) ;
pane . requestCallback = new NxComplexInterceptRequestCallback ( component ) ;
pane . browser . navigation ( ) . loadUrl ( "emb:dynamic" ) ;
return this ;
}
@ -221,8 +229,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
@Override
public NewModernUIPane . Builder < T > withComponent ( AssembleComponent component , Map < String , String > map ) {
Network network = pane . browser . engine ( ) . network ( ) ;
network . set ( InterceptRequestCallback . class , new NxComplexInterceptRequestCallback ( network , component , map ) ) ;
pane . scheme = Scheme . of ( "emb" ) ;
pane . requestCallback = new NxComplexInterceptRequestCallback ( component , map ) ;
pane . browser . navigation ( ) . loadUrl ( "emb:dynamic" ) ;
return this ;
}
@ -235,8 +243,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
@Override
public NewModernUIPane . Builder < T > withHTML ( String html ) {
Network network = pane . browser . engine ( ) . network ( ) ;
network . set ( InterceptRequestCallback . class , new NxInterceptRequestCallback ( network ) ) ;
pane . scheme = Scheme . of ( "html" ) ;
pane . requestCallback = new NxInterceptRequestCallback ( ) ;
pane . browser . mainFrame ( ) . ifPresent ( frame - > {
frame . loadHtml ( html ) ;
} ) ;