|
|
@ -15,6 +15,7 @@ import com.teamdev.jxbrowser.chromium.events.ScriptContextListener; |
|
|
|
import com.teamdev.jxbrowser.engine.Engine; |
|
|
|
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.event.Observer; |
|
|
|
import com.teamdev.jxbrowser.js.JsObject; |
|
|
|
import com.teamdev.jxbrowser.js.JsObject; |
|
|
|
import com.teamdev.jxbrowser.net.Scheme; |
|
|
|
import com.teamdev.jxbrowser.net.Scheme; |
|
|
|
import com.teamdev.jxbrowser.view.swing.BrowserView; |
|
|
|
import com.teamdev.jxbrowser.view.swing.BrowserView; |
|
|
@ -80,30 +81,33 @@ public class NewModernUIPane<T> extends ModernUIPane<T> { |
|
|
|
|
|
|
|
|
|
|
|
private void showDebuggerDialog() { |
|
|
|
private void showDebuggerDialog() { |
|
|
|
JDialog dialog = new JDialog(SwingUtilities.getWindowAncestor(this)); |
|
|
|
JDialog dialog = new JDialog(SwingUtilities.getWindowAncestor(this)); |
|
|
|
Engine engine = Engine.newInstance( |
|
|
|
|
|
|
|
EngineOptions.newBuilder(RenderingMode.HARDWARE_ACCELERATED) |
|
|
|
Browser debugger = browser.engine().newBrowser(); |
|
|
|
.addSwitch("--disable-google-traffic") |
|
|
|
|
|
|
|
.remoteDebuggingPort(9222).build()); |
|
|
|
|
|
|
|
Browser debugger = engine.newBrowser(); |
|
|
|
|
|
|
|
BrowserView debuggerView = BrowserView.newInstance(debugger); |
|
|
|
BrowserView debuggerView = BrowserView.newInstance(debugger); |
|
|
|
dialog.add(debuggerView, BorderLayout.CENTER); |
|
|
|
dialog.add(debuggerView, BorderLayout.CENTER); |
|
|
|
dialog.setSize(new Dimension(800, 400)); |
|
|
|
dialog.setSize(new Dimension(800, 400)); |
|
|
|
GUICoreUtils.centerWindow(dialog); |
|
|
|
GUICoreUtils.centerWindow(dialog); |
|
|
|
dialog.setVisible(true); |
|
|
|
dialog.setVisible(true); |
|
|
|
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
|
|
|
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
|
|
|
|
|
|
|
|
|
|
|
browser.devTools().remoteDebuggingUrl().ifPresent(url -> { |
|
|
|
browser.devTools().remoteDebuggingUrl().ifPresent(url -> { |
|
|
|
debugger.navigation().loadUrl(url); |
|
|
|
debugger.navigation().loadUrl(url); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initializeBrowser() { |
|
|
|
private void initializeBrowser() { |
|
|
|
EngineOptions options; |
|
|
|
EngineOptions.Builder builder; |
|
|
|
if (scheme != null && requestCallback != null) { |
|
|
|
if (scheme != null && requestCallback != null) { |
|
|
|
options = EngineOptions.newBuilder(RenderingMode.HARDWARE_ACCELERATED).addSwitch("--disable-google-traffic").addScheme(scheme, requestCallback).build(); |
|
|
|
builder = EngineOptions.newBuilder(RenderingMode.HARDWARE_ACCELERATED).addSwitch("--disable-google-traffic").addScheme(scheme, requestCallback); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
options = EngineOptions.newBuilder(RenderingMode.HARDWARE_ACCELERATED).addSwitch("--disable-google-traffic").build(); |
|
|
|
builder = EngineOptions.newBuilder(RenderingMode.HARDWARE_ACCELERATED).addSwitch("--disable-google-traffic"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (DesignerEnvManager.getEnvManager().isOpenDebug()) { |
|
|
|
|
|
|
|
builder.remoteDebuggingPort(9222); |
|
|
|
} |
|
|
|
} |
|
|
|
Engine engine = Engine.newInstance(options); |
|
|
|
|
|
|
|
|
|
|
|
Engine engine = Engine.newInstance(builder.build()); |
|
|
|
browser = engine.newBrowser(); |
|
|
|
browser = engine.newBrowser(); |
|
|
|
|
|
|
|
|
|
|
|
// 初始化的时候,就把命名空间对象初始化好,确保window.a.b.c("a.b.c"为命名空间)对象都是初始化过的
|
|
|
|
// 初始化的时候,就把命名空间对象初始化好,确保window.a.b.c("a.b.c"为命名空间)对象都是初始化过的
|
|
|
@ -161,6 +165,29 @@ public class NewModernUIPane<T> extends ModernUIPane<T> { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void disposeBrowser() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (browser != null) { |
|
|
|
|
|
|
|
browser.close(); |
|
|
|
|
|
|
|
browser = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void clearCache() { |
|
|
|
|
|
|
|
if (browser != null) { |
|
|
|
|
|
|
|
browser.engine().httpCache().clear(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void executeJavaScript(String javaScript) { |
|
|
|
|
|
|
|
if (browser != null) { |
|
|
|
|
|
|
|
browser.mainFrame().ifPresent(frame -> { |
|
|
|
|
|
|
|
frame.executeJavaScript(javaScript); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static class Builder<T> extends ModernUIPane.Builder<T> { |
|
|
|
public static class Builder<T> extends ModernUIPane.Builder<T> { |
|
|
|
|
|
|
|
|
|
|
|
private NewModernUIPane<T> pane = new NewModernUIPane<>(); |
|
|
|
private NewModernUIPane<T> pane = new NewModernUIPane<>(); |
|
|
@ -191,7 +218,7 @@ 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) { |
|
|
|
pane.scheme = Scheme.of("file"); |
|
|
|
pane.scheme = Scheme.of("file"); |
|
|
|
pane.requestCallback = new NxComplexInterceptRequestCallback(null); |
|
|
|
pane.requestCallback = new NxComplexInterceptRequestCallback(null); |
|
|
|
pane.browser.navigation().loadUrl(url); |
|
|
|
pane.browser.navigation().loadUrl(url); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
@ -301,6 +328,14 @@ public class NewModernUIPane<T> extends ModernUIPane<T> { |
|
|
|
return prepare(callback); |
|
|
|
return prepare(callback); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public ModernUIPane.Builder<T> prepareForV7(Class event, Observer listener) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pane.browser.navigation().on(event, listener); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public NewModernUIPane<T> build() { |
|
|
|
public NewModernUIPane<T> build() { |
|
|
|
return pane; |
|
|
|
return pane; |
|
|
|