示例#1
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 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
0
bool Application::Execute(
    const CefString& name,
    CefRefPtr<CefV8Value> object,
    const CefV8ValueList& arguments,
    CefRefPtr<CefV8Value>& retval,
    CefString& exception
) {
    if (name == "exit") {
        printf("Exiting with value %d!\n", arguments[0]->GetIntValue());
        this->firstBrowser = NULL;
        // see http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=891 for the 'right' way to do this
        CefRefPtr<CefProcessMessage> message = CefProcessMessage::Create("quit");
        message->GetArgumentList()->SetInt(0, arguments[0]->GetIntValue());
        message->GetArgumentList()->SetString(1, this->outBuffer);
        if(CefV8Context::GetEnteredContext()->GetBrowser()->SendProcessMessage(PID_BROWSER, message)) {
            printf("Got true from quit send process\n");
        } else { 
            printf("Got false from quit send process message\n");
        }
        return true;

    } else if (name == "open") {

    } else if (name == "openWindow") {
        CefPostTask(
            TID_UI,
            NewCefRunnableFunction(&noOpenWindow)
            );
        return true;

    } else if (name == "nop") {
        return true;

    } else if (name == "log") {
        /*if (object->IsSame(this->leprechaunObj)) {
            // Figure out if we need this some day...
            return false;
        }*/
        std::wstringstream ss;
        for (size_t i = 0; i < arguments.size(); ++i) {
            ss << arguments[i]->GetStringValue().ToWString();
        }
        printf("Got log: %S\n", ss.str().c_str());
        return true;
    } else if (name == "echo") {
        std::wstringstream ss;
        for (size_t i = 0; i < arguments.size(); ++i) {
            ss << arguments[i]->GetStringValue().ToWString();
        }
	this->outBuffer += ss.str().c_str();
	this->outBuffer += L"\n";
        return true;
    } else if (name == "onerror") {
        return true;
    }

    return false;
}
示例#4
0
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;
}
示例#5
0
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;
}
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;
}
示例#7
0
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();
}
示例#8
0
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;
}
void FUnrealCEFSubProcessRemoteScripting::CefToV8Arglist(CefRefPtr<CefListValue> List, CefV8ValueList& Values)
{
	for (size_t i = 0; i < List->GetSize(); ++i)
	{
		Values.push_back(CefToV8(List, i));
	}
}
示例#10
0
// 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);
}
示例#11
0
// Transfer a V8 vector to a list
void SetList(const CefV8ValueList& source, CefRefPtr<CefListValue> target)
{
    int arg_length = source.size();
    if (arg_length == 0)
        return;
    target->SetSize(arg_length);
    for (int i = 0; i < arg_length; ++i)
        SetListValue(target, i, source[i]);
}
CefRefPtr<CefListValue> FUnrealCEFSubProcessRemoteScripting::V8ArrayToCef(const CefV8ValueList& Values)
{
	CefRefPtr<CefListValue> Result = CefListValue::Create();
	for (size_t I = 0; I < Values.size(); ++I)
	{
		V8ToCef(Result, nullptr, I, Values[I]);
	}
	return Result;
}
示例#13
0
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);
}
示例#14
0
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;
}
示例#15
0
 // 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;
 }
