本文整理汇总了C++中CefRefPtr::GetGlobal方法的典型用法代码示例。如果您正苦于以下问题:C++ CefRefPtr::GetGlobal方法的具体用法?C++ CefRefPtr::GetGlobal怎么用?C++ CefRefPtr::GetGlobal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CefRefPtr
的用法示例。
在下文中一共展示了CefRefPtr::GetGlobal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnContextCreated
void ClientHandler::OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context)
{
// Retrieve the context's window object.
CefRefPtr<CefV8Value> window = context->GetGlobal();
// Create an instance of my CefV8Handler object.
// In this case it's this object, and content will be executed in bool ClientHandler::Execute(...)
CefRefPtr<CefV8Handler> handler = this;
// Create a function.
CefRefPtr<CefV8Value> fn_sqlite_exec = CefV8Value::CreateFunction("db_exec", handler);
CefRefPtr<CefV8Value> fn_sqlite_select = CefV8Value::CreateFunction("db_select", handler);
// Create a new object
CefRefPtr<CefV8Value> cpp = CefV8Value::CreateObject(NULL);
// Add the object to windows JS: window.cpp
window->SetValue("cpp", cpp, V8_PROPERTY_ATTRIBUTE_NONE);
// Add the function to the object
cpp->SetValue("db_exec", fn_sqlite_exec, V8_PROPERTY_ATTRIBUTE_NONE);
cpp->SetValue("db_select", fn_sqlite_select, V8_PROPERTY_ATTRIBUTE_NONE);
}
示例2: OnContextCreated
/*--cef()--*/
void App::OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
// RENDERER PROCESS.
LOG_DEBUG << "OnContextCreated()";
CefRefPtr<CefV8Value> window = context->GetGlobal();
CefRefPtr<CefV8Handler> handler = GetJavascriptApi(browser);
if (!handler.get()) {
LOG_ERROR << "GetJavascriptApi() failed in OnContextCreated()";
return;
}
// Javascipt bindings.
// The phpdesktop object.
CefRefPtr<CefV8Value> phpdesktop = CefV8Value::CreateObject(NULL);
window->SetValue("phpdesktop", phpdesktop, V8_PROPERTY_ATTRIBUTE_READONLY);
// Methods.
const char* methods[] = {
"GetVersion",
"ToggleFullscreen",
"IsFullscreen",
NULL
};
for (int i = 0; methods[i] != NULL; i++) {
CefRefPtr<CefV8Value> method = CefV8Value::CreateFunction(
methods[i], handler);
phpdesktop->SetValue(method->GetFunctionName(), method,
V8_PROPERTY_ATTRIBUTE_READONLY);
}
}
示例3:
// synchronously send a string from Node to browser, then return string result from browser to Node
Handle<Value> Window::SendSync(const Arguments& args) {
HandleScope scope;
NativeWindow *window = ObjectWrap::Unwrap<NativeWindow> (args.This());
if (window->GetBrowser()) {
// find browser's v8 context
CefRefPtr<CefV8Context> context = window->GetBrowser()->GetMainFrame()->GetV8Context();
// ensure it's usable and enter
if (context.get() && context->Enter()) {
// try to get "appjs.onmessage" function
CefRefPtr<CefV8Value> appjsObject = context->GetGlobal()->GetValue("appjs");
CefRefPtr<CefV8Value> callback = appjsObject->GetValue("onmessage");
if (callback.get()) {
// convert Node V8 string to Cef V8 string
CefV8ValueList argsOut;
argsOut.push_back(CefV8Value::CreateString(V8StringToChar(args[0]->ToString())));
// execute window.appjs fuction, passing in the string,
// then convert the return value from a CefValue to a Node V8 string
Handle<String> ret = CefStringToV8(callback->ExecuteFunction(appjsObject, argsOut)->GetStringValue());
// exit browser v8 context, return string result to Node caller
context->Exit();
return scope.Close(ret);
}
}
}
// likely error condition
return scope.Close(Undefined());
}
示例4: registerFunctions
void OverloadApp::registerFunctions(CefRefPtr<CefListValue> functionNames)
{
if (_browser != nullptr)
{
CefRefPtr<CefV8Context> currentContext = _browser->GetMainFrame()->GetV8Context();
currentContext->Enter();
CefRefPtr<CefV8Value> object = currentContext->GetGlobal();
for (std::size_t i = 0; i < functionNames->GetSize(); i++)
{
std::string functionName = functionNames->GetString(i).ToString();
object->SetValue(functionName, CefV8Value::CreateFunction(functionName, _v8Handler.get()), V8_PROPERTY_ATTRIBUTE_NONE);
_functionNames.push_back(functionName);
}
currentContext->Exit();
}
else
{
for (std::size_t i = 0; i < functionNames->GetSize(); i++)
{
_functionNames.push_back(functionNames->GetString(i).ToString());
}
}
}
示例5: OnContextCreated
void ClientHandler::OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
REQUIRE_UI_THREAD();
// Add the V8 bindings.
InitBindingTest(browser, frame, context->GetGlobal());
}
示例6: OnContextCreated
void ClientApp::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
{
//Register our JS functions
CefRefPtr<CefV8Value> object = context->GetGlobal();
for(int f = 0; f < __countof(func_names); f++){
CefRefPtr<CefV8Value> func = CefV8Value::CreateFunction(func_names[f], this);
object->SetValue(func_names[f], func, V8_PROPERTY_ATTRIBUTE_NONE);
}
}
示例7: OnContextCreated
void Application::OnContextCreated( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context )
{
HL_DEBUG(logger, "create native JS bridge object");
CefRefPtr<CefV8Value> global = context->GetGlobal();
_exposedJSObject = CefV8Value::CreateObject(NULL);
CefRefPtr<CefV8Value> exec = CefV8Value::CreateFunction("exec", this);
_exposedJSObject->SetValue("exec", exec, V8_PROPERTY_ATTRIBUTE_READONLY);
global->SetValue("_cordovaNative", _exposedJSObject, V8_PROPERTY_ATTRIBUTE_READONLY);
}
示例8: OnContextCreated
void CefAppUnmanagedWrapper::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
{
auto wrapper = FindBrowserWrapper(browser->GetIdentifier(), true);
if (wrapper->JavascriptRootObject != nullptr || wrapper->JavascriptAsyncRootObject != nullptr)
{
wrapper->JavascriptRootObjectWrapper = gcnew JavascriptRootObjectWrapper(browser->GetIdentifier(), wrapper->JavascriptRootObject, wrapper->JavascriptAsyncRootObject, wrapper->BrowserProcess);
wrapper->JavascriptRootObjectWrapper->Bind(context->GetGlobal());
}
};
示例9: HandleSetValueMessage
bool FUnrealCEFSubProcessRemoteScripting::HandleSetValueMessage(CefRefPtr<CefBrowser> Browser, CefRefPtr<CefListValue> MessageArguments)
{
CefRefPtr<CefFrame> MainFrame = Browser->GetMainFrame();
CefRefPtr<CefV8Context> Context = MainFrame->GetV8Context();
ScopedV8Context ContextScope(Context);
CefRefPtr<CefV8Value> RootObject = Context->GetGlobal()->GetValue("ue");
if (!RootObject.get())
{
// The root object should always be created on context creation.
return false;
}
for (size_t I = 0; I < MessageArguments->GetSize(); I++)
{
if (MessageArguments->GetType(I) != VTYPE_DICTIONARY)
{
return false;
}
CefRefPtr<CefDictionaryValue> Argument = MessageArguments->GetDictionary(I);
if (Argument->GetType("name") != VTYPE_STRING
|| Argument->GetType("value") != VTYPE_DICTIONARY
|| Argument->GetType("permanent") != VTYPE_BOOL)
{
// Wrong message argument types or count
return false;
}
CefString Name = Argument->GetString("name");
CefRefPtr<CefDictionaryValue> CefValue = Argument->GetDictionary("value");
bool bPermanent = Argument->GetBool("permanent");
if (bPermanent)
{
int32 BrowserID = Browser->GetIdentifier();
CefRefPtr<CefDictionaryValue> Bindings;
if (PermanentBindings.Contains(BrowserID))
{
Bindings = PermanentBindings[BrowserID];
}
else
{
Bindings = CefDictionaryValue::Create();
PermanentBindings.Add(BrowserID, Bindings);
}
Bindings->SetDictionary(Name, CefValue);
}
CefRefPtr<CefV8Value> Value = CefToV8(CefValue);
RootObject->SetValue(Name, Value, V8_PROPERTY_ATTRIBUTE_NONE);
}
return true;
}
示例10: OnContextCreated
void ClientHandler::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) {
REQUIRE_UI_THREAD();
if (!browser->IsPopup()) {
context->Enter();
CefRefPtr<CefV8Value> appjsObj = CefV8Value::CreateObject(NULL);
CefRefPtr<CefV8Value> func = CefV8Value::CreateFunction("send", new AppjsSyncHandler(browser));
context->GetGlobal()->SetValue("appjs", appjsObj, V8_PROPERTY_ATTRIBUTE_NONE);
appjsObj->SetValue("send", func, V8_PROPERTY_ATTRIBUTE_NONE);
context->Exit();
}
}
示例11: OnContextCreated
void ClientApp::OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
RenderDelegateSet::iterator it = render_delegates_.begin();
for (; it != render_delegates_.end(); ++it)
(*it)->OnContextCreated(this, browser, frame, context);
// JavaScript context created, add V8 bindings here...
CefRefPtr<CefV8Value> window = context->GetGlobal();
XCefAppManage::Instance()->CallbackLoad(window, context);
}
示例12: OnContextCreated
void ClientHandler::OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
REQUIRE_UI_THREAD();
CefRefPtr<CefV8Value> object = context->GetGlobal();
// Add the V8 bindings.
binding_test::InitTest(browser, frame, object);
std::string url = frame->GetURL();
if (url == performance_test::kTestUrl)
performance_test::InitTest(browser, frame, object);
}
示例13: OnContextCreated
void CefAppUnmanagedWrapper::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
{
auto wrapper = FindBrowserWrapper(browser, true);
if (wrapper->JavascriptRootObject != nullptr)
{
auto window = context->GetGlobal();
wrapper->JavascriptRootObjectWrapper = gcnew JavascriptRootObjectWrapper(wrapper->JavascriptRootObject, wrapper->BrowserProcess);
wrapper->JavascriptRootObjectWrapper->V8Value = window;
wrapper->JavascriptRootObjectWrapper->Bind();
}
};
示例14: OnContextCreated
void App::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
{
CefRefPtr<CefV8Value> global_object = context->GetGlobal();
CefRefPtr<CefV8Value> gengine_object = CefV8Value::CreateObject(nullptr);
CefRefPtr<CefV8Value> gui_object = CefV8Value::CreateObject(nullptr);
CefRefPtr<CefV8Value> execute_func = CefV8Value::CreateFunction("gengine_execute", new LocalExecute());
CefRefPtr<CefV8Value> gui_showpage_func = CefV8Value::CreateFunction("gengine_gui_showpage", new LocalShowPage());
gui_object->SetValue("showPage", gui_showpage_func, V8_PROPERTY_ATTRIBUTE_NONE);
gengine_object->SetValue("execute", execute_func, V8_PROPERTY_ATTRIBUTE_NONE);
gengine_object->SetValue("gui", gui_object, V8_PROPERTY_ATTRIBUTE_NONE);
global_object->SetValue("gengine", gengine_object, V8_PROPERTY_ATTRIBUTE_NONE);
}
示例15: OnContextCreated
void RenderProcessHandler::OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
// Retrieve the context's window object.
CefRefPtr<CefV8Value> object = context->GetGlobal();
CefRefPtr<CefV8Handler> handler = new AsyncMethodHandler(browser);
for (auto i = EXPORTED_FUNCTIONS.cbegin(); i != EXPORTED_FUNCTIONS.cend(); i++) {
CefRefPtr<CefV8Value> func = CefV8Value::CreateFunction(*i, handler);
object->SetValue(*i,
func,
V8_PROPERTY_ATTRIBUTE_NONE);
}
}