/* webxdc.c generated by valac 0.56.19, the Vala compiler
 * generated from webxdc.vala, do not modify */

/* Experimental Webxdc runner: hosts a Delta Chat mini-app (.xdc archive)
 * in a web view. Compiled only with -Dwebxdc=true; otherwise
 * webxdc_stub.vala provides the same entry points as no-ops so no other
 * file needs conditional compilation. The jsonrpc plumbing and the JS
 * bridge below are platform-independent; only the view layer splits:
 * WebKitGTK on GNOME, and isolated native shims on macOS and Windows. See
 * docs/webxdc.md for the security boundaries and the JS API. */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gdk/gdk.h>
#include <gobject/gvaluecollector.h>
#include <gio/gio.h>
#include <json-glib/json-glib.h>
#include <gtk/gtk.h>
#include <glib/gstdio.h>
#include <adwaita.h>
#include <webkit/webkit.h>
#include <jsc/jsc.h>
#include <libsoup/soup.h>

#define DC_WEBXDC_AVAILABLE TRUE
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DC_WEBXDC_TYPE_INSTANCE (dc_webxdc_instance_get_type ())
#define DC_WEBXDC_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_WEBXDC_TYPE_INSTANCE, DcWebxdcInstance))
#define DC_WEBXDC_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_WEBXDC_TYPE_INSTANCE, DcWebxdcInstanceClass))
#define DC_WEBXDC_IS_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_WEBXDC_TYPE_INSTANCE))
#define DC_WEBXDC_IS_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_WEBXDC_TYPE_INSTANCE))
#define DC_WEBXDC_INSTANCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_WEBXDC_TYPE_INSTANCE, DcWebxdcInstanceClass))

typedef struct _DcWebxdcInstance DcWebxdcInstance;
typedef struct _DcWebxdcInstanceClass DcWebxdcInstanceClass;

#define DC_WEBXDC_TYPE_MONITOR (dc_webxdc_monitor_get_type ())
#define DC_WEBXDC_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_WEBXDC_TYPE_MONITOR, DcWebxdcMonitor))
#define DC_WEBXDC_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_WEBXDC_TYPE_MONITOR, DcWebxdcMonitorClass))
#define DC_WEBXDC_IS_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_WEBXDC_TYPE_MONITOR))
#define DC_WEBXDC_IS_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_WEBXDC_TYPE_MONITOR))
#define DC_WEBXDC_MONITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_WEBXDC_TYPE_MONITOR, DcWebxdcMonitorClass))

typedef struct _DcWebxdcMonitor DcWebxdcMonitor;
typedef struct _DcWebxdcMonitorClass DcWebxdcMonitorClass;
typedef struct _DcWebxdcMonitorPrivate DcWebxdcMonitorPrivate;
enum  {
	DC_WEBXDC_MONITOR_0_PROPERTY,
	DC_WEBXDC_MONITOR_NUM_PROPERTIES
};
static GParamSpec* dc_webxdc_monitor_properties[DC_WEBXDC_MONITOR_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	DC_WEBXDC_MONITOR_CHANGED_SIGNAL,
	DC_WEBXDC_MONITOR_NUM_SIGNALS
};
static guint dc_webxdc_monitor_signals[DC_WEBXDC_MONITOR_NUM_SIGNALS] = {0};
typedef struct _DcWebxdcInstancePrivate DcWebxdcInstancePrivate;

#define DC_TYPE_RPC_CLIENT (dc_rpc_client_get_type ())
#define DC_RPC_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_RPC_CLIENT, DcRpcClient))
#define DC_RPC_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_RPC_CLIENT, DcRpcClientClass))
#define DC_IS_RPC_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_RPC_CLIENT))
#define DC_IS_RPC_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_RPC_CLIENT))
#define DC_RPC_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_RPC_CLIENT, DcRpcClientClass))

typedef struct _DcRpcClient DcRpcClient;
typedef struct _DcRpcClientClass DcRpcClientClass;

#define DC_TYPE_SETTINGS_MANAGER (dc_settings_manager_get_type ())
#define DC_SETTINGS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_SETTINGS_MANAGER, DcSettingsManager))
#define DC_SETTINGS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_SETTINGS_MANAGER, DcSettingsManagerClass))
#define DC_IS_SETTINGS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_SETTINGS_MANAGER))
#define DC_IS_SETTINGS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_SETTINGS_MANAGER))
#define DC_SETTINGS_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_SETTINGS_MANAGER, DcSettingsManagerClass))

typedef struct _DcSettingsManager DcSettingsManager;
typedef struct _DcSettingsManagerClass DcSettingsManagerClass;

#define DC_WEBXDC_TYPE_CARD_INFO (dc_webxdc_card_info_get_type ())
#define DC_WEBXDC_CARD_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_WEBXDC_TYPE_CARD_INFO, DcWebxdcCardInfo))
#define DC_WEBXDC_CARD_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_WEBXDC_TYPE_CARD_INFO, DcWebxdcCardInfoClass))
#define DC_WEBXDC_IS_CARD_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_WEBXDC_TYPE_CARD_INFO))
#define DC_WEBXDC_IS_CARD_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_WEBXDC_TYPE_CARD_INFO))
#define DC_WEBXDC_CARD_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_WEBXDC_TYPE_CARD_INFO, DcWebxdcCardInfoClass))

typedef struct _DcWebxdcCardInfo DcWebxdcCardInfo;
typedef struct _DcWebxdcCardInfoClass DcWebxdcCardInfoClass;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
typedef struct _DcWebxdcCardInfoPrivate DcWebxdcCardInfoPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _DcWebxdcParamSpecCardInfo DcWebxdcParamSpecCardInfo;
#define _dc_webxdc_card_info_unref0(var) ((var == NULL) ? NULL : (var = (dc_webxdc_card_info_unref (var), NULL)))
typedef struct _DcWebxdcCardInfoData DcWebxdcCardInfoData;

#define DC_TYPE_PARAMS (dc_params_get_type ())
#define DC_PARAMS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_PARAMS, DcParams))
#define DC_PARAMS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_PARAMS, DcParamsClass))
#define DC_IS_PARAMS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_PARAMS))
#define DC_IS_PARAMS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_PARAMS))
#define DC_PARAMS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_PARAMS, DcParamsClass))

typedef struct _DcParams DcParams;
typedef struct _DcParamsClass DcParamsClass;
#define __vala_JsonNode_free0(var) ((var == NULL) ? NULL : (var = (_vala_JsonNode_free (var), NULL)))
#define _json_object_unref0(var) ((var == NULL) ? NULL : (var = (json_object_unref (var), NULL)))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _DcWebxdcFetchCardInfoData DcWebxdcFetchCardInfoData;

#define DC_TYPE_MESSAGE (dc_message_get_type ())
#define DC_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_MESSAGE, DcMessage))
#define DC_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_MESSAGE, DcMessageClass))
#define DC_IS_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_MESSAGE))
#define DC_IS_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_MESSAGE))
#define DC_MESSAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_MESSAGE, DcMessageClass))

typedef struct _DcMessage DcMessage;
typedef struct _DcMessageClass DcMessageClass;
enum  {
	DC_WEBXDC_INSTANCE_0_PROPERTY,
	DC_WEBXDC_INSTANCE_NUM_PROPERTIES
};
static GParamSpec* dc_webxdc_instance_properties[DC_WEBXDC_INSTANCE_NUM_PROPERTIES];
typedef struct _DcWebxdcInstanceStartData DcWebxdcInstanceStartData;
typedef struct _DcWebxdcInstanceServeData DcWebxdcInstanceServeData;
#define _json_array_unref0(var) ((var == NULL) ? NULL : (var = (json_array_unref (var), NULL)))
typedef struct _DcWebxdcInstancePullUpdatesData DcWebxdcInstancePullUpdatesData;
#define __vala_WebKitNetworkProxySettings_free0(var) ((var == NULL) ? NULL : (var = (_vala_WebKitNetworkProxySettings_free (var), NULL)))
#define _soup_message_headers_unref0(var) ((var == NULL) ? NULL : (var = (soup_message_headers_unref (var), NULL)))

struct _DcWebxdcMonitor {
	GObject parent_instance;
	DcWebxdcMonitorPrivate * priv;
};

struct _DcWebxdcMonitorClass {
	GObjectClass parent_class;
};

struct _DcWebxdcInstance {
	GObject parent_instance;
	DcWebxdcInstancePrivate * priv;
	gint msg_id;
};

struct _DcWebxdcInstanceClass {
	GObjectClass parent_class;
};

struct _DcWebxdcCardInfo {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DcWebxdcCardInfoPrivate * priv;
	gchar* name;
	GdkTexture* icon;
};

struct _DcWebxdcCardInfoClass {
	GTypeClass parent_class;
	void (*finalize) (DcWebxdcCardInfo *self);
};

struct _DcWebxdcParamSpecCardInfo {
	GParamSpec parent_instance;
};

struct _DcWebxdcCardInfoData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gint msg_id;
	DcWebxdcCardInfo* result;
	GHashTable* _tmp0_;
	GHashFunc _tmp1_;
	GEqualFunc _tmp2_;
	GHashTable* _tmp3_;
	DcWebxdcCardInfo* hit;
	GHashTable* _tmp4_;
	gconstpointer _tmp5_;
	DcWebxdcCardInfo* _tmp6_;
	DcWebxdcCardInfo* _tmp7_;
	DcWebxdcCardInfo* _tmp8_;
};

struct _DcWebxdcFetchCardInfoData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gint msg_id;
	DcWebxdcCardInfo* result;
	DcWebxdcCardInfo* info;
	DcWebxdcCardInfo* _tmp0_;
	DcRpcClient* rpc;
	DcRpcClient* _tmp1_;
	DcRpcClient* _tmp2_;
	DcRpcClient* _tmp3_;
	gint acct;
	DcRpcClient* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	JsonNode* res;
	DcRpcClient* _tmp7_;
	DcParams* _tmp8_;
	DcParams* _tmp9_;
	DcParams* _tmp10_;
	DcParams* _tmp11_;
	DcParams* _tmp12_;
	DcParams* _tmp13_;
	JsonNode* _tmp14_;
	JsonNode* _tmp15_;
	JsonNode* _tmp16_;
	JsonNode* _tmp17_;
	JsonObject* obj;
	JsonNode* _tmp18_;
	JsonObject* _tmp19_;
	JsonObject* _tmp20_;
	gchar* name;
	JsonObject* _tmp21_;
	const gchar* _tmp22_;
	gchar* _tmp23_;
	const gchar* _tmp24_;
	gint _tmp25_;
	gint _tmp26_;
	DcWebxdcCardInfo* _tmp27_;
	const gchar* _tmp28_;
	gchar* _tmp29_;
	gchar* icon;
	JsonObject* _tmp30_;
	const gchar* _tmp31_;
	gchar* _tmp32_;
	const gchar* _tmp33_;
	gint _tmp34_;
	gint _tmp35_;
	JsonNode* blob;
	DcRpcClient* _tmp36_;
	DcParams* _tmp37_;
	DcParams* _tmp38_;
	DcParams* _tmp39_;
	DcParams* _tmp40_;
	DcParams* _tmp41_;
	DcParams* _tmp42_;
	const gchar* _tmp43_;
	DcParams* _tmp44_;
	DcParams* _tmp45_;
	JsonNode* _tmp46_;
	JsonNode* _tmp47_;
	JsonNode* _tmp48_;
	JsonNode* _tmp49_;
	GdkTexture* _tmp50_;
	JsonNode* _tmp51_;
	const gchar* _tmp52_;
	gsize _tmp53_;
	guchar* _tmp54_;
	guchar* _tmp55_;
	gint _tmp55__length1;
	GBytes* _tmp56_;
	GBytes* _tmp57_;
	GdkTexture* _tmp58_;
	GdkTexture* _tmp59_;
	DcWebxdcCardInfo* _tmp60_;
	GdkTexture* _tmp61_;
	GError* e;
	GError* _tmp62_;
	const gchar* _tmp63_;
	GHashTable* _tmp64_;
	DcWebxdcCardInfo* _tmp65_;
	DcWebxdcCardInfo* _tmp66_;
	GError* _inner_error0_;
};

struct _DcWebxdcInstancePrivate {
	DcRpcClient* rpc;
	gint account_id;
	gint chat_id;
	gint64 last_serial;
	gchar* self_addr;
	gchar* self_name;
	gchar* app_name;
	gchar* document_name;
	gchar* chat_name;
	gboolean allow_internet;
	gboolean allow_wasm;
	gboolean allow_webgl;
	gboolean allow_hardware_acceleration;
	gboolean hidden_by_follow;
	AdwWindow* win;
	WebKitWebView* view;
	gboolean minimized_by_bar;
};

struct _DcWebxdcInstanceStartData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcWebxdcInstance* self;
	JsonNode* info;
	DcRpcClient* _tmp0_;
	DcParams* _tmp1_;
	DcParams* _tmp2_;
	DcParams* _tmp3_;
	DcParams* _tmp4_;
	DcParams* _tmp5_;
	DcParams* _tmp6_;
	JsonNode* _tmp7_;
	JsonNode* _tmp8_;
	JsonNode* _tmp9_;
	JsonNode* _tmp10_;
	JsonObject* obj;
	JsonObject* _tmp11_;
	JsonObject* _tmp12_;
	gchar* name;
	JsonObject* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	const gchar* _tmp16_;
	gint _tmp17_;
	gint _tmp18_;
	const gchar* _tmp19_;
	gchar* _tmp20_;
	JsonObject* _tmp21_;
	const gchar* _tmp22_;
	gchar* _tmp23_;
	GError* e;
	GError* _tmp24_;
	const gchar* _tmp25_;
	JsonObject* chat;
	DcRpcClient* _tmp26_;
	JsonObject* _tmp27_;
	gchar* _vala1_name;
	const gchar* _tmp28_;
	gchar* _tmp29_;
	const gchar* _tmp30_;
	gint _tmp31_;
	gint _tmp32_;
	const gchar* _tmp33_;
	gchar* _tmp34_;
	GError* _vala1_e;
	GError* _tmp35_;
	const gchar* _tmp36_;
	gchar* _tmp37_;
	gchar* _tmp38_;
	gchar* dn;
	DcRpcClient* _tmp39_;
	gchar* _tmp40_;
	gboolean _tmp41_;
	gint _tmp42_;
	gint _tmp43_;
	gchar* _tmp44_;
	DcRpcClient* _tmp45_;
	const gchar* _tmp46_;
	const gchar* _tmp47_;
	DcRpcClient* _tmp48_;
	const gchar* _tmp49_;
	const gchar* _tmp50_;
	gchar* _tmp51_;
	DcRpcClient* _tmp52_;
	const gchar* _tmp53_;
	const gchar* _tmp54_;
	DcRpcClient* _tmp55_;
	const gchar* _tmp56_;
	const gchar* _tmp57_;
	gchar* _tmp58_;
	GError* _vala2_e;
	GError* _tmp59_;
	const gchar* _tmp60_;
	GError* _inner_error0_;
};

struct _DcWebxdcInstanceServeData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcWebxdcInstance* self;
	gchar* path;
	WebKitURISchemeRequest* token;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* p;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gboolean _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	guint8* _tmp14_;
	gint _tmp14__length1;
	gint _tmp15_;
	guint8* _tmp16_;
	gint _tmp16__length1;
	JsonNode* res;
	DcRpcClient* _tmp17_;
	DcParams* _tmp18_;
	DcParams* _tmp19_;
	DcParams* _tmp20_;
	DcParams* _tmp21_;
	DcParams* _tmp22_;
	DcParams* _tmp23_;
	const gchar* _tmp24_;
	DcParams* _tmp25_;
	DcParams* _tmp26_;
	JsonNode* _tmp27_;
	JsonNode* _tmp28_;
	JsonNode* _tmp29_;
	JsonNode* _tmp30_;
	guchar* data;
	JsonNode* _tmp31_;
	const gchar* _tmp32_;
	gsize _tmp33_;
	guchar* _tmp34_;
	gint data_length1;
	gint _data_size_;
	gboolean uncertain;
	gchar* ctype;
	const gchar* _tmp35_;
	guchar* _tmp36_;
	gint _tmp36__length1;
	gboolean _tmp37_;
	gchar* _tmp38_;
	gchar* _tmp39_;
	const gchar* _tmp40_;
	gchar* _tmp41_;
	gchar* _tmp42_;
	gchar* mime;
	gchar* _tmp43_;
	guchar* _tmp44_;
	gint _tmp44__length1;
	const gchar* _tmp45_;
	GError* e;
	GError* _tmp46_;
	const gchar* _tmp47_;
	GError* _inner_error0_;
};

