从 7.7.1 到 7.8
在 JxBrowser 7.8 中,Chromium Engine 已升级至版本 79。这个 Chromium 版本的源代码中存在几个重大变更,影响了 JxBrowser 的公共 API。在本迁移指南中,我们将详细说明在 7.8 版本中哪些 API 已被移除,以及您应该使用的相应替代方法。
下载
接受下载
v7.7.1
为了接受文件下载请求,使用了以下回调:
Downloads downloads = engine.downloads();
downloads.set(StartDownloadCallback.class, (params, tell) -> tell.cancel());
val downloads = engine.downloads()
downloads.set(StartDownloadCallback::class.java,
StartDownloadCallback { params, tell -> tell.cancel() }
)
v7.8
在 7.8 中,此功能已移至 Browser
,因此现在您可以独立地为每个 Browser
实例接受文件下载请求。例如:
browser.set(StartDownloadCallback.class, (params, tell) -> tell.cancel());
browser.set(StartDownloadCallback::class.java,
StartDownloadCallback { params, tell -> tell.cancel() }
)
网络
访问 Browser
v7.7.1
network.set(BeforeSendHeadersCallback.class, params -> {
params.browser().ifPresent(browser -> {});
...
});
network.set(BeforeUrlRequestCallback.class, params -> {
params.browser().ifPresent(browser -> {});
...
});
network.set(ReceiveHeadersCallback.class, params -> {
params.browser().ifPresent(browser -> {});
...
});
network.set(BeforeSendHeadersCallback::class.java,
BeforeSendHeadersCallback { params ->
params.browser().ifPresent{ browser -> {}}
}
)
network.set(BeforeUrlRequestCallback::class.java,
BeforeUrlRequestCallback { params ->
params.browser().ifPresent{ browser -> {}}
}
)
network.set(ReceiveHeadersCallback::class.java,
ReceiveHeadersCallback { params ->
params.browser().ifPresent{ browser -> {}}
}
)
v7.8
network.set(BeforeSendHeadersCallback.class, params -> {
params.urlRequest().browser().ifPresent(browser -> {});
...
});
network.set(BeforeUrlRequestCallback.class, params -> {
params.urlRequest().browser().ifPresent(browser -> {});
...
});
network.set(ReceiveHeadersCallback.class, params -> {
params.urlRequest().browser().ifPresent(browser -> {});
...
});
network.set(BeforeSendHeadersCallback::class.java,
BeforeSendHeadersCallback { params ->
params.urlRequest().browser().ifPresent{browser -> {}}
...
}
)
network.set(BeforeUrlRequestCallback::class.java,
BeforeUrlRequestCallback { params ->
params.urlRequest().browser().ifPresent{browser -> {}}
...
}
)
network.set(ReceiveHeadersCallback::class.java,
ReceiveHeadersCallback { params ->
params.urlRequest().browser().ifPresent{browser -> {}}
...
}
)
BytesSent
v7.7.1
network.on(BytesSent.class, event -> {
int bytesSentCount = event.count();
});
network.on(BytesSent.class) { event ->
val bytesSentCount = event.count()
});
v7.8
network.on(RequestCompleted.class, event -> {
long bytesSent = event.urlRequest().totalBytesSent();
});
network.on(RequestCompleted.class) { event ->
val bytesSent = event.urlRequest().totalBytesSent()
});
BytesReceived
v7.7.1
network.on(BytesReceived.class, event -> {
int bytesReceivedCount = event.count();
});
network.on(BytesReceived.class) { event ->
val bytesReceivedCount = event.count()
});
v7.8
network.on(RequestCompleted.class, event -> {
long bytesReceived = event.urlRequest().totalBytesReceived();
});
network.on(RequestCompleted.class) { event ->
val bytesReceived = event.urlRequest().totalBytesReceived()
});
内容
获取网页的位图
弃用的 com.teamdev.jxbrowser.view.javafx.BitmapUtil
和 com.teamdev.jxbrowser.view.swing.BitmapUtil
类已被移除。请改用 com.teamdev.jxbrowser.view.swing.graphics.BitmapImage
和 com.teamdev.jxbrowser.view.javafx.graphics.BitmapImage
类替代。
已移除的 API
由于 Chromium 79 中相应的功能已不存在,以下类和方法已被移除:
com.teamdev.jxbrowser.net.event.TransactionStarted
com.teamdev.jxbrowser.net.callback.CanAccessFileCallback.url()
com.teamdev.jxbrowser.browser.callback.CertificateErrorCallback.resourceType()