Пример #1
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);
    }
}
CefRefPtr<CefDictionaryValue> FUnrealCEFSubProcessRemoteScripting::V8FunctionToCef(CefRefPtr<CefV8Value> Object, CefRefPtr<CefV8Value> Function)
{
	CefRefPtr<CefDictionaryValue> Result = CefDictionaryValue::Create();
	FGuid Guid = CallbackRegistry.FindOrAdd(CefV8Context::GetCurrentContext(), Object, Function);
	Result->SetString("$type", "callback");
	Result->SetString("$id", *Guid.ToString(EGuidFormats::Digits));
	Result->SetString("$name", Function->GetFunctionName());
	return Result;
}
Пример #3
0
 // Simple function for formatted output of a V8 value.
 void PrintValue(CefRefPtr<CefV8Value> value, std::stringstream &stream,
                 int indent)
 {
   std::stringstream indent_stream;
   for(int i = 0; i < indent; ++i)
     indent_stream << "  ";
   std::string indent_str = indent_stream.str();
   
   if(value->IsUndefined())
     stream << "(undefined)";
   else if(value->IsNull())
     stream << "(null)";
   else if(value->IsBool())
     stream << "(bool) " << (value->GetBoolValue() ? "true" : "false");
   else if(value->IsInt())
     stream << "(int) " << value->GetIntValue();
   else if(value->IsDouble())
     stream << "(double) " << value->GetDoubleValue();
   else if(value->IsString())
     stream << "(string) " << std::string(value->GetStringValue());
   else if(value->IsFunction())
     stream << "(function) " << std::string(value->GetFunctionName());
   else if(value->IsArray()) {
     stream << "(array) [";
     int len = value->GetArrayLength();
     for(int i = 0; i < len; ++i) {
       stream << "\n  " << indent_str.c_str() << i << " = ";
       PrintValue(value->GetValue(i), stream, indent+1);
     }
     stream << "\n" << indent_str.c_str() << "]";
   } else if(value->IsObject()) {
     stream << "(object) [";
     std::vector<CefString> keys;
     if(value->GetKeys(keys)) {
       for(size_t i = 0; i < keys.size(); ++i) {
         stream << "\n  " << indent_str.c_str() << keys[i].c_str() << " = ";
         PrintValue(value->GetValue(keys[i]), stream, indent+1);
       }
     }
     stream << "\n" << indent_str.c_str() << "]";
   }
 }