struct _DcWebxdcInstancePullUpdatesData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcWebxdcInstance* self;
	gchar* updates;
	JsonNode* res;
	DcRpcClient* _tmp0_;
	DcParams* _tmp1_;
	DcParams* _tmp2_;
	DcParams* _tmp3_;
	DcParams* _tmp4_;
	DcParams* _tmp5_;
	DcParams* _tmp6_;
	DcParams* _tmp7_;
	DcParams* _tmp8_;
	JsonNode* _tmp9_;
	JsonNode* _tmp10_;
	JsonNode* _tmp11_;
	JsonNode* _tmp12_;
	JsonNode* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	JsonParser* parser;
	JsonParser* _tmp16_;
	JsonParser* _tmp17_;
	const gchar* _tmp18_;
	JsonArray* arr;
	JsonParser* _tmp19_;
	JsonNode* _tmp20_;
	JsonArray* _tmp21_;
	JsonArray* _tmp22_;
	JsonArray* _tmp23_;
	guint i;
	gboolean _tmp24_;
	guint _tmp25_;
	JsonArray* _tmp26_;
	JsonObject* item;
	JsonArray* _tmp27_;
	JsonObject* _tmp28_;
	JsonObject* _tmp29_;
	gint64 serial;
	JsonObject* _tmp30_;
	JsonNode* doc;
	JsonObject* _tmp31_;
	JsonNode* _tmp32_;
	JsonNode* _tmp33_;
	gboolean _tmp34_;
	JsonNode* _tmp35_;
	JsonNode* _tmp36_;
	gchar* d;
	JsonNode* _tmp37_;
	const gchar* _tmp38_;
	gchar* _tmp39_;
	gboolean _tmp40_;
	gboolean _tmp41_;
	const gchar* _tmp42_;
	const gchar* _tmp43_;
	gint _tmp44_;
	gint _tmp45_;
	const gchar* _tmp46_;
	const gchar* _tmp47_;
	const gchar* _tmp48_;
	gchar* _tmp49_;
	gchar* _tmp50_;
	gchar* _tmp51_;
	GError* e;
	GError* _tmp52_;
	const gchar* _tmp53_;
	const gchar* _tmp54_;
	gchar* _tmp55_;
	gchar* _tmp56_;
	GError* _inner_error0_;
};

VALA_EXTERN GHashTable* dc_webxdc_windows;
GHashTable* dc_webxdc_windows = NULL;
static gpointer dc_webxdc_monitor_parent_class = NULL;
static DcWebxdcMonitor* dc_webxdc_monitor_instance;
static DcWebxdcMonitor* dc_webxdc_monitor_instance = NULL;
VALA_EXTERN gint dc_webxdc_active_account;
gint dc_webxdc_active_account = 0;
VALA_EXTERN gint dc_webxdc_active_chat;
gint dc_webxdc_active_chat = 0;
VALA_EXTERN gboolean dc_webxdc_chat_window_visible;
gboolean dc_webxdc_chat_window_visible = TRUE;
VALA_EXTERN DcRpcClient* dc_webxdc_client;
DcRpcClient* dc_webxdc_client = NULL;
VALA_EXTERN DcSettingsManager* dc_webxdc_config;
DcSettingsManager* dc_webxdc_config = NULL;
VALA_EXTERN gboolean dc_webxdc_follow_setting_connected;
gboolean dc_webxdc_follow_setting_connected = FALSE;
VALA_EXTERN gboolean dc_webxdc_security_settings_connected;
gboolean dc_webxdc_security_settings_connected = FALSE;
VALA_EXTERN gboolean dc_webxdc_security_close_pending;
gboolean dc_webxdc_security_close_pending = FALSE;
VALA_EXTERN GHashTable* dc_webxdc_cards;
static gpointer dc_webxdc_card_info_parent_class = NULL;
GHashTable* dc_webxdc_cards = NULL;
static gint DcWebxdcInstance_private_offset;
static gpointer dc_webxdc_instance_parent_class = NULL;

VALA_EXTERN GType dc_webxdc_instance_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcWebxdcInstance, g_object_unref)
VALA_EXTERN GType dc_webxdc_monitor_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcWebxdcMonitor, g_object_unref)
VALA_EXTERN DcWebxdcMonitor* dc_webxdc_monitor_get_default (void);
VALA_EXTERN DcWebxdcMonitor* dc_webxdc_monitor_new (void);
VALA_EXTERN DcWebxdcMonitor* dc_webxdc_monitor_construct (GType object_type);
static void dc_webxdc_monitor_finalize (GObject * obj);
static GType dc_webxdc_monitor_get_type_once (void);
VALA_EXTERN void dc_webxdc_set_active_chat (gint account_id,
                                gint chat_id,
                                gboolean window_visible);
VALA_EXTERN void dc_webxdc_instance_apply_follow_visibility (DcWebxdcInstance* self);
VALA_EXTERN gboolean dc_webxdc_is_running (gint msg_id);
VALA_EXTERN gint* dc_webxdc_running_apps (gint account_id,
                              gint chat_id,
                              gint* result_length1);
VALA_EXTERN gboolean dc_webxdc_instance_belongs_to (DcWebxdcInstance* self,
                                        gint account_id,
                                        gint chat_id);
static void _vala_array_add72 (gint* * array,
                        gint* length,
                        gint* size,
                        gint value);
VALA_EXTERN void dc_webxdc_stop_app (gint msg_id);
VALA_EXTERN void dc_webxdc_instance_close_view (DcWebxdcInstance* self);
VALA_EXTERN void dc_webxdc_present_app (gint msg_id);
VALA_EXTERN void dc_webxdc_instance_present (DcWebxdcInstance* self);
VALA_EXTERN void dc_webxdc_minimize_app (gint msg_id);
VALA_EXTERN void dc_webxdc_instance_toggle_minimize_view (DcWebxdcInstance* self);
VALA_EXTERN GType dc_rpc_client_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcRpcClient, g_object_unref)
VALA_EXTERN GType dc_settings_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcSettingsManager, g_object_unref)
VALA_EXTERN void dc_webxdc_setup (DcRpcClient* rpc,
                      DcSettingsManager* settings);
VALA_EXTERN gpointer dc_webxdc_card_info_ref (gpointer instance);
VALA_EXTERN void dc_webxdc_card_info_unref (gpointer instance);
VALA_EXTERN GParamSpec* dc_webxdc_param_spec_card_info (const gchar* name,
                                            const gchar* nick,
                                            const gchar* blurb,
                                            GType object_type,
                                            GParamFlags flags);
VALA_EXTERN void dc_webxdc_value_set_card_info (GValue* value,
                                    gpointer v_object);
VALA_EXTERN void dc_webxdc_value_take_card_info (GValue* value,
                                     gpointer v_object);
VALA_EXTERN gpointer dc_webxdc_value_get_card_info (const GValue* value);
VALA_EXTERN GType dc_webxdc_card_info_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcWebxdcCardInfo, dc_webxdc_card_info_unref)
static void ___lambda355_ (void);
static void ____lambda355__g_object_notify (GObject* _sender,
                                     GParamSpec* pspec,
                                     gpointer self);
static void ___lambda356_ (void);
VALA_EXTERN void dc_webxdc_schedule_security_close (void);
static void ____lambda356__g_object_notify (GObject* _sender,
                                     GParamSpec* pspec,
                                     gpointer self);
static void ___lambda358_ (void);
static void ____lambda358__g_object_notify (GObject* _sender,
                                     GParamSpec* pspec,
                                     gpointer self);
static void ___lambda359_ (void);
static void ____lambda359__g_object_notify (GObject* _sender,
                                     GParamSpec* pspec,
                                     gpointer self);
static void ___lambda360_ (void);
static void ____lambda360__g_object_notify (GObject* _sender,
                                     GParamSpec* pspec,
                                     gpointer self);
static gboolean __lambda357_ (void);
static gboolean ___lambda357__gsource_func (gpointer self);
VALA_EXTERN gboolean dc_webxdc_enabled (void);
VALA_EXTERN gboolean dc_settings_manager_get_webxdc_apps (DcSettingsManager* self);
VALA_EXTERN DcWebxdcCardInfo* dc_webxdc_card_info_new (void);
VALA_EXTERN DcWebxdcCardInfo* dc_webxdc_card_info_construct (GType object_type);
static void dc_webxdc_card_info_finalize (DcWebxdcCardInfo * obj);
static GType dc_webxdc_card_info_get_type_once (void);
static void dc_webxdc_card_info_data_free (gpointer _data);
VALA_EXTERN void dc_webxdc_card_info (gint msg_id,
                          GAsyncReadyCallback _callback_,
                          gpointer _user_data_);
VALA_EXTERN DcWebxdcCardInfo* dc_webxdc_card_info_finish (GAsyncResult* _res_);
static gboolean dc_webxdc_card_info_co (DcWebxdcCardInfoData* _data_);
static void _dc_webxdc_card_info_unref0_ (gpointer var);
VALA_EXTERN void dc_webxdc_fetch_card_info (gint msg_id,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_);
VALA_EXTERN DcWebxdcCardInfo* dc_webxdc_fetch_card_info_finish (GAsyncResult* _res_);
static void dc_webxdc_card_info_ready (GObject* source_object,
                                GAsyncResult* _res_,
                                gpointer _user_data_);
static void dc_webxdc_fetch_card_info_data_free (gpointer _data);
static gboolean dc_webxdc_fetch_card_info_co (DcWebxdcFetchCardInfoData* _data_);
VALA_EXTERN gint dc_rpc_client_get_account_id (DcRpcClient* self);
VALA_EXTERN void dc_rpc_client_call (DcRpcClient* self,
                         const gchar* method,
                         JsonNode* params,
                         GAsyncReadyCallback _callback_,
                         gpointer _user_data_);
VALA_EXTERN JsonNode* dc_rpc_client_call_finish (DcRpcClient* self,
                                     GAsyncResult* _res_,
                                     GError** error);
VALA_EXTERN GType dc_params_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcParams, g_object_unref)
VALA_EXTERN DcParams* dc_params_begin (void);
VALA_EXTERN DcParams* dc_params_add_int (DcParams* self,
                             gint v);
VALA_EXTERN JsonNode* dc_params_build (DcParams* self);
static void dc_webxdc_fetch_card_info_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_);
static void _vala_JsonNode_free (JsonNode* self);
VALA_EXTERN DcParams* dc_params_add_string (DcParams* self,
                                const gchar* v);
VALA_EXTERN GType dc_message_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcMessage, g_object_unref)
VALA_EXTERN void dc_webxdc_open (GtkWindow* parent,
                     DcRpcClient* rpc,
                     DcMessage* msg);
VALA_EXTERN gboolean dc_webxdc_linux_sandbox_available (gchar** message);
VALA_EXTERN void dc_show_error (GtkWidget* parent,
                    const gchar* message);
static void _g_object_unref0_ (gpointer var);
VALA_EXTERN gint dc_message_get_id (DcMessage* self);
VALA_EXTERN DcWebxdcInstance* dc_webxdc_instance_new (DcRpcClient* rpc,
                                          DcMessage* msg);
VALA_EXTERN DcWebxdcInstance* dc_webxdc_instance_construct (GType object_type,
                                                DcRpcClient* rpc,
                                                DcMessage* msg);
VALA_EXTERN void dc_webxdc_status_update (gint msg_id);
VALA_EXTERN void dc_webxdc_instance_pull_updates (DcWebxdcInstance* self,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_);
VALA_EXTERN void dc_webxdc_instance_pull_updates_finish (DcWebxdcInstance* self,
                                             GAsyncResult* _res_);
VALA_EXTERN void dc_webxdc_instance_deleted (gint msg_id);
VALA_EXTERN gint dc_message_get_chat_id (DcMessage* self);
VALA_EXTERN gchar* dc_message_display_file_name (DcMessage* self,
                                     const gchar* fallback);
VALA_EXTERN gboolean dc_settings_manager_get_webxdc_allow_internet (DcSettingsManager* self);
VALA_EXTERN gboolean dc_settings_manager_get_webxdc_allow_wasm (DcSettingsManager* self);
VALA_EXTERN gboolean dc_settings_manager_get_webxdc_allow_webgl (DcSettingsManager* self);
VALA_EXTERN gboolean dc_settings_manager_get_webxdc_allow_hardware_acceleration (DcSettingsManager* self);
static void dc_webxdc_instance_create_view (DcWebxdcInstance* self,
                                     const gchar* title);
static void dc_webxdc_instance_start (DcWebxdcInstance* self,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_);
static void dc_webxdc_instance_start_finish (DcWebxdcInstance* self,
                                      GAsyncResult* _res_);
static gchar* dc_webxdc_instance_truncate_text (const gchar* text,
                                         gint max_len);
static gchar* dc_webxdc_instance_compose_title (DcWebxdcInstance* self);
static void dc_webxdc_instance_start_data_free (gpointer _data);
static gboolean dc_webxdc_instance_start_co (DcWebxdcInstanceStartData* _data_);
static void dc_webxdc_instance_start_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_);
VALA_EXTERN void dc_rpc_client_get_full_chat_by_id_for (DcRpcClient* self,
                                            gint acct_id,
                                            gint chat_id,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
VALA_EXTERN JsonObject* dc_rpc_client_get_full_chat_by_id_for_finish (DcRpcClient* self,
                                                          GAsyncResult* _res_,
                                                          GError** error);
static void dc_webxdc_instance_set_view_title (DcWebxdcInstance* self,
                                        const gchar* title);
VALA_EXTERN void dc_rpc_client_get_config (DcRpcClient* self,
                               const gchar* key,
                               gint acct_id,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_);
VALA_EXTERN gchar* dc_rpc_client_get_config_finish (DcRpcClient* self,
                                        GAsyncResult* _res_,
                                        GError** error);
VALA_EXTERN const gchar* dc_rpc_client_get_self_email (DcRpcClient* self);
static void dc_webxdc_instance_load_view (DcWebxdcInstance* self,
                                   const gchar* uri);
static void dc_webxdc_instance_serve_data_free (gpointer _data);
static void dc_webxdc_instance_serve (DcWebxdcInstance* self,
                               const gchar* path,
                               WebKitURISchemeRequest* token,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_);
static void dc_webxdc_instance_serve_finish (DcWebxdcInstance* self,
                                      GAsyncResult* _res_);
static gboolean dc_webxdc_instance_serve_co (DcWebxdcInstanceServeData* _data_);
static void dc_webxdc_instance_deliver (DcWebxdcInstance* self,
                                 WebKitURISchemeRequest* token,
                                 guint8* data,
                                 gint data_length1,
                                 const gchar* mime);
static gchar* dc_webxdc_instance_bridge_js (DcWebxdcInstance* self);
static void dc_webxdc_instance_serve_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_);
static void dc_webxdc_instance_fail (DcWebxdcInstance* self,
                              WebKitURISchemeRequest* token);
static gchar* dc_webxdc_instance_js_str (const gchar* s);
static void dc_webxdc_instance_on_message (DcWebxdcInstance* self,
                                    const gchar* json);
static JsonNode* _vala_JsonNode_copy (JsonNode* self);
static void dc_webxdc_instance_pull_updates_data_free (gpointer _data);
static gboolean dc_webxdc_instance_pull_updates_co (DcWebxdcInstancePullUpdatesData* _data_);
static void dc_webxdc_instance_pull_updates_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_);
static void dc_webxdc_instance_eval_js (DcWebxdcInstance* self,
                                 const gchar* js);
static void dc_webxdc_instance_on_view_closed (DcWebxdcInstance* self);
VALA_EXTERN gboolean dc_settings_manager_get_webxdc_follow_chat (DcSettingsManager* self);
static void dc_webxdc_instance_set_view_visible (DcWebxdcInstance* self,
                                          gboolean visible);
static void __lambda58_ (DcWebxdcInstance* self,
                  JSCValue* value);
static void ___lambda58__webkit_user_content_manager_script_message_received (WebKitUserContentManager* _sender,
                                                                       JSCValue* value,
                                                                       gpointer self);
static void __lambda59_ (DcWebxdcInstance* self,
                  WebKitURISchemeRequest* req);
static void ___lambda59__web_kit_uri_scheme_request_callback (WebKitURISchemeRequest* request,
                                                       gpointer self);
static void _vala_WebKitNetworkProxySettings_free (WebKitNetworkProxySettings* self);
static gboolean dc_webxdc_instance_on_decide_policy (DcWebxdcInstance* self,
                                              WebKitPolicyDecision* decision,
                                              WebKitPolicyDecisionType type);
static gboolean _dc_webxdc_instance_on_decide_policy_webkit_web_view_decide_policy (WebKitWebView* _sender,
                                                                             WebKitPolicyDecision* decision,
                                                                             WebKitPolicyDecisionType type,
                                                                             gpointer self);
static gboolean __lambda60_ (DcWebxdcInstance* self);
static gboolean ___lambda60__gtk_window_close_request (GtkWindow* _sender,
                                                gpointer self);
VALA_EXTERN gchar* dc_webxdc_security_wasm_csp (gboolean allow_wasm);
static void dc_webxdc_instance_finalize (GObject * obj);
static GType dc_webxdc_instance_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

