本文整理汇总了C++中CefV8ValueList类的典型用法代码示例。如果您正苦于以下问题:C++ CefV8ValueList类的具体用法?C++ CefV8ValueList怎么用?C++ CefV8ValueList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CefV8ValueList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// 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());
}
示例2: while
void CaffeineClientApp::NonBlockingSocketWrite(SOCKET s)
{
auto wb = wbMap.find(s); // s should exist
auto& data_list = wb->second;
// What if an error happens in the middle of draining the list
while(data_list.size())
{
auto data = data_list.front();
CaffeineSocketClient sc = scMap.find(s)->second;
// Write the data and call the callback
auto bytes_sent = sc.send(data.first.data(), data.first.size(), 0);
if(bytes_sent>=0 && static_cast<int>(data.first.size())>bytes_sent)
{
data.first.erase(bytes_sent);
}
else
{
// Call the callback
auto ctx = data.second.first;
ctx->Enter();
CefRefPtr<CefV8Value> CallbackArg1;
CefRefPtr<CefV8Value> CallbackArg2 = CefV8Value::CreateObject(NULL);
if(bytes_sent == SOCKET_ERROR)
{
int error_code = WSAGetLastError();
if (WSAEWOULDBLOCK != error_code && 0 != error_code)
{
CallbackArg1 = CefV8Value::CreateBool(true);
CallbackArg2->SetValue("status", CefV8Value::CreateString("error"), V8_PROPERTY_ATTRIBUTE_NONE);
CallbackArg2->SetValue("errorCode", CefV8Value::CreateInt(::WSAGetLastError()), V8_PROPERTY_ATTRIBUTE_NONE);
CallbackArg2->SetValue("handle", CefV8Value::CreateInt(s), V8_PROPERTY_ATTRIBUTE_NONE);
}
else
{
// The socket can't write anymore.
ctx->Exit();
break;
}
}
else
{
CallbackArg1 = CefV8Value::CreateNull();
CallbackArg2->SetValue("status", CefV8Value::CreateString("success"), V8_PROPERTY_ATTRIBUTE_NONE);
}
data_list.pop_front();
CefV8ValueList args;
args.push_back(CallbackArg1);
args.push_back(CallbackArg2);
data.second.second->ExecuteFunction(NULL, args);
ctx->Exit();
}
}
}
示例3: ASSERT
bool ClientApp::OnProcessMessageReceived(
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) {
ASSERT(source_process == PID_BROWSER);
bool handled = false;
RenderDelegateSet::iterator it = render_delegates_.begin();
for (; it != render_delegates_.end() && !handled; ++it) {
handled = (*it)->OnProcessMessageReceived(this, browser, source_process,
message);
}
if (handled)
return true;
// Execute the registered JavaScript callback if any.
if (!callback_map_.empty()) {
CefString message_name = message->GetName();
CallbackMap::const_iterator it = callback_map_.find(
std::make_pair(message_name.ToString(),
browser->GetIdentifier()));
if (it != callback_map_.end()) {
// Keep a local reference to the objects. The callback may remove itself
// from the callback map.
CefRefPtr<CefV8Context> context = it->second.first;
CefRefPtr<CefV8Value> callback = it->second.second;
// Enter the context.
context->Enter();
CefV8ValueList arguments;
// First argument is the message name.
arguments.push_back(CefV8Value::CreateString(message_name));
// Second argument is the list of message arguments.
CefRefPtr<CefListValue> list = message->GetArgumentList();
CefRefPtr<CefV8Value> args =
CefV8Value::CreateArray(static_cast<int>(list->GetSize()));
SetList(list, args);
arguments.push_back(args);
// Execute the callback.
CefRefPtr<CefV8Value> retval = callback->ExecuteFunction(NULL, arguments);
if (retval.get()) {
if (retval->IsBool())
handled = retval->GetBoolValue();
}
// Exit the context.
context->Exit();
}
}
return handled;
}
示例4: V8ValueListToCefListValue
CefRefPtr<CefListValue> V8ValueListToCefListValue(
const CefV8ValueList& v8List) {
// typedef std::vector<CefRefPtr<CefV8Value> > CefV8ValueList;
CefRefPtr<CefListValue> listValue = CefListValue::Create();
for (CefV8ValueList::const_iterator it = v8List.begin(); it != v8List.end(); \
++it) {
CefRefPtr<CefV8Value> v8Value = *it;
V8ValueAppendToCefListValue(v8Value, listValue);
}
return listValue;
}
示例5: Execute
bool Download_JS_Handler::Execute(const CefString& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
CefString& exception){
if (name == "start"){
auto msg=CefProcessMessage::Create("start_download");
msg->GetArgumentList()->SetString(0, arguments.at(3)->GetStringValue());
msg->GetArgumentList()->SetInt(1, arguments.at(0)->GetIntValue());
msg->GetArgumentList()->SetInt(2, arguments.at(4)->GetIntValue());
msg->GetArgumentList()->SetInt(3, arguments.at(5)->GetIntValue());
msg->GetArgumentList()->SetInt(4, arguments[6]->GetIntValue());
//CefV8Context::GetCurrentContext()->GetBrowser()->GetHost()->StartDownload("http://google.com");//nur im browser process
//arguments.at(1)->GetFunctionHandler()->Execute("drawPauseButton",arguments.at(2),arguments,CefV8Value::CreateNull(),CefString("nein"));
//::MessageBox(NULL, std::to_string(arguments.at(0)->GetIntValue()).c_str(),"okok",MB_OK);//problem bei derm ganzen getstringvalue usw.gibt im Fehlerfall nix zurück,also getstringvalue gibt nix zurück,ist aber eigentlich int
CefV8Context::GetCurrentContext()->GetBrowser()->SendProcessMessage(PID_BROWSER,msg);
do_execute_callback_function_dl_manager(arguments);//zwar net gut,dass er vor dem dlder button geändert wird(was passiert bei click vor download-start auf den button) wird,spart aber code(aktuell von jetzt ausgehend;-))
//@TODO(geringe Priorität):callback-function speichern und aufrufen wenn download begonnen
return true;
}
else if (name == "pause"){
auto msg = CefProcessMessage::Create("pause_download");
msg->GetArgumentList()->SetInt(0, arguments.at(0)->GetIntValue());
CefV8Context::GetCurrentContext()->GetBrowser()->SendProcessMessage(PID_BROWSER, msg);
do_execute_callback_function_dl_manager(arguments);
return true;
}
else if (name == "resume"){
auto msg = CefProcessMessage::Create("resume_download");
msg->GetArgumentList()->SetInt(0, arguments.at(0)->GetIntValue());
CefV8Context::GetCurrentContext()->GetBrowser()->SendProcessMessage(PID_BROWSER, msg);
do_execute_callback_function_dl_manager(arguments);
return true;
}
else if (name == "init_JS_Handler"){
//downloader_browser_ref->AddRef();
CefV8Context::GetCurrentContext()->GetBrowser()->SendProcessMessage(PID_BROWSER,CefProcessMessage::Create("js_code_initialized"));
return true;
}
else if (name == "download_of_group_finished"){
auto msg=CefProcessMessage::Create("download_of_group_finished");
msg->GetArgumentList()->SetInt(0, arguments[0]->GetIntValue());
CefV8Context::GetCurrentContext()->GetBrowser()->SendProcessMessage(PID_BROWSER,msg );
return true;
}
return false;
}
示例6: Execute
void CallbackTask::Execute()
{
m_v8Ctx->Enter();
if (m_Func&&m_Func->IsFunction())
{
CefRefPtr<CefV8Value> jsonRet;
jsonRet=CefV8Value::CreateString(CefString(m_strJson));
CefV8ValueList retList;
retList.push_back(jsonRet);
m_Func->ExecuteFunction(m_Object,retList);
}
m_v8Ctx->Exit();
}
示例7: Execute
bool ClientHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
if (name == "ChangeTextInJS") {
if (arguments.size() == 1 && arguments[0]->IsString()) {
CefString text = arguments[0]->GetStringValue();
CefRefPtr<CefFrame> frame = this->GetBrowser()->GetMainFrame();
std::string jscall = "ChangeText('";
jscall += text;
jscall += "');";
frame->ExecuteJavaScript(jscall, frame->GetURL(), 0);
/*
* If you want your method to return a value, just use retval, like this:
* retval = CefV8Value::CreateString("Hello World!");
* you can use any CefV8Value, what means you can return arrays, objects or whatever you can create with CefV8Value::Create* methods
*/
return true;
}
}
return false;
}
示例8:
void FUnrealCEFSubProcessRemoteScripting::CefToV8Arglist(CefRefPtr<CefListValue> List, CefV8ValueList& Values)
{
for (size_t i = 0; i < List->GetSize(); ++i)
{
Values.push_back(CefToV8(List, i));
}
}
示例9: SetList
// Transfer a list to V8 vector
void SetList(CefRefPtr<CefListValue> source, CefV8ValueList& target)
{
int arg_length = source->GetSize();
if (arg_length == 0)
return;
target.resize(arg_length);
for (int i = 0; i < arg_length; ++i)
target[i] = ListValueToV8Value(source, i);
}
示例10: GetJSFactory
ChromiumDLL::JSObjHandle JavaScriptObject::executeFunction(ChromiumDLL::JavaScriptFunctionArgs *args)
{
if (!isFunction())
return GetJSFactory()->CreateException("Not a function!");
if (!args)
return GetJSFactory()->CreateException("Args are null for function call");
JavaScriptContext* context = (JavaScriptContext*)args->context;
JavaScriptObject* jso = (JavaScriptObject*)args->object.get();
CefV8ValueList argList;
for (int x=0; x<args->argc; x++)
{
JavaScriptObject* jsoa = (JavaScriptObject*)args->argv[x].get();
if (jsoa)
argList.push_back(jsoa->getCefV8());
else
argList.push_back(NULL);
}
CefRefPtr<CefV8Value> retval;
CefString exception;
bool res = m_pObject->ExecuteFunctionWithContext(context->getCefV8(), jso?jso->getCefV8():NULL, argList, retval, exception);
if (!res)
{
if (exception.c_str())
return GetJSFactory()->CreateException(exception.c_str());
return GetJSFactory()->CreateException("failed to run function");
}
if (!retval)
return NULL;
return new JavaScriptObject(retval);
}
示例11: Execute
bool CSJsSocket::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
if (name == "connect")
{
if (arguments.size() == 2)
{
bool result = Connect(arguments[0]->GetStringValue(), arguments[1]->GetIntValue());
retval = CefV8Value::CreateBool(result);
return true;
}
}
else if (name == "send")
{
if (arguments.size() == 1)
{
std::string data = arguments[0]->GetStringValue().ToString();
int size = Write(data.c_str(), data.size());
retval = CefV8Value::CreateInt(size);
return true;
}
}
else if (name == "close")
{
Close();
}
else if (name == "onopen")
{
if (arguments.size() == 1)
{
mOpenCallback = arguments[0];
mOpenContext = CefV8Context::GetCurrentContext();
}
}
else if (name == "onmessage")
{
if (arguments.size() == 1)
{
mReadCallback = arguments[0];
mReadContext = CefV8Context::GetCurrentContext();
}
}
else if (name == "onclose")
{
if (arguments.size() == 1)
{
mCloseCallback = arguments[0];
mCloseContext = CefV8Context::GetCurrentContext();
}
}
else if (name == "onerror")
{
if (arguments.size() == 1)
{
mErrorCallback = arguments[0];
mErrorContext = CefV8Context::GetCurrentContext();
}
}
return false;
}
示例12: Execute
// Execute with the specified argument list and return value. Return true if
// the method was handled.
virtual bool Execute(const CefString& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
CefString& exception)
{
if(name == "Dummy")
{
// Used for performance testing.
return true;
}
else if(name == "SetTestParam")
{
// Handle the SetTestParam native function by saving the string argument
// into the local member.
if(arguments.size() != 1 || !arguments[0]->IsString())
return false;
test_param_ = arguments[0]->GetStringValue();
return true;
}
else if(name == "GetTestParam")
{
// Handle the GetTestParam native function by returning the local member
// value.
retval = CefV8Value::CreateString(test_param_);
return true;
}
else if(name == "GetTestObject")
{
// Handle the GetTestObject native function by creating and returning a
// new V8 object.
retval = CefV8Value::CreateObject(NULL, NULL);
// Add a string parameter to the new V8 object.
retval->SetValue("param", CefV8Value::CreateString(
"Retrieving a parameter on a native object succeeded."),
V8_PROPERTY_ATTRIBUTE_NONE);
// Add a function to the new V8 object.
retval->SetValue("GetMessage",
CefV8Value::CreateFunction("GetMessage", this),
V8_PROPERTY_ATTRIBUTE_NONE);
return true;
}
else if(name == "GetMessage")
{
// Handle the GetMessage object function by returning a string.
retval = CefV8Value::CreateString(
"Calling a function on a native object succeeded.");
return true;
}
return false;
}
示例13: Execute
bool Application::Execute( const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception )
{
if(name == "exec" && arguments.size() == 4)
{
std::string service = arguments[0]->GetStringValue().ToString();
std::string action = arguments[1]->GetStringValue().ToString();
std::string callbackId = arguments[2]->GetStringValue().ToString();
std::string rawArgs = arguments[3]->GetStringValue().ToString();
_pluginManager->exec(service, action, callbackId, rawArgs);
return true;
}
return false;
}
示例14:
void ClientApp::V8ValueListToCefListValue(const CefV8ValueList& src, CefRefPtr<CefListValue> & dst)
{
for (unsigned i = 0; i < src.size(); i++)
{
if (!src[i]->IsValid()) { dst->SetString(dst->GetSize(),"Invalid V8Value"); continue;}
if (src[i]->IsUndefined() || src[i]->IsNull()) { dst->SetNull(dst->GetSize()); continue;}
if (src[i]->IsBool()) { dst->SetBool(dst->GetSize(), src[i]->GetBoolValue()); continue;}
if (src[i]->IsInt()) { dst->SetInt(dst->GetSize(), src[i]->GetIntValue()); continue;}
if (src[i]->IsDouble()) { dst->SetDouble(dst->GetSize(),src[i]->GetDoubleValue()); continue;}
if (src[i]->IsString()) { dst->SetString(dst->GetSize(),src[i]->GetStringValue()); continue;}
dst->SetString(dst->GetSize(), "Unimplemented V8Value conversion");
}
}
示例15: ASSERT
bool Application::OnProcessMessageReceived(
CefRefPtr<CefBrowser> InBrowser,
CefProcessId InSourceProcess,
CefRefPtr<CefProcessMessage> InMessage)
{
ASSERT(InSourceProcess == PID_BROWSER); // call should have come from browser process.
if (!Hooks.empty())
{
CefString MessageName = InMessage->GetName();
JSHookMap::iterator it = Hooks.find(std::make_pair(MessageName, InBrowser->GetIdentifier()));
if (it != Hooks.end())
{
// invoke JS callback
JSHook Hook(it->second);
Hook.Context->Enter();
CefRefPtr<CefListValue> MessageArguments = InMessage->GetArgumentList();
const int NumMessageArguments = (int)MessageArguments->GetSize();
// convert message arguments
CefV8ValueList Arguments;
for (int i = 0; i < NumMessageArguments; ++i)
{
Arguments.push_back(ListItemToV8Value_RenderThread(MessageArguments, i));
}
Hook.Function->ExecuteFunction(nullptr, Arguments);
Hook.Context->Exit();
return true;
}
}
return false;
}