CEF4Delphi句柄打开选项卡(并下载文件)

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

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

问题不在于下载(这里回答得很好:) …但此特定链接标记为target=“\u blank”

使用targetDisposition=WOD\u NEW\u FOREGROUND\u选项卡触发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粘贴到地址栏中,下载会非常愉快地完成,因此我怀疑关键在于处理默认窗口

    注意:我已经找到了CEFAPI文档,它不是超级信息

    注意:我知道TabBrowser2处理弹出式截取,但还不清楚发生了什么,显然是调用了一个客户机窗口,然后调用了主窗口,而主窗口又调用了客户机窗口。加上我到目前为止的结构并不能真正适用于这个解决方案。
    部分答案: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;