IDictionary<String^, IValue^>^ CefExtensionWrapper::Manifest::get() { ThrowIfDisposed(); auto dictionary = _extension->GetManifest();; if (!dictionary.get() || (int)dictionary->GetSize() == 0) { return nullptr; } auto result = gcnew Dictionary<String^, IValue^>(); CefDictionaryValue::KeyList keys; dictionary->GetKeys(keys); for (auto i = 0; i < keys.size(); i++) { auto key = keys[i]; auto keyValue = StringUtils::ToClr(key); auto valueWrapper = gcnew CefValueWrapper(dictionary->GetValue(keys[i])); result->Add(keyValue, valueWrapper); } return result; }
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; } } }
//----------------------------------------------------------------------------- // 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; }