eagleoneraptor

GOA WebKitWebExtension

Feb 26th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.71 KB | None | 0 0
  1. diff --git a/configure.ac b/configure.ac
  2. index cda6916..847eace 100644
  3. --- a/configure.ac
  4. +++ b/configure.ac
  5. @@ -498,6 +498,7 @@ src/goa/Makefile
  6.  src/goa/goa-1.0.pc
  7.  src/goabackend/Makefile
  8.  src/goabackend/goa-backend-1.0.pc
  9. +src/goawebextension/Makefile
  10.  src/goaidentity/Makefile
  11.  src/daemon/Makefile
  12.  src/examples/Makefile
  13. diff --git a/src/Makefile.am b/src/Makefile.am
  14. index 63a20e5..3045044 100644
  15. --- a/src/Makefile.am
  16. +++ b/src/Makefile.am
  17. @@ -1,6 +1,6 @@
  18.  
  19.  NULL =
  20.  
  21. -SUBDIRS = goa goaidentity goabackend daemon examples
  22. +SUBDIRS = goa goaidentity goabackend goawebextension daemon examples
  23.  
  24.  -include $(top_srcdir)/git.mk
  25. diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am
  26. index 5ca8e5c..182090d 100644
  27. --- a/src/goabackend/Makefile.am
  28. +++ b/src/goabackend/Makefile.am
  29. @@ -3,24 +3,25 @@ NULL =
  30.  CLEANFILES =
  31.  EXTRA_DIST =
  32.  
  33. -AM_CPPFLAGS =                          \
  34. -   -I$(top_builddir)/src -I$(top_srcdir)/src       \
  35. -   -I$(top_builddir)/src -I$(top_srcdir)/src       \
  36. -   -I$(top_builddir)/src/goa               \
  37. -   -I$(top_srcdir)/src/goaidentity             \
  38. -   -I$(top_builddir)/src/goaidentity           \
  39. -   -DG_LOG_DOMAIN=\"GoaBackend\"               \
  40. -   -DGOA_BACKEND_COMPILATION               \
  41. -   -DGOA_API_IS_SUBJECT_TO_CHANGE              \
  42. -   -DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\"       \
  43. -   -DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\"       \
  44. -   -DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\"          \
  45. -   -DPACKAGE_BIN_DIR=\""$(bindir)"\"           \
  46. -   -DPACKAGE_LOCALSTATE_DIR=\""$(localstatedir)"\"     \
  47. -   -DPACKAGE_LOCALE_DIR=\""$(localedir)"\"         \
  48. -   -DPACKAGE_LIB_DIR=\""$(libdir)"\"           \
  49. -   -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT         \
  50. -   $(WARN_CFLAGS)                      \
  51. +AM_CPPFLAGS =                              \
  52. +   -I$(top_builddir)/src -I$(top_srcdir)/src           \
  53. +   -I$(top_builddir)/src -I$(top_srcdir)/src           \
  54. +   -I$(top_builddir)/src/goa                   \
  55. +   -I$(top_srcdir)/src/goaidentity                 \
  56. +   -I$(top_builddir)/src/goaidentity               \
  57. +   -DG_LOG_DOMAIN=\"GoaBackend\"                   \
  58. +   -DGOA_BACKEND_COMPILATION                   \
  59. +   -DGOA_API_IS_SUBJECT_TO_CHANGE                  \
  60. +   -DGOA_WEB_EXTENSIONS_DIR=\""$(libdir)/goa-1.0/web-extensions"\" \
  61. +   -DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\"           \
  62. +   -DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\"           \
  63. +   -DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\"              \
  64. +   -DPACKAGE_BIN_DIR=\""$(bindir)"\"               \
  65. +   -DPACKAGE_LOCALSTATE_DIR=\""$(localstatedir)"\"         \
  66. +   -DPACKAGE_LOCALE_DIR=\""$(localedir)"\"             \
  67. +   -DPACKAGE_LIB_DIR=\""$(libdir)"\"               \
  68. +   -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT             \
  69. +   $(WARN_CFLAGS)                          \
  70.     $(NULL)
  71.  
  72.  # ----------------------------------------------------------------------------------------------------
  73. diff --git a/src/goabackend/goawebview.c b/src/goabackend/goawebview.c
  74. index 2fe19d1..99504d3 100644
  75. --- a/src/goabackend/goawebview.c
  76. +++ b/src/goabackend/goawebview.c
  77. @@ -254,11 +254,16 @@ static void
  78.  goa_web_view_class_init (GoaWebViewClass *klass)
  79.  {
  80.    GObjectClass *object_class;
  81. +  WebKitWebContext *web_context;
  82.  
  83.    object_class = G_OBJECT_CLASS (klass);
  84.    object_class->dispose = goa_web_view_dispose;
  85.  
  86.    g_type_class_add_private (object_class, sizeof (GoaWebViewPrivate));
  87. +
  88. +  web_context = webkit_web_context_get_default ();
  89. +  webkit_web_context_set_web_extensions_directory (web_context,
  90. +                                                   GOA_WEB_EXTENSIONS_DIR);
  91.  }
  92.  
  93.  GtkWidget *
  94. diff --git a/src/goawebextension/goawebextension.c b/src/goawebextension/goawebextension.c
  95. new file mode 100644
  96. index 0000000..e207c14
  97. --- /dev/null
  98. +++ b/src/goawebextension/goawebextension.c
  99. @@ -0,0 +1,114 @@
  100. +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
  101. +/*
  102. + * Copyright (C) 2015 Damián Nohales
  103. + *
  104. + * This library is free software; you can redistribute it and/or
  105. + * modify it under the terms of the GNU Lesser General Public
  106. + * License as published by the Free Software Foundation; either
  107. + * version 2 of the License, or (at your option) any later version.
  108. + *
  109. + * This library is distributed in the hope that it will be useful,
  110. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  111. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  112. + * Lesser General Public License for more details.
  113. + *
  114. + * You should have received a copy of the GNU Lesser General
  115. + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  116. + */
  117. +
  118. +#include "goawebextension.h"
  119. +
  120. +struct _GoaWebExtensionPrivate
  121. +{
  122. +  WebKitWebExtension *extension;
  123. +  gboolean initialized;
  124. +};
  125. +
  126. +G_DEFINE_TYPE_WITH_PRIVATE (GoaWebExtension, goa_web_extension, G_TYPE_OBJECT)
  127. +
  128. +enum {
  129. +  PROP_0,
  130. +  LAST_PROP
  131. +};
  132. +
  133. +static GParamSpec *gParamSpecs [LAST_PROP];
  134. +
  135. +static void
  136. +goa_web_extension_finalize (GObject *object)
  137. +{
  138. +  GoaWebExtensionPrivate *priv = GOA_WEB_EXTENSION (object)->priv;
  139. +
  140. +  G_OBJECT_CLASS (goa_web_extension_parent_class)->finalize (object);
  141. +}
  142. +
  143. +static void
  144. +goa_web_extension_get_property (GObject    *object,
  145. +                                guint       prop_id,
  146. +                                GValue     *value,
  147. +                                GParamSpec *pspec)
  148. +{
  149. +  GoaWebExtension *self = GOA_WEB_EXTENSION (object);
  150. +
  151. +  switch (prop_id)
  152. +    {
  153. +    default:
  154. +      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  155. +    }
  156. +}
  157. +
  158. +static void
  159. +goa_web_extension_set_property (GObject      *object,
  160. +                                guint         prop_id,
  161. +                                const GValue *value,
  162. +                                GParamSpec   *pspec)
  163. +{
  164. +  GoaWebExtension *self = GOA_WEB_EXTENSION (object);
  165. +
  166. +  switch (prop_id)
  167. +    {
  168. +    default:
  169. +      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  170. +    }
  171. +}
  172. +
  173. +static void
  174. +goa_web_extension_class_init (GoaWebExtensionClass *klass)
  175. +{
  176. +  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  177. +
  178. +  object_class->finalize = goa_web_extension_finalize;
  179. +  object_class->get_property = goa_web_extension_get_property;
  180. +  object_class->set_property = goa_web_extension_set_property;
  181. +}
  182. +
  183. +static void
  184. +goa_web_extension_init (GoaWebExtension *self)
  185. +{
  186. +  self->priv = goa_web_extension_get_instance_private (self);
  187. +}
  188. +
  189. +static gpointer
  190. +goa_web_extension_create_instance(gpointer data)
  191. +{
  192. +  return g_object_new (EPHY_TYPE_WEB_EXTENSION, NULL);
  193. +}
  194. +
  195. +GoaWebExtension *
  196. +goa_web_extension_get (void)
  197. +{
  198. +  static GOnce once_init = G_ONCE_INIT;
  199. +  return GOA_WEB_EXTENSION (g_once (&once_init, goa_web_extension_create_instance, NULL));
  200. +}
  201. +
  202. +void
  203. +goa_web_extension_initialize (GoaWebExtension    *extension,
  204. +                              WebKitWebExtension *wk_extension)
  205. +{
  206. +  g_return_if_fail (EPHY_IS_WEB_EXTENSION (extension));
  207. +
  208. +  if (priv->initialized)
  209. +    return;
  210. +
  211. +  priv->initialized = TRUE;
  212. +  priv->extension = g_object_ref (wk_extension);
  213. +}
  214. diff --git a/src/goawebextension/goawebextension.h b/src/goawebextension/goawebextension.h
  215. new file mode 100644
  216. index 0000000..a0c66bd
  217. --- /dev/null
  218. +++ b/src/goawebextension/goawebextension.h
  219. @@ -0,0 +1,58 @@
  220. +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
  221. +/*
  222. + * Copyright (C) 2015 Damián Nohales
  223. + *
  224. + * This library is free software; you can redistribute it and/or
  225. + * modify it under the terms of the GNU Lesser General Public
  226. + * License as published by the Free Software Foundation; either
  227. + * version 2 of the License, or (at your option) any later version.
  228. + *
  229. + * This library is distributed in the hope that it will be useful,
  230. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  231. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  232. + * Lesser General Public License for more details.
  233. + *
  234. + * You should have received a copy of the GNU Lesser General
  235. + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  236. + */
  237. +
  238. +#ifndef __GOA_WEB_EXTENSION_H__
  239. +#define __GOA_WEB_EXTENSION_H__
  240. +
  241. +#include <glib-object.h>
  242. +
  243. +G_BEGIN_DECLS
  244. +
  245. +#define GOA_TYPE_WEB_EXTENSION            (goa_web_extension_get_type())
  246. +#define GOA_WEB_EXTENSION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOA_TYPE_WEB_EXTENSION, GoaWebExtension))
  247. +#define GOA_WEB_EXTENSION_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOA_TYPE_WEB_EXTENSION, GoaWebExtension const))
  248. +#define GOA_WEB_EXTENSION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GOA_TYPE_WEB_EXTENSION, GoaWebExtensionClass))
  249. +#define GOA_IS_WEB_EXTENSION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOA_TYPE_WEB_EXTENSION))
  250. +#define GOA_IS_WEB_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GOA_TYPE_WEB_EXTENSION))
  251. +#define GOA_WEB_EXTENSION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GOA_TYPE_WEB_EXTENSION, GoaWebExtensionClass))
  252. +
  253. +typedef struct _GoaWebExtension        GoaWebExtension;
  254. +typedef struct _GoaWebExtensionClass   GoaWebExtensionClass;
  255. +typedef struct _GoaWebExtensionPrivate GoaWebExtensionPrivate;
  256. +
  257. +struct _GoaWebExtension
  258. +{
  259. +  GObject parent;
  260. +
  261. +  /*< private >*/
  262. +  GoaWebExtensionPrivate *priv;
  263. +};
  264. +
  265. +struct _GoaWebExtensionClass
  266. +{
  267. +  GObjectClass parent;
  268. +};
  269. +
  270. +GType                goa_web_extension_get_type   (void);
  271. +GoaWebExtension     *goa_web_extension_get        (void);
  272. +void                 goa_web_extension_initialize (GoaWebExtension    *extension,
  273. +                                                   WebKitWebExtension *wk_extension);
  274. +
  275. +G_END_DECLS
  276. +
  277. +#endif /* __GOA_WEB_EXTENSION_H__ */
  278. diff --git a/src/goawebextension/goawebkitextensionmain.c b/src/goawebextension/goawebkitextensionmain.c
  279. new file mode 100644
  280. index 0000000..83d4517
  281. --- /dev/null
  282. +++ b/src/goawebextension/goawebkitextensionmain.c
  283. @@ -0,0 +1,58 @@
  284. +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
  285. +/*
  286. + * Copyright (C) 2015 Damián Nohales
  287. + *
  288. + * This library is free software; you can redistribute it and/or
  289. + * modify it under the terms of the GNU Lesser General Public
  290. + * License as published by the Free Software Foundation; either
  291. + * version 2 of the License, or (at your option) any later version.
  292. + *
  293. + * This library is distributed in the hope that it will be useful,
  294. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  295. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  296. + * Lesser General Public License for more details.
  297. + *
  298. + * You should have received a copy of the GNU Lesser General
  299. + * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  300. + */
  301. +
  302. +#include <webkit2/webkit-web-extension.h>
  303. +
  304. +#include "goawebextension.h"
  305. +
  306. +static void
  307. +web_page_created_callback (WebKitWebExtension *extension,
  308. +                           WebKitWebPage      *web_page,
  309. +                           gpointer            user_data)
  310. +{
  311. +  g_print ("Page %d created for %s\n",
  312. +           webkit_web_page_get_id (web_page),
  313. +           webkit_web_page_get_uri (web_page));
  314. +}
  315. +
  316. +G_MODULE_EXPORT void
  317. +webkit_web_extension_initialize (WebKitWebExtension *extension,
  318. +                                 GVariant *user_data)
  319. +{
  320. +  GoaWebExtension *web_extension;
  321. +  char *service_name;
  322. +  const char *extension_id;
  323. +  const char *dot_dir;
  324. +  gboolean private_profile;
  325. +  GError *error = NULL;
  326. +
  327. +  g_variant_get (user_data, "(&s&sb)", &extension_id, &dot_dir, &private_profile);
  328. +
  329. +  web_extension = goa_web_extension_get ();
  330. +  ephy_web_extension_initialize (web_extension, extension, dot_dir, private_profile);
  331. +
  332. +  service_name = g_strdup_printf ("%s-%s", EPHY_WEB_EXTENSION_SERVICE_NAME, extension_id);
  333. +  g_bus_own_name (G_BUS_TYPE_SESSION,
  334. +                  service_name,
  335. +                  G_BUS_NAME_OWNER_FLAGS_NONE,
  336. +                  NULL,
  337. +                  (GBusNameAcquiredCallback)name_acquired_cb,
  338. +                  NULL,
  339. +                  web_extension, NULL);
  340. +  g_free (service_name);
  341. +}
  342. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment