Xilium.CefGlue/3 & CefGlue/1

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

Moderator: fddima

Re: Xilium.CefGlue/3 & CefGlue/1 - RegisterScriptableObject

Postby fddima » Tue Oct 30, 2012 11:16 am

steven181 wrote:Can you please give me any suggestion?

Without full code this no have sense. CefGlue.1 can't help you 'cause it outdated but many changes was be introduced from CEF by modern 1 & 3 versions.

1. Create scheme handler factory first:
Code: Select all
    class MySchemeHandlerFactory : CefSchemeHandlerFactory
    {
        protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request)
        {
            return new MySchemeHandler();
        }
    }


2. Create scheme handler (resource handler):
Code: Select all
    // very-very-very simple stub
    class MySchemeHandler : CefResourceHandler
    {
        private static int _no;
        private bool _completed;

        protected override bool ProcessRequest(CefRequest request, CefCallback callback)
        {
            callback.Continue();
            return true;
        }

        protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
        {
            response.SetHeaderMap();

            response.Status = 200;
            response.MimeType = "text/html";
            response.StatusText = "OK";
            responseLength = -1; // unknown content-length
            redirectUrl = null;  // no-redirect
        }

        protected override bool ReadResponse(System.IO.Stream response, int bytesToRead, out int bytesRead, CefCallback callback)
        {
            if (_completed)
            {
                bytesRead = 0;
                return false;
            }
            else
            {
                _no++;
                // very simple response with one block
                var content = Encoding.UTF8.GetBytes("Response #" + _no.ToString());
                if (bytesToRead < content.Length) throw new NotImplementedException(); // oops
                response.Write(content, 0, content.Length);
                bytesRead = content.Length;

                _completed = true;

                return true;
            }
        }

        protected override bool CanGetCookie(CefCookie cookie)
        {
            return false;
        }

        protected override bool CanSetCookie(CefCookie cookie)
        {
            return false;
        }

        protected override void Cancel()
        {
        }
    }


3. Register scheme handler factory:
Code: Select all
CefRuntime.RegisterSchemeHandlerFactory("http", "_app.mycooldomain", new MySchemeHandlerFactory());


If you want use custom scheme name (not http) - then you must also register it within renderers, and they are restricted - body of POST requests are not delivered to scheme handler. So it is much easier use http scheme with own unique domain.
Just follow CEF docs.

Also follow CefRequest/CefResponse GetHeaderMap/SetHeaderMap methods issue - currently this methods not implemented and you can't access to request/response headers (for example to prevent caching). But this issue will be resolved soon.

May be i'm something missing - but it is looks as minimal setup.
fddima
Master
 
Posts: 775
Joined: Tue Dec 07, 2010 6:10 am

Re: Xilium.CefGlue/3 & CefGlue/1

Postby steven181 » Wed Oct 31, 2012 3:07 am

Thanks for you quickly and meaningful response.
Case 1: Access http://_app.mycooldomain/test.html using address bar
It runs normally and print out the result "Response #1" -> great.

Case 2: Trying with "XMLHttpRequest":
Code: Select all
var xhr = new XMLHttpRequest();
            xhr.open("GET", 'http://_app.mycooldomain/test.html', false);
            //xhr.setRequestHeader('My-Custom-Header', 'Some Value');
            xhr.send();
            document.getElementById('ta').value = "Status Code: " + xhr.status + "\n\n" + xhr.responseText;
            alert('done');


- I run in debug mode, it can step into MySchemeHandlerFactory, pass all the process "ProcessRequest", "GetResponseHeaders" and ReadResponse.
- But it didn't fire below code after MySchemeHandlerFactory cycle
Code: Select all
document.getElementById('ta').value = "Status Code: " + xhr.status + "\n\n" + xhr.responseText;
            alert('done');


Would you please give me some suggestion.

Thanks for your support.

Steven
steven181
Techie
 
Posts: 11
Joined: Mon Oct 29, 2012 12:42 am

Re: Xilium.CefGlue/3 & CefGlue/1

Postby fddima » Wed Oct 31, 2012 4:29 am

steven181 wrote:Case 2: Trying with "XMLHttpRequest":


Try play with cross-origin white list. If you play with file scheme then CefBrowserSettings.UniversalAccessFromFileUrlsAllowed can be helpful.
Code: Select all
CefRuntime.AddCrossOriginWhitelistEntry("http://localhost", "http", "_app.mycooldomain", false);


I.e. page from http://localhost domain can access to http://_app.mycooldomain.
fddima
Master
 
Posts: 775
Joined: Tue Dec 07, 2010 6:10 am

Re: Xilium.CefGlue/3 & CefGlue/1

Postby steven181 » Wed Oct 31, 2012 6:00 am

fddima wrote:
steven181 wrote:Case 2: Trying with "XMLHttpRequest":


Try play with cross-origin white list. If you play with file scheme then CefBrowserSettings.UniversalAccessFromFileUrlsAllowed can be helpful.
Code: Select all
CefRuntime.AddCrossOriginWhitelistEntry("http://localhost", "http", "_app.mycooldomain", false);


I.e. page from http://localhost domain can access to http://_app.mycooldomain.



Thanks for your response.
It's still can't work. I temporary trick it work by adding below lines into MySchemeHandler
Code: Select all
public MySchemeHandler(CefBrowser browser)
{
this._browser = browser
}

