aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Persch <chpe@src.gnome.org>2009-02-07 23:13:33 +0800
committerChristian Persch <chpe@src.gnome.org>2009-02-07 23:13:33 +0800
commit2e720b50fa23e3045d0869ba09a4d6a005e9e14c (patch)
tree3249821df198f34c00fa631df32abb0c06a7fb46 /src
parent642eb45983933bf096844c0acb6b841fd5fa9ad3 (diff)
downloadgsoc2013-epiphany-2e720b50fa23e3045d0869ba09a4d6a005e9e14c.tar
gsoc2013-epiphany-2e720b50fa23e3045d0869ba09a4d6a005e9e14c.tar.gz
gsoc2013-epiphany-2e720b50fa23e3045d0869ba09a4d6a005e9e14c.tar.bz2
gsoc2013-epiphany-2e720b50fa23e3045d0869ba09a4d6a005e9e14c.tar.lz
gsoc2013-epiphany-2e720b50fa23e3045d0869ba09a4d6a005e9e14c.tar.xz
gsoc2013-epiphany-2e720b50fa23e3045d0869ba09a4d6a005e9e14c.tar.zst
gsoc2013-epiphany-2e720b50fa23e3045d0869ba09a4d6a005e9e14c.zip
Add seed support; use --enable-seed to check it out. Patch by Robert Carr.
svn path=/trunk/; revision=8756
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am15
-rw-r--r--src/ephy-extensions-manager.c18
-rw-r--r--src/ephy-seed-extension.c274
-rw-r--r--src/ephy-seed-extension.h60
-rw-r--r--src/ephy-seed-loader.c108
-rw-r--r--src/ephy-seed-loader.h60
6 files changed, 535 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index b6e08414f..0722c73b6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -124,6 +124,21 @@ libephymain_la_SOURCES += \
ephy-net-monitor.h
endif
+if ENABLE_SEED
+NOINST_H_FILES += \
+ ephy-seed-extension.h \
+ ephy-seed-loader.h \
+ $(NULL)
+
+libephymain_la_SOURCES += \
+ ephy-seed-loader.c \
+ ephy-seed-extension.c \
+ $(NULL)
+
+libephymain_la_CFLAGS += $(SEED_CFLAGS)
+libephymain_la_LIBADD += $(SEED_LIBS)
+endif # ENABLE_SEED
+
if ENABLE_PYTHON
NOINST_H_FILES += \
ephy-python.h \
diff --git a/src/ephy-extensions-manager.c b/src/ephy-extensions-manager.c
index e6f3c58ef..bd195c616 100644
--- a/src/ephy-extensions-manager.c
+++ b/src/ephy-extensions-manager.c
@@ -60,6 +60,10 @@
#include "ephy-python-loader.h"
#endif
+#ifdef ENABLE_SEED
+#include "ephy-seed-loader.h"
+#endif
+
#define CONF_LOADED_EXTENSIONS "/apps/epiphany/general/active_extensions"
#define EE_GROUP "Epiphany Extension"
#define DOT_INI ".ephy-extension"
@@ -593,6 +597,20 @@ get_loader_for_type (EphyExtensionsManager *manager,
#endif
}
+#ifdef ENABLE_SEED
+ if (strcmp (type, "seed") == 0)
+ {
+ info = g_new (LoaderInfo, 1);
+ info->type = g_strdup (type);
+ info->loader = g_object_new (EPHY_TYPE_SEED_LOADER, NULL);
+
+ manager->priv->factories =
+ g_list_append (manager->priv->factories, info);
+
+ return g_object_ref (info->loader);
+ return NULL;
+ }
+#endif
shlib_loader = get_loader_for_type (manager, "shlib");
g_return_val_if_fail (shlib_loader != NULL, NULL);
diff --git a/src/ephy-seed-extension.c b/src/ephy-seed-extension.c
new file mode 100644
index 000000000..11e84f5b7
--- /dev/null
+++ b/src/ephy-seed-extension.c
@@ -0,0 +1,274 @@
+/*
+ * Copyright © 2009, Robert Carr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include <seed.h>
+
+#include "config.h"
+
+#include "ephy-seed-extension.h"
+
+#include "ephy-extension.h"
+#include "ephy-window.h"
+#include "ephy-file-helpers.h"
+#include "ephy-debug.h"
+
+SeedEngine * global_eng = NULL;
+
+static void ephy_seed_extension_iface_init (EphyExtensionIface *iface);
+
+#define EPHY_SEED_EXTENSION_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_SEED_EXTENSION, EphySeedExtensionPrivate))
+
+struct _EphySeedExtensionPrivate
+{
+ char *filename;
+
+ SeedContext ctx;
+ SeedObject obj;
+};
+
+enum
+ {
+ PROP_0,
+ PROP_FILENAME
+ };
+
+static void
+ephy_seed_extension_init (EphySeedExtension *extension)
+{
+ LOG ("EphySeedExtension initialising");
+
+ extension->priv = EPHY_SEED_EXTENSION_GET_PRIVATE (extension);
+}
+
+static void
+call_seed_func (EphyExtension *extension,
+ const char *func_name,
+ EphyWindow *window,
+ EphyEmbed *embed) /* HACK: tab may be NULL */
+{
+ EphySeedExtension *seed_ext;
+ EphySeedExtensionPrivate *priv;
+ SeedObject function;
+ SeedException exception = NULL;
+ SeedValue args[2];
+
+ seed_ext = EPHY_SEED_EXTENSION (extension);
+ priv = seed_ext->priv;
+
+ if (priv->obj == NULL || seed_value_is_null(priv->ctx, priv->obj))
+ return;
+
+ function = seed_object_get_property(priv->ctx, priv->obj, func_name);
+
+ if (!seed_value_is_function(priv->ctx, function))
+ return;
+
+ args[0] = seed_value_from_object(priv->ctx, G_OBJECT(window), exception);
+ if (embed != NULL)
+ args[1] = seed_value_from_object(priv->ctx, G_OBJECT(embed), exception);
+
+ seed_object_call(global_eng->context, function, NULL, embed == NULL ? 1 : 2,
+ args, &exception);
+ if (exception)
+ printf("seed_exception: %s \n", seed_exception_to_string(priv->ctx, exception));
+
+}
+
+static void
+impl_attach_tab (EphyExtension *extension,
+ EphyWindow *window,
+ EphyEmbed *embed)
+{
+ call_seed_func (extension, "attach_tab", window, embed);
+}
+
+static void
+impl_detach_tab (EphyExtension *extension,
+ EphyWindow *window,
+ EphyEmbed *embed)
+{
+ call_seed_func (extension, "detach_tab", window, embed);
+}
+
+static void
+impl_attach_window (EphyExtension *extension,
+ EphyWindow *window)
+{
+ call_seed_func (extension, "attach_window", window, NULL);
+}
+
+static void
+impl_detach_window (EphyExtension *extension,
+ EphyWindow *window)
+{
+ call_seed_func (extension, "detach_window", window, NULL);
+}
+
+static void
+ephy_seed_extension_iface_init (EphyExtensionIface *iface)
+{
+ iface->attach_tab = impl_attach_tab;
+ iface->detach_tab = impl_detach_tab;
+ iface->attach_window = impl_attach_window;
+ iface->detach_window = impl_detach_window;
+}
+
+G_DEFINE_TYPE_WITH_CODE (EphySeedExtension, ephy_seed_extension, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (EPHY_TYPE_EXTENSION,
+ ephy_seed_extension_iface_init))
+static gchar *
+ephy_seed_extension_get_file (const gchar * name)
+{
+ gchar *dot_dir, *dot_path, *system_path, *absolute, *dirname;
+
+ dot_dir = g_strconcat (ephy_dot_dir (), "/extensions", NULL);
+ dot_path = g_strconcat (dot_dir, "/", name, ".js", NULL);
+ if (g_file_test (dot_path, G_FILE_TEST_EXISTS))
+ {
+ g_free (dot_dir);
+ return dot_path;
+ }
+ g_free (dot_dir);
+
+ system_path = g_strconcat (EXTENSIONS_DIR, name);
+ if (g_file_test (system_path, G_FILE_TEST_EXISTS))
+ {
+ return system_path;
+ }
+ g_free (system_path);
+
+ dirname = g_path_get_dirname (name);
+ if (g_path_is_absolute (dirname))
+ {
+ g_free(dirname);
+ return name;
+ }
+ g_free(dirname);
+
+ return NULL;
+}
+
+static GObject *
+ephy_seed_extension_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_params)
+{
+ SeedScript *script;
+ GObject *object;
+ EphySeedExtension *ext;
+
+ object =
+ G_OBJECT_CLASS (ephy_seed_extension_parent_class)->constructor (type,
+ n_construct_properties,
+ construct_params);
+
+ ext = EPHY_SEED_EXTENSION (object);
+
+ if (ext->priv->filename)
+ script = seed_script_new_from_file(global_eng->context,
+ ext->priv->filename);
+
+ ext->priv->ctx = seed_context_create(global_eng->group, NULL);
+ ext->priv->obj = seed_evaluate(global_eng->context,
+ script,
+ NULL);
+
+ if (seed_script_exception(script))
+ g_warning("seed_exception: %s",
+ seed_exception_to_string(global_eng->context,
+ seed_script_exception(script)));
+
+
+ return object;
+}
+
+static void
+ephy_seed_extension_finalize (GObject *object)
+{
+ EphySeedExtension *extension =
+ EPHY_SEED_EXTENSION (object);
+
+ seed_value_unprotect(extension->priv->ctx,
+ extension->priv->obj);
+ seed_context_unref(extension->priv->ctx);
+
+ G_OBJECT_CLASS (ephy_seed_extension_parent_class)->finalize (object);
+}
+
+static void
+ephy_seed_extension_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ /* no readable properties */
+ g_return_if_reached ();
+}
+
+static void
+ephy_seed_extension_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphySeedExtension *ext = EPHY_SEED_EXTENSION (object);
+
+ switch (prop_id)
+ {
+ case PROP_FILENAME:
+ ext->priv->filename =
+ ephy_seed_extension_get_file(g_value_get_string (value));
+ break;
+ default:
+ g_return_if_reached ();
+ }
+}
+
+static void
+ephy_seed_extension_class_init (EphySeedExtensionClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = ephy_seed_extension_finalize;
+ object_class->constructor = ephy_seed_extension_constructor;
+ object_class->get_property = ephy_seed_extension_get_property;
+ object_class->set_property = ephy_seed_extension_set_property;
+
+ g_object_class_install_property
+ (object_class,
+ PROP_FILENAME,
+ g_param_spec_string ("filename",
+ "Filename",
+ "Filename",
+ NULL,
+ G_PARAM_WRITABLE | G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB |
+ G_PARAM_CONSTRUCT_ONLY));
+
+ g_type_class_add_private (object_class, sizeof (EphySeedExtensionPrivate));
+
+ if (global_eng == NULL)
+ {
+ global_eng = seed_init(NULL, NULL);
+ seed_simple_evaluate(global_eng->context,
+ "Seed.import_namespace('Gtk');"
+ "Seed.import_namespace('Epiphany');");
+ }
+}
+
diff --git a/src/ephy-seed-extension.h b/src/ephy-seed-extension.h
new file mode 100644
index 000000000..09141f6b4
--- /dev/null
+++ b/src/ephy-seed-extension.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright © 2009, Robert Carr <carrr@rpi.edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#if !defined (__EPHY_EPIPHANY_H_INSIDE__) && !defined (EPIPHANY_COMPILATION)
+#error "Only <epiphany/epiphany.h> can be included directly."
+#endif
+
+#ifndef EPHY_SEED_EXTENSION_H
+#define EPHY_SEED_EXTENSION_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_SEED_EXTENSION (ephy_seed_extension_get_type ())
+#define EPHY_SEED_EXTENSION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_SEED_EXTENSION, EphySeedExtension))
+#define EPHY_SEED_EXTENSION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_SEED_EXTENSION, EphySeedExtensionClass))
+#define EPHY_IS_SEED_EXTENSION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_SEED_EXTENSION))
+#define EPHY_IS_SEED_EXTENSION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_SEED_EXTENSION))
+#define EPHY_SEED_EXTENSION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_SEED_EXTENSION, EphySeedExtensionClass))
+
+typedef struct _EphySeedExtension EphySeedExtension;
+typedef struct _EphySeedExtensionClass EphySeedExtensionClass;
+typedef struct _EphySeedExtensionPrivate EphySeedExtensionPrivate;
+
+struct _EphySeedExtensionClass
+{
+ GObjectClass parent_class;
+};
+
+struct _EphySeedExtension
+{
+ GObject parent_instance;
+
+ /*< private >*/
+ EphySeedExtensionPrivate *priv;
+};
+
+GType ephy_seed_extension_get_type (void);
+
+G_END_DECLS
+
+#endif
diff --git a/src/ephy-seed-loader.c b/src/ephy-seed-loader.c
new file mode 100644
index 000000000..859a09a65
--- /dev/null
+++ b/src/ephy-seed-loader.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright © 2009, Robert Carr <carrr@rpi.edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include "ephy-seed-loader.h"
+#include "ephy-seed-extension.h"
+#include "ephy-loader.h"
+#include "ephy-debug.h"
+
+#include <seed.h>
+
+#define EPHY_SEED_LOADER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_SEED_LOADER, EphySeedLoaderPrivate))
+
+struct _EphySeedLoaderPrivate
+{
+ gpointer dummy;
+};
+
+static GObject *
+impl_get_object (EphyLoader *eloader,
+ GKeyFile *keyfile)
+{
+ char *filename;
+ GObject *object;
+
+ 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");
+ return NULL;
+ }
+
+ object = g_object_new (EPHY_TYPE_SEED_EXTENSION,
+ "filename", filename,
+ NULL);
+
+ g_free (filename);
+
+ /* we own one ref */
+ return g_object_ref (object);
+}
+
+static void
+impl_release_object (EphyLoader *eloader,
+ GObject *object)
+{
+ g_return_if_fail (object != NULL);
+
+ g_object_unref (object);
+}
+
+static void
+ephy_seed_loader_iface_init (EphyLoaderIface *iface)
+{
+ iface->type = "seed";
+ iface->get_object = impl_get_object;
+ iface->release_object = impl_release_object;
+}
+
+G_DEFINE_TYPE_WITH_CODE (EphySeedLoader, ephy_seed_loader, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (EPHY_TYPE_LOADER, ephy_seed_loader_iface_init))
+
+static void
+ephy_seed_loader_init (EphySeedLoader *loader)
+{
+ loader->priv = EPHY_SEED_LOADER_GET_PRIVATE (loader);
+
+ LOG ("EphySeedLoader initialising");
+
+}
+
+static void
+ephy_seed_loader_finalize (GObject *object)
+{
+ LOG ("EphySeedLoader finalising");
+
+ G_OBJECT_CLASS (ephy_seed_loader_parent_class)->finalize (object);
+}
+
+static void
+ephy_seed_loader_class_init (EphySeedLoaderClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = ephy_seed_loader_finalize;
+
+ g_type_class_add_private (object_class, sizeof (EphySeedLoaderPrivate));
+}
+
diff --git a/src/ephy-seed-loader.h b/src/ephy-seed-loader.h
new file mode 100644
index 000000000..71ca4fd42
--- /dev/null
+++ b/src/ephy-seed-loader.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright Robert Carr, <carrr@rpi.edu> 2009
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#if !defined (__EPHY_EPIPHANY_H_INSIDE__) && !defined (EPIPHANY_COMPILATION)
+#error "Only <epiphany/epiphany.h> can be included directly."
+#endif
+
+#ifndef EPHY_SEED_LOADER_H
+#define EPHY_SEED_LOADER_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_SEED_LOADER (ephy_seed_loader_get_type ())
+#define EPHY_SEED_LOADER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_SEED_LOADER, EphySeedLoader))
+#define EPHY_SEED_LOADER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_SEED_LOADER, EphySeedLoaderClass))
+#define EPHY_IS_SEED_LOADER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_SEED_LOADER))
+#define EPHY_IS_SEED_LOADER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_SEED_LOADER))
+#define EPHY_SEED_LOADER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_SEED_LOADER, EphySeedLoaderClass))
+
+typedef struct _EphySeedLoader EphySeedLoader;
+typedef struct _EphySeedLoaderClass EphySeedLoaderClass;
+typedef struct _EphySeedLoaderPrivate EphySeedLoaderPrivate;
+
+struct _EphySeedLoaderClass
+{
+ GObjectClass parent_class;
+};
+
+struct _EphySeedLoader
+{
+ GObject parent_instance;
+
+ /*< private >*/
+ EphySeedLoaderPrivate *priv;
+};
+
+GType ephy_seed_loader_get_type (void);
+
+G_END_DECLS
+
+#endif /* !EPHY_SEED_LOADER_H */