示例#16
0
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;
}
示例#17
0
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");
    }
}
示例#18
0
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;
}
示例#19
0
void CSJsSocket::OnRead(int fd, short ev)
{
    char buffer[1024];
    int len = Read(buffer, sizeof(buffer));
    if (len == 0 || len == -1)
    {
        if (len == -1 && mErrorCallback)
        {
            CefV8ValueList args;
            CefRefPtr<CefV8Value> retval;
            CefRefPtr<CefV8Exception> exception;     
            
            mErrorCallback->ExecuteFunctionWithContext(mErrorContext, NULL, args, retval, exception, false);            
        }
        
        Close();

		event_del(&mEventRead);
                
		return;
	}
    else
    {
        // we read something
        if (mReadCallback)
        {
            CefV8ValueList args;
            CefRefPtr<CefV8Value> retval;
            CefRefPtr<CefV8Exception> exception;     
                        
            std::string data(buffer, len);
            args.push_back(CefV8Value::CreateString(data));
            
            mReadCallback->ExecuteFunctionWithContext(mReadContext, NULL, args, retval, exception, false);
        }
    }
}
示例#20
0
文件: cefmouse.cpp 项目: Croydon/code
bool InexorCefMouseManager::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
    CEF_REQUIRE_RENDERER_THREAD();
    if (name == "show") {
        Show();
        return true;
    } else if (name == "hide") {
        Hide();
        return true;
    } else if (name == "setTexture") {
        if (arguments.size() == 2 && arguments[0]->IsString() && arguments[1]->IsInt()) {
            SetTexture(arguments[0]->GetStringValue().ToString(), arguments[1]->GetIntValue());
            return true;
        }
    }
    return false;
}
示例#21
0
bool JSContainer::NewHandler::Execute(
	const CefString& name,
	CefRefPtr<CefV8Value> object,
	const CefV8ValueList& arguments,
	CefRefPtr<CefV8Value>& retval,
	CefString& exception
)
{
	if (arguments.empty() || !arguments[0]->IsString())
	{
		exception = kMissingConfigException;
		return false;
	}

	AppConfig config;
	if (!LoadAppConfig(arguments[0]->GetStringValue().ToString().c_str(), &config))
	{
		exception = kConfigLoadingError;
		return false;
	}

	return m_app->LaunchContainer(m_browser, config);
}
示例#22
0
  // 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 == "modifyRotation") {
      // This function requires one argument.
      if(arguments.size() != 1)
        return false;

      float increment = 0.;
      if(arguments[0]->IsInt()) {
        // The argument is an integer value.
        increment = static_cast<float>(arguments[0]->GetIntValue());
      } else if(arguments[0]->IsDouble()) {
        // The argument is an double value.
        increment = static_cast<float>(arguments[0]->GetDoubleValue());
      }

      if(increment != 0.) {
        // Modify the rotation accordingly.
        ModifyRotation(increment);
        return true;
      }
    } else if(name == "resetRotation") {
      // Reset the rotation value.
      ResetRotation();
      return true;
    } else if(name == "viewSource") {
      // View the page source.
      AppGetBrowser()->GetMainFrame()->ViewSource();
      return true;
    }

    return false;
  }
