[gnome-online-accounts] provider: Add the :preseed-data property for account creation
- From: Emanuele Aina <emaaa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts] provider: Add the :preseed-data property for account creation
- Date: Thu, 7 Mar 2013 12:32:22 +0000 (UTC)
commit 1f714a8d536ea08fb9df0d3ce1250b4a67f35bba
Author: Emanuele Aina <emanuele aina collabora com>
Date: Sun Mar 3 17:09:00 2013 +0100
provider: Add the :preseed-data property for account creation
The :pre-seed property is a a{sv} GVariant used to store a provider-type
specific set of collected data that can be useful during account
creation (eg. http cookies from an existing browser session or the
entrypoint url for self-hosted services).
https://bugzilla.gnome.org/show_bug.cgi?id=694313
doc/goa-sections.txt | 2 +
src/goabackend/goaprovider.c | 151 +++++++++++++++++++++++++++++++++++++++++-
src/goabackend/goaprovider.h | 3 +
3 files changed, 155 insertions(+), 1 deletions(-)
---
diff --git a/doc/goa-sections.txt b/doc/goa-sections.txt
index 31caff6..2ec5bfb 100644
--- a/doc/goa-sections.txt
+++ b/doc/goa-sections.txt
@@ -421,6 +421,8 @@ goa_provider_get_provider_icon
goa_provider_get_provider_group
goa_provider_build_object
goa_provider_add_account
+goa_provider_set_preseed_data
+goa_provider_get_preseed_data
goa_provider_refresh_account
goa_provider_show_account
goa_provider_ensure_credentials
diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c
index c49cbff..4ed00b6 100644
--- a/src/goabackend/goaprovider.c
+++ b/src/goabackend/goaprovider.c
@@ -53,6 +53,19 @@
* #GoaProvider is the base type for all providers.
*/
+struct _GoaProviderPrivate
+{
+ GVariant *preseed_data;
+};
+
+enum {
+ PROP_0,
+ PROP_PRESEED_DATA,
+ NUM_PROPERTIES
+};
+
+static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
+
static gboolean goa_provider_ensure_credentials_sync_real (GoaProvider *provider,
GoaObject *object,
gint *out_expires_in,
@@ -79,21 +92,120 @@ static guint goa_provider_get_credentials_generation_real (GoaProvider *provider
static GIcon *goa_provider_get_provider_icon_default (GoaProvider *provider,
GoaObject *object);
+#define GOA_PROVIDER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOA_TYPE_PROVIDER,
GoaProviderPrivate))
+
G_DEFINE_ABSTRACT_TYPE (GoaProvider, goa_provider, G_TYPE_OBJECT);
static void
-goa_provider_init (GoaProvider *client)
+goa_provider_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GoaProvider *self = GOA_PROVIDER (object);
+
+ switch (property_id) {
+ case PROP_PRESEED_DATA:
+ g_value_set_variant (value, self->priv->preseed_data);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+goa_provider_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GoaProvider *self = GOA_PROVIDER (object);
+
+ switch (property_id) {
+ case PROP_PRESEED_DATA:
+ goa_provider_set_preseed_data (self, g_value_get_variant (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+goa_provider_dispose (GObject *object)
+{
+ GoaProvider *provider = GOA_PROVIDER (object);
+
+ g_clear_pointer (&provider->priv->preseed_data, g_variant_unref);
+
+ G_OBJECT_CLASS (goa_provider_parent_class)->dispose (object);
+}
+
+static void
+goa_provider_init (GoaProvider *provider)
{
+ provider->priv = GOA_PROVIDER_GET_PRIVATE (provider);
}
static void
goa_provider_class_init (GoaProviderClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (GoaProviderPrivate));
+
+ object_class->set_property = goa_provider_set_property;
+ object_class->get_property = goa_provider_get_property;
+ object_class->dispose = goa_provider_dispose;
+
klass->build_object = goa_provider_build_object_real;
klass->ensure_credentials_sync = goa_provider_ensure_credentials_sync_real;
klass->show_account = goa_provider_show_account_real;
klass->get_credentials_generation = goa_provider_get_credentials_generation_real;
klass->get_provider_icon = goa_provider_get_provider_icon_default;
+
+/**
+ * GoaProvider:preseed-data
+ *
+ * An #GVariant of type a{sv} storing any information already collected that
+ * can be useful when creating a new account. For instance, this can be useful
+ * to reuse the HTTP cookies from an existing browser session to skip the
+ * prompt for username and password in the OAuth2-based providers by passing
+ * a #GVariant with the following contents:
+ *
+ * <informalexample>
+ * <programlisting>
+ * {
+ * "cookies": [
+ * {
+ * "domain": "example.com",
+ * "name": "LSID",
+ * "value": "asdfasdfasdf"
+ * },
+ * {
+ * "domain": "accounts.example.com",
+ * "name": "SSID",
+ * "value": "asdfasdfasdf"
+ * }
+ * ]
+ * }
+ * </programlisting>
+ * </informalexample>
+ *
+ * Unknown or unsupported keys will be ignored by providers.
+ */
+ properties[PROP_PRESEED_DATA] =
+ g_param_spec_variant ("preseed-data",
+ "Collected data to pre-seed account creation",
+ "A a{sv} #GVariant containing a provider-type specific set of data that"
+ "can be useful during account creation (eg. http cookies from an existing"
+ "browser session or the entrypoint url for self-hosted services).",
+ G_VARIANT_TYPE_VARDICT,
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
}
/**
@@ -767,6 +879,43 @@ goa_provider_get_all (void)
/* ---------------------------------------------------------------------------------------------------- */
/**
+ * goa_provider_set_preseed_data:
+ * @provider: The #GoaProvider
+ * @preseed_data: A #GVariant of type a{sv}
+ *
+ * Sets the #GoaProvider:preseed-data property to feed any information already
+ * collected that can be useful when creating a new account.
+ *
+ * If the @preseed_data #GVariant is floating, it is consumed to allow
+ * 'inline' use of the g_variant_new() family of functions.
+ */
+void
+goa_provider_set_preseed_data (GoaProvider *provider,
+ GVariant *preseed_data)
+{
+ g_clear_pointer (&provider->priv->preseed_data, g_variant_unref);
+ provider->priv->preseed_data = g_variant_ref_sink (preseed_data);
+ g_object_notify (G_OBJECT (provider), "preseed-data");
+}
+
+/**
+ * goa_provider_get_preseed_data:
+ * @provider: The #GoaProvider
+ *
+ * Gets the #GVariant set through the #GoaProvider:preseed-data property.
+ *
+ * Returns: (transfer none): A #GVariant that is known to be valid until
+ * the property is overridden or the provider freed.
+ */
+GVariant *
+goa_provider_get_preseed_data (GoaProvider *provider)
+{
+ return provider->priv->preseed_data;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+/**
* SECTION:goautil
* @title: Utilities
* @short_description: Various utility routines
diff --git a/src/goabackend/goaprovider.h b/src/goabackend/goaprovider.h
index 15a4b94..a960a78 100644
--- a/src/goabackend/goaprovider.h
+++ b/src/goabackend/goaprovider.h
@@ -128,6 +128,9 @@ gchar *goa_provider_get_provider_name (GoaProvider *provid
GIcon *goa_provider_get_provider_icon (GoaProvider *provider,
GoaObject *object);
GoaProviderGroup goa_provider_get_provider_group (GoaProvider *provider);
+void goa_provider_set_preseed_data (GoaProvider *provider,
+ GVariant *preseed_data);
+GVariant *goa_provider_get_preseed_data (GoaProvider *provider);
GoaObject *goa_provider_add_account (GoaProvider *provider,
GoaClient *client,
GtkDialog *dialog,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]