Beispiel #1
0
            CefTime GetCefTime(CefRefPtr<TList> list, TIndex index)
            {
                double doubleT;

                auto binaryValue = list->GetBinary(index);
                binaryValue->GetData(&doubleT, sizeof(double), 1);

                return CefTime(doubleT);
            }
Beispiel #2
0
            int64 GetInt64(CefRefPtr<TList> list, TIndex index)
            {
                int64 result;

                auto binaryValue = list->GetBinary(index);
                binaryValue->GetData(&result, sizeof(int64), 1);

                return result;
            }
Beispiel #3
0
static void _list_to_dict(
	CefRefPtr<CefListValue> &		src,
	CefRefPtr<CefDictionaryValue> & dest,
	CefDictionaryValue::KeyList &	keys
	)
{
	if (!src.get())
		return;
	if (!dest.get())
		dest = CefDictionaryValue::Create();

	bool has_keys = keys.size() == dest->GetSize();
	for (int i = 0, nsize = static_cast<int>(src->GetSize()); i < nsize; ++i)
	{
		std::string key = has_keys ? keys[i] : std::to_string(i);
		switch (src->GetType(i))
		{
		case VTYPE_NULL:
			dest->SetNull(key);
			break;
		case VTYPE_BOOL:
			dest->SetBool(key, src->GetBool(i));
			break;
		case VTYPE_INT:
			dest->SetInt(key, src->GetInt(i));
			break;
		case VTYPE_DOUBLE:
			dest->SetDouble(key, src->GetDouble(i));
			break;
		case VTYPE_STRING:
			dest->SetString(key, src->GetString(i));
			break;
		case VTYPE_BINARY:
			dest->SetBinary(key, src->GetBinary(i));
			break;
		case VTYPE_DICTIONARY:
			dest->SetDictionary(key, src->GetDictionary(i));
			break;
		case VTYPE_LIST:
			dest->SetList(key, src->GetList(i));
			break;
		default:
			assert(0);
			break;
		}
	}
}
Beispiel #4
0
// ¶ªÆúkey
static void _dict_to_list(CefRefPtr<CefDictionaryValue> & src, CefRefPtr<CefListValue> & dest)
{
	if (!src.get())
		return;
	if (!dest.get())
		dest = CefListValue::Create();

	CefDictionaryValue::KeyList keys;
	src->GetKeys(keys);

	int idx = 0;
	for (CefString & i : keys)
	{
		switch (src->GetType(i))
		{
		case VTYPE_NULL:
			dest->SetNull(idx);
			break;
		case VTYPE_BOOL:
			dest->SetBool(idx, src->GetBool(i));
			break;
		case VTYPE_INT:
			dest->SetInt(idx, src->GetInt(i));
			break;
		case VTYPE_DOUBLE:
			dest->SetDouble(idx, src->GetDouble(i));
			break;
		case VTYPE_STRING:
			dest->SetString(idx, src->GetString(i));
			break;
		case VTYPE_BINARY:
			dest->SetBinary(idx, src->GetBinary(i));
			break;
		case VTYPE_DICTIONARY:
			dest->SetDictionary(idx, src->GetDictionary(i));
			break;
		case VTYPE_LIST:
			dest->SetList(idx, src->GetList(i));
			break;
		default:
			assert(0);
			break;
		}
		++idx;
	}
}
Beispiel #5
0
CefRefPtr<CefV8Value> CefDictionaryValueToV8Value(
        CefRefPtr<CefDictionaryValue> dictValue,
        int nestingLevel) {
    if (!dictValue->IsValid()) {
        DebugLog("CefDictionaryValueToV8Value() FAILED: " \
                "CefDictionaryValue is invalid");
        return CefV8Value::CreateNull();
    }
    if (nestingLevel > 8) {
        DebugLog("CefDictionaryValueToV8Value(): WARNING: " \
            "max nesting level (8) exceeded");
        return CefV8Value::CreateNull();
    }
    std::vector<CefString> keys;
    if (!dictValue->GetKeys(keys)) {
        DebugLog("CefDictionaryValueToV8Value() FAILED: " \
            "dictValue->GetKeys() failed");
        return CefV8Value::CreateNull();
    }
    CefRefPtr<CefV8Value> ret = CefV8Value::CreateObject(NULL);
    CefRefPtr<CefBinaryValue> binaryValue;
    PythonCallback pyCallback;
    CefRefPtr<CefV8Handler> v8FunctionHandler;
    for (std::vector<CefString>::iterator it = keys.begin(); \
            it != keys.end(); ++it) {
        CefString key = *it;
        cef_value_type_t valueType = dictValue->GetType(key);
        bool success;
        std::string callbackName = "python_callback_";
        if (valueType == VTYPE_NULL) {
            success = ret->SetValue(key,
                    CefV8Value::CreateNull(),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else if (valueType == VTYPE_BOOL) {
            success = ret->SetValue(key,
                    CefV8Value::CreateBool(dictValue->GetBool(key)),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else if (valueType == VTYPE_INT) {
            success = ret->SetValue(key,
                    CefV8Value::CreateInt(dictValue->GetInt(key)),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else if (valueType == VTYPE_DOUBLE) {
            success = ret->SetValue(key,
                    CefV8Value::CreateDouble(dictValue->GetDouble(key)),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else if (valueType == VTYPE_STRING) {
            success = ret->SetValue(key,
                    CefV8Value::CreateString(dictValue->GetString(key)),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else if (valueType == VTYPE_BINARY) {
            binaryValue = dictValue->GetBinary(key);
            if (binaryValue->GetSize() == sizeof(pyCallback)) {
                binaryValue->GetData(&pyCallback, sizeof(pyCallback), 0);
                v8FunctionHandler = new V8FunctionHandler(
                        NULL, pyCallback.callbackId);
                // You must provide a function name to
                // CefV8Value::CreateFunction(), otherwise it fails.
                callbackName.append(AnyToString(pyCallback.callbackId));
                success = ret->SetValue(key,
                                CefV8Value::CreateFunction(
                                        callbackName, v8FunctionHandler),
                                V8_PROPERTY_ATTRIBUTE_NONE);
            } else {
                DebugLog("CefListValueToV8Value(): WARNING: " \
                        "unknown binary value, setting value to null");
                success = ret->SetValue(key,
                        CefV8Value::CreateNull(),
                        V8_PROPERTY_ATTRIBUTE_NONE);
            }
        } else if (valueType == VTYPE_DICTIONARY) {
            success = ret->SetValue(key,
                    CefDictionaryValueToV8Value(
                            dictValue->GetDictionary(key),
                            nestingLevel + 1),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else if (valueType == VTYPE_LIST) {
            success = ret->SetValue(key,
                    CefListValueToV8Value(
                            dictValue->GetList(key),
                            nestingLevel + 1),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else {
            DebugLog("CefDictionaryValueToV8Value(): WARNING: " \
                    "unknown type, setting value to null");
            success = ret->SetValue(key,
                    CefV8Value::CreateNull(),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        }
        if (!success) {
            DebugLog("CefDictionaryValueToV8Value(): WARNING: " \
                    "ret->SetValue() failed");
        }
    }
    return ret;
}
Beispiel #6
0
CefRefPtr<CefV8Value> CefListValueToV8Value(
        CefRefPtr<CefListValue> listValue,
        int nestingLevel) {
    if (!listValue->IsValid()) {
        DebugLog("CefListValueToV8Value() FAILED: " \
                "CefDictionaryValue is invalid");
        return CefV8Value::CreateNull();
    }
    if (nestingLevel > 8) {
        DebugLog("CefListValueToV8Value(): WARNING: " \
            "max nesting level (8) exceeded");
        return CefV8Value::CreateNull();
    }
    int listSize = (int)listValue->GetSize();
    CefRefPtr<CefV8Value> ret = CefV8Value::CreateArray(listSize);
    CefRefPtr<CefBinaryValue> binaryValue;
    PythonCallback pyCallback;
    CefRefPtr<CefV8Handler> v8FunctionHandler;
    for (int key = 0; key < listSize; ++key) {
        cef_value_type_t valueType = listValue->GetType(key);
        bool success;
        std::string callbackName = "python_callback_";
        if (valueType == VTYPE_NULL) {
            success = ret->SetValue(key,
                    CefV8Value::CreateNull());
        } else if (valueType == VTYPE_BOOL) {
            success = ret->SetValue(key,
                    CefV8Value::CreateBool(listValue->GetBool(key)));
        } else if (valueType == VTYPE_INT) {
            success = ret->SetValue(key,
                    CefV8Value::CreateInt(listValue->GetInt(key)));
        } else if (valueType == VTYPE_DOUBLE) {
            success = ret->SetValue(key,
                    CefV8Value::CreateDouble(listValue->GetDouble(key)));
        } else if (valueType == VTYPE_STRING) {
            success = ret->SetValue(key,
                    CefV8Value::CreateString(listValue->GetString(key)));
        } else if (valueType == VTYPE_BINARY) {
            binaryValue = listValue->GetBinary(key);
            if (binaryValue->GetSize() == sizeof(pyCallback)) {
                binaryValue->GetData(&pyCallback, sizeof(pyCallback), 0);
                v8FunctionHandler = new V8FunctionHandler(
                        NULL, pyCallback.callbackId);
                // You must provide a function name to
                // CefV8Value::CreateFunction(), otherwise it fails.
                callbackName.append(AnyToString(pyCallback.callbackId));
                success = ret->SetValue(key,
                                CefV8Value::CreateFunction(
                                        callbackName, v8FunctionHandler));
            } else {
                DebugLog("CefListValueToV8Value(): WARNING: " \
                        "unknown binary value, setting value to null");
                success = ret->SetValue(key, CefV8Value::CreateNull());
            }
        } else if (valueType == VTYPE_DICTIONARY) {
            success = ret->SetValue(key,
                    CefDictionaryValueToV8Value(
                            listValue->GetDictionary(key),
                            nestingLevel + 1));
        } else if (valueType == VTYPE_LIST) {
            success = ret->SetValue(key,
                    CefListValueToV8Value(
                            listValue->GetList(key),
                            nestingLevel + 1));
        } else {
            DebugLog("CefListValueToV8Value(): WARNING: " \
                    "unknown type, setting value to null");
            success = ret->SetValue(key,
                    CefV8Value::CreateNull());
        }
        if (!success) {
            DebugLog("CefListValueToV8Value(): WARNING: " \
                    "ret->SetValue() failed");
        }
    }
    return ret;
}
Beispiel #7
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
boost::python::dict CefDictionaryValueToPy( CefRefPtr<CefDictionaryValue> d )
{
	boost::python::dict result;

	CefDictionaryValue::KeyList keys;
	d->GetKeys( keys );

	for( size_t i = 0; i < keys.size(); i++ )
	{
		std::string k = keys[i].ToString();

		switch( d->GetType( keys[i] ) )
		{
			case VTYPE_INT:
			{
				result[k.c_str()] = d->GetInt( keys[i] );
				break;
			}
			case VTYPE_DOUBLE:
			{
				result[k.c_str()] = d->GetDouble( keys[i] );
				break;
			}
			case VTYPE_BOOL:
			{
				result[k.c_str()] = d->GetBool( keys[i] );
				break;
			}
			case VTYPE_STRING:
			{
				result[k.c_str()] = d->GetString( keys[i] ).ToString().c_str();
				break;
			}
			case VTYPE_BINARY:
			{
				WarsCefData_t warsCefData;
				CefRefPtr<CefBinaryValue> binaryData = d->GetBinary( keys[i] );
				binaryData->GetData( &warsCefData, sizeof( warsCefData ), 0 );
				if( warsCefData.type == WARSCEF_TYPE_JSOBJECT )
				{
					WarsCefJSObject_t warsCefJSObject;
					binaryData->GetData( &warsCefJSObject, sizeof( warsCefJSObject ), 0 );

					CefRefPtr<JSObject> jsResultObject = new JSObject( "", warsCefJSObject.uuid );
					result[k.c_str()] = boost::python::object( PyJSObject( jsResultObject ) );
				}
				else
				{
					result[k.c_str()] = boost::python::object();
				}
				break;
			}
			case VTYPE_DICTIONARY:
			{
				result[k.c_str()] = CefDictionaryValueToPy( d->GetDictionary( keys[i] ) );
				break;
			}
			case VTYPE_LIST:
			{
				result[k.c_str()] = CefValueListToPy( d->GetList( keys[i] ) );
				break;
			}
			default:
			{
				result[k.c_str()] = d->GetString( keys[i] ).ToString().c_str();
				break;
			}
		}
	}

	return result;
}
Beispiel #8
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
boost::python::list CefValueListToPy( CefRefPtr<CefListValue> l )
{
	boost::python::list result;
	for( size_t i = 0; i < l->GetSize(); i++ )
	{
		switch( l->GetType( i ) )
		{
			case VTYPE_INT:
			{
				result.append( l->GetInt( i ) );
				break;
			}
			case VTYPE_DOUBLE:
			{
				result.append( l->GetDouble( i ) );
				break;
			}
			case VTYPE_BOOL:
			{
				result.append( l->GetBool( i ) );
				break;
			}
			case VTYPE_STRING:
			{
				result.append( l->GetString( i ).ToString().c_str() );
				break;
			}
			case VTYPE_BINARY:
			{
				WarsCefData_t warsCefData;
				l->GetBinary( i )->GetData( &warsCefData, sizeof( warsCefData ), 0 );
				if( warsCefData.type == WARSCEF_TYPE_JSOBJECT )
				{
					WarsCefJSObject_t warsCefJSObject;
					l->GetBinary( i )->GetData( &warsCefJSObject, sizeof( warsCefJSObject ), 0 );

					CefRefPtr<JSObject> jsResultObject = new JSObject( "", warsCefJSObject.uuid );
					result.append( boost::python::object( PyJSObject( jsResultObject ) ) );
				}
				else
				{
					result.append( boost::python::object() );
				}
				break;
			}
			case VTYPE_DICTIONARY:
			{
				result.append( CefDictionaryValueToPy( l->GetDictionary( i ) ) );
				break;
			}
			case VTYPE_LIST:
			{
				result.append( CefValueListToPy( l->GetList( i ) ) );
				break;
			}
			default:
			{
				result.append( l->GetString( i ).ToString().c_str() );
				break;
			}
		}
	}
	return result;
}