Browse Source

Pull request #5368: KERNEL-7634 jxbrowser 小版本再升级下

Merge in DESIGN/design from ~HADES/design:feature/10.0 to feature/10.0

* commit 'c95c24b7b6ce626b2d8b22ce54f523c9376c7c61':
  KERNEL-7634 jxbrowser 小版本再升级下
feature/10.0
Hades 3 years ago
parent
commit
132e11bdc6
  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-mac:6.23'
implementation 'com.fr.third:jxbrowser-win64:6.23'
implementation 'com.fr.third:jxbrowser-v7:7.7'
implementation 'com.fr.third:jxbrowser-mac-v7:7.7'
implementation 'com.fr.third:jxbrowser-win64-v7:7.7'
implementation 'com.fr.third:jxbrowser-swing-v7:7.7'
implementation 'com.fr.third:jxbrowser-v7:7.15'
implementation 'com.fr.third:jxbrowser-mac-v7:7.15'
implementation 'com.fr.third:jxbrowser-win64-v7:7.15'
implementation 'com.fr.third:jxbrowser-swing-v7:7.15'
implementation 'com.fr.third.server:servlet-api:3.0'
implementation 'org.swingexplorer:swexpl:2.0.1'
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 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<>();
} else {
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.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);
});

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.category.ScriptPath;
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.nio.charset.StandardCharsets;
@ -26,21 +23,20 @@ public class NxComplexInterceptRequestCallback extends NxInterceptRequestCallbac
private AssembleComponent component;
public NxComplexInterceptRequestCallback(Network network, AssembleComponent component) {
super(network);
public NxComplexInterceptRequestCallback(AssembleComponent component) {
this.component = component;
}
public NxComplexInterceptRequestCallback(Network network, AssembleComponent component, Map<String, String> map) {
super(network, map);
public NxComplexInterceptRequestCallback(AssembleComponent component, Map<String, String> map) {
super(map);
this.component = component;
}
@Override
protected Response next(UrlRequest urlRequest, String path) {
protected Response next(Params params, String path) {
if (path.startsWith("emb:dynamic")) {
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 {
int index = path.indexOf("=");
if (index > 0) {
@ -52,7 +48,7 @@ public class NxComplexInterceptRequestCallback extends NxInterceptRequestCallbac
if (inputStream == null) {
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.teamdev.jxbrowser.net.HttpHeader;
import com.teamdev.jxbrowser.net.HttpStatus;
import com.teamdev.jxbrowser.net.Network;
import com.teamdev.jxbrowser.net.UrlRequest;
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.IOException;
import java.io.InputStream;
@ -29,17 +28,14 @@ import java.util.Optional;
* @version 10.0
* Created by richie on 2020/3/25
*/
public class NxInterceptRequestCallback implements InterceptRequestCallback {
public class NxInterceptRequestCallback implements InterceptUrlRequestCallback {
Network network;
Map<String, String> map;
public NxInterceptRequestCallback(Network network) {
this.network = network;
public NxInterceptRequestCallback() {
}
public NxInterceptRequestCallback(Network network, Map<String, String> map) {
this.network = network;
public NxInterceptRequestCallback(Map<String, String> map) {
this.map = map;
}
@ -48,21 +44,21 @@ public class NxInterceptRequestCallback implements InterceptRequestCallback {
UrlRequest urlRequest = params.urlRequest();
String path = urlRequest.url();
if (path.startsWith("file:")) {
Optional<UrlRequestJob> optional = generateFileProtocolUrlRequestJob(urlRequest, path);
Optional<UrlRequestJob> optional = generateFileProtocolUrlRequestJob(params, path);
if (optional.isPresent()) {
return InterceptRequestCallback.Response.intercept(optional.get());
return Response.intercept(optional.get());
}
} else {
return next(urlRequest, path);
return next(params, path);
}
return Response.proceed();
}
Response next(UrlRequest urlRequest, String path) {
Response next(Params params, String path) {
return Response.proceed();
}
private Optional<UrlRequestJob> generateFileProtocolUrlRequestJob(UrlRequest urlRequest, String path) {
private Optional<UrlRequestJob> generateFileProtocolUrlRequestJob(Params params, String path) {
try {
String url = new URLCodec().decode(path);
String filePath = TemplateUtils.renderParameter4Tpl(url, map);
@ -77,7 +73,7 @@ public class NxInterceptRequestCallback implements InterceptRequestCallback {
} else {
bytes = IOUtils.inputStream2Bytes(inputStream);
}
return Optional.of(generateBasicUrlRequestJob(urlRequest, mimeType, bytes));
return Optional.of(generateBasicUrlRequestJob(params, mimeType, bytes));
} catch (Exception 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);
}
UrlRequestJob generateBasicUrlRequestJob(UrlRequest urlRequest, String mimeType, byte[] bytes) {
UrlRequestJob generateBasicUrlRequestJob(Params params, String mimeType, byte[] bytes) {
UrlRequestJob.Options options = UrlRequestJob.Options
.newBuilder(urlRequest.id(), HttpStatus.OK)
.newBuilder(HttpStatus.OK)
.addHttpHeader(HttpHeader.of("Content-Type", mimeType))
.build();
UrlRequestJob urlRequestJob = network.newUrlRequestJob(options);
UrlRequestJob urlRequestJob = params.newUrlRequestJob(options);
urlRequestJob.write(bytes);
urlRequestJob.complete();
return urlRequestJob;
@ -145,4 +141,8 @@ public class NxInterceptRequestCallback implements InterceptRequestCallback {
return "text/html";
}
}
public void setMap(Map<String, String> map) {
this.map = map;
}
}
Loading…
Cancel
Save