【问题标题】:CEF4Delphi Handle Opening a Tab (and Download a File)CEF4Delphi 处理打开选项卡(并下载文件)
【发布时间】:2021-05-27 06:25:17
【问题描述】:

我在处理 Chromium 中的下载链接时遇到了特殊问题。

问题不在于下载(这里回答得很好:CEF4 Chromium Delphi 10.2 Tokyo - how to handle download dialogue?) ...但是这个特定的链接标有 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% 但永远不会“完成”),并且新窗口永远不会消失。

我的问题分为两部分:

  1. 我能否就如何创建一个我可以在 OnBeforePopup 事件中控制的新浏览器窗口获得一些指导?
  2. 如何正确完成下载?

注意:如果我将下载文件的实际targetURL粘贴到地址栏中,下载完成的相当愉快,所以我怀疑关键在于默认窗口的处理。

注意:我找到了 CEF API 文档,它信息量不是很大。

注意:我知道 TabBrowser2 处理弹出窗口拦截,但目前还不清楚发生了什么,显然是调用客户端窗口然后调用主窗口,而主窗口又调用客户端窗口。再加上我到目前为止的结构并不适合这种解决方案。

【问题讨论】:

    标签: delphi chromium chromium-embedded cef4delphi


    【解决方案1】:

    部分答案:PopupBrowser 演示更清楚地显示了这一点。并且至少 部分记录正在发生的事情。

    来自cmets:

    // 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 参数。

    【讨论】:

      【解决方案2】:

      您可以使用 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;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-02
        • 2016-02-15
        • 1970-01-01
        • 2023-04-04
        • 1970-01-01
        相关资源
        最近更新 更多