DcWebxdcMonitor*
dc_webxdc_monitor_get_default (void)
{
	DcWebxdcMonitor* _tmp0_;
	DcWebxdcMonitor* _tmp2_;
	DcWebxdcMonitor* _tmp3_;
	DcWebxdcMonitor* result;
	_tmp0_ = dc_webxdc_monitor_instance;
	if (_tmp0_ == NULL) {
		DcWebxdcMonitor* _tmp1_;
		_tmp1_ = dc_webxdc_monitor_new ();
		_g_object_unref0 (dc_webxdc_monitor_instance);
		dc_webxdc_monitor_instance = _tmp1_;
	}
	_tmp2_ = dc_webxdc_monitor_instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

DcWebxdcMonitor*
dc_webxdc_monitor_construct (GType object_type)
{
	DcWebxdcMonitor * self = NULL;
	self = (DcWebxdcMonitor*) g_object_new (object_type, NULL);
	return self;
}

DcWebxdcMonitor*
dc_webxdc_monitor_new (void)
{
	return dc_webxdc_monitor_construct (DC_WEBXDC_TYPE_MONITOR);
}

static void
dc_webxdc_monitor_class_init (DcWebxdcMonitorClass * klass,
                              gpointer klass_data)
{
	dc_webxdc_monitor_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = dc_webxdc_monitor_finalize;
	dc_webxdc_monitor_signals[DC_WEBXDC_MONITOR_CHANGED_SIGNAL] = g_signal_new ("changed", DC_WEBXDC_TYPE_MONITOR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
}

static void
dc_webxdc_monitor_instance_init (DcWebxdcMonitor * self,
                                 gpointer klass)
{
}

static void
dc_webxdc_monitor_finalize (GObject * obj)
{
	DcWebxdcMonitor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_WEBXDC_TYPE_MONITOR, DcWebxdcMonitor);
	G_OBJECT_CLASS (dc_webxdc_monitor_parent_class)->finalize (obj);
}

/** Signal hub for run-state and preference changes, so UI like the
        per-chat apps bar can stay in sync without polling. */
static GType
dc_webxdc_monitor_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcWebxdcMonitorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_webxdc_monitor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcWebxdcMonitor), 0, (GInstanceInitFunc) dc_webxdc_monitor_instance_init, NULL };
	GType dc_webxdc_monitor_type_id;
	dc_webxdc_monitor_type_id = g_type_register_static (G_TYPE_OBJECT, "DcWebxdcMonitor", &g_define_type_info, 0);
	return dc_webxdc_monitor_type_id;
}

GType
dc_webxdc_monitor_get_type (void)
{
	static volatile gsize dc_webxdc_monitor_type_id__once = 0;
	if (g_once_init_enter (&dc_webxdc_monitor_type_id__once)) {
		GType dc_webxdc_monitor_type_id;
		dc_webxdc_monitor_type_id = dc_webxdc_monitor_get_type_once ();
		g_once_init_leave (&dc_webxdc_monitor_type_id__once, dc_webxdc_monitor_type_id);
	}
	return dc_webxdc_monitor_type_id__once;
}

void
dc_webxdc_set_active_chat (gint account_id,
                           gint chat_id,
                           gboolean window_visible)
{
	GHashTable* _tmp0_;
	GHashTable* _tmp1_;
	GList* _tmp2_;
	dc_webxdc_active_account = account_id;
	dc_webxdc_active_chat = chat_id;
	dc_webxdc_chat_window_visible = window_visible;
	_tmp0_ = dc_webxdc_windows;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = dc_webxdc_windows;
	_tmp2_ = g_hash_table_get_values (_tmp1_);
	{
		GList* app_collection = NULL;
		GList* app_it = NULL;
		app_collection = _tmp2_;
		for (app_it = app_collection; app_it != NULL; app_it = app_it->next) {
			DcWebxdcInstance* app = NULL;
			app = (DcWebxdcInstance*) app_it->data;
			{
				DcWebxdcInstance* _tmp3_;
				_tmp3_ = app;
				dc_webxdc_instance_apply_follow_visibility (_tmp3_);
			}
		}
		(app_collection == NULL) ? NULL : (app_collection = (g_list_free (app_collection), NULL));
	}
}

gboolean
dc_webxdc_is_running (gint msg_id)
{
	gboolean _tmp0_ = FALSE;
	GHashTable* _tmp1_;
	gboolean result;
	_tmp1_ = dc_webxdc_windows;
	if (_tmp1_ != NULL) {
		GHashTable* _tmp2_;
		gconstpointer _tmp3_;
		_tmp2_ = dc_webxdc_windows;
		_tmp3_ = g_hash_table_lookup (_tmp2_, (gpointer) ((gintptr) msg_id));
		_tmp0_ = ((DcWebxdcInstance*) _tmp3_) != NULL;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

/** Msg ids of the running app windows started from the given chat. */
static void
_vala_array_add72 (gint* * array,
                   gint* length,
                   gint* size,
                   gint value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gint, *array, *size);
	}
	(*array)[(*length)++] = value;
}

gint*
dc_webxdc_running_apps (gint account_id,
                        gint chat_id,
                        gint* result_length1)
{
	gint* ids = NULL;
	gint* _tmp0_;
	gint ids_length1;
	gint _ids_size_;
	GHashTable* _tmp1_;
	GHashTable* _tmp3_;
	GList* _tmp4_;
	gint* _tmp7_;
	gint _tmp7__length1;
	gint* result;
	_tmp0_ = g_new0 (gint, 0);
	ids = _tmp0_;
	ids_length1 = 0;
	_ids_size_ = ids_length1;
	_tmp1_ = dc_webxdc_windows;
	if (_tmp1_ == NULL) {
		gint* _tmp2_;
		gint _tmp2__length1;
		_tmp2_ = ids;
		_tmp2__length1 = ids_length1;
		if (result_length1) {
			*result_length1 = _tmp2__length1;
		}
		result = _tmp2_;
		return result;
	}
	_tmp3_ = dc_webxdc_windows;
	_tmp4_ = g_hash_table_get_values (_tmp3_);
	{
		GList* app_collection = NULL;
		GList* app_it = NULL;
		app_collection = _tmp4_;
		for (app_it = app_collection; app_it != NULL; app_it = app_it->next) {
			DcWebxdcInstance* app = NULL;
			app = (DcWebxdcInstance*) app_it->data;
			{
				DcWebxdcInstance* _tmp5_;
				_tmp5_ = app;
				if (dc_webxdc_instance_belongs_to (_tmp5_, account_id, chat_id)) {
					DcWebxdcInstance* _tmp6_;
					_tmp6_ = app;
					_vala_array_add72 (&ids, &ids_length1, &_ids_size_, _tmp6_->msg_id);
				}
			}
		}
		(app_collection == NULL) ? NULL : (app_collection = (g_list_free (app_collection), NULL));
	}
	_tmp7_ = ids;
	_tmp7__length1 = ids_length1;
	if (result_length1) {
		*result_length1 = _tmp7__length1;
	}
	result = _tmp7_;
	return result;
}

void
dc_webxdc_stop_app (gint msg_id)
{
	DcWebxdcInstance* _tmp0_ = NULL;
	GHashTable* _tmp1_;
	DcWebxdcInstance* app = NULL;
	DcWebxdcInstance* _tmp4_;
	DcWebxdcInstance* _tmp5_;
	_tmp1_ = dc_webxdc_windows;
	if (_tmp1_ == NULL) {
		_tmp0_ = NULL;
	} else {
		GHashTable* _tmp2_;
		gconstpointer _tmp3_;
		_tmp2_ = dc_webxdc_windows;
		_tmp3_ = g_hash_table_lookup (_tmp2_, (gpointer) ((gintptr) msg_id));
		_tmp0_ = (DcWebxdcInstance*) _tmp3_;
	}
	_tmp4_ = _g_object_ref0 (_tmp0_);
	app = _tmp4_;
	_tmp5_ = app;
	if (_tmp5_ != NULL) {
		DcWebxdcInstance* _tmp6_;
		_tmp6_ = app;
		dc_webxdc_instance_close_view (_tmp6_);
	}
	_g_object_unref0 (app);
}

/** Raise the app window (and restore it if minimized). */
void
dc_webxdc_present_app (gint msg_id)
{
	DcWebxdcInstance* _tmp0_ = NULL;
	GHashTable* _tmp1_;
	DcWebxdcInstance* app = NULL;
	DcWebxdcInstance* _tmp4_;
	DcWebxdcInstance* _tmp5_;
	_tmp1_ = dc_webxdc_windows;
	if (_tmp1_ == NULL) {
		_tmp0_ = NULL;
	} else {
		GHashTable* _tmp2_;
		gconstpointer _tmp3_;
		_tmp2_ = dc_webxdc_windows;
		_tmp3_ = g_hash_table_lookup (_tmp2_, (gpointer) ((gintptr) msg_id));
		_tmp0_ = (DcWebxdcInstance*) _tmp3_;
	}
	_tmp4_ = _g_object_ref0 (_tmp0_);
	app = _tmp4_;
	_tmp5_ = app;
	if (_tmp5_ != NULL) {
		DcWebxdcInstance* _tmp6_;
		_tmp6_ = app;
		dc_webxdc_instance_present (_tmp6_);
	}
	_g_object_unref0 (app);
}

/** Minimize the app window, or restore it if already minimized. */
void
dc_webxdc_minimize_app (gint msg_id)
{
	DcWebxdcInstance* _tmp0_ = NULL;
	GHashTable* _tmp1_;
	DcWebxdcInstance* app = NULL;
	DcWebxdcInstance* _tmp4_;
	DcWebxdcInstance* _tmp5_;
	_tmp1_ = dc_webxdc_windows;
	if (_tmp1_ == NULL) {
		_tmp0_ = NULL;
	} else {
		GHashTable* _tmp2_;
		gconstpointer _tmp3_;
		_tmp2_ = dc_webxdc_windows;
		_tmp3_ = g_hash_table_lookup (_tmp2_, (gpointer) ((gintptr) msg_id));
		_tmp0_ = (DcWebxdcInstance*) _tmp3_;
	}
	_tmp4_ = _g_object_ref0 (_tmp0_);
	app = _tmp4_;
	_tmp5_ = app;
	if (_tmp5_ != NULL) {
		DcWebxdcInstance* _tmp6_;
		_tmp6_ = app;
		dc_webxdc_instance_toggle_minimize_view (_tmp6_);
	}
	_g_object_unref0 (app);
}

static void
___lambda355_ (void)
{
	GHashTable* _tmp0_;
	GHashTable* _tmp1_;
	GList* _tmp2_;
	_tmp0_ = dc_webxdc_windows;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = dc_webxdc_windows;
	_tmp2_ = g_hash_table_get_values (_tmp1_);
	{
		GList* app_collection = NULL;
		GList* app_it = NULL;
		app_collection = _tmp2_;
		for (app_it = app_collection; app_it != NULL; app_it = app_it->next) {
			DcWebxdcInstance* app = NULL;
			app = (DcWebxdcInstance*) app_it->data;
			{
				DcWebxdcInstance* _tmp3_;
				_tmp3_ = app;
				dc_webxdc_instance_apply_follow_visibility (_tmp3_);
			}
		}
		(app_collection == NULL) ? NULL : (app_collection = (g_list_free (app_collection), NULL));
	}
}

static void
____lambda355__g_object_notify (GObject* _sender,
                                GParamSpec* pspec,
                                gpointer self)
{
	___lambda355_ ();
}

static void
___lambda356_ (void)
{
	dc_webxdc_schedule_security_close ();
}

static void
____lambda356__g_object_notify (GObject* _sender,
                                GParamSpec* pspec,
                                gpointer self)
{
	___lambda356_ ();
}

static void
___lambda358_ (void)
{
	dc_webxdc_schedule_security_close ();
}

static void
____lambda358__g_object_notify (GObject* _sender,
                                GParamSpec* pspec,
                                gpointer self)
{
	___lambda358_ ();
}

static void
___lambda359_ (void)
{
	dc_webxdc_schedule_security_close ();
}

static void
____lambda359__g_object_notify (GObject* _sender,
                                GParamSpec* pspec,
                                gpointer self)
{
	___lambda359_ ();
}

static void
___lambda360_ (void)
{
	dc_webxdc_schedule_security_close ();
}

static void
____lambda360__g_object_notify (GObject* _sender,
                                GParamSpec* pspec,
                                gpointer self)
{
	___lambda360_ ();
}

void
dc_webxdc_setup (DcRpcClient* rpc,
                 DcSettingsManager* settings)
{
	DcRpcClient* _tmp0_;
	g_return_if_fail (rpc != NULL);
	g_return_if_fail (settings != NULL);
	_tmp0_ = _g_object_ref0 (rpc);
	_g_object_unref0 (dc_webxdc_client);
	dc_webxdc_client = _tmp0_;
	dc_webxdc_config = settings;
	_g_hash_table_unref0 (dc_webxdc_cards);
	dc_webxdc_cards = NULL;
	if (!dc_webxdc_follow_setting_connected) {
		dc_webxdc_follow_setting_connected = TRUE;
		g_signal_connect ((GObject*) settings, "notify::webxdc-follow-chat", (GCallback) ____lambda355__g_object_notify, NULL);
	}
	if (!dc_webxdc_security_settings_connected) {
		dc_webxdc_security_settings_connected = TRUE;
		g_signal_connect ((GObject*) settings, "notify::webxdc-allow-internet", (GCallback) ____lambda356__g_object_notify, NULL);
		g_signal_connect ((GObject*) settings, "notify::webxdc-allow-wasm", (GCallback) ____lambda358__g_object_notify, NULL);
		g_signal_connect ((GObject*) settings, "notify::webxdc-allow-webgl", (GCallback) ____lambda359__g_object_notify, NULL);
		g_signal_connect ((GObject*) settings, "notify::webxdc-allow-hardware-acceleration", (GCallback) ____lambda360__g_object_notify, NULL);
	}
}

static gboolean
__lambda357_ (void)
{
	GHashTable* _tmp0_;
	gboolean result;
	dc_webxdc_security_close_pending = FALSE;
	_tmp0_ = dc_webxdc_windows;
	if (_tmp0_ != NULL) {
		GHashTable* _tmp1_;
		GList* _tmp2_;
		_tmp1_ = dc_webxdc_windows;
		_tmp2_ = g_hash_table_get_values (_tmp1_);
		{
			GList* app_collection = NULL;
			GList* app_it = NULL;
			app_collection = _tmp2_;
			for (app_it = app_collection; app_it != NULL; app_it = app_it->next) {
				DcWebxdcInstance* app = NULL;
				app = (DcWebxdcInstance*) app_it->data;
				{
					DcWebxdcInstance* _tmp3_;
					_tmp3_ = app;
					dc_webxdc_instance_close_view (_tmp3_);
				}
			}
			(app_collection == NULL) ? NULL : (app_collection = (g_list_free (app_collection), NULL));
		}
	}
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda357__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda357_ ();
	return result;
}

void
dc_webxdc_schedule_security_close (void)
{
	if (dc_webxdc_security_close_pending) {
		return;
	}
	dc_webxdc_security_close_pending = TRUE;
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda357__gsource_func, NULL, NULL);
}

/** Compile-time support plus the runtime settings toggle. */
gboolean
dc_webxdc_enabled (void)
{
	gboolean _tmp0_ = FALSE;
	DcSettingsManager* _tmp1_;
	gboolean result;
	_tmp1_ = dc_webxdc_config;
	if (_tmp1_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		DcSettingsManager* _tmp2_;
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp2_ = dc_webxdc_config;
		_tmp3_ = dc_settings_manager_get_webxdc_apps (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_;
	}
	result = _tmp0_;
	return result;
}

DcWebxdcCardInfo*
dc_webxdc_card_info_construct (GType object_type)
{
	DcWebxdcCardInfo* self = NULL;
	self = (DcWebxdcCardInfo*) g_type_create_instance (object_type);
	return self;
}

DcWebxdcCardInfo*
dc_webxdc_card_info_new (void)
{
	return dc_webxdc_card_info_construct (DC_WEBXDC_TYPE_CARD_INFO);
}

static void
dc_webxdc_value_card_info_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
dc_webxdc_value_card_info_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dc_webxdc_card_info_unref (value->data[0].v_pointer);
	}
}

static void
dc_webxdc_value_card_info_copy_value (const GValue* src_value,
                                      GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dc_webxdc_card_info_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
dc_webxdc_value_card_info_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
dc_webxdc_value_card_info_collect_value (GValue* value,
                                         guint n_collect_values,
                                         GTypeCValue* collect_values,
                                         guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DcWebxdcCardInfo * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dc_webxdc_card_info_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
dc_webxdc_value_card_info_lcopy_value (const GValue* value,
                                       guint n_collect_values,
                                       GTypeCValue* collect_values,
                                       guint collect_flags)
{
	DcWebxdcCardInfo ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dc_webxdc_card_info_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
dc_webxdc_param_spec_card_info (const gchar* name,
                                const gchar* nick,
                                const gchar* blurb,
                                GType object_type,
                                GParamFlags flags)
{
	DcWebxdcParamSpecCardInfo* spec;
	g_return_val_if_fail (g_type_is_a (object_type, DC_WEBXDC_TYPE_CARD_INFO), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
dc_webxdc_value_get_card_info (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_WEBXDC_TYPE_CARD_INFO), NULL);
	return value->data[0].v_pointer;
}

void
dc_webxdc_value_set_card_info (GValue* value,
                               gpointer v_object)
{
	DcWebxdcCardInfo * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_WEBXDC_TYPE_CARD_INFO));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DC_WEBXDC_TYPE_CARD_INFO));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dc_webxdc_card_info_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dc_webxdc_card_info_unref (old);
	}
}

void
dc_webxdc_value_take_card_info (GValue* value,
                                gpointer v_object)
{
	DcWebxdcCardInfo * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_WEBXDC_TYPE_CARD_INFO));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DC_WEBXDC_TYPE_CARD_INFO));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dc_webxdc_card_info_unref (old);
	}
}

static void
dc_webxdc_card_info_class_init (DcWebxdcCardInfoClass * klass,
                                gpointer klass_data)
{
	dc_webxdc_card_info_parent_class = g_type_class_peek_parent (klass);
	((DcWebxdcCardInfoClass *) klass)->finalize = dc_webxdc_card_info_finalize;
}

