delphi - CEF4Delphi 处理打开选项卡(并下载文件)
问题描述
我在处理 Chromium 中的下载链接时遇到了一个特殊问题。
问题不在于下载(这里回答得很好:CEF4 Chromium Delphi 10.2 Tokyo - 如何处理下载对话?)...但是这个特定的链接被标记为 target="_blank"。
使用 targetDisposition=WOD_NEW_FOREGROUND_TAB 触发 OnBeforePopup 但是,在几乎所有示例代码中,OnBeforePopup 处理程序具有以下代码:
// For simplicity, this demo blocks all popup windows and new tabs
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
这有效地阻止了该链接继续进行,因此 OnBeforeDownload 事件永远不会触发。
如果我注释掉弹出窗口阻止程序,默认行为似乎是打开一个新的空白窗口,然后按预期继续下载事件。但是,下载永远不会完全完成(它会达到 100% 但永远不会“完成”),并且新窗口永远不会消失。
我的问题分为两部分:
- 我能否就如何在 OnBeforePopup 事件中创建一个我可以控制的新浏览器窗口获得一些指导?
- 如何使下载正确完成?
注意:如果我将下载文件的实际targetURL粘贴到地址栏中,下载完成的非常愉快,所以我怀疑关键在于默认窗口的处理。
注意:我找到了 CEF API 文档,它的信息量不是很大。
注意:我知道 TabBrowser2 处理弹出窗口拦截,但还不清楚发生了什么,显然是调用客户端窗口然后调用主窗口,而主窗口又再次调用客户端窗口。再加上我到目前为止的结构并不适合这种解决方案。这
解决方案
部分答案:PopupBrowser演示更清楚地显示了它。并且至少部分记录了正在发生的事情。
从评论:
// VCL components *MUST* be created and destroyed in the main thread but CEF executes the
// TChromium.OnBeforePopup in a different thread.
// For this reason this demo creates a hidden popup form (TChildForm) in case CEF needs to show a popup window.
// TChromium.OnBeforePopup calls TChildForm.CreateClientHandler to initialize some parameters and create the new ICefClient.
// After that, it sends a CEF_CREATENEXTCHILD message to show the popup form and create a new one.
这相当清楚地解释了正在发生的事情。
CreateClientHandler(var aClient : ICefClient...
填充在 BeforePopup 调用中传递的 clienthandler 参数。
推荐阅读
- python - 将修改后的数据发送到 DRF API 中的序列化程序
- entity-framework-core - 带有接口的脚手架 EF Core 实体
- r - spark_apply 错误指定列名
- r - R - 从具有链接信息的其他矩阵构建矩阵
- java - 如何在 Eclipse 便携版中设置 jdk?
- reactjs - 如何在 IIS 中使用 .NetCore 在开发模式下运行 React?
- node.js - Azure blockBlobURL.download() 是否对文件大小有限制?
- css - 当鼠标悬停在颜色选择器上时更改产品颜色
- node.js - 当且仅当 JOI 不为空时如何验证电子邮件
- c# - 如何解决 Unity 中 Watson Unity SDK 的 C# 参考错误?