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);
}
Exemple #2
0
/*--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);
    }
}
Exemple #3
0
// 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());
}
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());
		}
	}
}
Exemple #5
0
void NUIApp::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
{
	CefRefPtr<CefV8Value> window = context->GetGlobal();

	window->SetValue("registerPollFunction", CefV8Value::CreateFunction("registerPollFunction", this), V8_PROPERTY_ATTRIBUTE_READONLY);
	window->SetValue("registerFrameFunction", CefV8Value::CreateFunction("registerFrameFunction", this), V8_PROPERTY_ATTRIBUTE_READONLY);
	window->SetValue("invokeNative", CefV8Value::CreateFunction("invokeNative", this), V8_PROPERTY_ATTRIBUTE_READONLY);
}
Exemple #6
0
void ClientHandler::OnContextCreated(CefRefPtr<CefBrowser> browser,
                                     CefRefPtr<CefFrame> frame,
                                     CefRefPtr<CefV8Context> context) {
  REQUIRE_UI_THREAD();

  // Add the V8 bindings.
  InitBindingTest(browser, frame, context->GetGlobal());
}
Exemple #7
0
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);
	}			
}
Exemple #8
0
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);
}
    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());
        }
    };
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;
}
Exemple #11
0
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();
  }
}
Exemple #12
0
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);
}
Exemple #13
0
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);
}
    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();
        }
    };
Exemple #15
0
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);
}
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);
    }
}
void FUnrealCEFSubProcessRemoteScripting::OnContextCreated(CefRefPtr<CefBrowser> Browser, CefRefPtr<CefFrame> Frame, CefRefPtr<CefV8Context> Context)
{
	ScopedV8Context ContextScope(Context);
	CefRefPtr<CefV8Value> Global = Context->GetGlobal();
	if ( !Global->HasValue("ue") )
	{
		Global->SetValue("ue", CefV8Value::CreateObject(nullptr), V8_PROPERTY_ATTRIBUTE_DONTDELETE);
	}
	CefRefPtr<CefV8Value> RootObject = Context->GetGlobal()->GetValue("ue");

	int32 BrowserID = Browser->GetIdentifier();

	if (PermanentBindings.Contains(BrowserID))
	{
		CefRefPtr<CefDictionaryValue> Bindings = PermanentBindings[BrowserID];
		CefDictionaryValue::KeyList Keys;
		Bindings->GetKeys(Keys);
		for (CefString Key : Keys)
		{
			CefRefPtr<CefV8Value> Value = CefToV8(Bindings->GetDictionary(Key));
			RootObject->SetValue(Key, Value, V8_PROPERTY_ATTRIBUTE_NONE);
		}
	}
}
void V8_Container::AddContainerArray(CefRefPtr<CefV8Context> context, std::string js_var_name, int arraySize)
{
    if (context->Enter())
    {
        CefRefPtr<CefV8Value> array = CefV8Value::CreateArray(arraySize);
        for (int i = 0; i < arraySize; i++)
        {
            array->SetValue(i, CreateContainerV8Object());
        }

        // Add empty array of container objects to context's global object
        context->GetGlobal()->SetValue(js_var_name, array, V8_PROPERTY_ATTRIBUTE_NONE);
        context->Exit();
    }
}
Exemple #19
0
void OverloadApp::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
{
	REQUIRE_UI_THREAD();
	_v8Handler = new V8Handler(*this);
	if (frame->IsMain())
	{
		CefRefPtr<CefV8Value> object = context->GetGlobal();

		for (std::size_t i = 0; i < _functionNames.size(); i++)
		{
			object->SetValue(_functionNames[i], CefV8Value::CreateFunction(_functionNames[i], _v8Handler.get()), V8_PROPERTY_ATTRIBUTE_NONE);
		}
	}	
	_browser = browser;
}
Exemple #20
0
void neutron_app::OnContextCreated(CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame,
    CefRefPtr<CefV8Context> context) {

    // Get 'window'
    auto window = context->GetGlobal();

    // Create 'neutron' object
    CefRefPtr<CefV8Accessor> accessor = m_broker;
    auto neutron = CefV8Value::CreateObject(accessor);
    neutron->SetValue("flob", V8_ACCESS_CONTROL_DEFAULT, V8_PROPERTY_ATTRIBUTE_NONE);

    // Store it
    window->SetValue("neutron", neutron, static_cast<cef_v8_propertyattribute_t>(
        V8_PROPERTY_ATTRIBUTE_READONLY | V8_PROPERTY_ATTRIBUTE_DONTENUM | V8_PROPERTY_ATTRIBUTE_DONTDELETE));
}
void ClientAppRender::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
{
	// Retrieve the context's window object.
	CefRefPtr<CefV8Value> object = context->GetGlobal();

	// Create an instance of my CefV8Handler object.
	CefRefPtr<CefV8Handler> handler = new V8Handler();

	for (const auto& funName : V8WindowFunciotn::Functions)
	{

		// Create the "myfunc" function.
		CefRefPtr<CefV8Value> func = CefV8Value::CreateFunction(funName, handler);

		// Add the "myfunc" function to the "window" object.
		object->SetValue(funName, func, V8_PROPERTY_ATTRIBUTE_NONE);
	}

}
Exemple #22
0
void Application::OnContextCreated(
    CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame,
    CefRefPtr<CefV8Context> context
) {
    CefRefPtr<CefV8Value> global = context->GetGlobal();

    CefRefPtr<CefV8Value> notification = CefV8Value::CreateFunction("Notification", this);
    global->SetValue("Notification", notification, V8_PROPERTY_ATTRIBUTE_READONLY);

    if (this->firstBrowser != NULL) {
        // Disallow window.open

        CefRefPtr<CefV8Value> openWindow = CefV8Value::CreateFunction("openWindow", this);
        global->SetValue("open", openWindow, V8_PROPERTY_ATTRIBUTE_READONLY);

        // have first window debugger connect to the new browser
        firstBrowser->GetMainFrame()->ExecuteJavaScript("onNewBrowser();", "NewBrowser.js", 0);
        return;
    }
    this->firstBrowser = browser;

    this->leprechaunObj = CefV8Value::CreateObject(0);
    CefRefPtr<CefV8Value> exit = CefV8Value::CreateFunction("exit", this);
    this->leprechaunObj->SetValue("exit", exit, V8_PROPERTY_ATTRIBUTE_READONLY);
    CefRefPtr<CefV8Value> echo = CefV8Value::CreateFunction("echo", this);
    this->leprechaunObj->SetValue("echo", echo, V8_PROPERTY_ATTRIBUTE_READONLY);
    CefRefPtr<CefV8Value> open = CefV8Value::CreateFunction("open", this);
    this->leprechaunObj->SetValue("open", open, V8_PROPERTY_ATTRIBUTE_READONLY);

    CefRefPtr<CefV8Value> onConsoleMessage = CefV8Value::CreateFunction("onConsoleMessage", this);
    this->leprechaunObj->SetValue("onConsoleMessage", onConsoleMessage, V8_PROPERTY_ATTRIBUTE_NONE);
    CefRefPtr<CefV8Value> onError = CefV8Value::CreateFunction("onError", this);
    this->leprechaunObj->SetValue("onError", onError, V8_PROPERTY_ATTRIBUTE_NONE);
    CefRefPtr<CefV8Value> log = CefV8Value::CreateFunction("log", this);
    this->leprechaunObj->SetValue("log", log, V8_PROPERTY_ATTRIBUTE_READONLY);

    CefRefPtr<CefV8Value> args = CefV8Value::CreateArray(0);
    this->leprechaunObj->SetValue("args", args, V8_PROPERTY_ATTRIBUTE_NONE);

    global->SetValue("leprechaun", this->leprechaunObj, V8_PROPERTY_ATTRIBUTE_READONLY);
}
			virtual void OnContextCreated(CefRefPtr<ClientAppRenderer> app,
				CefRefPtr<CefBrowser> browser,
				CefRefPtr<CefFrame> frame,
				CefRefPtr<CefV8Context> context) override
			{
				CefRefPtr<CefV8Value> object = context->GetGlobal();

				CefRefPtr<CefV8Handler> handler = new ChiV8();

				int functionListSize = jsCpp.size();

				if (functionListSize > 0)
				{
					for (std::map<std::string, enum JsEnum>::iterator iter = jsCpp.begin(); iter != jsCpp.end(); iter++)
					{
						object->SetValue(kNamespace + iter->first,
							CefV8Value::CreateFunction(kNamespace + iter->first, handler),
							V8_PROPERTY_ATTRIBUTE_READONLY);
					}
				}
			}
CefRefPtr<CefV8Value> IPC_Container::GetAttributesV8Value(
    CefRefPtr<CefV8Context> context,
    std::string array_variable,
    int obj_index_in_array,
    ContainerAttribute attr)
{
    CefRefPtr<CefV8Value> containerObjArray = context->GetGlobal()->GetValue(array_variable);

    if (obj_index_in_array < containerObjArray->GetArrayLength())
    {
        CefRefPtr<CefV8Value> containerObj = containerObjArray->GetValue(obj_index_in_array);

        // Get objects attribute by attribute's name
        return containerObj->GetValue(attr.GetName());
    }
    else
    {
        // DLOG(WARNING) << "WARNING: V8ArrayLength not as big as expected!";
        // TODO: Handle NULL in following steps...
        return CefV8Value::CreateNull();
    }
}
    void CefAppUnmanagedWrapper::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
    {
        //Send a message to the browser processing signaling that OnContextCreated has been called
        //only param is the FrameId. Currently an IPC message is only sent for the main frame - will see
        //how viable this solution is and if it's worth expanding to sub/child frames.
        if (frame->IsMain())
        {
            auto contextCreatedMessage = CefProcessMessage::Create(kOnContextCreatedRequest);

            SetInt64(contextCreatedMessage->GetArgumentList(), 0, frame->GetIdentifier());

            browser->SendProcessMessage(CefProcessId::PID_BROWSER, contextCreatedMessage);
        }

        auto browserWrapper = FindBrowserWrapper(browser->GetIdentifier(), true);

        auto rootObjectWrappers = browserWrapper->JavascriptRootObjectWrappers;
        auto frameId = frame->GetIdentifier();

        JavascriptRootObjectWrapper^ rootObject;
        if (!rootObjectWrappers->TryGetValue(frameId, rootObject))
        {
            rootObject = gcnew JavascriptRootObjectWrapper(browser->GetIdentifier(), browserWrapper->BrowserProcess);
            rootObjectWrappers->TryAdd(frameId, rootObject);
        }

        if (rootObject->IsBound)
        {
            LOG(WARNING) << "A context has been created for the same browser / frame without context released called previously";
        }
        else
        {
            if (!Object::ReferenceEquals(_javascriptRootObject, nullptr) || !Object::ReferenceEquals(_javascriptAsyncRootObject, nullptr))
            {
                rootObject->Bind(_javascriptRootObject, _javascriptAsyncRootObject, context->GetGlobal());
            }
        }
    };
Exemple #26
0
void RenderProcessApp::OnContextCreated(CefRefPtr<CefBrowser> browser,
										CefRefPtr<CefFrame> frame,
										CefRefPtr<CefV8Context> context)
{

	if(CefCurrentlyOn(TID_RENDERER) == false)
	{
		return;
	}
	
	CefRefPtr<CefV8Value> window = context->GetGlobal();

	CefRefPtr<V8Handler> handler = new V8Handler(this);

	CefV8Value::PropertyAttribute attributes = static_cast<CefV8Value::PropertyAttribute>(V8_PROPERTY_ATTRIBUTE_READONLY |
																								V8_PROPERTY_ATTRIBUTE_DONTENUM |
																								V8_PROPERTY_ATTRIBUTE_DONTDELETE);

	CefRefPtr<CefV8Value> invoke = CefV8Value::CreateFunction(invoke_host_call, handler.get());
	window->SetValue(invoke_host_call, invoke, attributes);

	
}
  class Handler : public CefV8Handler {
   public:
    Handler() {}
    virtual bool Execute(const CefString& name,
                         CefRefPtr<CefV8Value> object,
                         const CefV8ValueList& arguments,
                         CefRefPtr<CefV8Value>& retval,
                         CefString& exception) OVERRIDE { return true; }
    IMPLEMENT_REFCOUNTING(Handler);
  };

  CefString name = "name";
  CefRefPtr<CefV8Handler> handler = new Handler();
  CefRefPtr<CefV8Value> func = CefV8Value::CreateFunction(name, handler);
  CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
  CefRefPtr<CefV8Value> obj = context->GetGlobal();
  CefV8ValueList args;

  PERF_ITERATIONS_START()
  func->ExecuteFunctionWithContext(context, obj, args);
  PERF_ITERATIONS_END()
}

PERF_TEST_FUNC(V8ObjectCreate) {
  PERF_ITERATIONS_START()
  CefRefPtr<CefV8Value> value = CefV8Value::CreateObject(NULL);
  PERF_ITERATIONS_END()
}

PERF_TEST_FUNC(V8ObjectCreateWithAccessor) {
  class Accessor : public CefV8Accessor {
Exemple #28
0
void ClientApp::OnContextCreated( CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefV8Context> context )
{
	CefRefPtr<CefV8Value> object = context->GetGlobal();
	CefRefPtr<CefV8Value> OSSClient = CefV8Value::CreateObject(NULL);
	object->SetValue("OSSClient",OSSClient,V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Handler> handler=new CMyV8Handler;

	CefRefPtr<CefV8Value> getAccessID = CefV8Value::CreateFunction("getAccessID", handler);
	OSSClient->SetValue("getAccessID", getAccessID, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> getRamSignature = CefV8Value::CreateFunction("getRamSignature", handler);
	OSSClient->SetValue("getRamSignature", getRamSignature, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> getSignature = CefV8Value::CreateFunction("getSignature", handler);
	OSSClient->SetValue("getSignature", getSignature, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> addFile = CefV8Value::CreateFunction("addFile", handler);
	OSSClient->SetValue("addFile", addFile, V8_PROPERTY_ATTRIBUTE_NONE);
	
	CefRefPtr<CefV8Value> saveFile = CefV8Value::CreateFunction("saveFile", handler);
	OSSClient->SetValue("saveFile", saveFile, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> saveFileDlg = CefV8Value::CreateFunction("saveFileDlg", handler);
	OSSClient->SetValue("saveFileDlg", saveFileDlg, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> selectFileDlg = CefV8Value::CreateFunction("selectFileDlg", handler);
	OSSClient->SetValue("selectFileDlg", selectFileDlg, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> getUpload = CefV8Value::CreateFunction("getUpload", handler);
	OSSClient->SetValue("getUpload", getUpload, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> getDownload = CefV8Value::CreateFunction("getDownload", handler);
	OSSClient->SetValue("getDownload", getDownload, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> startUpload = CefV8Value::CreateFunction("startUpload", handler);
	OSSClient->SetValue("startUpload", startUpload, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> startDownload = CefV8Value::CreateFunction("startDownload", handler);
	OSSClient->SetValue("startDownload", startDownload, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> stopUpload = CefV8Value::CreateFunction("stopUpload", handler);
	OSSClient->SetValue("stopUpload", stopUpload, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> stopDownload = CefV8Value::CreateFunction("stopDownload", handler);
	OSSClient->SetValue("stopDownload", stopDownload, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> deleteUpload = CefV8Value::CreateFunction("deleteUpload", handler);
	OSSClient->SetValue("deleteUpload", deleteUpload, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> deleteDownload = CefV8Value::CreateFunction("deleteDownload", handler);
	OSSClient->SetValue("deleteDownload", deleteDownload, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> getClipboardData = CefV8Value::CreateFunction("getClipboardData", handler);
	OSSClient->SetValue("getClipboardData", getClipboardData, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  getDragFiles= CefV8Value::CreateFunction("getDragFiles", handler);
	OSSClient->SetValue("getDragFiles", getDragFiles, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  deleteObject= CefV8Value::CreateFunction("deleteObject", handler);
	OSSClient->SetValue("deleteObject", deleteObject, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  copyObject= CefV8Value::CreateFunction("copyObject", handler);
	OSSClient->SetValue("copyObject", copyObject, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  changeUpload= CefV8Value::CreateFunction("changeUpload", handler);
	OSSClient->SetValue("changeUpload", changeUpload, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  changeDownload= CefV8Value::CreateFunction("changeDownload", handler);
	OSSClient->SetValue("changeDownload", changeDownload, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  getErrorLog= CefV8Value::CreateFunction("getErrorLog", handler);
	OSSClient->SetValue("getErrorLog", getErrorLog, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  loginByKey= CefV8Value::CreateFunction("loginByKey", handler);
	OSSClient->SetValue("loginByKey", loginByKey, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  loginByFile= CefV8Value::CreateFunction("loginByFile", handler);
	OSSClient->SetValue("loginByFile", loginByFile, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  setPassword= CefV8Value::CreateFunction("setPassword", handler);
	OSSClient->SetValue("setPassword", setPassword, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  loginPassword= CefV8Value::CreateFunction("loginPassword", handler);
	OSSClient->SetValue("loginPassword", loginPassword, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  setServerLocation= CefV8Value::CreateFunction("setServerLocation", handler);
	OSSClient->SetValue("setServerLocation", setServerLocation, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  saveAuthorization= CefV8Value::CreateFunction("saveAuthorization", handler);
	OSSClient->SetValue("saveAuthorization", saveAuthorization, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  getDeviceEncoding= CefV8Value::CreateFunction("getDeviceEncoding", handler);
	OSSClient->SetValue("getDeviceEncoding", getDeviceEncoding, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value>  showLaunchpad= CefV8Value::CreateFunction("showLaunchpad", handler);
	OSSClient->SetValue("showLaunchpad", showLaunchpad, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> setClipboardData = CefV8Value::CreateFunction("setClipboardData", handler);
	OSSClient->SetValue("setClipboardData", setClipboardData, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> closeWnd = CefV8Value::CreateFunction("closeWnd", handler);
	OSSClient->SetValue("closeWnd", closeWnd, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> showWnd = CefV8Value::CreateFunction("showWnd", handler);
	OSSClient->SetValue("showWnd", showWnd, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> clearPassword = CefV8Value::CreateFunction("clearPassword", handler);
	OSSClient->SetValue("clearPassword", clearPassword, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> showAuthorizationDlg = CefV8Value::CreateFunction("showAuthorizationDlg", handler);
	OSSClient->SetValue("showAuthorizationDlg", showAuthorizationDlg, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> getUIPath = CefV8Value::CreateFunction("getUIPath", handler);
	OSSClient->SetValue("getUIPath", getUIPath, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> openLogFolder = CefV8Value::CreateFunction("openLogFolder", handler);
	OSSClient->SetValue("openLogFolder", openLogFolder, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> deleteBucket = CefV8Value::CreateFunction("deleteBucket", handler);
	OSSClient->SetValue("deleteBucket", deleteBucket, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> changeHost = CefV8Value::CreateFunction("changeHost", handler);
	OSSClient->SetValue("changeHost", changeHost, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> loadFinish = CefV8Value::CreateFunction("loadFinish", handler);
	OSSClient->SetValue("loadFinish", loadFinish, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> configInfo = CefV8Value::CreateFunction("configInfo", handler);
	OSSClient->SetValue("configInfo", configInfo, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> setTransInfo = CefV8Value::CreateFunction("setTransInfo", handler);
	OSSClient->SetValue("setTransInfo", setTransInfo, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> getTransInfo = CefV8Value::CreateFunction("getTransInfo", handler);
	OSSClient->SetValue("getTransInfo", getTransInfo, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> getCurrentLocation = CefV8Value::CreateFunction("getCurrentLocation", handler);
	OSSClient->SetValue("getCurrentLocation", getCurrentLocation, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> getCurrentHost = CefV8Value::CreateFunction("getCurrentHost", handler);
	OSSClient->SetValue("getCurrentHost", getCurrentHost, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> setMetaObject = CefV8Value::CreateFunction("setMetaObject", handler);
	OSSClient->SetValue("setMetaObject", setMetaObject, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> stopLoadDownload = CefV8Value::CreateFunction("stopLoadDownload", handler);
	OSSClient->SetValue("stopLoadDownload", stopLoadDownload, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> openUrl = CefV8Value::CreateFunction("openUrl", handler);
	OSSClient->SetValue("openUrl", openUrl, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> getCallFunctionInfo = CefV8Value::CreateFunction("getCallFunctionInfo", handler);
	OSSClient->SetValue("getCallFunctionInfo", getCallFunctionInfo, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> setCallFunctionInfo = CefV8Value::CreateFunction("setCallFunctionInfo", handler);
	OSSClient->SetValue("setCallFunctionInfo", setCallFunctionInfo, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> changelanguage = CefV8Value::CreateFunction("gChangeLanguage", handler);
	OSSClient->SetValue("gChangeLanguage", changelanguage, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> getlanguage = CefV8Value::CreateFunction("gGetLanguage", handler);
	OSSClient->SetValue("gGetLanguage", getlanguage, V8_PROPERTY_ATTRIBUTE_NONE);

	CefRefPtr<CefV8Value> gAccountAction = CefV8Value::CreateFunction("gAccountAction", handler);
	OSSClient->SetValue("gAccountAction", gAccountAction, V8_PROPERTY_ATTRIBUTE_NONE);
}
Exemple #29
0
void InexorCefApp::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> browser_context)
{
    // cefdebug("InexorCefApp::OnContextCreated", "Injecting inexor object into javascript context");
    browser_context->GetGlobal()->SetValue(context_manager->GetContextName(), context_manager->GetContext(), V8_PROPERTY_ATTRIBUTE_NONE);
}
bool FUnrealCEFSubProcessRemoteScripting::HandleDeleteValueMessage(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("id") != VTYPE_STRING
			|| Argument->GetType("permanent") != VTYPE_BOOL)
		{
			// Wrong message argument types or count
			return false;
		}

		CefString Name = Argument->GetString("name");
		CefString Id = Argument->GetString("id");
		bool bPermanent = Argument->GetBool("permanent");

		FGuid Guid;
		if (!FGuid::Parse(Id.ToWString().c_str(), Guid))
		{
			return false;
		}

		if (bPermanent)
		{
			int32 BrowserID = Browser->GetIdentifier();
			CefRefPtr<CefDictionaryValue> Bindings;
			if (PermanentBindings.Contains(BrowserID))
			{
				Bindings = PermanentBindings[BrowserID];
				if (!Bindings->HasKey(Name))
				{
					return false;
				}
				if (Guid.IsValid())
				{
					CefRefPtr<CefDictionaryValue> CefValue = Bindings->GetDictionary(Name);
					if (CefValue.get() && CefValue->GetString("$id") != Id)
					{
						return false;
					}
				}
				Bindings->Remove(Name);
			}
		}

		if (!RootObject->HasValue(Name))
		{
			return false;
		}
		if (Guid.IsValid())
		{
			CefRefPtr<CefV8Value> Value = RootObject->GetValue(Name);
			if (!Value->HasValue("$id") || !Value->GetValue("$id")->IsString() || Value->GetValue("$id")->GetStringValue() != Id)
			{
				return false;
			}
		}
		RootObject->DeleteValue(Name);
	}
	return true;

}