static void
dc_webxdc_card_info_instance_init (DcWebxdcCardInfo * self,
                                   gpointer klass)
{
	self->ref_count = 1;
}

static void
dc_webxdc_card_info_finalize (DcWebxdcCardInfo * obj)
{
	DcWebxdcCardInfo * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_WEBXDC_TYPE_CARD_INFO, DcWebxdcCardInfo);
	g_signal_handlers_destroy (self);
	_g_free0 (self->name);
	_g_object_unref0 (self->icon);
}

static GType
dc_webxdc_card_info_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dc_webxdc_value_card_info_init, dc_webxdc_value_card_info_free_value, dc_webxdc_value_card_info_copy_value, dc_webxdc_value_card_info_peek_pointer, "p", dc_webxdc_value_card_info_collect_value, "p", dc_webxdc_value_card_info_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DcWebxdcCardInfoClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_webxdc_card_info_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcWebxdcCardInfo), 0, (GInstanceInitFunc) dc_webxdc_card_info_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType dc_webxdc_card_info_type_id;
	dc_webxdc_card_info_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DcWebxdcCardInfo", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return dc_webxdc_card_info_type_id;
}

GType
dc_webxdc_card_info_get_type (void)
{
	static volatile gsize dc_webxdc_card_info_type_id__once = 0;
	if (g_once_init_enter (&dc_webxdc_card_info_type_id__once)) {
		GType dc_webxdc_card_info_type_id;
		dc_webxdc_card_info_type_id = dc_webxdc_card_info_get_type_once ();
		g_once_init_leave (&dc_webxdc_card_info_type_id__once, dc_webxdc_card_info_type_id);
	}
	return dc_webxdc_card_info_type_id__once;
}