and below lines for "ReadResponse"
Code: Select all
var currentURL = _browser.GetMainFrame().Url;

            _browser.GetMainFrame().ExecuteJavaScript("SayHello('Steven')", currentURL, 0);


:D It's run cool.


Another issue is Browser.GetHost().GetDevToolsUrl(false). It's always return Null or Empty. Sorry for troubleshoot you again.

Thanks for your great support.

Steven
steven181
Techie
 
Posts: 11
Joined: Mon Oct 29, 2012 12:42 am

Re: Xilium.CefGlue/3 & CefGlue/1

Postby fddima » Wed Oct 31, 2012 6:33 am

steven181 wrote:It's still can't work. I temporary trick it work by adding below lines into MySchemeHandler
Another issue is Browser.GetHost().GetDevToolsUrl(false). It's always return Null or Empty. Sorry for troubleshoot you again.

It must work. Yes, better see on this in devtools.
To enable remote debugging you must specify port via CefSettings.RemoteDebuggingPort.
Code: Select all
        /// <summary>
        /// Set to a value between 1024 and 65535 to enable remote debugging on the
        /// specified port. For example, if 8080 is specified the remote debugging URL
        /// will be http://localhost:8080. CEF can be remotely debugged from any CEF or
        /// Chrome browser window.
        /// </summary>
        public int RemoteDebuggingPort { get; set; }
fddima
Master
 
Posts: 775
Joined: Tue Dec 07, 2010 6:10 am

Re: Xilium.CefGlue/3 & CefGlue/1

Postby steven181 » Wed Oct 31, 2012 9:04 am

fddima wrote:
steven181 wrote:It's still can't work. I temporary trick it work by adding below lines into MySchemeHandler
Another issue is Browser.GetHost().GetDevToolsUrl(false). It's always return Null or Empty. Sorry for troubleshoot you again.

It must work. Yes, better see on this in devtools.
To enable remote debugging you must specify port via CefSettings.RemoteDebuggingPort.
Code: Select all
        /// <summary>
        /// Set to a value between 1024 and 65535 to enable remote debugging on the
        /// specified port. For example, if 8080 is specified the remote debugging URL
        /// will be http://localhost:8080. CEF can be remotely debugged from any CEF or
        /// Chrome browser window.
        /// </summary>
        public int RemoteDebuggingPort { get; set; }


I'm so stupid. It's work great.
Million thanks to your effort help.

Steven
steven181
Techie
 
Posts: 11
Joined: Mon Oct 29, 2012 12:42 am

Re: Xilium.CefGlue/3 & CefGlue/1

Postby steven181 » Sun Nov 04, 2012 1:47 am

Hi my friends,

Do you have any plan for RegisterExtension?

Regards,
Steven
steven181
Techie
 
Posts: 11
Joined: Mon Oct 29, 2012 12:42 am

Re: Xilium.CefGlue/3 & CefGlue/1

Postby fddima » Sun Nov 04, 2012 10:26 am

steven181 wrote:Hi my friends,

Do you have any plan for RegisterExtension?

Regards,
Steven

What you exactly mean?
You already can do any required work. May be little hardly in comparison with cefglue.1, but it is possible. We open for any proposals.
fddima
Master
 
Posts: 775
Joined: Tue Dec 07, 2010 6:10 am

Re: Xilium.CefGlue/3 & CefGlue/1

Postby sebarnolds » Fri Nov 09, 2012 10:27 am

Hello.

I am currently working with CefGlue 3 (latest version, for cef 899) and I have a problem with tooltips not being displayed (it was already the case in the previous version I was using). I checked the CefDisplayHandler class and the on_tooltip method is never called (breakpoint never reached).

Tooltips are correctly displayed on the page I am using when displayed in FireFox.

The HTML element is like this:
Code: Select all
<li><span onclick="javascript:mainViewModel.calendarEyeItemClick(\'#= Guid #\');" class="smallbox eventsbox eye#= Guid #" title="Voir les événements" style="background-color: #= WebColor() #"></span><span onclick="javascript:mainViewModel.templateClockItemClick(\'#= Guid #\');" class="smallbox slot#= Guid # timeslotsbox_grayed" title="Voir les plages horaires" style="background-color: #= WebColor() #"></span>#= Name #</li>'

The tooltip is specified with the "title" attribute.

I tried cefclient.exe which shown correctly the tooltips while the CefGlue.Demo.WinForms didn't.

Any idea ?

Thanks,
Sebastien
sebarnolds
Techie
 
Posts: 18
Joined: Fri Nov 09, 2012 10:16 am

Re: Xilium.CefGlue/3 & CefGlue/1

Postby fddima » Fri Nov 09, 2012 3:37 pm

sebarnolds wrote:I am currently working with CefGlue 3 (latest version, for cef 899) and I have a problem with tooltips not being displayed (it was already the case in the previous version I was using). I checked the CefDisplayHandler class and the on_tooltip method is never called (breakpoint never reached).

It is happens 'cause application manifest was be not included in image file. Update sources and you will got working solution (i.e. tooltips works same as in cefclient) in winforms application. What about on_tooltip, sorry, i'm doesn't know. Default implementation work only with manifest, custom impl (on_tooltip) also must work, but require investigation. May be you something miss, or it is real bug. If you interested in handling on_tooltip method, then try provide reproduction sample.
fddima
Master
 
Posts: 775
Joined: Tue Dec 07, 2010 6:10 am

PreviousNext

Return to CefGlue Forum

Who is online

Users browsing this forum: No registered users and 3 guests