How can I support window.external.xxx in cef framework - javascript

I want to switch from an embedded IE activeX to the libcef framework. My web project's javascript call C++ function use window.external.xxx method. But I can't get window.external object in cef framework. I try to bind my c++ function in window object. sadly, it doesn't work for me.
My code for binding c++ function to window object is like that:
CefRefPtr<CefV8Value> ptrGlobalObj = context->GetGlobal();
CefRefPtr<CefV8Value> jsCallOrthoLink = CefV8Value::CreateFunction(_T("CallOrthoLink"), m_ptrV8Handler);
ptrGlobalObj->SetValue(_T("CallOrthoLink"), jsCallOrthoLink, V8_PROPERTY_ATTRIBUTE_NONE);
I test it with window.xxx method in javascript. it works. so I know my bind codes are correctly.
How can I fixed this issue with window.external.xxxx method?

Try this:
external = CefV8Value::CreateObject(NULL, NULL)
external->SetValue("CallOrthoLink", jsCallOrthoLink, V8_PROPERTY_ATTRIBUTE_NONE)
global->SetValue("external", external, V8_PROPERTY_ATTRIBUTE_NONE)

Related

Angular 2 application breaks when HTMLElement.prototype.addEventListener is modified

I am trying to instrument an application using some JS monkey-patching. I am testing my monkey-patch using the Angular-JumpStart application. But when I try to do even the simplest thing with HTMLElement.addEventListener function, it breaks the application. For instance, executing something like:
(function() {
var originalAEL = HTMLElement.prototype.addEventListener;
HTMLElement.prototype.addEventListener = originalAEL;
})();
breaks the application - the component's template is unable to find any values bound in the component class . What could possibly be happening here?
Replacing HTMLElement with EventTarget works - I am not sure why though.

OnContextCreated() in Cef not being called

I have a similar problem to the person in this post; I'm trying to extend the cefsimple.exe app included with the chromium embedded framework binaries to include a V8 handler. I implemented the OnContextCreated() method and made sure to extend RenderProcessHandler in the SimpleHandler class. I'm trying to implement a simple window bound variable called test_string; here's what my code looks like;
void SimpleHandler::OnContextCreated(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context)
{
CefRefPtr<CefV8Value> object = context->GetGlobal();
object->SetValue("test_string", CefV8Value::CreateString("this is a test"), V8_PROPERTY_ATTRIBUTE_NONE);
}
But the program never arrives at any breakpoints I add within the method, and the variable is undefined on any webpages I load within the app. I saw that one of the solutions in the other thread is to enable the settings.single_process flag, which i've done, but my code still doesn't reach the breakpoint.
To be clear, I'm accessing the variable on pages with window.test_string.
Make sure that you are sending that CefApp to CefExecuteProcess.
CefRefPtr<SimpleApp> app(new SimpleApp);
// CEF applications have multiple sub-processes (render, plugin, GPU, etc)
// that share the same executable. This function checks the command-line and,
// if this is a sub-process, executes the appropriate logic.
int exit_code = CefExecuteProcess(main_args, app, sandbox_info);
if (exit_code >= 0) {
// The sub-process has completed so return here.
return exit_code;
}
Found this solution here
Have you read through the General Usage guide? Some key points below
https://bitbucket.org/chromiumembedded/cef/wiki/GeneralUsage#markdown-header-cefapp
https://bitbucket.org/chromiumembedded/cef/wiki/GeneralUsage#markdown-header-processes
The single_process mode is not supported so I've never used it. In general I'd avoid it. The multi process architecture means you need to attach the debugger to the process. The Chromium guide is relevant to CEF in this instance.
https://www.chromium.org/developers/how-tos/debugging-on-windows#TOC-Attaching-to-the-renderer
you need to ensure your App is derived from CefRenderProcessHandler
not SimpleHandler!!!
class SimpleApp : public CefApp
, public CefRenderProcessHandler
{
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) OVERRIDE;
valdemar-rudolfovich says you need to pass instance of SimpleApp in
CefExecuteProcess

Create a JSAPIPtr in javascript side of firebreath

I have a requirement as follows:
I wanted to initialize a user-defined class inheriting from FB::JSAPIAuto but I wanted to create it plugin independent..like
In JS, earlier i used to do this::
plugin().CreateJSAPIObject("someParameter");
//in order to initialize the c++ object with a value..It was successfully compiling..
What I want to do is to create a c++ object plugin independent
So in JS>>
UserDefinedJSAPIClassPtr obj=new UserDefinedJSAPIClass();
obj->SetMember1="This is Member 1";
//not necessarily using new keyword
plugin().DoSomethingWithObject(obj);
I came to know of boost::clipp library..and other numerous frameworks but am finding difficulty...as everything is strongly tied to the root JSAPI.
My doubt>>Is this possible?
My objective later on>>
P.S:: DoSomethingWithObject(FB::variant& object) will get the members of the JSAPI object (set in the JS side) and process them
EDIT after Taxilian's answer::
what in the case of this,
In JS side,
function AnotherJavascriptfunction(member1)
{
member1='2';
}
var UserClass=function(color,settings){}
var userObject=new UserClass('Red',AnotherJavascriptfunction);
plugin().DoTheChanges(userObject);
In FB side,
how do i access member1.?
which method should i Look for to get the member of settings
Regards,
Pratik
Definitely not possible to create a JSAPIPtr from javascript, but you can create a normal javascript object and pass it into a JSAPI method; it'll be a FB::JSObjectPtr type and you can then call methods/properties on it using Invoke, GetProperty, SetProperty, etc.

how to call dlls from java script

Can any one please help me how to call dll functions from javascript. while using activexobject I am getting error "automation server cannot create object". Here is my code
var jMyAcctId = document.all.RefNum.value;
var jMyAcctType = document.all.TrxType.value;
var NewObject = new ActiveXObject("HDMFCDV.cdv");
if (NewObject.IsValidID(jMyAcctId,jMyAcctType) == true)
{
document.all.RefNumError.innerText = "";
CnvUp(sel);
document.all.CustFName.disabled = false;
document.all.CustFName.focus();
}
Thanak in advance.
Your JavaScript code is good. I suspect the problem is with the HDMFCDV.cdv ActiveX - either they way you implemented it or they way you registered it.
I'm not familiar with HDMFCDV object. Is that a proprietary object you implemented? Here are few tips to troubleshoot:
Make sure your object is registered (did you run regsrv32?)
Verify HDMFCDF.cdv is in the registry: HKCR\HDMFCDF.cdv
Make sure there is a CLSID
Make sure the class ID is in the registry, and that it points to the DLL implementing your object. HKCR\CLSID{your-guide}\InprocServer32 (REG_SZ)
A very common lookout: have you implemented IObjectSafety. Without this interface, and without this interface returning that it is safe for untrusted caller, IE will refuse to instantiate this object

How to call javascript from applet without use showDocument?

I'm using
getAppletContext().showDocument(new URL("javascript:" + command));
to call javascript from applet.
But sometimes in firefox this doen't work, I don't know why.
So, now I'm trying to use JSObject, using this:
JSObject jsObject = new JSObject();
jsObject.eval(command);
But I got this error:
Exception in thread "thread applet-com.foo.bar.TestApplet-6"
java.lang.InstantiationError: netscape.javascript.JSObject
Why I'm getting this error?
There is another way to do java applet to javascript communication?
I'm using
JSObject jsObject = JSObject.getWindow(this);
jsObject.eval(....);
And it works now.

Categories