Xilium.CefGlue handling resource calls in WinForm

Having problems with building or using the CefGlue .NET/Mono binding? Ask your questions here.

Moderator: fddima

Xilium.CefGlue handling resource calls in WinForm

Postby AndyPlaylane » Thu Feb 07, 2013 9:10 am

Hey all,

i got Xilium.CefGlue working in my winforms application, this is my code:

Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Xilium.CefGlue;
using Xilium.CefGlue.WindowsForms;

namespace CefGlueBrowser
{
    public partial class Form1 : Form
    {
        private readonly string _mainTitle;
        private CefWebBrowser _browser;
         
        public Form1()
        {
            InitializeComponent();

            _mainTitle = Text;

            OpenAndBrowse("http://www.google.com");
        }

        private void OpenAndBrowse(string startUrl)
        {
           
            _browser = new CefWebBrowser();
            _browser.StartUrl = startUrl;
            _browser.Dock = DockStyle.Top;
            _browser.Location = new Point(0, 0);
            _browser.Size = new Size(1024, 768);

            Controls.Add(_browser);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            _browser.Browser.StopLoad();
            _browser.Browser.GetMainFrame().LoadUrl("http://www.magpcss.org");
        }
    }
}


So basicly, i open a new form, add a browser and go to the page. Everything works like it should, but now i'm trying to redirect the requests from the browser to local files. After doing some research, i found out i need to implement the CefRequestHandler. But i have totally no idea on how to do this.

I've also tried with CefSharp and there i need to implement the iRequestHandler to get into the OnBeforeResourceLoad method and do the redirect there, which works, but CefGlue is alot better in my eyes so i really want to get this working.

Any help will be greatly appreciated.

Thanks in advance.
AndyPlaylane
Newbie
 
Posts: 6
Joined: Thu Feb 07, 2013 8:33 am

Re: Xilium.CefGlue handling resource calls in WinForm

Postby fddima » Thu Feb 07, 2013 10:48 am

Hi.

Look at DumpRequestResourceHandler.cs for starting point.
Read comments for CefResourceHandler first.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Xilium.CefGlue handling resource calls in WinForm

Postby AndyPlaylane » Thu Feb 07, 2013 11:29 am

Thanks fddima, I was allready messing around with SchemeFactoryHandlers, but wasn't able to get it working, your example pointed me in the correct direction.
AndyPlaylane
Newbie
 
Posts: 6
Joined: Thu Feb 07, 2013 8:33 am

Re: Xilium.CefGlue handling resource calls in WinForm

Postby dimirc » Fri Feb 08, 2013 2:51 am

Take a look at DumpRequestResourceHandler.cs

Code: Select all
ReadResponse(Stream response, int bytesToRead, out int bytesRead, CefCallback callback)


ReadResponse will be called several times depending on the size of your file (will ask for small chunks of the resource)

Check this thread for an examaple:
https://groups.google.com/forum/#!topic/cefglue/0_bJabHCjbI/discussion
dimirc
Newbie
 
Posts: 4
Joined: Fri Feb 08, 2013 2:42 am

Re: Xilium.CefGlue handling resource calls in WinForm

Postby AndyPlaylane » Fri Feb 08, 2013 9:49 am

So, i got this working, but i'm still having problems when playing ogg files. They stop playing after a certain amount of time and white squares appear in the corners. You can test this by loading http://labs.playlane.be/sensoa/graad_1/index.html?2 in the CefGlue.Client example project.
AndyPlaylane
Newbie
 
Posts: 6
Joined: Thu Feb 07, 2013 8:33 am

Re: Xilium.CefGlue handling resource calls in WinForm

Postby fddima » Tue Feb 12, 2013 4:39 am

AndyPlaylane wrote:So, i got this working, but i'm still having problems when playing ogg files. They stop playing after a certain amount of time and white squares appear in the corners. You can test this by loading http://labs.playlane.be/sensoa/graad_1/index.html?2 in the CefGlue.Client example project.

No have idea - same happens with CEF client, so probably it is CEF issue.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Xilium.CefGlue handling resource calls in WinForm

Postby AndyPlaylane » Wed Feb 13, 2013 4:08 pm

In the cef support forum, they say that i should handle accept-ranges for playing video, but when i add this to my headers, the video no longer plays at all. You got any other idea's on how to do this so the ranges are handled correctly?
AndyPlaylane
Newbie
 
Posts: 6
Joined: Thu Feb 07, 2013 8:33 am

Re: Xilium.CefGlue handling resource calls in WinForm

Postby fddima » Wed Feb 13, 2013 5:19 pm

AndyPlaylane wrote:In the cef support forum, they say that i should handle accept-ranges for playing video, but when i add this to my headers, the video no longer plays at all. You got any other idea's on how to do this so the ranges are handled correctly?

Yes, custom resource handler must handle ranges.
But your's sample not working in cefclient with ogv video - it loads only 6.2Mb from 8.6Mb.

Log contains:

[0214/001211:VERBOSE1:resource_loader.cc(347)] OnReadCompleted: "http://labs.playlane.be/sensoa/graad_1/assets/videos/page02/movie.ogv" bytes_read = 28016
[0214/001211:VERBOSE1:pipeline.cc(333)] Media pipeline error: 3
[0214/001211:VERBOSE1:resource_loader.cc(437)] CancelRequestInternal: http://labs.playlane.be/sensoa/graad_1/ ... /movie.ogv
[0214/001211:VERBOSE1:resource_loader.cc(347)] OnReadCompleted: "http://labs.playlane.be/sensoa/graad_1/assets/videos/page02/movie.ogv" bytes_read = -1
[0214/001211:VERBOSE1:resource_loader.cc(570)] ResponseCompleted: http://labs.playlane.be/sensoa/graad_1/ ... /movie.ogv

I'm doesn't know what exact problem, and doesn't have idea. Probably it's CEF's bug in ogv playing.
Needed to be rechecked with latest release and with local source file (i.e. ensure that it actually can be played completely).
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am


Return to CefGlue Forum

Who is online

Users browsing this forum: No registered users and 22 guests