CEF4Delphi句柄打开选项卡(并下载文件)
我在处理Chromium中的下载链接时遇到了一个特殊问题 问题不在于下载(这里回答得很好:) …但此特定链接标记为target=“\u blank” 使用targetDisposition=WOD\u NEW\u FOREGROUND\u选项卡触发OnBeforePopup 但是,在几乎所有示例代码中,OnBeforePopup处理程序都有以下代码:CEF4Delphi句柄打开选项卡(并下载文件),delphi,chromium,chromium-embedded,cef4delphi,Delphi,Chromium,Chromium Embedded,Cef4delphi,我在处理Chromium中的下载链接时遇到了一个特殊问题 问题不在于下载(这里回答得很好:) …但此特定链接标记为target=“\u blank” 使用targetDisposition=WOD\u NEW\u FOREGROUND\u选项卡触发OnBeforePopup 但是,在几乎所有示例代码中,OnBeforePopup处理程序都有以下代码: // For simplicity, this demo blocks all popup windows and new tabs Re
// 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%,但从未“完成”),新窗口也从未消失
我的问题分为两部分:
部分答案:PopubBrowser演示更清楚地展示了它。至少 部分记录正在发生的事情 从评论中:
// 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参数。您可以使用事件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;