diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2005-10-21 23:31:19 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2005-10-21 23:31:19 +0800 |
commit | 8e4b79936d79e1fb33947fbfbea1f69141488790 (patch) | |
tree | 3ea3a4c212b43be8b3526d5098800a61f63b1d41 | |
parent | 944263b78b78513f86b48dd74a1ba9900f05ed10 (diff) | |
download | gsoc2013-epiphany-8e4b79936d79e1fb33947fbfbea1f69141488790.tar gsoc2013-epiphany-8e4b79936d79e1fb33947fbfbea1f69141488790.tar.gz gsoc2013-epiphany-8e4b79936d79e1fb33947fbfbea1f69141488790.tar.bz2 gsoc2013-epiphany-8e4b79936d79e1fb33947fbfbea1f69141488790.tar.lz gsoc2013-epiphany-8e4b79936d79e1fb33947fbfbea1f69141488790.tar.xz gsoc2013-epiphany-8e4b79936d79e1fb33947fbfbea1f69141488790.tar.zst gsoc2013-epiphany-8e4b79936d79e1fb33947fbfbea1f69141488790.zip |
Expose the extension description keyfile directly to the loaders.
2005-10-21 Christian Persch <chpe@cvs.gnome.org>
* lib/ephy-loader.c: (ephy_loader_get_object):
* lib/ephy-loader.h:
* lib/ephy-module.c: (ephy_module_load), (ephy_module_new):
* lib/ephy-module.h:
* lib/ephy-shlib-loader.c: (impl_get_object),
(ephy_shlib_loader_class_init):
* src/ephy-extensions-manager.c: (free_extension_info),
(ephy_extensions_manager_load_ini_string), (get_loader_for_type),
(load_extension):
* src/ephy-python-loader.c: (impl_get_object):
Expose the extension description keyfile directly to the loaders.
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | lib/ephy-loader.c | 4 | ||||
-rw-r--r-- | lib/ephy-loader.h | 4 | ||||
-rw-r--r-- | lib/ephy-module.c | 10 | ||||
-rw-r--r-- | lib/ephy-module.h | 3 | ||||
-rw-r--r-- | lib/ephy-shlib-loader.c | 27 | ||||
-rw-r--r-- | src/ephy-extensions-manager.c | 135 | ||||
-rw-r--r-- | src/ephy-extensions-manager.h | 5 | ||||
-rw-r--r-- | src/ephy-python-loader.c | 12 |
9 files changed, 92 insertions, 123 deletions
@@ -1,3 +1,18 @@ +2005-10-21 Christian Persch <chpe@cvs.gnome.org> + + * lib/ephy-loader.c: (ephy_loader_get_object): + * lib/ephy-loader.h: + * lib/ephy-module.c: (ephy_module_load), (ephy_module_new): + * lib/ephy-module.h: + * lib/ephy-shlib-loader.c: (impl_get_object), + (ephy_shlib_loader_class_init): + * src/ephy-extensions-manager.c: (free_extension_info), + (ephy_extensions_manager_load_ini_string), (get_loader_for_type), + (load_extension): + * src/ephy-python-loader.c: (impl_get_object): + + Expose the extension description keyfile directly to the loaders. + 2005-10-20 Christian Persch <chpe@cvs.gnome.org> * lib/ephy-stock-icons.c: (ephy_stock_icons_init): diff --git a/lib/ephy-loader.c b/lib/ephy-loader.c index 9d682caa9..d7df7de8c 100644 --- a/lib/ephy-loader.c +++ b/lib/ephy-loader.c @@ -54,10 +54,10 @@ ephy_loader_type (const EphyLoader *loader) GObject * ephy_loader_get_object (EphyLoader *loader, - GData **attributes) + GKeyFile *keyfile) { EphyLoaderIface *iface = EPHY_LOADER_GET_IFACE (loader); - return iface->get_object (loader, attributes); + return iface->get_object (loader, keyfile); } void diff --git a/lib/ephy-loader.h b/lib/ephy-loader.h index c987bb636..0a77f6d6f 100644 --- a/lib/ephy-loader.h +++ b/lib/ephy-loader.h @@ -46,7 +46,7 @@ struct _EphyLoaderIface /* Methods */ GObject * (* get_object) (EphyLoader *loader, - GData **attributes); + GKeyFile *keyfile); void (* release_object) (EphyLoader *loader, GObject *object); }; @@ -56,7 +56,7 @@ GType ephy_loader_get_type (void); const char *ephy_loader_type (const EphyLoader *loader); GObject *ephy_loader_get_object (EphyLoader *loader, - GData **attributes); + GKeyFile *keyfile); void ephy_loader_release_object (EphyLoader *loader, GObject *object); diff --git a/lib/ephy-module.c b/lib/ephy-module.c index 9572d2010..39bf5b35c 100644 --- a/lib/ephy-module.c +++ b/lib/ephy-module.c @@ -42,6 +42,7 @@ struct _EphyModule char *path; GType type; + guint resident : 1; }; typedef GType (*EphyModuleRegisterFunc) (GTypeModule *); @@ -139,6 +140,11 @@ ephy_module_load (GTypeModule *gmodule) return FALSE; } + if (module->resident) + { + g_module_make_resident (module->library); + } + return TRUE; } @@ -209,7 +215,8 @@ ephy_module_class_init (EphyModuleClass *class) } EphyModule * -ephy_module_new (const char *path) +ephy_module_new (const char *path, + gboolean resident) { EphyModule *result; @@ -222,6 +229,7 @@ ephy_module_new (const char *path) g_type_module_set_name (G_TYPE_MODULE (result), path); result->path = g_strdup (path); + result->resident = resident != FALSE; return result; } diff --git a/lib/ephy-module.h b/lib/ephy-module.h index aaacbff63..191b1ffde 100644 --- a/lib/ephy-module.h +++ b/lib/ephy-module.h @@ -37,7 +37,8 @@ typedef struct _EphyModule EphyModule; GType ephy_module_get_type (void); -EphyModule *ephy_module_new (const char *path); +EphyModule *ephy_module_new (const char *path, + gboolean resident); const char *ephy_module_get_path (EphyModule *module); diff --git a/lib/ephy-shlib-loader.c b/lib/ephy-shlib-loader.c index 2b0b9b6d2..c1a82e938 100644 --- a/lib/ephy-shlib-loader.c +++ b/lib/ephy-shlib-loader.c @@ -36,9 +36,6 @@ typedef struct GObject *object; } LoaderData; -static GQuark Library_quark = 0; -static GQuark library_quark = 0; - #define EPHY_SHLIB_LOADER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_SHLIB_LOADER, EphyShlibLoaderPrivate)) struct _EphyShlibLoaderPrivate @@ -143,24 +140,25 @@ find_object (const LoaderData *data, static GObject * impl_get_object (EphyLoader *eloader, - GData **attributes) + GKeyFile *keyfile) { EphyShlibLoader *loader = EPHY_SHLIB_LOADER (eloader); GSList *l; LoaderData *data = NULL; - const char *library; + char *library; + gboolean resident; - library = g_datalist_id_get_data (attributes, Library_quark); - if (library == NULL) - { - library = g_datalist_id_get_data (attributes, library_quark); - } + g_return_val_if_fail (keyfile != NULL, NULL); + + library = g_key_file_get_string (keyfile, "Loader", "Library", NULL); if (library == NULL) { g_warning ("NULL library name!\n"); return NULL; } + resident = g_key_file_get_boolean (keyfile, "Loader", "Resident", NULL); + l = g_slist_find_custom (loader->priv->data, library, (GCompareFunc) find_library); @@ -171,6 +169,7 @@ impl_get_object (EphyLoader *eloader, if (data->object != NULL) { + g_free (library); return g_object_ref (data->object); } } @@ -182,13 +181,14 @@ impl_get_object (EphyLoader *eloader, if (data->module == NULL) { - data->module = ephy_module_new (library); + data->module = ephy_module_new (library, resident); } g_return_val_if_fail (data->object == NULL, data->object); if (g_type_module_use (G_TYPE_MODULE (data->module)) == FALSE) { + g_free (library); g_warning ("Could not load extension file at %s\n", ephy_module_get_path (data->module)); return NULL; @@ -203,6 +203,8 @@ impl_get_object (EphyLoader *eloader, g_object_set_data (G_OBJECT (data->object), DATA_KEY, data); } + g_free (library); + return data->object; } @@ -241,7 +243,4 @@ ephy_shlib_loader_class_init (EphyShlibLoaderClass *klass) object_class->finalize = ephy_shlib_loader_finalize; g_type_class_add_private (object_class, sizeof (EphyShlibLoaderPrivate)); - - Library_quark = g_quark_from_string ("Library"); - library_quark = g_quark_from_string ("library"); } diff --git a/src/ephy-extensions-manager.c b/src/ephy-extensions-manager.c index e7589be6d..30fdb11f8 100644 --- a/src/ephy-extensions-manager.c +++ b/src/ephy-extensions-manager.c @@ -59,7 +59,8 @@ #endif #define CONF_LOADED_EXTENSIONS "/apps/epiphany/general/active_extensions" -#define DOT_INI ".ephy-extension" +#define EE_GROUP "Epiphany Extension" +#define DOT_INI ".ephy-extension" #define ENABLE_LEGACY_FORMAT @@ -84,11 +85,9 @@ struct _EphyExtensionsManagerPrivate typedef struct { EphyExtensionInfo info; - guint version; gboolean load_failed; char *loader_type; - GData *loader_attributes; EphyLoader *loader; /* NULL if never loaded */ GObject *extension; /* NULL if unloaded */ @@ -266,13 +265,8 @@ free_extension_info (ExtensionInfo *info) EphyExtensionInfo *einfo = (EphyExtensionInfo *) info; g_free (einfo->identifier); - g_free (einfo->name); - g_free (einfo->description); - g_list_foreach (einfo->authors, (GFunc) g_free, NULL); - g_list_free (einfo->authors); - g_free (einfo->url); + g_key_file_free (einfo->keyfile); g_free (info->loader_type); - g_datalist_clear (&info->loader_attributes); if (info->extension != NULL) { @@ -310,10 +304,9 @@ ephy_extensions_manager_load_ini_string (EphyExtensionsManager *manager, { ExtensionInfo *info; EphyExtensionInfo *einfo; - gchar ** list; - int i; GKeyFile *key_file; GError *err = NULL; + char *start_group; LOG ("Loading INI description file for '%s'", identifier); @@ -336,89 +329,41 @@ ephy_extensions_manager_load_ini_string (EphyExtensionsManager *manager, return; } - if (g_key_file_has_group (key_file, "Epiphany Extension") == FALSE || - g_key_file_has_group (key_file, "Loader") == FALSE) + start_group = g_key_file_get_start_group (key_file); + if (start_group == NULL || + strcmp (start_group, EE_GROUP) != 0 || + !g_key_file_has_group (key_file, "Loader")) { g_warning ("Invalid extension description file for '%s'; " "missing 'Epiphany Extension' or 'Loader' group", identifier); g_key_file_free (key_file); + g_free (start_group); return; } + g_free (start_group); - info = g_new0 (ExtensionInfo, 1); - einfo = (EphyExtensionInfo *) info; - einfo->identifier = g_strdup (identifier); - g_datalist_init (&info->loader_attributes); - - einfo->name = g_key_file_get_locale_string (key_file, - "Epiphany Extension", - "Name", - NULL, NULL); - - einfo->description = g_key_file_get_locale_string (key_file, - "Epiphany Extension", - "Description", - NULL, NULL); - - einfo->url = g_key_file_get_locale_string (key_file, - "Epiphany Extension", - "URL", - NULL, NULL); - - list = g_key_file_get_string_list (key_file, - "Epiphany Extension", - "Authors", NULL, NULL); - if (list) + if (!g_key_file_has_key (key_file, EE_GROUP, "Name", NULL) || + !g_key_file_has_key (key_file, EE_GROUP, "Description", NULL)) { - for (i = 0 ; list[i]; i++ ) - { - einfo->authors = g_list_prepend (einfo->authors, - g_strstrip (g_strdup (list[i]))); - } - g_strfreev (list); - } - - einfo->authors = g_list_reverse (einfo->authors); - - info->version = g_key_file_get_integer (key_file, - "Epiphany Extension", - "Version", NULL); - - /* Load the loader flags */ - list = g_key_file_get_keys (key_file, "Loader", NULL, NULL); - - if (list) - { - for (i = 0 ; list[i]; i++ ) - { - char * value; - GQuark attr_quark = 0; - - value = g_key_file_get_string (key_file, "Loader", - list[i], NULL); + g_warning ("Invalid extension description file for '%s'; " + "missing 'Name' or 'Description' keys.", + identifier); - if (strcmp (list[i], "Type") == 0) - { - info->loader_type = value; - continue; - } - - attr_quark = g_quark_from_string (list[i]); + g_key_file_free (key_file); + return; + } - g_datalist_id_set_data_full (&info->loader_attributes, - attr_quark, value, - (GDestroyNotify) g_free); - } - g_strfreev (list); - } + info = g_new0 (ExtensionInfo, 1); + einfo = (EphyExtensionInfo *) info; + einfo->identifier = g_strdup (identifier); + einfo->keyfile = key_file; - g_key_file_free (key_file); + info->loader_type = g_key_file_get_string (key_file, "Loader", "Type", NULL); /* sanity check */ - if (einfo->name == NULL || einfo->description == NULL || - info->loader_type == NULL || info->loader_type[0] == '\0') + if (info->loader_type == NULL || info->loader_type[0] == '\0') { free_extension_info (info); return; @@ -566,8 +511,8 @@ get_loader_for_type (EphyExtensionsManager *manager, { LoaderInfo *info; GList *l; - GData *attr = NULL; - char *path, *name, *stype; + char *path, *name, *stype, *data; + GKeyFile *keyfile; EphyLoader *shlib_loader; GObject *loader; @@ -608,21 +553,27 @@ get_loader_for_type (EphyExtensionsManager *manager, #endif } - stype = sanitise_type (type); - name = g_strconcat ("lib", stype, "loader.", G_MODULE_SUFFIX, NULL); - path = g_build_filename (LOADER_DIR, name, NULL); - g_datalist_init (&attr); - g_datalist_set_data (&attr, "library", path); - shlib_loader = get_loader_for_type (manager, "shlib"); g_return_val_if_fail (shlib_loader != NULL, NULL); - loader = ephy_loader_get_object (shlib_loader, &attr); - g_datalist_clear (&attr); + stype = sanitise_type (type); + name = g_strconcat ("lib", stype, "loader.", G_MODULE_SUFFIX, NULL); + path = g_build_filename (LOADER_DIR, name, NULL); + data = g_strconcat ("[Loader]\nType=shlib\nLibrary=", path, "\n", NULL); g_free (stype); g_free (name); g_free (path); + keyfile = g_key_file_new (); + if (!g_key_file_load_from_data (keyfile, data, strlen (data), 0, NULL)) + { + g_free (data); + return NULL; + } + + loader = ephy_loader_get_object (shlib_loader, keyfile); + g_key_file_free (keyfile); + if (EPHY_IS_LOADER (loader)) { info = g_new (LoaderInfo, 1); @@ -671,8 +622,7 @@ load_extension (EphyExtensionsManager *manager, if (info->load_failed) return; /* get a loader */ - loader = get_loader_for_type (manager, - info->loader_type); + loader = get_loader_for_type (manager, info->loader_type); if (loader == NULL) { g_message ("No loader found for extension '%s' of type '%s'\n", @@ -682,8 +632,7 @@ load_extension (EphyExtensionsManager *manager, info->loader = loader; - info->extension = ephy_loader_get_object (loader, - &info->loader_attributes); + info->extension = ephy_loader_get_object (loader, info->info.keyfile); /* attach if the extension implements EphyExtensionIface */ if (EPHY_IS_EXTENSION (info->extension)) diff --git a/src/ephy-extensions-manager.h b/src/ephy-extensions-manager.h index 22e70a8d7..2e3d1a07b 100644 --- a/src/ephy-extensions-manager.h +++ b/src/ephy-extensions-manager.h @@ -44,10 +44,7 @@ typedef struct _EphyExtensionsManagerPrivate EphyExtensionsManagerPrivate; typedef struct { char *identifier; - char *name; - char *description; - GList *authors; - char *url; + GKeyFile *keyfile; gboolean active; } EphyExtensionInfo; diff --git a/src/ephy-python-loader.c b/src/ephy-python-loader.c index ff23bd7ce..1e0e697c8 100644 --- a/src/ephy-python-loader.c +++ b/src/ephy-python-loader.c @@ -39,16 +39,14 @@ static GObjectClass *parent_class = NULL; static GObject * impl_get_object (EphyLoader *eloader, - GData **attributes) + GKeyFile *keyfile) { char *filename; GObject *object; - filename = g_datalist_get_data (attributes, "Module"); - if (filename == NULL) - { - filename = g_datalist_get_data (attributes, "module"); - } + g_return_val_if_fail (keyfile != NULL, NULL); + + filename = g_key_file_get_string (keyfile, "Loader", "Module", NULL); if (filename == NULL) { g_warning ("NULL module name!\n"); @@ -59,6 +57,8 @@ impl_get_object (EphyLoader *eloader, "filename", filename, NULL); + g_free (filename); + /* we own one ref */ return g_object_ref (object); } |