示例#23
0
bool CMyV8Handler::Execute( const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception )
{
	if (name==_T("configInfo"))
	{
		retval= CefV8Value::CreateString(CefString(configInfo()));
		return true;
	}
	if (name==_T("clearPassword"))
	{
		GetUserDb()->DeleteUserInfo();
		return true;
	}
	if (name==_T("changeHost"))
	{
		if (arguments.size()>0&&arguments[0]->IsString())
		{
			CString strContent;
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			if(strContent.GetLength()>2)
				strContent=strContent.Mid(1,strContent.GetLength()-2);
			CString strTemp;
			if (COssApi::m_strHost!=_T(""))
				strTemp.Format(_T("\"%s\""),COssApi::m_strHost.c_str());
			else
				strTemp.Format(_T("\"%s\""),GetStaroneControl()->ChangeHost(wstring(strContent)).c_str());
			retval= CefV8Value::CreateString(CefString(strTemp));
		}
		return true;
	}
	if (name==_T("loadFinish"))
	{
		GetStaroneControl()->m_bLoadFinish=TRUE;
		return true;
	}
	if (name==_T("showAuthorizationDlg"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
		}
		CefRefPtr<CefV8Value> func=NULL;
		if (arguments.size()>1)
			func=arguments[1];
		Handler_Msg *hmsg=new Handler_Msg;
		hmsg->strJson=strContent;
		hmsg->v8Ctx=CefV8Context::GetCurrentContext();
		hmsg->vObject=object;
		hmsg->vFunc=func;
		CWebBaseDlg::m_HanderMsg.push_back(hmsg);
		CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
		CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgshowAuthorizationDlg"));
		CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
		msglist->SetInt(0,(int)hmsg);
		browser->SendProcessMessage(PID_RENDERER,msg);
		return true;
	}
	if (name==_T("showWnd"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgMain"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("closeWnd"))
	{
		CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
		CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgcloseWnd"));
		browser->SendProcessMessage(PID_RENDERER,msg);
		return true;
	}
	if (name==_T("setClipboardData"))
	{
		if (arguments.size()>0&&arguments[0]->IsString())
		{
			CString strContent;
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			if(strContent.GetLength()>2)
				strContent=strContent.Mid(1,strContent.GetLength()-2);
			if(OpenClipboard(NULL)) 
			{   
				HGLOBAL clipbuffer; 
				char   *buffer; 
				EmptyClipboard(); 
				clipbuffer=GlobalAlloc(GMEM_DDESHARE,strContent.GetLength()*2+2); 
				buffer=(char *)GlobalLock(clipbuffer);
				memset(buffer,0,strContent.GetLength()*2+2);
				memcpy(buffer,strContent.GetBuffer(0),strContent.GetLength()*2);
				GlobalUnlock(clipbuffer); 
				SetClipboardData(CF_UNICODETEXT,clipbuffer); 
				CloseClipboard();
			}
		}
		return true;
	}
	if (name==_T("showLaunchpad"))
	{
		GetStaroenHummerDlg()->ShowLauchpad();
		return true;
	}
	if (name==_T("getAccessID"))
	{
		CString strTemp;
		strTemp.Format(_T("\"%s\""),GetStaroneControl()->m_UserInfo.strAccessID);
		retval= CefV8Value::CreateString(CefString(strTemp));
		return true;
	}
	if (name==_T("getSignature"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CString strTemp;
			strTemp.Format(_T("\"%s\""),GetSignature(strContent));
			retval= CefV8Value::CreateString(CefString(strTemp));
		}
		return true;
	}
	if (name==_T("getRamSignature"))
	{
		CString strCmd;
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strCmd.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
		}
		if(arguments.size()>1&&arguments[1]->IsString())
		{
			strContent.Format(_T("%s"),arguments[1]->GetStringValue().c_str());
		}
		CString strTemp;
		strTemp.Format(_T("\"%s\""),getRamSignature(strCmd,strContent));
		retval= CefV8Value::CreateString(CefString(strTemp));
		return true;
	}
	if (name==_T("addFile"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgaddFile"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("saveFile"))
	{
		if (arguments.size()>=1&&arguments[0]->IsString())
		{
			CString strContent;
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgsaveFile"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("saveFileDlg"))
	{
		if (arguments.size()==1)
		{
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>0)
				func=arguments[0];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=_T("");
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgsaveFileDlg"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("selectFileDlg"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgselectFileDlg"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("getUpload"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
		}
		retval = CefV8Value::CreateString(CefString(getUpload(strContent)));
		return true;
	}
	if (name==_T("getDownload"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
		}
		retval = CefV8Value::CreateString(CefString(getDownload(strContent)));
		return true;
	}
	if (name==_T("startUpload"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			CHandlerTask *pTask=new CHandlerTask;
			pTask->Init(CefV8Context::GetCurrentContext(),object,func,strContent,_T("startUpload"));
			GetStaroneControl()->m_ThreadPool.AddTask(pTask);
		}
		return true;
	}
	if (name==_T("startDownload"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			CHandlerTask *pTask=new CHandlerTask;
			pTask->Init(CefV8Context::GetCurrentContext(),object,func,strContent,_T("startDownload"));
			GetStaroneControl()->m_ThreadPool.AddTask(pTask);
		}
		return true;
	}
	if (name==_T("stopUpload"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			CHandlerTask *pTask=new CHandlerTask;
			pTask->Init(CefV8Context::GetCurrentContext(),object,func,strContent,_T("stopUpload"));
			GetStaroneControl()->m_ThreadPool.AddTask(pTask);
		}
		return true;
	}
	if (name==_T("stopDownload"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			CHandlerTask *pTask=new CHandlerTask;
			pTask->Init(CefV8Context::GetCurrentContext(),object,func,strContent,_T("stopDownload"));
			GetStaroneControl()->m_ThreadPool.AddTask(pTask);
		}
		return true;
	}
	if (name==_T("deleteUpload"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			CHandlerTask *pTask=new CHandlerTask;
			pTask->Init(CefV8Context::GetCurrentContext(),object,func,strContent,_T("deleteUpload"));
			GetStaroneControl()->m_ThreadPool.AddTask(pTask);
		}
		return true;
	}
	if (name==_T("deleteDownload"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			CHandlerTask *pTask=new CHandlerTask;
			pTask->Init(CefV8Context::GetCurrentContext(),object,func,strContent,_T("deleteDownload"));
			GetStaroneControl()->m_ThreadPool.AddTask(pTask);
		}
		return true;
	}
	if (name==_T("setMetaObject"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			CHandlerTask *pTask=new CHandlerTask;
			pTask->Init(CefV8Context::GetCurrentContext(),object,func,strContent,_T("setMetaObject"));
			GetStaroneControl()->m_ThreadPool.AddTask(pTask);
		}
		return true;
	}
	if (name==_T("getClipboardData"))
	{
		retval = CefV8Value::CreateString(CefString(getClipboardData()));
		return true;
	}
	if (name==_T("getDragFiles"))
	{
		CString strContent=_T("{\"list\":[");
		for (int i=0;i<GetStaroneControl()->m_strDragList.size();i++)
		{
			if (i!=0)
				strContent+=_T(",");
			CString str;
			str.Format(_T("{\"path\":\"%s\"}"),slnhelper::ReplaceToJson(GetStaroneControl()->m_strDragList[i]));
			strContent+=str;
		}
		strContent+=_T("]}");
		retval = CefV8Value::CreateString(CefString(strContent));
		return true;
	}
	if (name==_T("deleteObject"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgdeleteObject"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("copyObject"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgcopyObject"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("changeUpload"))
	{
		CString strContent;
		CefRefPtr<CefV8Value> func=NULL;
		if(arguments.size()>0&&arguments[0]->IsString())
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
		if (arguments.size()>1)
			func=arguments[1];
		GetCallbackUploadThread()->SetCallbackStatus(CefV8Context::GetCurrentContext(),object,func,strContent);
		return true;
	}
	if (name==_T("changeDownload"))
	{
		CString strContent;
		CefRefPtr<CefV8Value> func=NULL;
		if(arguments.size()>0&&arguments[0]->IsString())
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
		if (arguments.size()>1)
			func=arguments[1];
		GetCallbackDownloadThread()->SetCallbackStatus(CefV8Context::GetCurrentContext(),object,func,strContent);
		return true;
	}
	if (name==_T("getErrorLog"))
	{
		retval = CefV8Value::CreateString(CefString(getErrorLog()));
		return true;
	}
	if (name==_T("loginByKey"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgloginByKey"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("loginByFile"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgloginByFile"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("setPassword"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgsetPassword"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("loginPassword"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgloginPassword"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("setServerLocation"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgsetServerLocation"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("saveAuthorization"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgsaveAuthorization"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("getDeviceEncoding"))
	{
		CString strDevice=CRsa::GetDevice();
		wstring hash=L"";
		if (strDevice!=_T(""))
			hash=slnhelper::getstringhash(wstring(strDevice));
		CString strRet;
		strRet.Format(_T("\"%s\""),hash.c_str());
		retval = CefV8Value::CreateString(CefString(strRet));
		return true;
	}
	if (name==_T("getUIPath"))
	{
		CString strRet=_T("");
		if (GetUserDb()->GetUIPath()!=_T(""))
			strRet.Format(_T("\"%s\""),slnhelper::ReplaceToJson(GetUserDb()->GetUIPath()));
		else
			strRet.Format(_T("\"%s\""),slnhelper::ReplaceToJson(GetStaroneControl()->m_strUIPath));
		retval= CefV8Value::CreateString(CefString(strRet));
		return true;
	}
	if (name==_T("openLogFolder"))
	{
		ShellExecute(NULL,_T("open"),GetStaroneControl()->m_strUserConfig+_T("\\log"),NULL,NULL, SW_SHOW);
		return true;
	}
	if (name==_T("deleteBucket"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			CefRefPtr<CefV8Value> func=NULL;
			if (arguments.size()>1)
				func=arguments[1];
			Handler_Msg *hmsg=new Handler_Msg;
			hmsg->strJson=strContent;
			hmsg->v8Ctx=CefV8Context::GetCurrentContext();
			hmsg->vObject=object;
			hmsg->vFunc=func;
			CWebBaseDlg::m_HanderMsg.push_back(hmsg);
			CefRefPtr<CefBrowser> browser=CefV8Context::GetCurrentContext()->GetBrowser();
			CefRefPtr<CefProcessMessage> msg=CefProcessMessage::Create(_T("msgdeleteBucket"));
			CefRefPtr<CefListValue>msglist=msg->GetArgumentList();
			msglist->SetInt(0,(int)hmsg);
			browser->SendProcessMessage(PID_RENDERER,msg);
		}
		return true;
	}
	if (name==_T("setTransInfo"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			setTransInfo(strContent);
		}
		return true;
	}
	if (name==_T("getTransInfo"))
	{
		retval = CefV8Value::CreateString(CefString(getTransInfo()));
		return true;
	}
	if (name==_T("getCurrentLocation"))
	{
		CString strTemp=_T("");
		if (GetStaroneControl()->m_UserInfo.strArea!=_T(""))
		{
			strTemp.Format(_T("\"%s\""),GetStaroneControl()->m_UserInfo.strArea);
		}
		retval = CefV8Value::CreateString(CefString(strTemp));
		return true;
	}
	if (name==_T("getCurrentHost"))
	{
		CString strTemp=_T("");
		if (GetStaroneControl()->m_UserInfo.strHost!=_T(""))
		{
			strTemp.Format(_T("\"%s\""),GetStaroneControl()->m_UserInfo.strHost);
		}
		retval = CefV8Value::CreateString(CefString(strTemp));
		return true;
	}
	if (name==_T("stopLoadDownload"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			stopLoadDownload(strContent);
		}
		return true;
	}
	if (name==_T("openUrl")) 
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			openUrl(strContent);
		}
		return true;
	}
	if (name==_T("setCallFunctionInfo"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			setCallFunctionInfo(strContent);
		}
		return true;
	}
	if (name==_T("getCallFunctionInfo"))
	{
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
			retval = CefV8Value::CreateString(CefString(getCallFunctionInfo(strContent)));
		}
		return true;
	}
	if (name==_T("gGetLanguage"))
	{
		retval = CefV8Value::CreateString(CefString(gGetLanguage()));
		return true;
	}
	if (name==_T("gChangeLanguage"))
	{
		CString strContent=_T("");
		if(arguments.size()>0&&arguments[0]->IsString())
			strContent.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
		gChangeLanguage(strContent);
		return true;
	}
	if (name==_T("gAccountAction"))
	{
		CString strCmd;
		CString strContent;
		if(arguments.size()>0&&arguments[0]->IsString())
		{
			strCmd.Format(_T("%s"),arguments[0]->GetStringValue().c_str());
		}
		if(arguments.size()>1&&arguments[1]->IsString())
		{
			strContent.Format(_T("%s"),arguments[1]->GetStringValue().c_str());
		}
		retval = CefV8Value::CreateString(CefString(gAccountAction(strCmd,strContent)));
		return true;
	}
	return false;
}
//--------------------------------------------------------------
bool ofxCEFV8ExtensionHandler::Execute(const CefString &name,
                                       CefRefPtr<CefV8Value> object,
                                       const CefV8ValueList &arguments,
                                       CefRefPtr<CefV8Value> &retval,
                                       CefString &exception)
{
    if (name == "sendMessageToOF") {
        if (arguments.size() == 2 && arguments[0]->IsString()) {
            CefString type;
            
            if (arguments[1]->IsString()) {
                type = "string";
            }
            else if (arguments[1]->IsDouble()) {
                type = "double";
            }
            else if (arguments[1]->IsInt()) {
                type = "int";
            }
            else if (arguments[1]->IsBool()) {
                type = "bool";
            }
            else {
                std::cout << "ofxCEFV8ExtensionHandler received a message of unknown type." << std::endl;
                return false;
            }
            
            // Create the message object.
            CefRefPtr<CefProcessMessage> message = CefProcessMessage::Create(type);
            
            // Retrieve the argument list object.
            CefRefPtr<CefListValue> args = message->GetArgumentList();
            
            // Message mane
            args->SetString(0, arguments[0]->GetStringValue());
            
            // Message value
            if (type == "string") {
                args->SetString(1, arguments[1]->GetStringValue());
            }
            else if (type == "double") {
                args->SetDouble(1, arguments[1]->GetDoubleValue());
            }
            else if (type == "int") {
                args->SetInt(1, arguments[1]->GetIntValue());
            }
            else if (type == "bool") {
                args->SetBool(1, arguments[1]->GetBoolValue());
            }
            
            // Send message
            CefRefPtr<CefBrowser> browser = CefV8Context::GetCurrentContext()->GetBrowser();
            browser->SendProcessMessage(PID_BROWSER, message);
            return true;
            
        }
    }
    else if (name == "sendMessageWithTypeToOF") {
        if (arguments.size() == 3 && arguments[0]->IsString() && arguments[1]->IsString()) {
            // Populate the argument values.
            CefString type = arguments[0]->GetStringValue();
            
            // Create the message object.
            CefRefPtr<CefProcessMessage> message = CefProcessMessage::Create(type);
            
            // Retrieve the argument list object.
            CefRefPtr<CefListValue> args = message->GetArgumentList();
            
            // Message mane
            args->SetString(0, arguments[1]->GetStringValue());
            
            // Message value
            if (type == "string") {
                args->SetString(1, arguments[2]->GetStringValue());
            }
            else if (type == "double") {
                args->SetDouble(1, arguments[2]->GetDoubleValue());
            }
            else if (type == "int") {
                args->SetInt(1, arguments[2]->GetIntValue());
            }
            else if (type == "bool") {
                args->SetBool(1, arguments[2]->GetBoolValue());
            }
            else {
                std::cout << "ofxCEFV8ExtensionHandler received a message of unknown type." << std::endl;
                return false;
            }
            
            // Send message
            CefRefPtr<CefBrowser> browser = CefV8Context::GetCurrentContext()->GetBrowser();
            browser->SendProcessMessage(PID_BROWSER, message);
            return true;

         }
    }

    return false;
}
bool ClientHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
	if (name == "db_exec") {
		if (arguments.size() == 1 && arguments[0]->IsString()) {			
			CefString stmt = arguments[0]->GetStringValue();			
			sqlite3 *db; char *err;
			if (sqlite3_open("myDB.db", &db)) {
				retval = CefV8Value::CreateString("ERROR: FAILED to open SQLite db!");
			} else {						
				if (sqlite3_exec(db, std::string(stmt).c_str(), NULL, NULL, &err)) {				
					retval = CefV8Value::CreateString(std::string("ERROR: ") + sqlite3_errmsg(db));		
				} else {
					retval = CefV8Value::CreateString(std::string("SUCCESS: [db_exec] ") + std::string(stmt));
				}						
			}
			sqlite3_close(db);
		} else {
			retval = CefV8Value::CreateString("ERROR: Empty/invalid query string.");
		}
		return true;
	}

	if (name == "db_select") {
		if (arguments.size() == 1 && arguments[0]->IsString()) {			
			CefString stmt = arguments[0]->GetStringValue();
			sqlite3 *db; char *err;
			if (sqlite3_open("myDB.db", &db)) {
				retval = CefV8Value::CreateString("ERROR: FAILED to open SQLite db!");
			} else {				
				char **results = NULL;
				int rows, columns;				
				if (sqlite3_get_table(db, std::string(stmt).c_str(), &results, &rows, &columns, &err)) {				
					retval = CefV8Value::CreateString(sqlite3_errmsg(db));		
				} else {
					std::string jsonStr = "[";
					for (int rowCtr = 1; rowCtr <= rows; ++rowCtr)
					{
						jsonStr += "{";
						for (int colCtr = 0; colCtr < columns; ++colCtr)
						{							
							int cellPosition = (rowCtr * columns) + colCtr;
							int cellPositionHeader = (0 * columns) + colCtr;
							jsonStr += std::string("\"") + results[cellPositionHeader] + std::string("\": \"") + results[cellPosition] + std::string("\"");							
							jsonStr += (colCtr!=columns-1) ? "," : "";
						}
						jsonStr += (rowCtr<rows) ? "}," : "}";
					}
					jsonStr += "]";
					sqlite3_free_table(results);					
					retval = CefV8Value::CreateString(jsonStr);								
				}						
			}
			sqlite3_close(db);
		} else {
			retval = CefV8Value::CreateString("ERROR: Empty/invalid query string.");
		}
		return true;
	}	
    
    return false;
}
void do_execute_callback_function_dl_manager(const CefV8ValueList& arguments){
	CefV8ValueList argumentss;
	arguments.at(1)->ExecuteFunction(arguments.at(2), argumentss);

}
示例#27
0
bool BluScriptHandler::Execute(const CefString& name,
	CefRefPtr<CefV8Value> object,
	const CefV8ValueList& arguments,
	CefRefPtr<CefV8Value>& retval,
	CefString& exception)
{

	// CEF_REQUIRE_RENDERER_THREAD();

	// Our event function
	if (name == "blu_event") {

		if (arguments.size() < 2)
		{
			exception = "Invalid number of arguments! (two required)";
			return true;
		}

		if (!arguments[0]->IsString())
		{
			exception = "Parameter 1 must be a string!";
			return true;
		}

		// Get the first argument as a string, used for the event name
		CefString event_name = arguments[0]->GetStringValue();

		CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create("blu_event");

		// Event ID
		msg->GetArgumentList()->SetString(0, event_name);

		// Now we need to see what type of data they passed
		if (arguments[1]->IsBool())
		{
			msg->GetArgumentList()->SetBool(1, arguments[1]->GetBoolValue());
			msg->GetArgumentList()->SetString(3, "bool");
		}
		else if (arguments[1]->IsString())
		{
			msg->GetArgumentList()->SetString(1, arguments[1]->GetStringValue());
			msg->GetArgumentList()->SetString(3, "string");
		}
		else if (arguments[1]->IsDouble())
		{
			msg->GetArgumentList()->SetDouble(1, arguments[1]->GetDoubleValue());
			msg->GetArgumentList()->SetString(3, "double");
		}
		else if (arguments[1]->IsInt())
		{
			msg->GetArgumentList()->SetInt(1, arguments[1]->GetIntValue());
			msg->GetArgumentList()->SetString(3, "int");
		}
		else
		{
			exception = "Parameter 2 - unsupported type! (int, double, string and bool only)";
			return true;
		}


		// Set the type of the event for UE4 to parse
		msg->GetArgumentList()->SetString(2, "js_event");

		if (browser == nullptr)
		{
			exception = "Browser pointer at NULL";
			return true;
		}

		// Send the message to the browser process
		browser->SendProcessMessage(PID_BROWSER, msg);

		// return a true value in js context
		retval = CefV8Value::CreateBool(true);

		// We're done
		return true;
	}

	// Function does not exist.
	return false;
}
示例#28
0
	virtual bool Execute(const CefString& InName,
		CefRefPtr<CefV8Value> InObject,
		const CefV8ValueList& InArguments,
		CefRefPtr<CefV8Value>& OutRetval,
		CefString& OutException)
	{
		bool Handled = false;
		bool ValidAPI = true;

		if (InName == "TriggerEvent")
		{
			// dispatch hook to the browser process for execution on the game thread
			if ((InArguments.size() == 1) && InArguments[0]->IsArray())
			{
				CefRefPtr<CefV8Value> ArgumentArray = InArguments[0];
				if (ArgumentArray->GetArrayLength() > 0)
				{
					CefRefPtr<CefBrowser> Browser = CefV8Context::GetCurrentContext()->GetBrowser();
					ASSERT(Browser.get());

					CefString HookName = ArgumentArray->GetValue(0)->GetStringValue();
					if (!HookName.empty())
					{
						CefRefPtr<CefProcessMessage> Message = CefProcessMessage::Create(HookName);

						// translate remaining args.
						if ((ArgumentArray->GetArrayLength() > 1) && ArgumentArray->GetValue(1)->IsArray())
						{
							CefRefPtr<CefV8Value> InParameters = ArgumentArray->GetValue(1);
							const int NumParameters = InParameters->GetArrayLength();

							CefRefPtr<CefListValue> OutParameters = Message->GetArgumentList();
							OutParameters->SetSize(NumParameters);

							for (int i = 0; i < (int)NumParameters; ++i)
							{
								V8ValueToListItem_RenderThread(InParameters->GetValue(i), OutParameters, i);
							}
						}

						Browser->SendProcessMessage(PID_BROWSER, Message);
						Handled = true;
					}
				}
			}
		}
		else if (InName == "SetHook")
		{
			if ((InArguments.size() == 2) && (InArguments[0]->IsString()) && (InArguments[1]->IsFunction()))
			{
				CefString HookName = InArguments[0]->GetStringValue().ToString();
				CefRefPtr<CefV8Context> Context = CefV8Context::GetCurrentContext();
				App->SetJSHook(HookName, Context->GetBrowser()->GetIdentifier(), Context, InArguments[1]);
				Handled = true;
			}
		}
		else if (InName == "RemoveHook")
		{
			if ((InArguments.size() == 1) && InArguments[0]->IsString())
			{
				CefRefPtr<CefV8Context> Context = CefV8Context::GetCurrentContext();
				App->RemoveJSHook(InArguments[0]->GetStringValue(), Context->GetBrowser()->GetIdentifier());
				Handled = true;
			}
		}
		else
		{
			ValidAPI = false;
			OutException = std::string("Unrecognized JSHook API Call: '") + InName.ToString() + std::string("'");
		}

		if (!Handled && ValidAPI)
		{
			OutException = std::string("Invalid Arguments Passed To '") + InName.ToString() + std::string("'");
		}

		return Handled;
	}
示例#29
0
bool ClientApp::OnProcessMessageReceived(
        CefRefPtr<CefBrowser> browser,
        CefProcessId source_process,
        CefRefPtr<CefProcessMessage> message) {
    ASSERT(source_process == PID_BROWSER);

    bool handled = false;

    // Execute delegate callbacks.
    RenderDelegateSet::iterator it = render_delegates_.begin();
    for (; it != render_delegates_.end() && !handled; ++it) {
        handled = (*it)->OnProcessMessageReceived(this, browser, source_process, message);
    }

    if (!handled) {
        if (message->GetName() == "invokeCallback") {
            // This is called by the appshell extension handler to invoke the asynchronous 
            // callback function
            
            CefRefPtr<CefListValue> messageArgs = message->GetArgumentList();
            int32 callbackId = messageArgs->GetInt(0);
                    
            CefRefPtr<CefV8Context> context = callback_map_[callbackId].first;
            CefRefPtr<CefV8Value> callbackFunction = callback_map_[callbackId].second;
            CefV8ValueList arguments;
            context->Enter();
            
            // Sanity check to make sure the context is still attched to a browser.
            // Async callbacks could be initiated after a browser instance has been deleted,
            // which can lead to bad things. If the browser instance has been deleted, don't
            // invoke this callback. 
            if (context->GetBrowser()) {
                for (size_t i = 1; i < messageArgs->GetSize(); i++) {
                    arguments.push_back(ListValueToV8Value(messageArgs, i));
                }
                
                callbackFunction->ExecuteFunction(NULL, arguments);
            }
            
            context->Exit();
            
            callback_map_.erase(callbackId);
        } else if (message->GetName() == "executeCommand") {
            // This is called by the browser process to execute a command via JavaScript
            // 
            // The first argument is the command name. This is required.
            // The second argument is a message id. This is optional. If set, a response
            // message will be sent back to the browser process.
            
            CefRefPtr<CefListValue> messageArgs = message->GetArgumentList();
            CefString commandName = messageArgs->GetString(0);
            int messageId = messageArgs->GetSize() > 1 ? messageArgs->GetInt(1) : -1;
            bool handled = false;
            
            StContextScope ctx(browser->GetMainFrame()->GetV8Context());
            
            CefRefPtr<CefV8Value> global = ctx.GetContext()->GetGlobal();
            
            if (global->HasValue("brackets")) { 
                
                CefRefPtr<CefV8Value> brackets = global->GetValue("brackets");
                
                if (brackets->HasValue("shellAPI")) {
                    
                    CefRefPtr<CefV8Value> shellAPI = brackets->GetValue("shellAPI");
                    
                    if (shellAPI->HasValue("executeCommand")) {
                        
                        CefRefPtr<CefV8Value> executeCommand = shellAPI->GetValue("executeCommand");
                        
                        if (executeCommand->IsFunction()) {
                            
                            CefRefPtr<CefV8Value> retval;
                            CefV8ValueList args;
                            args.push_back(CefV8Value::CreateString(commandName));
                            
                            retval = executeCommand->ExecuteFunction(global, args);
                            
                            if (retval) {
                                handled = retval->GetBoolValue();
                            }
                        }
                    }
                }
            }
            
            // Return a message saying whether or not the command was handled
            if (messageId != -1) {
                CefRefPtr<CefProcessMessage> result = CefProcessMessage::Create("executeCommandCallback");
                result->GetArgumentList()->SetInt(0, messageId);
                result->GetArgumentList()->SetBool(1, handled);
                
                browser->SendProcessMessage(PID_BROWSER, result);
            }
        }
    }
    
    return handled;
}
示例#30
0
JNIEXPORT jboolean JNICALL Java_org_limewire_cef_CefV8Value_1N_N_1ExecuteFunction
  (JNIEnv *env, jobject obj, jobject params)
{
	CefRefPtr<CefV8Value> value(
		(CefV8Value*)GetCefBaseFromJNIObject(env, obj));
	if(!value.get())
		return JNI_FALSE;

	jclass params_cls = env->GetObjectClass(params);

	// Retrieve the object member.
	jobject object_obj = NULL;
	{
		jfieldID fieldID = env->GetFieldID(params_cls, "object",
			"Lorg/limewire/cef/CefV8Value;");
		if(fieldID != 0)
			object_obj = env->GetObjectField(params, fieldID);
		else
			env->ExceptionClear();
	}
	if(!object_obj)
		return JNI_FALSE;

	CefRefPtr<CefV8Value> object(
		(CefV8Value*)GetCefBaseFromJNIObject(env, object_obj));
	if(!object.get())
		return JNI_FALSE;

	// Retrieve the argument member.
	jobjectArray arg_arr = NULL;
	{
		jfieldID fieldID = env->GetFieldID(params_cls, "owner",
			"[Lorg/limewire/cef/CefV8Value;");
		if(fieldID != 0)
			arg_arr = (jobjectArray)env->GetObjectField(params, fieldID);
		else
			env->ExceptionClear();
	}
	if(!arg_arr)
		return JNI_FALSE;

	CefV8ValueList argList;
	int len = env->GetArrayLength(arg_arr);

	for(int i = 0; i < len; i++)
	{
		jobject cobj = env->GetObjectArrayElement(arg_arr, i);
		if(!cobj)
			continue;

		CefRefPtr<CefV8Value> argobj(
			(CefV8Value*)GetCefBaseFromJNIObject(env, cobj));
		if(!argobj.get())
			continue;

		argList.push_back(argobj);
	}

	CefString exception;
	
	// Execute the function.
	CefRefPtr<CefV8Value> retVal = value->ExecuteFunction(object, argList);

	// Set the return value member.
	{
		jfieldID fieldID = env->GetFieldID(params_cls, "retval",
			"Lorg/limewire/cef/CefV8Value;");
		if(fieldID != 0)
		{
			jobject robj = NULL;
			if(retVal.get())
			{
				robj = CreateJNIObject(env, "org/limewire/cef/CefV8Value_N",
					retVal.get(), (long)retVal.get());
			}
			env->SetObjectField(params, fieldID, robj);
		}
		else
		{
			env->ExceptionClear();
		}
	}

	// Set the exception member.
	{
		jfieldID fieldID = env->GetFieldID(params_cls, "exception",
			"Ljava/lang/String;");
		if(fieldID != 0)
		{
			env->SetObjectField(params, fieldID,
				CreateJNIString(env, exception));
		}
		else
		{
			env->ExceptionClear();
		}
	}

	return JNI_TRUE;
}