How to implement Download Handler

4,514 views
Skip to first unread message

Benjamin Hoffmann

unread,
Mar 26, 2014, 10:57:16 AM3/26/14
to cefs...@googlegroups.com
I'm using CEFsharp in my wpf object, but when I try to download something from a website, nothing happens.
I only have CefSharp and CefSharp.WPF in my references. When I try to follow this topic : https://groups.google.com/forum/#!topic/cefsharp/3cMUHSGxPDc I have some errors on this code :
           
            var settings = new CefSettings();
            settings.RegisterScheme(new CefCustomScheme
            {
                SchemeName = CefSharpSchemeHandlerFactory.SchemeName,
                SchemeHandlerFactory = new CefSharpSchemeHandlerFactory()
            });

CefSettings and CefCustomScheme can not be found (they aren't defined).
Can you help me to implement a downloader ?

Benjamin Hoffmann

unread,
Mar 26, 2014, 5:08:05 PM3/26/14
to cefs...@googlegroups.com
*in my wpf project

Jørn Hansen

unread,
Mar 27, 2014, 4:40:13 AM3/27/14
to cefs...@googlegroups.com
If you are using the CefSharp3.29.<something> NuGet then maybe what you see is a consequence of missing references due to (a variation of) https://groups.google.com/forum/?nomobile=true#!topic/cefsharp/e6vX4CBHWa0 ??

Please pitch in over there and/or in issues if relevant :-)

--
Best regards,
JornH

Benjamin Hoffmann

unread,
Apr 10, 2014, 12:01:44 PM4/10/14
to cefs...@googlegroups.com
I'm not using CefSharp 3, I'm using CefSharp 1.25.7. Is the download handler implementation compatible with this version ?

Jørn Hansen

unread,
Apr 10, 2014, 1:17:49 PM4/10/14
to cefs...@googlegroups.com
On Thursday, April 10, 2014 6:01:44 PM UTC+2, Benjamin Hoffmann wrote:
> I'm not using CefSharp 3, I'm using CefSharp 1.25.7. Is the download handler implementation compatible with this version ?
>

Ah, that explains it :-)

The link to the ExamplePresenter code you followed from the other post was for CefSharp3 (the branch for that is now called `master` BTW.)

For CefSharp 1 you want to look at https://github.com/cefsharp/CefSharp/blob/CefSharp1/CefSharp.Example/ExamplePresenter.cs

Yeah, the API around CEF.Settings() had to change a bit in CefSharp3 between 3.29 and now to support issue #212 (multiple browser tabs etc.)

I hope I hit the nail this time (and not your fingers ;-)

Benjamin Hoffmann

unread,
Apr 14, 2014, 9:56:46 AM4/14/14
to cefs...@googlegroups.com
I'm sorry but that's not very clear for me. I've added the IRequestHandler interface in my main class, I have implemented these methods :


            bool IRequestHandler.GetDownloadHandler(IWebBrowser browser, string mimeType, string fileName, long contentLength, ref IDownloadHandler handler)
            {
                handler = new DownloadHandler(fileName);
                return true;
            }
          
            public bool GetAuthCredentials(IWebBrowser browser, bool isProxy, string host, int port, string realm, string scheme, ref string username, ref string password)
            {
                throw new NotImplementedException();
            }

            public bool GetDownloadHandler(IWebBrowser browser, string mimeType, string fileName, long contentLength, ref IDownloadHandler handler)
            {
                throw new NotImplementedException();
            }

            public bool OnBeforeBrowse(IWebBrowser browser, IRequest request, NavigationType naigationvType, bool isRedirect)
            {
                throw new NotImplementedException();
            }

            public bool OnBeforeResourceLoad(IWebBrowser browser, IRequestResponse requestResponse)
            {
                throw new NotImplementedException();
            }

            public void OnResourceResponse(IWebBrowser browser, string url, int status, string statusText, string mimeType, System.Net.WebHeaderCollection headers)
            {
                throw new NotImplementedException();
            }


But GetDownloadHandler never fire when I click on a link.
I can't even run the project of the link you gave me, I have a lot of missing reference when I try to run the project downloaded from GitHub.
How can I bind the GetDownloadHandlerevent ?

Jørn Hansen

unread,
Apr 14, 2014, 11:31:09 AM4/14/14
to cefs...@googlegroups.com
On Monday, April 14, 2014 3:56:46 PM UTC+2, Benjamin Hoffmann wrote:
I'm sorry but that's not very clear for me. I've added the IRequestHandler interface in my main class, I have implemented these methods :

In my previous post I said: "Yeah, the API around CEF.Settings() had to change a bit in CefSharp3 between 3.29 and now to support issue #212 (multiple browser tabs etc.) "
Please forget that - that was just plain wrong! I confused it with some other change ...
 

But GetDownloadHandler never fire when I click on a link.

OK, I think to problem *could* be that you are missing a line similar to:


I can't even run the project of the link you gave me, I have a lot of missing reference when I try to run the project downloaded from GitHub.

Sorry, `CefSharp.Example` is not the project you are supposed to run. It only contains some common logic used from both `CefSharp.Wpf.Example` and `CefSharp.WinForms.Example` (maybe we should consider to rename that project to avoid confusion?). Please set `CefSharp.Wpf.Example` as your startup project!

Missing references sounds like you *might* have gotten the CefSharp3 aka master branch and then didn't succeed pulling the `cef.redist` and `cef.sdk` NuGet packages. If you have downloaded recent CefSharp1 sources it *must* contain a `CEF/` folder. 

Benjamin Hoffmann

unread,
Apr 14, 2014, 12:01:04 PM4/14/14
to cefs...@googlegroups.com
Thank you Jørn for your precious help !
It works well now, I had actually forgotten to set the model RequestHandler .

Thank you for your great job !
Reply all
Reply to author
Forward
0 new messages