1. CEF技术介绍
JS加载项以CEF为技术基础,加载项的JS代码是运行在CEF内部的。CEF内部提供接口比如执行JS代码
CefRefPtr<CefBrowser> browser = ...;
CefRefPtr<CefFrame> frame = browser->GetMainFrame();
frame->ExecuteJavaScript("alert('ExecuteJavaScript works!');",frame->GetURL(), 0);
比如JS对象绑定
void MyRenderProcessHandler::OnContextCreated(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context)
{
// Retrieve the context's window object.
CefRefPtr<CefV8Value> object = context->GetGlobal();
// Create a new V8 string value. See the "Basic JS Types" section below.
CefRefPtr<CefV8Value> str = CefV8Value::CreateString("My Value!");
// Add the string to the window object as "window.myval". See the "JS Objects" section below.
object->SetValue("myval", str, V8_PROPERTY_ATTRIBUTE_NONE);
}
JS加载项在这些技术的基础上面开发完整的JSAPI的接口,更多CEF的技术细节
可以查看下面的网站:
chromiumembedded / cef / wiki / Home — Bitbucket