Browse Source

KERNEL-7634 jxbrowser 小版本再升级下

feature/10.0
hades 3 years ago
parent
commit
c95c24b7b6
  1. 8
      build.gradle
  2. 9
      designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java
  3. 44
      designer-base/src/main/java/com/fr/design/ui/compatible/NewModernUIPane.java
  4. 16
      designer-base/src/main/java/com/fr/design/ui/compatible/NxComplexInterceptRequestCallback.java
  5. 34
      designer-base/src/main/java/com/fr/design/ui/compatible/NxInterceptRequestCallback.java

8
build.gradle

@ -60,10 +60,10 @@ allprojects {
implementation 'com.fr.third:jxbrowser:6.23' implementation 'com.fr.third:jxbrowser:6.23'
implementation 'com.fr.third:jxbrowser-mac:6.23' implementation 'com.fr.third:jxbrowser-mac:6.23'
implementation 'com.fr.third:jxbrowser-win64:6.23' implementation 'com.fr.third:jxbrowser-win64:6.23'
implementation 'com.fr.third:jxbrowser-v7:7.7' implementation 'com.fr.third:jxbrowser-v7:7.15'
implementation 'com.fr.third:jxbrowser-mac-v7:7.7' implementation 'com.fr.third:jxbrowser-mac-v7:7.15'
implementation 'com.fr.third:jxbrowser-win64-v7:7.7' implementation 'com.fr.third:jxbrowser-win64-v7:7.15'
implementation 'com.fr.third:jxbrowser-swing-v7:7.7' implementation 'com.fr.third:jxbrowser-swing-v7:7.15'
implementation 'com.fr.third.server:servlet-api:3.0' implementation 'com.fr.third.server:servlet-api:3.0'
implementation 'org.swingexplorer:swexpl:2.0.1' implementation 'org.swingexplorer:swexpl:2.0.1'
implementation 'org.swingexplorer:swag:1.0' implementation 'org.swingexplorer:swag:1.0'

9
designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java

@ -11,7 +11,14 @@ import com.fr.stable.os.OperatingSystem;
public class ModernUIPaneFactory { public class ModernUIPaneFactory {
public static <T> ModernUIPane.Builder<T> modernUIPaneBuilder() { public static <T> ModernUIPane.Builder<T> modernUIPaneBuilder() {
if (OperatingSystem.isWindows()) { // 7.15的class不存在时 走老版本
boolean hasJxBrowserV7_15 = true;
try {
Class.forName("com.teamdev.jxbrowser.net.Scheme");
} catch (ClassNotFoundException e) {
hasJxBrowserV7_15 = false;
}
if (OperatingSystem.isWindows() && hasJxBrowserV7_15) {
return new NewModernUIPane.Builder<>(); return new NewModernUIPane.Builder<>();
} else { } else {
return new ModernUIPane.Builder<>(); return new ModernUIPane.Builder<>();

44
designer-base/src/main/java/com/fr/design/ui/compatible/NewModernUIPane.java

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

16
designer-base/src/main/java/com/fr/design/ui/compatible/NxComplexInterceptRequestCallback.java

@ -9,9 +9,6 @@ import com.fr.web.struct.AtomBuilder;
import com.fr.web.struct.PathGroup; import com.fr.web.struct.PathGroup;
import com.fr.web.struct.category.ScriptPath; import com.fr.web.struct.category.ScriptPath;
import com.fr.web.struct.category.StylePath; import com.fr.web.struct.category.StylePath;
import com.teamdev.jxbrowser.net.Network;
import com.teamdev.jxbrowser.net.UrlRequest;
import com.teamdev.jxbrowser.net.callback.InterceptRequestCallback;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -26,21 +23,20 @@ public class NxComplexInterceptRequestCallback extends NxInterceptRequestCallbac
private AssembleComponent component; private AssembleComponent component;
public NxComplexInterceptRequestCallback(Network network, AssembleComponent component) { public NxComplexInterceptRequestCallback(AssembleComponent component) {
super(network);
this.component = component; this.component = component;
} }
public NxComplexInterceptRequestCallback(Network network, AssembleComponent component, Map<String, String> map) { public NxComplexInterceptRequestCallback(AssembleComponent component, Map<String, String> map) {
super(network, map); super(map);
this.component = component; this.component = component;
} }
@Override @Override
protected Response next(UrlRequest urlRequest, String path) { protected Response next(Params params, String path) {
if (path.startsWith("emb:dynamic")) { if (path.startsWith("emb:dynamic")) {
String text = htmlText(map); String text = htmlText(map);
return InterceptRequestCallback.Response.intercept(generateBasicUrlRequestJob(urlRequest, "text/html", text.getBytes(StandardCharsets.UTF_8))); return Response.intercept(generateBasicUrlRequestJob(params, "text/html", text.getBytes(StandardCharsets.UTF_8)));
} else { } else {
int index = path.indexOf("="); int index = path.indexOf("=");
if (index > 0) { if (index > 0) {
@ -52,7 +48,7 @@ public class NxComplexInterceptRequestCallback extends NxInterceptRequestCallbac
if (inputStream == null) { if (inputStream == null) {
return Response.proceed(); return Response.proceed();
} }
return InterceptRequestCallback.Response.intercept(generateBasicUrlRequestJob(urlRequest, getMimeType(path), IOUtils.inputStream2Bytes(inputStream))); return Response.intercept(generateBasicUrlRequestJob(params, getMimeType(path), IOUtils.inputStream2Bytes(inputStream)));
} }
} }

34
designer-base/src/main/java/com/fr/design/ui/compatible/NxInterceptRequestCallback.java

@ -9,11 +9,10 @@ import com.fr.stable.StringUtils;
import com.fr.third.org.apache.commons.codec.net.URLCodec; import com.fr.third.org.apache.commons.codec.net.URLCodec;
import com.teamdev.jxbrowser.net.HttpHeader; import com.teamdev.jxbrowser.net.HttpHeader;
import com.teamdev.jxbrowser.net.HttpStatus; import com.teamdev.jxbrowser.net.HttpStatus;
import com.teamdev.jxbrowser.net.Network;
import com.teamdev.jxbrowser.net.UrlRequest; import com.teamdev.jxbrowser.net.UrlRequest;
import com.teamdev.jxbrowser.net.UrlRequestJob; import com.teamdev.jxbrowser.net.UrlRequestJob;
import com.teamdev.jxbrowser.net.callback.InterceptRequestCallback;
import com.teamdev.jxbrowser.net.callback.InterceptUrlRequestCallback;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -29,17 +28,14 @@ import java.util.Optional;
* @version 10.0 * @version 10.0
* Created by richie on 2020/3/25 * Created by richie on 2020/3/25
*/ */
public class NxInterceptRequestCallback implements InterceptRequestCallback { public class NxInterceptRequestCallback implements InterceptUrlRequestCallback {
Network network;
Map<String, String> map; Map<String, String> map;
public NxInterceptRequestCallback(Network network) { public NxInterceptRequestCallback() {
this.network = network;
} }
public NxInterceptRequestCallback(Network network, Map<String, String> map) { public NxInterceptRequestCallback(Map<String, String> map) {
this.network = network;
this.map = map; this.map = map;
} }
@ -48,21 +44,21 @@ public class NxInterceptRequestCallback implements InterceptRequestCallback {
UrlRequest urlRequest = params.urlRequest(); UrlRequest urlRequest = params.urlRequest();
String path = urlRequest.url(); String path = urlRequest.url();
if (path.startsWith("file:")) { if (path.startsWith("file:")) {
Optional<UrlRequestJob> optional = generateFileProtocolUrlRequestJob(urlRequest, path); Optional<UrlRequestJob> optional = generateFileProtocolUrlRequestJob(params, path);
if (optional.isPresent()) { if (optional.isPresent()) {
return InterceptRequestCallback.Response.intercept(optional.get()); return Response.intercept(optional.get());
} }
} else { } else {
return next(urlRequest, path); return next(params, path);
} }
return Response.proceed(); return Response.proceed();
} }
Response next(UrlRequest urlRequest, String path) { Response next(Params params, String path) {
return Response.proceed(); return Response.proceed();
} }
private Optional<UrlRequestJob> generateFileProtocolUrlRequestJob(UrlRequest urlRequest, String path) { private Optional<UrlRequestJob> generateFileProtocolUrlRequestJob(Params params, String path) {
try { try {
String url = new URLCodec().decode(path); String url = new URLCodec().decode(path);
String filePath = TemplateUtils.renderParameter4Tpl(url, map); String filePath = TemplateUtils.renderParameter4Tpl(url, map);
@ -77,7 +73,7 @@ public class NxInterceptRequestCallback implements InterceptRequestCallback {
} else { } else {
bytes = IOUtils.inputStream2Bytes(inputStream); bytes = IOUtils.inputStream2Bytes(inputStream);
} }
return Optional.of(generateBasicUrlRequestJob(urlRequest, mimeType, bytes)); return Optional.of(generateBasicUrlRequestJob(params, mimeType, bytes));
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
@ -88,12 +84,12 @@ public class NxInterceptRequestCallback implements InterceptRequestCallback {
return ArrayUtils.contains(new String[]{"text/html", "text/javascript", "text/css"}, mimeType); return ArrayUtils.contains(new String[]{"text/html", "text/javascript", "text/css"}, mimeType);
} }
UrlRequestJob generateBasicUrlRequestJob(UrlRequest urlRequest, String mimeType, byte[] bytes) { UrlRequestJob generateBasicUrlRequestJob(Params params, String mimeType, byte[] bytes) {
UrlRequestJob.Options options = UrlRequestJob.Options UrlRequestJob.Options options = UrlRequestJob.Options
.newBuilder(urlRequest.id(), HttpStatus.OK) .newBuilder(HttpStatus.OK)
.addHttpHeader(HttpHeader.of("Content-Type", mimeType)) .addHttpHeader(HttpHeader.of("Content-Type", mimeType))
.build(); .build();
UrlRequestJob urlRequestJob = network.newUrlRequestJob(options); UrlRequestJob urlRequestJob = params.newUrlRequestJob(options);
urlRequestJob.write(bytes); urlRequestJob.write(bytes);
urlRequestJob.complete(); urlRequestJob.complete();
return urlRequestJob; return urlRequestJob;
@ -145,4 +141,8 @@ public class NxInterceptRequestCallback implements InterceptRequestCallback {
return "text/html"; return "text/html";
} }
} }
public void setMap(Map<String, String> map) {
this.map = map;
}
} }
Loading…
Cancel
Save