cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.88k stars 2.92k forks source link

`IBeforeDownloadCallback`.Continue(path, showDialog:true) does not open correct path if full path with file name is used #4951

Closed m-kovac closed 1 month ago

m-kovac commented 1 month ago

Is there an existing issue for this?

CefSharp Version

129.0.110

Operating System

Windows 11

Architecture

x64

.Net Version

.NET 4.8

Implementation

WinForms

Reproduction Steps

  1. Clone CefSharp.WinForms example

  2. Create custom IDownloadHandler and assign it to browser.DownloadHandler

  3. Implement the OnBeforeDownload method:

    public bool OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
    {
    if (callback.IsDisposed)
    {
        return false;
    }
    
    using (callback)
    {
        var downloadedFilePath = Path.Combine("C:\\Users\\currentUser\\Downloads\\", downloadItem.SuggestedFileName);
        callback.Continue(downloadedFilePath, showDialog: true);
    }
    return true;
    }
  4. Buld and start the project

  5. Go to https://codepen.io/chriddyp/pen/aVammp and download the example file

Expected behavior

The dialog should open in the "C:\Users\currentUser\Downloads\" folder with pre-filled File name text field.

Actual behavior

The dialog is opened in the C:\Users\user folder with pre-filled File name text field. Only way to show the correct folder is to not specify the file name e.g.

var downloadedFilePath = "C:\\Users\\currentUser\\Downloads"; which will leave the File name text field and type of file empty.

Regression?

Same issue was spotted in v127.3.50 and v128.4.90

Known Workarounds

No response

Does this problem also occur in the CEF Sample Application

Not Tested

Other information

No response

amaitland commented 1 month ago

The Chromium Embedded Framework (CEF) project has it's own Issue Tracker, please report this issue there. CefSharp is just one of many wrappers around the Chromium Embedded Framework (CEF)

If you do find an existing issue that matches this one or create a new one then post a link here for others.

Closing this as upstream as changes/fixes need to be made in CEF.

amaitland commented 1 month ago

https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Core.Runtime/Internals/CefBeforeDownloadCallbackWrapper.h#L40

See https://github.com/cefsharp/CefSharp/wiki/General-Usage for background