Window JSBinding

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Window JSBinding

Postby albay » Mon Dec 17, 2012 5:00 am

Hi,

I am trying to implement window JSBinding by referring to http://code.google.com/p/chromiumembedded/wiki/JavaScriptIntegration#Extensions However function is not being invoked at all. Would you please have a look at the following codes and tell where I am doing wrong ?

CefV8Handler implementation

Code: Select all
public class HelloV8Handler : CefV8Handler
   {
      protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
      {
         if (name == "world")
         {
            returnValue = CefV8Value.CreateString("test();");
            exception = "";
            return true;
         }

         returnValue = CefV8Value.CreateUndefined();
         exception = "undefined method";
         return false;
      }
   }


RenderProcessHandler implementation

Code: Select all
public class RenderProcessHandler : CefRenderProcessHandler
   {
      protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context)
      {
         // Retrieve the 'window' object.
         var window = context.GetGlobal();

         CefV8Handler handler = new HelloV8Handler();

         CefV8Value obj = CefV8Value.CreateObject(null);
         obj.SetValue("world", CefV8Value.CreateFunction("world", handler), CefV8PropertyAttribute.None);
         obj.SetValue("str", CefV8Value.CreateString("hello world!"), CefV8PropertyAttribute.None);

         window.SetValue("hello", obj, CefV8PropertyAttribute.None);
         
         base.OnContextCreated(browser, frame, context);
      }
   }


HTML test page. Results are commented in code.


Code: Select all
<html>
<body>
 <script>
   window.hello.world();         // successfull binding but invocation didn't occur.
   alert(window.hello.world());  // displays "undefined"
   alert(window.hello.str);      // displays "hello world!" as expected.
   
   function test()
   {
   alert('js invocation from v8handler!');
   }
 </script>
</body>
</html>


Thanks in advance,

albay
albay
Newbie
 
Posts: 5
Joined: Mon Dec 17, 2012 4:43 am

Re: Window JSBinding

Postby albay » Mon Dec 17, 2012 6:05 am

In the meantime, when I set the parameter named 'exception' and call hello.world(), I am getting the exception successfully.

Code: Select all
if (name == "world")
         {
            returnValue = CefV8Value.CreateString("test");
            exception = "Exception, from HelloV8Handler!";
            return true;
         }


Image
http://imgur.com/KLOMf
albay
Newbie
 
Posts: 5
Joined: Mon Dec 17, 2012 4:43 am

Re: Window JSBinding

Postby magreenblatt » Mon Dec 17, 2012 6:15 am

Your example shows a string value of: "test();". Try using a string that doesn't look like a function call.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Window JSBinding

Postby albay » Mon Dec 17, 2012 6:22 am

Hi Marshal,

magreenblatt wrote:Your example shows a string value of: "test();". Try using a string that doesn't look like a function call.


I have already tried it but no luck. alert window displays "undefined".
albay
Newbie
 
Posts: 5
Joined: Mon Dec 17, 2012 4:43 am

Re: Window JSBinding

Postby magreenblatt » Mon Dec 17, 2012 6:23 am

What happens if you use CreateInt, CreateDouble, etc instead of CreateString?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Window JSBinding

Postby albay » Mon Dec 17, 2012 6:29 am

magreenblatt wrote:What happens if you use CreateInt, CreateDouble, etc instead of CreateString?


Please see the following screenshot. I can access the primitive data types successfully.

http://imgur.com/2609z
albay
Newbie
 
Posts: 5
Joined: Mon Dec 17, 2012 4:43 am

Re: Window JSBinding

Postby magreenblatt » Mon Dec 17, 2012 6:34 am

Sounds like a bug. You should file an issue with the wrapper project that you're using.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Window JSBinding

Postby albay » Mon Dec 17, 2012 6:37 am

magreenblatt wrote:Sounds like a bug. You should file an issue with the wrapper project that you're using.


Thank you. I will do it right away.
albay
Newbie
 
Posts: 5
Joined: Mon Dec 17, 2012 4:43 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 212 guests