在处理铬中的下载链接时,我遇到了一个特殊的问题。
问题不在于下载(在这里回答得很好:CEF4 Chromium Delphi 10.2 Tokyo - how to handle download dialogue? ) ...but --这个特定的链接被标记为target="_blank“。
但是,在几乎所有示例代码中,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%,但从未“完成”),并且新的窗口永远不会消失。
我的问题分两部分:
注意:如果我将下载文件的实际targetURL粘贴到地址栏中,下载就会非常愉快地完成,因此我怀疑密钥是在处理默认窗口。
注意:我已经找到了CEF文档,它并不是信息丰富的。
注意:我知道TabBrowser2处理弹出拦截,但还不清楚发生了什么,显然调用了客户端窗口,然后调用主窗口,而主窗口又再次调用客户端窗口。另外,我到目前为止所拥有的结构并不真正适用于这个解决方案。这个
发布于 2021-05-28 03:37:03
部分答案: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参数。
发布于 2021-05-28 09:58:43
可以使用事件ChromiumBeforePopup打开新选项卡。
procedure ChromiumBeforePopup(Sender: TObject; const browser: ICefBrowser;
const frame: ICefFrame; const targetUrl, targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var noJavascriptAccess,
Result: Boolean);
begin
Result := not(CreateClientHandler(windowInfo, client, targetFrameName, popupFeatures));
end;https://stackoverflow.com/questions/67716734
复制相似问题