gpointer
dc_webxdc_card_info_ref (gpointer instance)
{
	DcWebxdcCardInfo * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
dc_webxdc_card_info_unref (gpointer instance)
{
	DcWebxdcCardInfo * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DC_WEBXDC_CARD_INFO_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
dc_webxdc_card_info_data_free (gpointer _data)
{
	DcWebxdcCardInfoData* _data_;
	_data_ = _data;
	_dc_webxdc_card_info_unref0 (_data_->result);
	g_slice_free (DcWebxdcCardInfoData, _data_);
}

void
dc_webxdc_card_info (gint msg_id,
                     GAsyncReadyCallback _callback_,
                     gpointer _user_data_)
{
	DcWebxdcCardInfoData* _data_;
	_data_ = g_slice_new0 (DcWebxdcCardInfoData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_webxdc_card_info_data_free);
	_data_->msg_id = msg_id;
	dc_webxdc_card_info_co (_data_);
}

DcWebxdcCardInfo*
dc_webxdc_card_info_finish (GAsyncResult* _res_)
{
	DcWebxdcCardInfo* result;
	DcWebxdcCardInfoData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/** App name and icon for the chat/gallery card, cached per message. */
static void
_dc_webxdc_card_info_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (dc_webxdc_card_info_unref (var), NULL));
}

static gpointer
_dc_webxdc_card_info_ref0 (gpointer self)
{
	return self ? dc_webxdc_card_info_ref (self) : NULL;
}

static void
dc_webxdc_card_info_ready (GObject* source_object,
                           GAsyncResult* _res_,
                           gpointer _user_data_)
{
	DcWebxdcCardInfoData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_webxdc_card_info_co (_data_);
}

static gboolean
dc_webxdc_card_info_co (DcWebxdcCardInfoData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = dc_webxdc_cards;
	if (_data_->_tmp0_ == NULL) {
		_data_->_tmp1_ = g_direct_hash;
		_data_->_tmp2_ = g_direct_equal;
		_data_->_tmp3_ = g_hash_table_new_full (_data_->_tmp1_, _data_->_tmp2_, NULL, _dc_webxdc_card_info_unref0_);
		_g_hash_table_unref0 (dc_webxdc_cards);
		dc_webxdc_cards = _data_->_tmp3_;
	}
	_data_->_tmp4_ = dc_webxdc_cards;
	_data_->_tmp5_ = g_hash_table_lookup (_data_->_tmp4_, (gpointer) ((gintptr) _data_->msg_id));
	_data_->_tmp6_ = _dc_webxdc_card_info_ref0 ((DcWebxdcCardInfo*) _data_->_tmp5_);
	_data_->hit = _data_->_tmp6_;
	_data_->_tmp7_ = _data_->hit;
	if (_data_->_tmp7_ != NULL) {
		_data_->result = _data_->hit;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_state_ = 1;
	dc_webxdc_fetch_card_info (_data_->msg_id, dc_webxdc_card_info_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp8_ = dc_webxdc_fetch_card_info_finish (_data_->_res_);
	_data_->result = _data_->_tmp8_;
	_dc_webxdc_card_info_unref0 (_data_->hit);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dc_webxdc_fetch_card_info_data_free (gpointer _data)
{
	DcWebxdcFetchCardInfoData* _data_;
	_data_ = _data;
	_dc_webxdc_card_info_unref0 (_data_->result);
	g_slice_free (DcWebxdcFetchCardInfoData, _data_);
}

void
dc_webxdc_fetch_card_info (gint msg_id,
                           GAsyncReadyCallback _callback_,
                           gpointer _user_data_)
{
	DcWebxdcFetchCardInfoData* _data_;
	_data_ = g_slice_new0 (DcWebxdcFetchCardInfoData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_webxdc_fetch_card_info_data_free);
	_data_->msg_id = msg_id;
	dc_webxdc_fetch_card_info_co (_data_);
}

DcWebxdcCardInfo*
dc_webxdc_fetch_card_info_finish (GAsyncResult* _res_)
{
	DcWebxdcCardInfo* result;
	DcWebxdcFetchCardInfoData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
dc_webxdc_fetch_card_info_ready (GObject* source_object,
                                 GAsyncResult* _res_,
                                 gpointer _user_data_)
{
	DcWebxdcFetchCardInfoData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_webxdc_fetch_card_info_co (_data_);
}

static void
_vala_JsonNode_free (JsonNode* self)
{
	g_boxed_free (json_node_get_type (), self);
}

static gpointer
_json_object_ref0 (gpointer self)
{
	return self ? json_object_ref (self) : NULL;
}

static gboolean
dc_webxdc_fetch_card_info_co (DcWebxdcFetchCardInfoData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = dc_webxdc_card_info_new ();
	_data_->info = _data_->_tmp0_;
	_data_->_tmp1_ = dc_webxdc_client;
	_data_->_tmp2_ = _g_object_ref0 (_data_->_tmp1_);
	_data_->rpc = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->rpc;
	if (_data_->_tmp3_ == NULL) {
		_data_->result = _data_->info;
		_g_object_unref0 (_data_->rpc);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp4_ = _data_->rpc;
	_data_->_tmp5_ = dc_rpc_client_get_account_id (_data_->_tmp4_);
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->acct = _data_->_tmp6_;
	{
		_data_->_tmp7_ = _data_->rpc;
		_data_->_tmp8_ = dc_params_begin ();
		_data_->_tmp9_ = _data_->_tmp8_;
		_data_->_tmp10_ = dc_params_add_int (_data_->_tmp9_, _data_->acct);
		_data_->_tmp11_ = _data_->_tmp10_;
		_data_->_tmp12_ = dc_params_add_int (_data_->_tmp11_, _data_->msg_id);
		_data_->_tmp13_ = _data_->_tmp12_;
		_data_->_tmp14_ = dc_params_build (_data_->_tmp13_);
		_data_->_tmp15_ = _data_->_tmp14_;
		_data_->_state_ = 1;
		dc_rpc_client_call (_data_->_tmp7_, "get_webxdc_info", _data_->_tmp15_, dc_webxdc_fetch_card_info_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp16_ = dc_rpc_client_call_finish (_data_->_tmp7_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp17_ = _data_->_tmp16_;
		__vala_JsonNode_free0 (_data_->_tmp15_);
		_g_object_unref0 (_data_->_tmp13_);
		_g_object_unref0 (_data_->_tmp11_);
		_g_object_unref0 (_data_->_tmp9_);
		_data_->res = _data_->_tmp17_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp18_ = _data_->res;
		_data_->_tmp19_ = json_node_get_object (_data_->_tmp18_);
		_data_->_tmp20_ = _json_object_ref0 (_data_->_tmp19_);
		_data_->obj = _data_->_tmp20_;
		_data_->_tmp21_ = _data_->obj;
		_data_->_tmp22_ = json_object_get_string_member_with_default (_data_->_tmp21_, "name", "");
		_data_->_tmp23_ = g_strdup (_data_->_tmp22_);
		_data_->name = _data_->_tmp23_;
		_data_->_tmp24_ = _data_->name;
		_data_->_tmp25_ = strlen (_data_->_tmp24_);
		_data_->_tmp26_ = _data_->_tmp25_;
		if (_data_->_tmp26_ > 0) {
			_data_->_tmp27_ = _data_->info;
			_data_->_tmp28_ = _data_->name;
			_data_->_tmp29_ = g_strdup (_data_->_tmp28_);
			_g_free0 (_data_->_tmp27_->name);
			_data_->_tmp27_->name = _data_->_tmp29_;
		}
		_data_->_tmp30_ = _data_->obj;
		_data_->_tmp31_ = json_object_get_string_member_with_default (_data_->_tmp30_, "icon", "");
		_data_->_tmp32_ = g_strdup (_data_->_tmp31_);
		_data_->icon = _data_->_tmp32_;
		_data_->_tmp33_ = _data_->icon;
		_data_->_tmp34_ = strlen (_data_->_tmp33_);
		_data_->_tmp35_ = _data_->_tmp34_;
		if (_data_->_tmp35_ > 0) {
			_data_->_tmp36_ = _data_->rpc;
			_data_->_tmp37_ = dc_params_begin ();
			_data_->_tmp38_ = _data_->_tmp37_;
			_data_->_tmp39_ = dc_params_add_int (_data_->_tmp38_, _data_->acct);
			_data_->_tmp40_ = _data_->_tmp39_;
			_data_->_tmp41_ = dc_params_add_int (_data_->_tmp40_, _data_->msg_id);
			_data_->_tmp42_ = _data_->_tmp41_;
			_data_->_tmp43_ = _data_->icon;
			_data_->_tmp44_ = dc_params_add_string (_data_->_tmp42_, _data_->_tmp43_);
			_data_->_tmp45_ = _data_->_tmp44_;
			_data_->_tmp46_ = dc_params_build (_data_->_tmp45_);
			_data_->_tmp47_ = _data_->_tmp46_;
			_data_->_state_ = 2;
			dc_rpc_client_call (_data_->_tmp36_, "get_webxdc_blob", _data_->_tmp47_, dc_webxdc_fetch_card_info_ready, _data_);
			return FALSE;
			_state_2:
			_data_->_tmp48_ = dc_rpc_client_call_finish (_data_->_tmp36_, _data_->_res_, &_data_->_inner_error0_);
			_data_->_tmp49_ = _data_->_tmp48_;
			__vala_JsonNode_free0 (_data_->_tmp47_);
			_g_object_unref0 (_data_->_tmp45_);
			_g_object_unref0 (_data_->_tmp42_);
			_g_object_unref0 (_data_->_tmp40_);
			_g_object_unref0 (_data_->_tmp38_);
			_data_->blob = _data_->_tmp49_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_free0 (_data_->icon);
				_g_free0 (_data_->name);
				_json_object_unref0 (_data_->obj);
				__vala_JsonNode_free0 (_data_->res);
				goto __catch0_g_error;
			}
			_data_->_tmp51_ = _data_->blob;
			_data_->_tmp52_ = json_node_get_string (_data_->_tmp51_);
			_data_->_tmp53_ = 0;
			_data_->_tmp54_ = g_base64_decode (_data_->_tmp52_, &_data_->_tmp53_);
			_data_->_tmp55_ = _data_->_tmp54_;
			_data_->_tmp55__length1 = _data_->_tmp53_;
			_data_->_tmp56_ = g_bytes_new (_data_->_tmp55_, _data_->_tmp53_);
			_data_->_tmp57_ = _data_->_tmp56_;
			_data_->_tmp58_ = gdk_texture_new_from_bytes (_data_->_tmp57_, &_data_->_inner_error0_);
			_data_->_tmp59_ = _data_->_tmp58_;
			_g_bytes_unref0 (_data_->_tmp57_);
			_data_->_tmp55_ = (g_free (_data_->_tmp55_), NULL);
			_data_->_tmp50_ = _data_->_tmp59_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				__vala_JsonNode_free0 (_data_->blob);
				_g_free0 (_data_->icon);
				_g_free0 (_data_->name);
				_json_object_unref0 (_data_->obj);
				__vala_JsonNode_free0 (_data_->res);
				goto __catch0_g_error;
			}
			_data_->_tmp60_ = _data_->info;
			_data_->_tmp61_ = _data_->_tmp50_;
			_data_->_tmp50_ = NULL;
			_g_object_unref0 (_data_->_tmp60_->icon);
			_data_->_tmp60_->icon = _data_->_tmp61_;
			_g_object_unref0 (_data_->_tmp50_);
			__vala_JsonNode_free0 (_data_->blob);
		}
		_g_free0 (_data_->icon);
		_g_free0 (_data_->name);
		_json_object_unref0 (_data_->obj);
		__vala_JsonNode_free0 (_data_->res);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp62_ = _data_->e;
		_data_->_tmp63_ = _data_->_tmp62_->message;
		g_debug ("webxdc.vala:177: webxdc card info: %s", _data_->_tmp63_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->rpc);
		_dc_webxdc_card_info_unref0 (_data_->info);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp64_ = dc_webxdc_cards;
	_data_->_tmp65_ = _data_->info;
	_data_->_tmp66_ = _dc_webxdc_card_info_ref0 (_data_->_tmp65_);
	g_hash_table_replace (_data_->_tmp64_, (gpointer) ((gintptr) _data_->msg_id), _data_->_tmp66_);
	_data_->result = _data_->info;
	_g_object_unref0 (_data_->rpc);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

void
dc_webxdc_open (GtkWindow* parent,
                DcRpcClient* rpc,
                DcMessage* msg)
{
	gchar* sandbox_error = NULL;
	gchar* _tmp0_ = NULL;
	gboolean _tmp1_;
	GHashTable* _tmp4_;
	DcWebxdcInstance* existing = NULL;
	GHashTable* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	gconstpointer _tmp11_;
	DcWebxdcInstance* _tmp12_;
	DcWebxdcInstance* _tmp13_;
	GHashTable* _tmp15_;
	gint _tmp16_;
	gint _tmp17_;
	DcWebxdcInstance* _tmp18_;
	DcWebxdcMonitor* _tmp19_;
	DcWebxdcMonitor* _tmp20_;
	gint _tmp21_;
	gint _tmp22_;
	g_return_if_fail (rpc != NULL);
	g_return_if_fail (msg != NULL);
	_tmp1_ = dc_webxdc_linux_sandbox_available (&_tmp0_);
	_g_free0 (sandbox_error);
	sandbox_error = _tmp0_;
	if (!_tmp1_) {
		if (parent != NULL) {
			const gchar* _tmp2_;
			_tmp2_ = sandbox_error;
			dc_show_error ((GtkWidget*) parent, _tmp2_);
		} else {
			const gchar* _tmp3_;
			_tmp3_ = sandbox_error;
			g_warning ("webxdc.vala:188: %s", _tmp3_);
		}
		_g_free0 (sandbox_error);
		return;
	}
	_tmp4_ = dc_webxdc_windows;
	if (_tmp4_ == NULL) {
		GHashFunc _tmp5_;
		GEqualFunc _tmp6_;
		GHashTable* _tmp7_;
		_tmp5_ = g_direct_hash;
		_tmp6_ = g_direct_equal;
		_tmp7_ = g_hash_table_new_full (_tmp5_, _tmp6_, NULL, _g_object_unref0_);
		_g_hash_table_unref0 (dc_webxdc_windows);
		dc_webxdc_windows = _tmp7_;
	}
	_tmp8_ = dc_webxdc_windows;
	_tmp9_ = dc_message_get_id (msg);
	_tmp10_ = _tmp9_;
	_tmp11_ = g_hash_table_lookup (_tmp8_, (gpointer) ((gintptr) _tmp10_));
	_tmp12_ = _g_object_ref0 ((DcWebxdcInstance*) _tmp11_);
	existing = _tmp12_;
	_tmp13_ = existing;
	if (_tmp13_ != NULL) {
		DcWebxdcInstance* _tmp14_;
		_tmp14_ = existing;
		dc_webxdc_instance_present (_tmp14_);
		_g_object_unref0 (existing);
		_g_free0 (sandbox_error);
		return;
	}
	_tmp15_ = dc_webxdc_windows;
	_tmp16_ = dc_message_get_id (msg);
	_tmp17_ = _tmp16_;
	_tmp18_ = dc_webxdc_instance_new (rpc, msg);
	g_hash_table_insert (_tmp15_, (gpointer) ((gintptr) _tmp17_), _tmp18_);
	_tmp19_ = dc_webxdc_monitor_get_default ();
	_tmp20_ = _tmp19_;
	_tmp21_ = dc_message_get_id (msg);
	_tmp22_ = _tmp21_;
	g_signal_emit (_tmp20_, dc_webxdc_monitor_signals[DC_WEBXDC_MONITOR_CHANGED_SIGNAL], 0, _tmp22_);
	_g_object_unref0 (_tmp20_);
	_g_object_unref0 (existing);
	_g_free0 (sandbox_error);
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

gboolean
dc_webxdc_linux_sandbox_available (gchar** message)
{
	gchar* _vala_message = NULL;
	gchar* _tmp0_;
	gchar* restricted = NULL;
	gchar* label = NULL;
	gboolean _tmp6_ = FALSE;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gboolean _tmp10_;
	gchar* _tmp14_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	_tmp0_ = g_strdup ("");
	_g_free0 (_vala_message);
	_vala_message = _tmp0_;
	{
		gchar* _tmp1_ = NULL;
		gchar* _tmp3_ = NULL;
		g_file_get_contents ("/proc/sys/kernel/apparmor_restrict_unprivileged_userns", &_tmp1_, NULL, &_inner_error0_);
		_g_free0 (restricted);
		restricted = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp2_ = FALSE;
			if (_inner_error0_->domain == G_FILE_ERROR) {
				goto __catch0_g_file_error;
			}
			_g_free0 (label);
			_g_free0 (restricted);
			_g_free0 (_vala_message);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp2_;
		}
		g_file_get_contents ("/proc/self/attr/current", &_tmp3_, NULL, &_inner_error0_);
		_g_free0 (label);
		label = _tmp3_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp4_ = FALSE;
			if (_inner_error0_->domain == G_FILE_ERROR) {
				goto __catch0_g_file_error;
			}
			_g_free0 (label);
			_g_free0 (restricted);
			_g_free0 (_vala_message);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp4_;
		}
	}
	goto __finally0;
	__catch0_g_file_error:
	{
		g_clear_error (&_inner_error0_);
		result = TRUE;
		_g_free0 (label);
		_g_free0 (restricted);
		if (message) {
			*message = _vala_message;
		} else {
			_g_free0 (_vala_message);
		}
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp5_ = FALSE;
		_g_free0 (label);
		_g_free0 (restricted);
		_g_free0 (_vala_message);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp5_;
	}
	_tmp7_ = restricted;
	_tmp8_ = string_strip (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_strcmp0 (_tmp9_, "1") != 0;
	_g_free0 (_tmp9_);
	if (_tmp10_) {
		_tmp6_ = TRUE;
	} else {
		const gchar* _tmp11_;
		gchar* _tmp12_;
		gchar* _tmp13_;
		_tmp11_ = label;
		_tmp12_ = string_strip (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp6_ = g_strcmp0 (_tmp13_, "unconfined") != 0;
		_g_free0 (_tmp13_);
	}
	if (_tmp6_) {
		result = TRUE;
		_g_free0 (label);
		_g_free0 (restricted);
		if (message) {
			*message = _vala_message;
		} else {
			_g_free0 (_vala_message);
		}
		return result;
	}
	_tmp14_ = g_strdup ("Ubuntu AppArmor is blocking the user namespace required " "by WebKitGTK's sandbox. Install this Webxdc build with " "‘sudo make install WITH_WEBXDC=1’, then restart Parla. " "Webxdc will not run without its web-engine sandbox.");
	_g_free0 (_vala_message);
	_vala_message = _tmp14_;
	result = FALSE;
	_g_free0 (label);
	_g_free0 (restricted);
	if (message) {
		*message = _vala_message;
	} else {
		_g_free0 (_vala_message);
	}
	return result;
}

/** Routed from the WebxdcStatusUpdate core event. */
void
dc_webxdc_status_update (gint msg_id)
{
	DcWebxdcInstance* _tmp0_ = NULL;
	GHashTable* _tmp1_;
	DcWebxdcInstance* app = NULL;
	DcWebxdcInstance* _tmp4_;
	DcWebxdcInstance* _tmp5_;
	_tmp1_ = dc_webxdc_windows;
	if (_tmp1_ == NULL) {
		_tmp0_ = NULL;
	} else {
		GHashTable* _tmp2_;
		gconstpointer _tmp3_;
		_tmp2_ = dc_webxdc_windows;
		_tmp3_ = g_hash_table_lookup (_tmp2_, (gpointer) ((gintptr) msg_id));
		_tmp0_ = (DcWebxdcInstance*) _tmp3_;
	}
	_tmp4_ = _g_object_ref0 (_tmp0_);
	app = _tmp4_;
	_tmp5_ = app;
	if (_tmp5_ != NULL) {
		DcWebxdcInstance* _tmp6_;
		_tmp6_ = app;
		dc_webxdc_instance_pull_updates (_tmp6_, NULL, NULL);
	}
	_g_object_unref0 (app);
}

/** Routed from the WebxdcInstanceDeleted core event. */
void
dc_webxdc_instance_deleted (gint msg_id)
{
	DcWebxdcInstance* _tmp0_ = NULL;
	GHashTable* _tmp1_;
	DcWebxdcInstance* app = NULL;
	DcWebxdcInstance* _tmp4_;
	DcWebxdcInstance* _tmp5_;
	_tmp1_ = dc_webxdc_windows;
	if (_tmp1_ == NULL) {
		_tmp0_ = NULL;
	} else {
		GHashTable* _tmp2_;
		gconstpointer _tmp3_;
		_tmp2_ = dc_webxdc_windows;
		_tmp3_ = g_hash_table_lookup (_tmp2_, (gpointer) ((gintptr) msg_id));
		_tmp0_ = (DcWebxdcInstance*) _tmp3_;
	}
	_tmp4_ = _g_object_ref0 (_tmp0_);
	app = _tmp4_;
	_tmp5_ = app;
	if (_tmp5_ != NULL) {
		DcWebxdcInstance* _tmp6_;
		_tmp6_ = app;
		dc_webxdc_instance_close_view (_tmp6_);
	}
	_g_object_unref0 (app);
}

static inline gpointer
dc_webxdc_instance_get_instance_private (DcWebxdcInstance* self)
{
	return G_STRUCT_MEMBER_P (self, DcWebxdcInstance_private_offset);
}

DcWebxdcInstance*
dc_webxdc_instance_construct (GType object_type,
                              DcRpcClient* rpc,
                              DcMessage* msg)
{
	DcWebxdcInstance * self = NULL;
	DcRpcClient* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gchar* _tmp7_;
	DcSettingsManager* _tmp8_;
	const gchar* _tmp21_;
	g_return_val_if_fail (rpc != NULL, NULL);
	g_return_val_if_fail (msg != NULL, NULL);
	self = (DcWebxdcInstance*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (rpc);
	_g_object_unref0 (self->priv->rpc);
	self->priv->rpc = _tmp0_;
	_tmp1_ = dc_rpc_client_get_account_id (rpc);
	_tmp2_ = _tmp1_;
	self->priv->account_id = _tmp2_;
	_tmp3_ = dc_message_get_id (msg);
	_tmp4_ = _tmp3_;
	self->msg_id = _tmp4_;
	_tmp5_ = dc_message_get_chat_id (msg);
	_tmp6_ = _tmp5_;
	self->priv->chat_id = _tmp6_;
	_tmp7_ = dc_message_display_file_name (msg, "Webxdc");
	_g_free0 (self->priv->app_name);
	self->priv->app_name = _tmp7_;
	_tmp8_ = dc_webxdc_config;
	if (_tmp8_ != NULL) {
		DcSettingsManager* _tmp9_;
		gboolean _tmp10_;
		gboolean _tmp11_;
		DcSettingsManager* _tmp12_;
		gboolean _tmp13_;
		gboolean _tmp14_;
		DcSettingsManager* _tmp15_;
		gboolean _tmp16_;
		gboolean _tmp17_;
		DcSettingsManager* _tmp18_;
		gboolean _tmp19_;
		gboolean _tmp20_;
		_tmp9_ = dc_webxdc_config;
		_tmp10_ = dc_settings_manager_get_webxdc_allow_internet (_tmp9_);
		_tmp11_ = _tmp10_;
		self->priv->allow_internet = _tmp11_;
		_tmp12_ = dc_webxdc_config;
		_tmp13_ = dc_settings_manager_get_webxdc_allow_wasm (_tmp12_);
		_tmp14_ = _tmp13_;
		self->priv->allow_wasm = _tmp14_;
		_tmp15_ = dc_webxdc_config;
		_tmp16_ = dc_settings_manager_get_webxdc_allow_webgl (_tmp15_);
		_tmp17_ = _tmp16_;
		self->priv->allow_webgl = _tmp17_;
		_tmp18_ = dc_webxdc_config;
		_tmp19_ = dc_settings_manager_get_webxdc_allow_hardware_acceleration (_tmp18_);
		_tmp20_ = _tmp19_;
		self->priv->allow_hardware_acceleration = _tmp20_;
	}
	_tmp21_ = self->priv->app_name;
	dc_webxdc_instance_create_view (self, _tmp21_);
	dc_webxdc_instance_present (self);
	dc_webxdc_instance_start (self, NULL, NULL);
	return self;
}

DcWebxdcInstance*
dc_webxdc_instance_new (DcRpcClient* rpc,
                        DcMessage* msg)
{
	return dc_webxdc_instance_construct (DC_WEBXDC_TYPE_INSTANCE, rpc, msg);
}

/** Mirror the official Delta Chat clients: cut at max_len
            characters and append an ellipsis only when truncating. */
static gint
string_index_of_nth_char (const gchar* self,
                          glong c)
{
	gchar* _tmp0_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = g_utf8_offset_to_pointer (self, c);
	result = (gint) (_tmp0_ - ((gchar*) self));
	return result;
}

static gchar*
string_slice (const gchar* self,
              glong start,
              glong end)
{
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	if (start < ((glong) 0)) {
		start = string_length + start;
	}
	if (end < ((glong) 0)) {
		end = string_length + end;
	}
	if (start >= ((glong) 0)) {
		_tmp2_ = start <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	if (end >= ((glong) 0)) {
		_tmp3_ = end <= string_length;
	} else {
		_tmp3_ = FALSE;
	}
	g_return_val_if_fail (_tmp3_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	_tmp4_ = g_strndup (((gchar*) self) + start, (gsize) (end - start));
	result = _tmp4_;
	return result;
}

static gchar*
dc_webxdc_instance_truncate_text (const gchar* text,
                                  gint max_len)
{
	gint end = 0;
	gboolean _tmp1_ = FALSE;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* result;
	g_return_val_if_fail (text != NULL, NULL);
	if (max_len <= 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (text);
		result = _tmp0_;
		return result;
	}
	end = string_index_of_nth_char (text, (glong) max_len);
	if (end < 0) {
		_tmp1_ = TRUE;
	} else {
		gint _tmp2_;
		gint _tmp3_;
		_tmp2_ = strlen (text);
		_tmp3_ = _tmp2_;
		_tmp1_ = end >= _tmp3_;
	}
	if (_tmp1_) {
		gchar* _tmp4_;
		_tmp4_ = g_strdup (text);
		result = _tmp4_;
		return result;
	}
	_tmp5_ = string_slice (text, (glong) 0, (glong) end);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_strdup_printf ("%s…", _tmp6_);
	_tmp8_ = _tmp7_;
	_g_free0 (_tmp6_);
	result = _tmp8_;
	return result;
}

/** "app – chat" (or "document - app – chat" for editing apps),
            exactly how the official clients build webxdc window titles.
            The chat is where the app's binding to a chat is visible. */
static gchar*
dc_webxdc_instance_compose_title (DcWebxdcInstance* self)
{
	gchar* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	gchar* document = NULL;
	gchar* _tmp11_;
	gchar* name = NULL;
	const gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_ = NULL;
	gboolean _tmp15_ = FALSE;
	const gchar* _tmp16_;
	gchar* _tmp27_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp2_ = self->priv->document_name;
	if (_tmp2_ != NULL) {
		const gchar* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		_tmp3_ = self->priv->document_name;
		_tmp4_ = strlen (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_ > 0;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		const gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		_tmp6_ = self->priv->document_name;
		_tmp7_ = dc_webxdc_instance_truncate_text (_tmp6_, 32);
		_tmp8_ = _tmp7_;
		_tmp9_ = g_strdup_printf ("%s - ", _tmp8_);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp9_;
		_g_free0 (_tmp8_);
	} else {
		gchar* _tmp10_;
		_tmp10_ = g_strdup ("");
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp10_;
	}
	_tmp11_ = _tmp0_;
	_tmp0_ = NULL;
	document = _tmp11_;
	_tmp12_ = self->priv->app_name;
	_tmp13_ = dc_webxdc_instance_truncate_text (_tmp12_, 42);
	name = _tmp13_;
	_tmp16_ = self->priv->chat_name;
	if (_tmp16_ != NULL) {
		const gchar* _tmp17_;
		gint _tmp18_;
		gint _tmp19_;
		_tmp17_ = self->priv->chat_name;
		_tmp18_ = strlen (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp15_ = _tmp19_ > 0;
	} else {
		_tmp15_ = FALSE;
	}
	if (_tmp15_) {
		const gchar* _tmp20_;
		const gchar* _tmp21_;
		const gchar* _tmp22_;
		gchar* _tmp23_;
		_tmp20_ = document;
		_tmp21_ = name;
		_tmp22_ = self->priv->chat_name;
		_tmp23_ = g_strdup_printf ("%s%s – %s", _tmp20_, _tmp21_, _tmp22_);
		_g_free0 (_tmp14_);
		_tmp14_ = _tmp23_;
	} else {
		const gchar* _tmp24_;
		const gchar* _tmp25_;
		gchar* _tmp26_;
		_tmp24_ = document;
		_tmp25_ = name;
		_tmp26_ = g_strdup_printf ("%s%s", _tmp24_, _tmp25_);
		_g_free0 (_tmp14_);
		_tmp14_ = _tmp26_;
	}
	_tmp27_ = _tmp14_;
	_tmp14_ = NULL;
	result = _tmp27_;
	_g_free0 (_tmp14_);
	_g_free0 (name);
	_g_free0 (document);
	_g_free0 (_tmp0_);
	return result;
}

static void
dc_webxdc_instance_start_data_free (gpointer _data)
{
	DcWebxdcInstanceStartData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DcWebxdcInstanceStartData, _data_);
}

static void
dc_webxdc_instance_start (DcWebxdcInstance* self,
                          GAsyncReadyCallback _callback_,
                          gpointer _user_data_)
{
	DcWebxdcInstanceStartData* _data_;
	DcWebxdcInstance* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcWebxdcInstanceStartData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_webxdc_instance_start_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_webxdc_instance_start_co (_data_);
}

static void
dc_webxdc_instance_start_finish (DcWebxdcInstance* self,
                                 GAsyncResult* _res_)
{
	DcWebxdcInstanceStartData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_webxdc_instance_start_ready (GObject* source_object,
                                GAsyncResult* _res_,
                                gpointer _user_data_)
{
	DcWebxdcInstanceStartData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_webxdc_instance_start_co (_data_);
}

static gboolean
dc_webxdc_instance_start_co (DcWebxdcInstanceStartData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_tmp0_ = _data_->self->priv->rpc;
		_data_->_tmp1_ = dc_params_begin ();
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp3_ = dc_params_add_int (_data_->_tmp2_, _data_->self->priv->account_id);
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp5_ = dc_params_add_int (_data_->_tmp4_, _data_->self->msg_id);
		_data_->_tmp6_ = _data_->_tmp5_;
		_data_->_tmp7_ = dc_params_build (_data_->_tmp6_);
		_data_->_tmp8_ = _data_->_tmp7_;
		_data_->_state_ = 1;
		dc_rpc_client_call (_data_->_tmp0_, "get_webxdc_info", _data_->_tmp8_, dc_webxdc_instance_start_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp9_ = dc_rpc_client_call_finish (_data_->_tmp0_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp10_ = _data_->_tmp9_;
		__vala_JsonNode_free0 (_data_->_tmp8_);
		_g_object_unref0 (_data_->_tmp6_);
		_g_object_unref0 (_data_->_tmp4_);
		_g_object_unref0 (_data_->_tmp2_);
		_data_->info = _data_->_tmp10_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp11_ = json_node_get_object (_data_->info);
		_data_->_tmp12_ = _json_object_ref0 (_data_->_tmp11_);
		_data_->obj = _data_->_tmp12_;
		_data_->_tmp13_ = _data_->obj;
		_data_->_tmp14_ = json_object_get_string_member_with_default (_data_->_tmp13_, "name", "");
		_data_->_tmp15_ = g_strdup (_data_->_tmp14_);
		_data_->name = _data_->_tmp15_;
		_data_->_tmp16_ = _data_->name;
		_data_->_tmp17_ = strlen (_data_->_tmp16_);
		_data_->_tmp18_ = _data_->_tmp17_;
		if (_data_->_tmp18_ > 0) {
			_data_->_tmp19_ = _data_->name;
			_data_->_tmp20_ = g_strdup (_data_->_tmp19_);
			_g_free0 (_data_->self->priv->app_name);
			_data_->self->priv->app_name = _data_->_tmp20_;
		}
		_data_->_tmp21_ = _data_->obj;
		_data_->_tmp22_ = json_object_get_string_member_with_default (_data_->_tmp21_, "document", "");
		_data_->_tmp23_ = g_strdup (_data_->_tmp22_);
		_g_free0 (_data_->self->priv->document_name);
		_data_->self->priv->document_name = _data_->_tmp23_;
		_g_free0 (_data_->name);
		_json_object_unref0 (_data_->obj);
		__vala_JsonNode_free0 (_data_->info);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp24_ = _data_->e;
		_data_->_tmp25_ = _data_->_tmp24_->message;
		g_warning ("webxdc.vala:319: webxdc info: %s", _data_->_tmp25_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp26_ = _data_->self->priv->rpc;
		_data_->_state_ = 2;
		dc_rpc_client_get_full_chat_by_id_for (_data_->_tmp26_, _data_->self->priv->account_id, _data_->self->priv->chat_id, dc_webxdc_instance_start_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp27_ = dc_rpc_client_get_full_chat_by_id_for_finish (_data_->_tmp26_, _data_->_res_, &_data_->_inner_error0_);
		_data_->chat = _data_->_tmp27_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch1_g_error;
		}
		if (_data_->chat != NULL) {
			_data_->_tmp28_ = json_object_get_string_member_with_default (_data_->chat, "name", "");
			_data_->_tmp29_ = g_strdup (_data_->_tmp28_);
			_data_->_vala1_name = _data_->_tmp29_;
			_data_->_tmp30_ = _data_->_vala1_name;
			_data_->_tmp31_ = strlen (_data_->_tmp30_);
			_data_->_tmp32_ = _data_->_tmp31_;
			if (_data_->_tmp32_ > 0) {
				_data_->_tmp33_ = _data_->_vala1_name;
				_data_->_tmp34_ = g_strdup (_data_->_tmp33_);
				_g_free0 (_data_->self->priv->chat_name);
				_data_->self->priv->chat_name = _data_->_tmp34_;
			}
			_g_free0 (_data_->_vala1_name);
		}
		_json_object_unref0 (_data_->chat);
	}
	goto __finally1;
	__catch1_g_error:
	{
		_data_->_vala1_e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp35_ = _data_->_vala1_e;
		_data_->_tmp36_ = _data_->_tmp35_->message;
		g_warning ("webxdc.vala:330: webxdc chat info: %s", _data_->_tmp36_);
		_g_error_free0 (_data_->_vala1_e);
	}
	__finally1:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp37_ = dc_webxdc_instance_compose_title (_data_->self);
	_data_->_tmp38_ = _data_->_tmp37_;
	dc_webxdc_instance_set_view_title (_data_->self, _data_->_tmp38_);
	_g_free0 (_data_->_tmp38_);
	{
		_data_->_tmp39_ = _data_->self->priv->rpc;
		_data_->_state_ = 3;
		dc_rpc_client_get_config (_data_->_tmp39_, "displayname", _data_->self->priv->account_id, dc_webxdc_instance_start_ready, _data_);
		return FALSE;
		_state_3:
		_data_->_tmp40_ = dc_rpc_client_get_config_finish (_data_->_tmp39_, _data_->_res_, &_data_->_inner_error0_);
		_data_->dn = _data_->_tmp40_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch2_g_error;
		}
		if (_data_->dn != NULL) {
			_data_->_tmp42_ = strlen (_data_->dn);
			_data_->_tmp43_ = _data_->_tmp42_;
			_data_->_tmp41_ = _data_->_tmp43_ > 0;
		} else {
			_data_->_tmp41_ = FALSE;
		}
		if (_data_->_tmp41_) {
			_data_->_tmp44_ = g_strdup (_data_->dn);
			_g_free0 (_data_->self->priv->self_name);
			_data_->self->priv->self_name = _data_->_tmp44_;
		} else {
			_data_->_tmp45_ = _data_->self->priv->rpc;
			_data_->_tmp46_ = dc_rpc_client_get_self_email (_data_->_tmp45_);
			_data_->_tmp47_ = _data_->_tmp46_;
			if (_data_->_tmp47_ != NULL) {
				_data_->_tmp48_ = _data_->self->priv->rpc;
				_data_->_tmp49_ = dc_rpc_client_get_self_email (_data_->_tmp48_);
				_data_->_tmp50_ = _data_->_tmp49_;
				_data_->_tmp51_ = g_strdup (_data_->_tmp50_);
				_g_free0 (_data_->self->priv->self_name);
				_data_->self->priv->self_name = _data_->_tmp51_;
			}
		}
		_data_->_tmp52_ = _data_->self->priv->rpc;
		_data_->_tmp53_ = dc_rpc_client_get_self_email (_data_->_tmp52_);
		_data_->_tmp54_ = _data_->_tmp53_;
		if (_data_->_tmp54_ != NULL) {
			_data_->_tmp55_ = _data_->self->priv->rpc;
			_data_->_tmp56_ = dc_rpc_client_get_self_email (_data_->_tmp55_);
			_data_->_tmp57_ = _data_->_tmp56_;
			_data_->_tmp58_ = g_strdup (_data_->_tmp57_);
			_g_free0 (_data_->self->priv->self_addr);
			_data_->self->priv->self_addr = _data_->_tmp58_;
		}
		_g_free0 (_data_->dn);
	}
	goto __finally2;
	__catch2_g_error:
	{
		_data_->_vala2_e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp59_ = _data_->_vala2_e;
		_data_->_tmp60_ = _data_->_tmp59_->message;
		g_warning ("webxdc.vala:339: webxdc config: %s", _data_->_tmp60_);
		_g_error_free0 (_data_->_vala2_e);
	}
	__finally2:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	dc_webxdc_instance_load_view (_data_->self, "webxdc://app/index.html");
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dc_webxdc_instance_serve_data_free (gpointer _data)
{
	DcWebxdcInstanceServeData* _data_;
	_data_ = _data;
	_g_free0 (_data_->path);
	_g_object_unref0 (_data_->token);
	_g_object_unref0 (_data_->self);
	g_slice_free (DcWebxdcInstanceServeData, _data_);
}

static void
dc_webxdc_instance_serve (DcWebxdcInstance* self,
                          const gchar* path,
                          WebKitURISchemeRequest* token,
                          GAsyncReadyCallback _callback_,
                          gpointer _user_data_)
{
	DcWebxdcInstanceServeData* _data_;
	DcWebxdcInstance* _tmp0_;
	gchar* _tmp1_;
	WebKitURISchemeRequest* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (path != NULL);
	g_return_if_fail (token != NULL);
	_data_ = g_slice_new0 (DcWebxdcInstanceServeData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_webxdc_instance_serve_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (path);
	_g_free0 (_data_->path);
	_data_->path = _tmp1_;
	_tmp2_ = _g_object_ref0 (token);
	_g_object_unref0 (_data_->token);
	_data_->token = _tmp2_;
	dc_webxdc_instance_serve_co (_data_);
}

static void
dc_webxdc_instance_serve_finish (DcWebxdcInstance* self,
                                 GAsyncResult* _res_)
{
	DcWebxdcInstanceServeData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static guint8*
string_get_data (const gchar* self,
                 gint* result_length1)
{
	guint8* result;
	guint8* res = NULL;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static void
dc_webxdc_instance_serve_ready (GObject* source_object,
                                GAsyncResult* _res_,
                                gpointer _user_data_)
{
	DcWebxdcInstanceServeData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_webxdc_instance_serve_co (_data_);
}

static gboolean
dc_webxdc_instance_serve_co (DcWebxdcInstanceServeData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (g_str_has_prefix (_data_->path, "/")) {
		_data_->_tmp1_ = string_substring (_data_->path, (glong) 1, (glong) -1);
		_g_free0 (_data_->_tmp0_);
		_data_->_tmp0_ = _data_->_tmp1_;
	} else {
		_data_->_tmp2_ = g_strdup (_data_->path);
		_g_free0 (_data_->_tmp0_);
		_data_->_tmp0_ = _data_->_tmp2_;
	}
	_data_->_tmp3_ = _data_->_tmp0_;
	_data_->_tmp0_ = NULL;
	_data_->p = _data_->_tmp3_;
	_data_->_tmp4_ = _data_->p;
	_data_->_tmp5_ = strlen (_data_->_tmp4_);
	_data_->_tmp6_ = _data_->_tmp5_;
	if (_data_->_tmp6_ == 0) {
		_data_->_tmp7_ = g_strdup ("index.html");
		_g_free0 (_data_->p);
		_data_->p = _data_->_tmp7_;
	}
	_data_->_tmp8_ = _data_->p;
	_data_->_tmp9_ = g_path_get_basename (_data_->_tmp8_);
	_data_->_tmp10_ = _data_->_tmp9_;
	_data_->_tmp11_ = g_strcmp0 (_data_->_tmp10_, "webxdc.js") == 0;
	_g_free0 (_data_->_tmp10_);
	if (_data_->_tmp11_) {
		_data_->_tmp12_ = dc_webxdc_instance_bridge_js (_data_->self);
		_data_->_tmp13_ = _data_->_tmp12_;
		_data_->_tmp15_ = 0;
		_data_->_tmp14_ = string_get_data (_data_->_tmp13_, &_data_->_tmp15_);
		_data_->_tmp14__length1 = _data_->_tmp15_;
		_data_->_tmp16_ = _data_->_tmp14_;
		_data_->_tmp16__length1 = _data_->_tmp14__length1;
		dc_webxdc_instance_deliver (_data_->self, _data_->token, _data_->_tmp16_, (gint) _data_->_tmp16__length1, "text/javascript");
		_g_free0 (_data_->_tmp13_);
		_g_free0 (_data_->p);
		_g_free0 (_data_->_tmp0_);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp17_ = _data_->self->priv->rpc;
		_data_->_tmp18_ = dc_params_begin ();
		_data_->_tmp19_ = _data_->_tmp18_;
		_data_->_tmp20_ = dc_params_add_int (_data_->_tmp19_, _data_->self->priv->account_id);
		_data_->_tmp21_ = _data_->_tmp20_;
		_data_->_tmp22_ = dc_params_add_int (_data_->_tmp21_, _data_->self->msg_id);
		_data_->_tmp23_ = _data_->_tmp22_;
		_data_->_tmp24_ = _data_->p;
		_data_->_tmp25_ = dc_params_add_string (_data_->_tmp23_, _data_->_tmp24_);
		_data_->_tmp26_ = _data_->_tmp25_;
		_data_->_tmp27_ = dc_params_build (_data_->_tmp26_);
		_data_->_tmp28_ = _data_->_tmp27_;
		_data_->_state_ = 1;
		dc_rpc_client_call (_data_->_tmp17_, "get_webxdc_blob", _data_->_tmp28_, dc_webxdc_instance_serve_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp29_ = dc_rpc_client_call_finish (_data_->_tmp17_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp30_ = _data_->_tmp29_;
		__vala_JsonNode_free0 (_data_->_tmp28_);
		_g_object_unref0 (_data_->_tmp26_);
		_g_object_unref0 (_data_->_tmp23_);
		_g_object_unref0 (_data_->_tmp21_);
		_g_object_unref0 (_data_->_tmp19_);
		_data_->res = _data_->_tmp30_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp31_ = _data_->res;
		_data_->_tmp32_ = json_node_get_string (_data_->_tmp31_);
		_data_->_tmp33_ = 0;
		_data_->_tmp34_ = g_base64_decode (_data_->_tmp32_, &_data_->_tmp33_);
		_data_->data = _data_->_tmp34_;
		_data_->data_length1 = _data_->_tmp33_;
		_data_->_data_size_ = _data_->data_length1;
		_data_->_tmp35_ = _data_->p;
		_data_->_tmp36_ = _data_->data;
		_data_->_tmp36__length1 = _data_->data_length1;
		_data_->_tmp37_ = FALSE;
		_data_->_tmp38_ = g_content_type_guess (_data_->_tmp35_, _data_->_tmp36_, (gsize) _data_->_tmp36__length1, &_data_->_tmp37_);
		_data_->uncertain = _data_->_tmp37_;
		_data_->ctype = _data_->_tmp38_;
		_data_->_tmp40_ = _data_->ctype;
		_data_->_tmp41_ = g_content_type_get_mime_type (_data_->_tmp40_);
		_data_->_tmp39_ = _data_->_tmp41_;
		if (_data_->_tmp39_ == NULL) {
			_data_->_tmp42_ = g_strdup ("application/octet-stream");
			_g_free0 (_data_->_tmp39_);
			_data_->_tmp39_ = _data_->_tmp42_;
		}
		_data_->_tmp43_ = _data_->_tmp39_;
		_data_->_tmp39_ = NULL;
		_data_->mime = _data_->_tmp43_;
		_data_->_tmp44_ = _data_->data;
		_data_->_tmp44__length1 = _data_->data_length1;
		_data_->_tmp45_ = _data_->mime;
		dc_webxdc_instance_deliver (_data_->self, _data_->token, _data_->_tmp44_, (gint) _data_->_tmp44__length1, _data_->_tmp45_);
		_g_free0 (_data_->mime);
		_g_free0 (_data_->_tmp39_);
		_g_free0 (_data_->ctype);
		_data_->data = (g_free (_data_->data), NULL);
		__vala_JsonNode_free0 (_data_->res);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp46_ = _data_->e;
		_data_->_tmp47_ = _data_->_tmp46_->message;
		g_warning ("webxdc.vala:369: webxdc blob '%s': %s", _data_->path, _data_->_tmp47_);
		dc_webxdc_instance_fail (_data_->self, _data_->token);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_free0 (_data_->p);
		_g_free0 (_data_->_tmp0_);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_free0 (_data_->p);
	_g_free0 (_data_->_tmp0_);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gchar*
dc_webxdc_instance_js_str (const gchar* s)
{
	JsonNode* node = NULL;
	JsonNode* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	g_return_val_if_fail (s != NULL, NULL);
	_tmp0_ = json_node_new (JSON_NODE_VALUE);
	node = _tmp0_;
	json_node_set_string (node, s);
	_tmp1_ = json_to_string (node, FALSE);
	result = _tmp1_;
	__vala_JsonNode_free0 (node);
	return result;
}

static gchar*
dc_webxdc_instance_bridge_js (DcWebxdcInstance* self)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->self_addr;
	_tmp1_ = dc_webxdc_instance_js_str (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->self_name;
	_tmp4_ = dc_webxdc_instance_js_str (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_strdup_printf ("window.webxdc = (function () {\n" \
"    'use strict';\n" \
"    var handler = window.webkit.messageHandlers.webxdc;\n" \
"    var listener = null;\n" \
"    var last = 0;\n" \
"    window.__webxdc_deliver = function (updates) {\n" \
"        updates.forEach(function (u) {\n" \
"            if (u.serial > last) {\n" \
"                last = u.serial;\n" \
"                if (listener) listener(u);\n" \
"            }\n" \
"        });\n" \
"    };\n" \
"    return {\n" \
"        selfAddr: %s,\n" \
"        selfName: %s,\n" \
"        sendUpdate: function (update, description) {\n" \
"            handler.postMessage(JSON.stringify({ type: 'send', update:" \
" update }));\n" \
"        },\n" \
"        setUpdateListener: function (cb, serial) {\n" \
"            listener = cb;\n" \
"            last = serial || 0;\n" \
"            handler.postMessage(JSON.stringify({ type: 'pull', serial:" \
" last }));\n" \
"            return Promise.resolve();\n" \
"        }\n" \
"    };\n" \
"})();\n", _tmp2_, _tmp5_);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	_g_free0 (_tmp2_);
	result = _tmp7_;
	return result;
}

static JsonNode*
_vala_JsonNode_copy (JsonNode* self)
{
	return g_boxed_copy (json_node_get_type (), self);
}

static gpointer
__vala_JsonNode_copy0 (gpointer self)
{
	return self ? _vala_JsonNode_copy (self) : NULL;
}

static void
dc_webxdc_instance_on_message (DcWebxdcInstance* self,
                               const gchar* json)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (json != NULL);
	{
		JsonParser* parser = NULL;
		JsonParser* _tmp0_;
		JsonParser* _tmp1_;
		JsonObject* obj = NULL;
		JsonParser* _tmp2_;
		JsonNode* _tmp3_;
		JsonObject* _tmp4_;
		JsonObject* _tmp5_;
		JsonObject* _tmp6_;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		GQuark _tmp10_ = 0U;
		static GQuark _tmp9_label0 = 0;
		static GQuark _tmp9_label1 = 0;
		_tmp0_ = json_parser_new ();
		parser = _tmp0_;
		_tmp1_ = parser;
		json_parser_load_from_data (_tmp1_, json, (gssize) -1, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (parser);
			goto __catch0_g_error;
		}
		_tmp2_ = parser;
		_tmp3_ = json_parser_get_root (_tmp2_);
		_tmp4_ = json_node_get_object (_tmp3_);
		_tmp5_ = _json_object_ref0 (_tmp4_);
		obj = _tmp5_;
		_tmp6_ = obj;
		_tmp7_ = json_object_get_string_member_with_default (_tmp6_, "type", "");
		_tmp8_ = _tmp7_;
		_tmp10_ = (NULL == _tmp8_) ? 0 : g_quark_from_string (_tmp8_);
		if (_tmp10_ == ((0 != _tmp9_label0) ? _tmp9_label0 : (_tmp9_label0 = g_quark_from_static_string ("send")))) {
			switch (0) {
				default:
				{
					JsonNode* member = NULL;
					JsonObject* _tmp11_;
					JsonNode* _tmp12_;
					JsonNode* _tmp13_;
					JsonNode* _tmp14_;
					gchar* update = NULL;
					JsonNode* _tmp15_;
					gchar* _tmp16_;
					DcRpcClient* _tmp17_;
					DcParams* _tmp18_;
					DcParams* _tmp19_;
					DcParams* _tmp20_;
					DcParams* _tmp21_;
					DcParams* _tmp22_;
					DcParams* _tmp23_;
					const gchar* _tmp24_;
					DcParams* _tmp25_;
					DcParams* _tmp26_;
					DcParams* _tmp27_;
					DcParams* _tmp28_;
					JsonNode* _tmp29_;
					JsonNode* _tmp30_;
					_tmp11_ = obj;
					_tmp12_ = json_object_get_member (_tmp11_, "update");
					_tmp13_ = __vala_JsonNode_copy0 (_tmp12_);
					member = _tmp13_;
					_tmp14_ = member;
					if (_tmp14_ == NULL) {
						__vala_JsonNode_free0 (member);
						break;
					}
					_tmp15_ = member;
					_tmp16_ = json_to_string (_tmp15_, FALSE);
					update = _tmp16_;
					_tmp17_ = self->priv->rpc;
					_tmp18_ = dc_params_begin ();
					_tmp19_ = _tmp18_;
					_tmp20_ = dc_params_add_int (_tmp19_, self->priv->account_id);
					_tmp21_ = _tmp20_;
					_tmp22_ = dc_params_add_int (_tmp21_, self->msg_id);
					_tmp23_ = _tmp22_;
					_tmp24_ = update;
					_tmp25_ = dc_params_add_string (_tmp23_, _tmp24_);
					_tmp26_ = _tmp25_;
					_tmp27_ = dc_params_add_string (_tmp26_, "");
					_tmp28_ = _tmp27_;
					_tmp29_ = dc_params_build (_tmp28_);
					_tmp30_ = _tmp29_;
					dc_rpc_client_call (_tmp17_, "send_webxdc_status_update", _tmp30_, NULL, NULL);
					__vala_JsonNode_free0 (_tmp30_);
					_g_object_unref0 (_tmp28_);
					_g_object_unref0 (_tmp26_);
					_g_object_unref0 (_tmp23_);
					_g_object_unref0 (_tmp21_);
					_g_object_unref0 (_tmp19_);
					_g_free0 (update);
					__vala_JsonNode_free0 (member);
					break;
				}
			}
		} else if (_tmp10_ == ((0 != _tmp9_label1) ? _tmp9_label1 : (_tmp9_label1 = g_quark_from_static_string ("pull")))) {
			switch (0) {
				default:
				{
					JsonObject* _tmp31_;
					_tmp31_ = obj;
					self->priv->last_serial = json_object_get_int_member_with_default (_tmp31_, "serial", (gint64) 0);
					dc_webxdc_instance_pull_updates (self, NULL, NULL);
					break;
				}
			}
		}
		_json_object_unref0 (obj);
		_g_object_unref0 (parser);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp32_;
		const gchar* _tmp33_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp32_ = e;
		_tmp33_ = _tmp32_->message;
		g_warning ("webxdc.vala:435: webxdc message: %s", _tmp33_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static void
dc_webxdc_instance_pull_updates_data_free (gpointer _data)
{
	DcWebxdcInstancePullUpdatesData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DcWebxdcInstancePullUpdatesData, _data_);
}

void
dc_webxdc_instance_pull_updates (DcWebxdcInstance* self,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_)
{
	DcWebxdcInstancePullUpdatesData* _data_;
	DcWebxdcInstance* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcWebxdcInstancePullUpdatesData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_webxdc_instance_pull_updates_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_webxdc_instance_pull_updates_co (_data_);
}

void
dc_webxdc_instance_pull_updates_finish (DcWebxdcInstance* self,
                                        GAsyncResult* _res_)
{
	DcWebxdcInstancePullUpdatesData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

/** Fetch status updates newer than last_serial and hand them to the
            page. Called on setUpdateListener and on core events. */
static void
dc_webxdc_instance_pull_updates_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_)
{
	DcWebxdcInstancePullUpdatesData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_webxdc_instance_pull_updates_co (_data_);
}

static gpointer
_json_array_ref0 (gpointer self)
{
	return self ? json_array_ref (self) : NULL;
}

static gboolean
dc_webxdc_instance_pull_updates_co (DcWebxdcInstancePullUpdatesData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_tmp0_ = _data_->self->priv->rpc;
		_data_->_tmp1_ = dc_params_begin ();
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp3_ = dc_params_add_int (_data_->_tmp2_, _data_->self->priv->account_id);
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp5_ = dc_params_add_int (_data_->_tmp4_, _data_->self->msg_id);
		_data_->_tmp6_ = _data_->_tmp5_;
		_data_->_tmp7_ = dc_params_add_int (_data_->_tmp6_, (gint) _data_->self->priv->last_serial);
		_data_->_tmp8_ = _data_->_tmp7_;
		_data_->_tmp9_ = dc_params_build (_data_->_tmp8_);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_state_ = 1;
		dc_rpc_client_call (_data_->_tmp0_, "get_webxdc_status_updates", _data_->_tmp10_, dc_webxdc_instance_pull_updates_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp11_ = dc_rpc_client_call_finish (_data_->_tmp0_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp12_ = _data_->_tmp11_;
		__vala_JsonNode_free0 (_data_->_tmp10_);
		_g_object_unref0 (_data_->_tmp8_);
		_g_object_unref0 (_data_->_tmp6_);
		_g_object_unref0 (_data_->_tmp4_);
		_g_object_unref0 (_data_->_tmp2_);
		_data_->res = _data_->_tmp12_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp13_ = _data_->res;
		_data_->_tmp14_ = json_node_get_string (_data_->_tmp13_);
		_data_->_tmp15_ = g_strdup (_data_->_tmp14_);
		_g_free0 (_data_->updates);
		_data_->updates = _data_->_tmp15_;
		_data_->_tmp16_ = json_parser_new ();
		_data_->parser = _data_->_tmp16_;
		_data_->_tmp17_ = _data_->parser;
		_data_->_tmp18_ = _data_->updates;
		json_parser_load_from_data (_data_->_tmp17_, _data_->_tmp18_, (gssize) -1, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->parser);
			__vala_JsonNode_free0 (_data_->res);
			goto __catch0_g_error;
		}
		_data_->_tmp19_ = _data_->parser;
		_data_->_tmp20_ = json_parser_get_root (_data_->_tmp19_);
		_data_->_tmp21_ = json_node_get_array (_data_->_tmp20_);
		_data_->_tmp22_ = _json_array_ref0 (_data_->_tmp21_);
		_data_->arr = _data_->_tmp22_;
		_data_->_tmp23_ = _data_->arr;
		if (json_array_get_length (_data_->_tmp23_) == ((guint) 0)) {
			_json_array_unref0 (_data_->arr);
			_g_object_unref0 (_data_->parser);
			__vala_JsonNode_free0 (_data_->res);
			_g_free0 (_data_->updates);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		{
			_data_->i = (guint) 0;
			{
				_data_->_tmp24_ = TRUE;
				while (TRUE) {
					if (!_data_->_tmp24_) {
						_data_->_tmp25_ = _data_->i;
						_data_->i = _data_->_tmp25_ + 1;
					}
					_data_->_tmp24_ = FALSE;
					_data_->_tmp26_ = _data_->arr;
					if (!(_data_->i < json_array_get_length (_data_->_tmp26_))) {
						break;
					}
					_data_->_tmp27_ = _data_->arr;
					_data_->_tmp28_ = json_array_get_object_element (_data_->_tmp27_, _data_->i);
					_data_->_tmp29_ = _json_object_ref0 (_data_->_tmp28_);
					_data_->item = _data_->_tmp29_;
					_data_->_tmp30_ = _data_->item;
					_data_->serial = json_object_get_int_member_with_default (_data_->_tmp30_, "serial", (gint64) 0);
					if (_data_->serial > _data_->self->priv->last_serial) {
						_data_->self->priv->last_serial = _data_->serial;
					}
					_data_->_tmp31_ = _data_->item;
					_data_->_tmp32_ = json_object_get_member (_data_->_tmp31_, "document");
					_data_->_tmp33_ = __vala_JsonNode_copy0 (_data_->_tmp32_);
					_data_->doc = _data_->_tmp33_;
					_data_->_tmp35_ = _data_->doc;
					if (_data_->_tmp35_ != NULL) {
						_data_->_tmp36_ = _data_->doc;
						_data_->_tmp34_ = json_node_get_node_type (_data_->_tmp36_) == JSON_NODE_VALUE;
					} else {
						_data_->_tmp34_ = FALSE;
					}
					if (_data_->_tmp34_) {
						_data_->_tmp37_ = _data_->doc;
						_data_->_tmp38_ = json_node_get_string (_data_->_tmp37_);
						_data_->_tmp39_ = g_strdup (_data_->_tmp38_);
						_data_->d = _data_->_tmp39_;
						_data_->_tmp42_ = _data_->d;
						if (_data_->_tmp42_ != NULL) {
							_data_->_tmp43_ = _data_->d;
							_data_->_tmp44_ = strlen (_data_->_tmp43_);
							_data_->_tmp45_ = _data_->_tmp44_;
							_data_->_tmp41_ = _data_->_tmp45_ > 0;
						} else {
							_data_->_tmp41_ = FALSE;
						}
						if (_data_->_tmp41_) {
							_data_->_tmp46_ = _data_->d;
							_data_->_tmp47_ = _data_->self->priv->document_name;
							_data_->_tmp40_ = g_strcmp0 (_data_->_tmp46_, _data_->_tmp47_) != 0;
						} else {
							_data_->_tmp40_ = FALSE;
						}
						if (_data_->_tmp40_) {
							_data_->_tmp48_ = _data_->d;
							_data_->_tmp49_ = g_strdup (_data_->_tmp48_);
							_g_free0 (_data_->self->priv->document_name);
							_data_->self->priv->document_name = _data_->_tmp49_;
							_data_->_tmp50_ = dc_webxdc_instance_compose_title (_data_->self);
							_data_->_tmp51_ = _data_->_tmp50_;
							dc_webxdc_instance_set_view_title (_data_->self, _data_->_tmp51_);
							_g_free0 (_data_->_tmp51_);
						}
						_g_free0 (_data_->d);
					}
					__vala_JsonNode_free0 (_data_->doc);
					_json_object_unref0 (_data_->item);
				}
			}
		}
		_json_array_unref0 (_data_->arr);
		_g_object_unref0 (_data_->parser);
		__vala_JsonNode_free0 (_data_->res);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp52_ = _data_->e;
		_data_->_tmp53_ = _data_->_tmp52_->message;
		g_warning ("webxdc.vala:468: webxdc updates: %s", _data_->_tmp53_);
		_g_error_free0 (_data_->e);
		_g_free0 (_data_->updates);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_free0 (_data_->updates);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp54_ = _data_->updates;
	_data_->_tmp55_ = g_strdup_printf ("window.__webxdc_deliver(%s)", _data_->_tmp54_);
	_data_->_tmp56_ = _data_->_tmp55_;
	dc_webxdc_instance_eval_js (_data_->self, _data_->_tmp56_);
	_g_free0 (_data_->_tmp56_);
	_g_free0 (_data_->updates);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dc_webxdc_instance_on_view_closed (DcWebxdcInstance* self)
{
	GHashTable* _tmp0_;
	DcWebxdcMonitor* _tmp2_;
	DcWebxdcMonitor* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = dc_webxdc_windows;
	if (_tmp0_ != NULL) {
		GHashTable* _tmp1_;
		_tmp1_ = dc_webxdc_windows;
		g_hash_table_remove (_tmp1_, (gpointer) ((gintptr) self->msg_id));
	}
	_tmp2_ = dc_webxdc_monitor_get_default ();
	_tmp3_ = _tmp2_;
	g_signal_emit (_tmp3_, dc_webxdc_monitor_signals[DC_WEBXDC_MONITOR_CHANGED_SIGNAL], 0, self->msg_id);
	_g_object_unref0 (_tmp3_);
}

gboolean
dc_webxdc_instance_belongs_to (DcWebxdcInstance* self,
                               gint account_id,
                               gint chat_id)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (self->priv->account_id == account_id) {
		_tmp0_ = self->priv->chat_id == chat_id;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

/** Re-evaluate follow-chat visibility against the chat the main
            window currently shows. Called when the global window-behavior
            setting changes and whenever window.vala reports a chat or
            visibility change. */
void
dc_webxdc_instance_apply_follow_visibility (DcWebxdcInstance* self)
{
	gboolean want_hidden = FALSE;
	gboolean _tmp0_ = FALSE;
	DcSettingsManager* _tmp1_;
	g_return_if_fail (self != NULL);
	want_hidden = FALSE;
	_tmp1_ = dc_webxdc_config;
	if (_tmp1_ != NULL) {
		DcSettingsManager* _tmp2_;
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp2_ = dc_webxdc_config;
		_tmp3_ = dc_settings_manager_get_webxdc_follow_chat (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gboolean _tmp5_ = FALSE;
		gboolean _tmp6_ = FALSE;
		if (dc_webxdc_chat_window_visible) {
			_tmp6_ = self->priv->account_id == dc_webxdc_active_account;
		} else {
			_tmp6_ = FALSE;
		}
		if (_tmp6_) {
			_tmp5_ = self->priv->chat_id == dc_webxdc_active_chat;
		} else {
			_tmp5_ = FALSE;
		}
		want_hidden = !_tmp5_;
	}
	if (want_hidden == self->priv->hidden_by_follow) {
		return;
	}
	self->priv->hidden_by_follow = want_hidden;
	dc_webxdc_instance_set_view_visible (self, !want_hidden);
}

static void
__lambda58_ (DcWebxdcInstance* self,
             JSCValue* value)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (value != NULL);
	_tmp0_ = jsc_value_to_string (value);
	_tmp1_ = _tmp0_;
	dc_webxdc_instance_on_message (self, _tmp1_);
	_g_free0 (_tmp1_);
}

static void
___lambda58__webkit_user_content_manager_script_message_received (WebKitUserContentManager* _sender,
                                                                  JSCValue* value,
                                                                  gpointer self)
{
	__lambda58_ ((DcWebxdcInstance*) self, value);
}

static void
__lambda59_ (DcWebxdcInstance* self,
             WebKitURISchemeRequest* req)
{
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp1_;
	g_return_if_fail (req != NULL);
	_tmp1_ = webkit_uri_scheme_request_get_path (req);
	_tmp0_ = _tmp1_;
	if (_tmp0_ == NULL) {
		_tmp0_ = "";
	}
	dc_webxdc_instance_serve (self, _tmp0_, req, NULL, NULL);
}

static void
___lambda59__web_kit_uri_scheme_request_callback (WebKitURISchemeRequest* request,
                                                  gpointer self)
{
	__lambda59_ ((DcWebxdcInstance*) self, request);
}

static void
_vala_WebKitNetworkProxySettings_free (WebKitNetworkProxySettings* self)
{
	g_boxed_free (webkit_network_proxy_settings_get_type (), self);
}

static gboolean
_dc_webxdc_instance_on_decide_policy_webkit_web_view_decide_policy (WebKitWebView* _sender,
                                                                    WebKitPolicyDecision* decision,
                                                                    WebKitPolicyDecisionType type,
                                                                    gpointer self)
{
	gboolean result;
	result = dc_webxdc_instance_on_decide_policy ((DcWebxdcInstance*) self, decision, type);
	return result;
}

static gboolean
__lambda60_ (DcWebxdcInstance* self)
{
	gboolean result;
	_g_object_unref0 (self->priv->win);
	self->priv->win = NULL;
	dc_webxdc_instance_on_view_closed (self);
	result = FALSE;
	return result;
}

static gboolean
___lambda60__gtk_window_close_request (GtkWindow* _sender,
                                       gpointer self)
{
	gboolean result;
	result = __lambda60_ ((DcWebxdcInstance*) self);
	return result;
}

static void
dc_webxdc_instance_create_view (DcWebxdcInstance* self,
                                const gchar* title)
{
	AdwWindow* _tmp0_;
	AdwWindow* _tmp1_;
	AdwWindow* _tmp2_;
	AdwWindow* _tmp3_;
	WebKitUserContentManager* ucm = NULL;
	WebKitUserContentManager* _tmp4_;
	WebKitUserContentManager* _tmp5_;
	WebKitUserContentManager* _tmp6_;
	WebKitWebContext* ctx = NULL;
	WebKitWebContext* _tmp7_;
	WebKitWebContext* _tmp8_;
	WebKitSecurityManager* sec = NULL;
	WebKitWebContext* _tmp9_;
	WebKitSecurityManager* _tmp10_;
	WebKitSecurityManager* _tmp11_;
	WebKitSecurityManager* _tmp12_;
	WebKitNetworkSession* session = NULL;
	WebKitNetworkSession* _tmp13_;
	WebKitWebContext* _tmp17_;
	WebKitNetworkSession* _tmp18_;
	WebKitUserContentManager* _tmp19_;
	GObject* _tmp20_;
	GObject* _tmp21_;
	WebKitSettings* s = NULL;
	WebKitWebView* _tmp22_;
	WebKitSettings* _tmp23_;
	WebKitSettings* _tmp24_;
	WebKitSettings* _tmp25_;
	WebKitSettings* _tmp26_;
	WebKitSettings* _tmp27_;
	WebKitSettings* _tmp28_;
	WebKitSettings* _tmp29_;
	WebKitHardwareAccelerationPolicy _tmp30_ = 0;
	WebKitSettings* _tmp31_;
	WebKitWebView* _tmp32_;
	WebKitWebView* _tmp33_;
	AdwToolbarView* toolbar = NULL;
	AdwToolbarView* _tmp34_;
	AdwHeaderBar* _tmp35_;
	AdwHeaderBar* _tmp36_;
	WebKitWebView* _tmp37_;
	AdwWindow* _tmp38_;
	AdwWindow* _tmp39_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (title != NULL);
	_tmp0_ = (AdwWindow*) adw_window_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->win);
	self->priv->win = _tmp0_;
	_tmp1_ = self->priv->win;
	gtk_window_set_title ((GtkWindow*) _tmp1_, title);
	_tmp2_ = self->priv->win;
	g_object_set ((GtkWindow*) _tmp2_, "default-width", 420, NULL);
	_tmp3_ = self->priv->win;
	g_object_set ((GtkWindow*) _tmp3_, "default-height", 640, NULL);
	_tmp4_ = webkit_user_content_manager_new ();
	ucm = _tmp4_;
	_tmp5_ = ucm;
	webkit_user_content_manager_register_script_message_handler (_tmp5_, "webxdc", (const gchar*) NULL);
	_tmp6_ = ucm;
	g_signal_connect_object (_tmp6_, "script-message-received::webxdc", (GCallback) ___lambda58__webkit_user_content_manager_script_message_received, self, 0);
	_tmp7_ = webkit_web_context_new ();
	ctx = _tmp7_;
	_tmp8_ = ctx;
	webkit_web_context_register_uri_scheme (_tmp8_, "webxdc", ___lambda59__web_kit_uri_scheme_request_callback, g_object_ref (self), g_object_unref);
	_tmp9_ = ctx;
	_tmp10_ = webkit_web_context_get_security_manager (_tmp9_);
	_tmp11_ = _g_object_ref0 (_tmp10_);
	sec = _tmp11_;
	_tmp12_ = sec;
	webkit_security_manager_register_uri_scheme_as_secure (_tmp12_, "webxdc");
	_tmp13_ = webkit_network_session_new_ephemeral ();
	session = _tmp13_;
	if (!self->priv->allow_internet) {
		WebKitNetworkSession* _tmp14_;
		WebKitNetworkProxySettings* _tmp15_;
		WebKitNetworkProxySettings* _tmp16_;
		_tmp14_ = session;
		_tmp15_ = webkit_network_proxy_settings_new ("socks5://127.0.0.1:1", NULL);
		_tmp16_ = _tmp15_;
		webkit_network_session_set_proxy_settings (_tmp14_, WEBKIT_NETWORK_PROXY_MODE_CUSTOM, _tmp16_);
		__vala_WebKitNetworkProxySettings_free0 (_tmp16_);
	}
	_tmp17_ = ctx;
	_tmp18_ = session;
	_tmp19_ = ucm;
	_tmp20_ = g_object_new (webkit_web_view_get_type (), "web-context", _tmp17_, "network-session", _tmp18_, "user-content-manager", _tmp19_, NULL);
	_tmp21_ = G_IS_INITIALLY_UNOWNED (_tmp20_) ? g_object_ref_sink (_tmp20_) : _tmp20_;
	_g_object_unref0 (self->priv->view);
	self->priv->view = G_TYPE_CHECK_INSTANCE_CAST (_tmp21_, webkit_web_view_get_type (), WebKitWebView);
	_tmp22_ = self->priv->view;
	_tmp23_ = webkit_web_view_get_settings (_tmp22_);
	_tmp24_ = _g_object_ref0 (_tmp23_);
	s = _tmp24_;
	_tmp25_ = s;
	webkit_settings_set_enable_developer_extras (_tmp25_, FALSE);
	_tmp26_ = s;
	webkit_settings_set_allow_modal_dialogs (_tmp26_, FALSE);
	_tmp27_ = s;
	webkit_settings_set_javascript_can_open_windows_automatically (_tmp27_, FALSE);
	_tmp28_ = s;
	webkit_settings_set_enable_webrtc (_tmp28_, self->priv->allow_internet);
	_tmp29_ = s;
	webkit_settings_set_enable_webgl (_tmp29_, self->priv->allow_webgl);
	if (self->priv->allow_hardware_acceleration) {
		_tmp30_ = WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS;
	} else {
		_tmp30_ = WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER;
	}
	_tmp31_ = s;
	webkit_settings_set_hardware_acceleration_policy (_tmp31_, _tmp30_);
	_tmp32_ = self->priv->view;
	g_signal_connect_object (_tmp32_, "decide-policy", (GCallback) _dc_webxdc_instance_on_decide_policy_webkit_web_view_decide_policy, self, 0);
	_tmp33_ = self->priv->view;
	gtk_widget_set_vexpand ((GtkWidget*) _tmp33_, TRUE);
	_tmp34_ = (AdwToolbarView*) adw_toolbar_view_new ();
	g_object_ref_sink (_tmp34_);
	toolbar = _tmp34_;
	_tmp35_ = (AdwHeaderBar*) adw_header_bar_new ();
	g_object_ref_sink (_tmp35_);
	_tmp36_ = _tmp35_;
	adw_toolbar_view_add_top_bar (toolbar, (GtkWidget*) _tmp36_);
	_g_object_unref0 (_tmp36_);
	_tmp37_ = self->priv->view;
	adw_toolbar_view_set_content (toolbar, (GtkWidget*) _tmp37_);
	_tmp38_ = self->priv->win;
	adw_window_set_content (_tmp38_, (GtkWidget*) toolbar);
	_tmp39_ = self->priv->win;
	g_signal_connect_object ((GtkWindow*) _tmp39_, "close-request", (GCallback) ___lambda60__gtk_window_close_request, self, 0);
	_g_object_unref0 (toolbar);
	_g_object_unref0 (s);
	_g_object_unref0 (session);
	_g_object_unref0 (sec);
	_g_object_unref0 (ctx);
	_g_object_unref0 (ucm);
}

static gboolean
dc_webxdc_instance_on_decide_policy (DcWebxdcInstance* self,
                                     WebKitPolicyDecision* decision,
                                     WebKitPolicyDecisionType type)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (decision != NULL, FALSE);
	if (type == WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = type == WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION;
	}
	if (_tmp0_) {
		WebKitNavigationPolicyDecision* nav = NULL;
		WebKitNavigationPolicyDecision* _tmp1_;
		gchar* uri = NULL;
		WebKitNavigationPolicyDecision* _tmp2_;
		WebKitNavigationAction* _tmp3_;
		WebKitNavigationAction* _tmp4_;
		WebKitURIRequest* _tmp5_;
		const gchar* _tmp6_;
		gchar* _tmp7_;
		const gchar* _tmp8_;
		_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (decision, webkit_navigation_policy_decision_get_type (), WebKitNavigationPolicyDecision));
		nav = _tmp1_;
		_tmp2_ = nav;
		_tmp3_ = webkit_navigation_policy_decision_get_navigation_action (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = webkit_navigation_action_get_request (_tmp4_);
		_tmp6_ = webkit_uri_request_get_uri (_tmp5_);
		_tmp7_ = g_strdup (_tmp6_);
		uri = _tmp7_;
		_tmp8_ = uri;
		if (!g_str_has_prefix (_tmp8_, "webxdc:")) {
			webkit_policy_decision_ignore (decision);
			result = TRUE;
			_g_free0 (uri);
			_g_object_unref0 (nav);
			return result;
		}
		_g_free0 (uri);
		_g_object_unref0 (nav);
	}
	result = FALSE;
	return result;
}

void
dc_webxdc_instance_present (DcWebxdcInstance* self)
{
	AdwWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	self->priv->minimized_by_bar = FALSE;
	_tmp0_ = self->priv->win;
	if (_tmp0_ != NULL) {
		AdwWindow* _tmp1_;
		_tmp1_ = self->priv->win;
		gtk_window_present ((GtkWindow*) _tmp1_);
	}
}

void
dc_webxdc_instance_toggle_minimize_view (DcWebxdcInstance* self)
{
	AdwWindow* _tmp0_;
	gboolean minimized = FALSE;
	GdkToplevel* toplevel = NULL;
	AdwWindow* _tmp1_;
	GdkSurface* _tmp2_;
	GdkToplevel* _tmp3_;
	gboolean _tmp4_ = FALSE;
	GdkToplevel* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->win;
	if (_tmp0_ == NULL) {
		return;
	}
	minimized = self->priv->minimized_by_bar;
	_tmp1_ = self->priv->win;
	_tmp2_ = gtk_native_get_surface ((GtkNative*) _tmp1_);
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, gdk_toplevel_get_type ()) ? ((GdkToplevel*) _tmp2_) : NULL);
	toplevel = _tmp3_;
	_tmp5_ = toplevel;
	if (_tmp5_ != NULL) {
		GdkToplevel* _tmp6_;
		GdkToplevelState _tmp7_;
		GdkToplevelState _tmp8_;
		_tmp6_ = toplevel;
		_tmp7_ = gdk_toplevel_get_state (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp4_ = (_tmp8_ & GDK_TOPLEVEL_STATE_MINIMIZED) != 0;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		minimized = TRUE;
	}
	if (minimized) {
		AdwWindow* _tmp9_;
		self->priv->minimized_by_bar = FALSE;
		_tmp9_ = self->priv->win;
		gtk_window_present ((GtkWindow*) _tmp9_);
	} else {
		AdwWindow* _tmp10_;
		self->priv->minimized_by_bar = TRUE;
		_tmp10_ = self->priv->win;
		gtk_window_minimize ((GtkWindow*) _tmp10_);
	}
	_g_object_unref0 (toplevel);
}

static void
dc_webxdc_instance_set_view_visible (DcWebxdcInstance* self,
                                     gboolean visible)
{
	AdwWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->win;
	if (_tmp0_ != NULL) {
		AdwWindow* _tmp1_;
		_tmp1_ = self->priv->win;
		gtk_widget_set_visible ((GtkWidget*) _tmp1_, visible);
	}
}

static void
dc_webxdc_instance_load_view (DcWebxdcInstance* self,
                              const gchar* uri)
{
	WebKitWebView* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (uri != NULL);
	_tmp0_ = self->priv->view;
	webkit_web_view_load_uri (_tmp0_, uri);
}

static void
dc_webxdc_instance_set_view_title (DcWebxdcInstance* self,
                                   const gchar* title)
{
	AdwWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (title != NULL);
	_tmp0_ = self->priv->win;
	if (_tmp0_ != NULL) {
		AdwWindow* _tmp1_;
		_tmp1_ = self->priv->win;
		gtk_window_set_title ((GtkWindow*) _tmp1_, title);
	}
}

static void
dc_webxdc_instance_eval_js (DcWebxdcInstance* self,
                            const gchar* js)
{
	WebKitWebView* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (js != NULL);
	_tmp0_ = self->priv->view;
	webkit_web_view_evaluate_javascript (_tmp0_, js, (gssize) -1, NULL, NULL, NULL, NULL, NULL);
}

static void
dc_webxdc_instance_deliver (DcWebxdcInstance* self,
                            WebKitURISchemeRequest* token,
                            guint8* data,
                            gint data_length1,
                            const gchar* mime)
{
	GMemoryInputStream* stream = NULL;
	GBytes* _tmp0_;
	GBytes* _tmp1_;
	GMemoryInputStream* _tmp2_;
	GMemoryInputStream* _tmp3_;
	gchar* csp = NULL;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	WebKitURISchemeResponse* response = NULL;
	GMemoryInputStream* _tmp7_;
	WebKitURISchemeResponse* _tmp8_;
	WebKitURISchemeResponse* _tmp9_;
	SoupMessageHeaders* headers = NULL;
	SoupMessageHeaders* _tmp10_;
	SoupMessageHeaders* _tmp11_;
	const gchar* _tmp12_;
	WebKitURISchemeResponse* _tmp13_;
	SoupMessageHeaders* _tmp14_;
	WebKitURISchemeResponse* _tmp15_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (token != NULL);
	g_return_if_fail (mime != NULL);
	_tmp0_ = g_bytes_new (data, data_length1);
	_tmp1_ = _tmp0_;
	_tmp2_ = (GMemoryInputStream*) g_memory_input_stream_new_from_bytes (_tmp1_);
	_tmp3_ = _tmp2_;
	_g_bytes_unref0 (_tmp1_);
	stream = _tmp3_;
	_tmp4_ = dc_webxdc_security_wasm_csp (self->priv->allow_wasm);
	csp = _tmp4_;
	_tmp5_ = csp;
	if (_tmp5_ == NULL) {
		GMemoryInputStream* _tmp6_;
		_tmp6_ = stream;
		webkit_uri_scheme_request_finish (token, (GInputStream*) _tmp6_, (gint64) data_length1, mime);
		_g_free0 (csp);
		_g_object_unref0 (stream);
		return;
	}
	_tmp7_ = stream;
	_tmp8_ = webkit_uri_scheme_response_new ((GInputStream*) _tmp7_, (gint64) data_length1);
	response = _tmp8_;
	_tmp9_ = response;
	webkit_uri_scheme_response_set_content_type (_tmp9_, mime);
	_tmp10_ = soup_message_headers_new (SOUP_MESSAGE_HEADERS_RESPONSE);
	headers = _tmp10_;
	_tmp11_ = headers;
	_tmp12_ = csp;
	soup_message_headers_append (_tmp11_, "Content-Security-Policy", _tmp12_);
	_tmp13_ = response;
	_tmp14_ = headers;
	headers = NULL;
	webkit_uri_scheme_response_set_http_headers (_tmp13_, _tmp14_);
	_tmp15_ = response;
	webkit_uri_scheme_request_finish_with_response (token, _tmp15_);
	_soup_message_headers_unref0 (headers);
	_g_object_unref0 (response);
	_g_free0 (csp);
	_g_object_unref0 (stream);
}

static void
dc_webxdc_instance_fail (DcWebxdcInstance* self,
                         WebKitURISchemeRequest* token)
{
	GError* _tmp0_;
	GError* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (token != NULL);
	_tmp0_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "webxdc blob");
	_tmp1_ = _tmp0_;
	webkit_uri_scheme_request_finish_error (token, _tmp1_);
	_g_error_free0 (_tmp1_);
}

void
dc_webxdc_instance_close_view (DcWebxdcInstance* self)
{
	AdwWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->win;
	if (_tmp0_ != NULL) {
		AdwWindow* _tmp1_;
		_tmp1_ = self->priv->win;
		gtk_window_close ((GtkWindow*) _tmp1_);
	}
}

static void
dc_webxdc_instance_class_init (DcWebxdcInstanceClass * klass,
                               gpointer klass_data)
{
	dc_webxdc_instance_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcWebxdcInstance_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dc_webxdc_instance_finalize;
}

static void
dc_webxdc_instance_instance_init (DcWebxdcInstance * self,
                                  gpointer klass)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	self->priv = dc_webxdc_instance_get_instance_private (self);
	self->priv->last_serial = (gint64) 0;
	_tmp0_ = g_strdup ("unknown");
	self->priv->self_addr = _tmp0_;
	_tmp1_ = g_strdup ("me");
	self->priv->self_name = _tmp1_;
	_tmp2_ = g_strdup ("");
	self->priv->document_name = _tmp2_;
	self->priv->chat_name = NULL;
	self->priv->allow_internet = FALSE;
	self->priv->allow_wasm = FALSE;
	self->priv->allow_webgl = FALSE;
	self->priv->allow_hardware_acceleration = FALSE;
	self->priv->hidden_by_follow = FALSE;
	self->priv->win = NULL;
	self->priv->minimized_by_bar = FALSE;
}

static void
dc_webxdc_instance_finalize (GObject * obj)
{
	DcWebxdcInstance * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_WEBXDC_TYPE_INSTANCE, DcWebxdcInstance);
	_g_object_unref0 (self->priv->rpc);
	_g_free0 (self->priv->self_addr);
	_g_free0 (self->priv->self_name);
	_g_free0 (self->priv->app_name);
	_g_free0 (self->priv->document_name);
	_g_free0 (self->priv->chat_name);
	_g_object_unref0 (self->priv->win);
	_g_object_unref0 (self->priv->view);
	G_OBJECT_CLASS (dc_webxdc_instance_parent_class)->finalize (obj);
}

static GType
dc_webxdc_instance_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcWebxdcInstanceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_webxdc_instance_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcWebxdcInstance), 0, (GInstanceInitFunc) dc_webxdc_instance_instance_init, NULL };
	GType dc_webxdc_instance_type_id;
	dc_webxdc_instance_type_id = g_type_register_static (G_TYPE_OBJECT, "DcWebxdcInstance", &g_define_type_info, 0);
	DcWebxdcInstance_private_offset = g_type_add_instance_private (dc_webxdc_instance_type_id, sizeof (DcWebxdcInstancePrivate));
	return dc_webxdc_instance_type_id;
}

GType
dc_webxdc_instance_get_type (void)
{
	static volatile gsize dc_webxdc_instance_type_id__once = 0;
	if (g_once_init_enter (&dc_webxdc_instance_type_id__once)) {
		GType dc_webxdc_instance_type_id;
		dc_webxdc_instance_type_id = dc_webxdc_instance_get_type_once ();
		g_once_init_leave (&dc_webxdc_instance_type_id__once, dc_webxdc_instance_type_id);
	}
	return dc_webxdc_instance_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

