当前位置: 首页>>代码示例>>C++>>正文


C++ CefRefPtr::GetGlobal方法代码示例

本文整理汇总了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);
}
开发者ID:eunshi,项目名称:CEFSimpleSampleSQLite3-WithBinaries,代码行数:25,代码来源:ClientHandler.cpp

示例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);
    }
}
开发者ID:ARSrabon,项目名称:phpdesktop,代码行数:30,代码来源:app.cpp

示例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());
}
开发者ID:chorfa672m,项目名称:appjs,代码行数:34,代码来源:appjs_window.cpp

示例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());
		}
	}
}
开发者ID:TomRouillard,项目名称:Overload,代码行数:25,代码来源:overloadApp.cpp

示例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());
}
开发者ID:AlloyTeam,项目名称:webtop,代码行数:8,代码来源:client_handler.cpp

示例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);
	}			
}
开发者ID:guowei8412,项目名称:upp-mirror,代码行数:9,代码来源:ClientApp.cpp

示例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);
}
开发者ID:hsimpson,项目名称:cordova-cef,代码行数:9,代码来源:application.cpp

示例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());
        }
    };
开发者ID:haozhouxu,项目名称:CefSharp,代码行数:10,代码来源:CefAppUnmanagedWrapper.cpp

示例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;
}
开发者ID:amyvmiwei,项目名称:UnrealEngine4,代码行数:54,代码来源:UnrealCEFSubProcessRemoteScripting.cpp

示例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();
  }
}
开发者ID:chorfa672m,项目名称:appjs,代码行数:11,代码来源:cef_handler.cpp

示例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);
}
开发者ID:Zion-007,项目名称:XCef,代码行数:12,代码来源:client_app.cpp

示例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);
}
开发者ID:airpfei,项目名称:cef1,代码行数:14,代码来源:client_handler.cpp

示例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();
        }
    };
开发者ID:CharlesPang,项目名称:CefSharp,代码行数:14,代码来源:CefAppUnmanagedWrapper.cpp

示例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);
}
开发者ID:gogoprog,项目名称:gengine-old,代码行数:15,代码来源:gui_cef_app.cpp

示例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);
    }
}
开发者ID:Xinkai,项目名称:QtMetaObjectWithCef,代码行数:15,代码来源:RenderProcessHandler.cpp


注:本文中的CefRefPtr::GetGlobal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。