Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New functions? #3

Open
zbozo opened this issue Aug 28, 2018 · 12 comments
Open

New functions? #3

zbozo opened this issue Aug 28, 2018 · 12 comments

Comments

@zbozo
Copy link

zbozo commented Aug 28, 2018

Hello, i noticed that your branch develop has some functions but I did not see any use of them, could you tell me what it does?

Cef3DBrowser::CreateJsObject

thank you

@0x61726b
Copy link
Owner

0x61726b commented Aug 28, 2018

Hi, this project is pretty much dead. I've added C++ -> javascript integration to use in another project and that was pretty much it. It sets a javascript object from C++ side so you can access the variables in javascript.

@zbozo
Copy link
Author

zbozo commented Aug 28, 2018

is a great project, awesomium has been unavailable for a long time, I ended up finding your project, apparently it is very light because it is an old version of cef, it is good for games
I'm going to use it, how should I call the variables in js for

Cef3DJsValue test("test", "my string");
this->CreateJsObject(test);

@0x61726b
Copy link
Owner

That would be window.test in javascript. Here is a sample project where i did use those stuff.

https://github.com/arkenthera/cef3d/tree/develop/Demos/MMD_Nowplaying

@zbozo
Copy link
Author

zbozo commented Aug 29, 2018

It's what I tested, it's giving undefined, I thought it would be another way :(

@0x61726b
Copy link
Owner

When are you calling CreateJsObject ? Can you post your full code?

@zbozo
Copy link
Author

zbozo commented Aug 29, 2018

Cef3DRenderer::OnProcessMessageReceived
http://prntscr.com/ko9ysr
(i received all msgbox)

SampleBrowser::OnAfterCreated
http://prntscr.com/koa1j0
(i received the messagebox)

My html code:

<!DOCTYPE html>
<html>
<head>
    <script>
        window.addEventListener('load', function() {
            var myelement = document.getElementById("xx");
            myelement.innerHTML = window.test;
        })
    </script>
</head>
<div id="xx">???</div>
</body>
</html>

Is there any way to send javascript values to the client like in awesomium?
http://prntscr.com/koa7va

The only way I found it was using V8::Execute in the subprocess, however, it does not have access to client variables to return the requested values in javascript
It would also be a more dynamic form because whenever requested will take the current value of the variable instead of the fixed value

@0x61726b
Copy link
Owner

Yes, though that is a little more complicated. In the video below i was using a color picker from html side to send color values to c++. I will do a write-up when i have time(sometime today) about how you can do that.

https://youtu.be/CvzLLPfRe34

@zbozo
Copy link
Author

zbozo commented Aug 29, 2018

oh ok, thank you very much :P

@0x61726b
Copy link
Owner

So, here I will try to explain but bear with me since its been few years since I last worked on this.

To be able to call C++ code from Javascript, first you need an "extension".

The extension is a javascript code which will be uploaded by renderer process. Internally, when this javascript code is called on the client, it will call V8Handler::Execute, we will catch this and create an IPC message to let the Browser process know that an event has occured. In the Browser process, we catch this IPC message with the data and forward it to the listeners and do whatever you want with it.

Note that all javascript stuff happens in Renderer process so you need to do IPC messaging to communicate with it. Below I will list sample code step by step so you can inspect it and implement yourself.

Here is a sample extension code. Attention to the native keyword, as it is required by extensions. This code will be loaded in renderer process which then you will call CefRegisterExtension when Webkit is initialized.

When, for example, native function SendDomEvent is called on Javascript side, it will invoke V8Handler::Execute here and we will create an IPC to let the browser know.

Then in browser process, we catch this IPC and after that its up to you to whatever you want with it.

Here is an example of turning a check box on and off, and letting the C++ side know about it.

Cef3D.SendDomEvent(this.onSendDomEvent,$(element.target).attr("id"),"InputChecked","" + $(element.target).is(':checked') + "");

This will then be catched here.

I hope this helps!

@zbozo
Copy link
Author

zbozo commented Aug 30, 2018

I am very grateful for the explanation and the codes shown
-- removed
oh, sorry, I got it fixed, I was running the wrong javascript, after hours I realized 👍

I finally managed to make interaction

@0x61726b
Copy link
Owner

I am not really sure what's happening there. Maybe check if Cef3DRendererApp::OnContextReleased is called or not to understand maybe something is causing that context to be invalid, thus crashing on Enter() ?

@0x61726b
Copy link
Owner

Just saw your edit, nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants