[gnome-online-accounts] New GoaWebView widget based on Epiphany's
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts] New GoaWebView widget based on Epiphany's
- Date: Thu, 5 Apr 2012 14:45:03 +0000 (UTC)
commit fb6d5fbe6a9e3304ef88ec182dd85e1fc966ca89
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Apr 5 16:32:56 2012 +0200
New GoaWebView widget based on Epiphany's
Fixes: https://bugzilla.gnome.org/672510
data/Makefile.am | 4 +
data/gnome-online-accounts.css | 28 +++++
src/goabackend/Makefile.am | 1 +
src/goabackend/goaoauth2provider.c | 45 ++------
src/goabackend/goaoauthprovider.c | 46 ++-------
src/goabackend/goaprovider.c | 10 ++
src/goabackend/goaprovider.h | 2 +
src/goabackend/goawebview.c | 194 ++++++++++++++++++++++++++++++++++++
src/goabackend/goawebview.h | 58 +++++++++++
9 files changed, 319 insertions(+), 69 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 1254c9a..25d0c56 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -3,6 +3,9 @@ NULL =
SUBDIRS = icons
+cssdir = $(pkgdatadir)
+css_DATA = gnome-online-accounts.css
+
servicedir = $(datadir)/dbus-1/services
service_in_files = org.gnome.OnlineAccounts.service.in
service_DATA = $(service_in_files:.service.in=.service)
@@ -11,6 +14,7 @@ $(service_DATA): $(service_in_files) Makefile
@sed -e "s|\ libexecdir\@|$(libexecdir)|" $< > $@
EXTRA_DIST = \
+ $(CSS_DATA) \
$(service_in_files) \
dbus-interfaces.xml \
$(NULL)
diff --git a/data/gnome-online-accounts.css b/data/gnome-online-accounts.css
new file mode 100644
index 0000000..b9db250
--- /dev/null
+++ b/data/gnome-online-accounts.css
@@ -0,0 +1,28 @@
+#goa-progress-bar {
+ -GtkProgressBar-xspacing: 0;
+ -GtkProgressBar-yspacing: 3px;
+ -GtkProgressBar-min-horizontal-bar-height: 3px;
+ padding: 0;
+}
+
+.progressbar#goa-progress-bar {
+ border-style: none;
+ background-color: @theme_selected_bg_color;
+ background-image: none;
+ border-radius: 0;
+ -adwaita-progressbar-pattern: none;
+}
+
+GtkProgressBar#goa-progress-bar.trough {
+ padding: 0;
+ border-image: none;
+ border-style: none;
+ border-width: 0;
+ background-image: none;
+ background-color: transparent;
+ border-radius: 0;
+}
+
+#goa-overlay {
+ background-color: rgba(0,0,0,0);
+}
diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am
index 2a5fc57..82c9e0b 100644
--- a/src/goabackend/Makefile.am
+++ b/src/goabackend/Makefile.am
@@ -76,6 +76,7 @@ libgoa_backend_1_0_la_SOURCES = \
goayahooprovider.h goayahooprovider.c \
goatwitterprovider.h goatwitterprovider.c \
goawindowsliveprovider.h goawindowsliveprovider.c \
+ goawebview.h goawebview.c \
$(NULL)
libgoa_backend_1_0_la_CPPFLAGS = \
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 468989c..9640e3b 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -27,12 +27,12 @@
#include <rest/oauth2-proxy.h>
#include <libsoup/soup.h>
-#include <libsoup/soup-gnome.h>
#include <webkit/webkit.h>
#include <json-glib/json-glib.h>
#include "goalogging.h"
#include "goaprovider.h"
+#include "goawebview.h"
#include "goaoauth2provider.h"
/**
@@ -818,47 +818,24 @@ get_tokens_and_identity (GoaOAuth2Provider *provider,
}
else
{
- GtkWidget *scrolled_window;
GtkWidget *web_view;
- SoupSession *webkit_soup_session;
- SoupCookieJar *cookie_jar;
+ GtkWidget *embed;
- webkit_soup_session = webkit_get_default_session ();
- /* Get the proxy configuration from the GNOME settings */
- soup_session_add_feature_by_type (webkit_soup_session, SOUP_TYPE_PROXY_RESOLVER_GNOME);
+ web_view = goa_web_view_new ();
+ embed = goa_web_view_get_view (GOA_WEB_VIEW (web_view));
- /* Ensure we use an empty non-persistent cookie to avoid login
- * credentials being reused...
- */
- soup_session_remove_feature_by_type (webkit_soup_session, SOUP_TYPE_COOKIE_JAR);
- cookie_jar = soup_cookie_jar_new ();
- soup_session_add_feature (webkit_soup_session, SOUP_SESSION_FEATURE (cookie_jar));
- g_object_unref (cookie_jar);
-
- /* TODO: we might need to add some more web browser UI to make this
- * work...
- */
- web_view = webkit_web_view_new ();
- webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), url);
- g_signal_connect (web_view,
+ webkit_web_view_load_uri (WEBKIT_WEB_VIEW (embed), url);
+ g_signal_connect (embed,
"document-load-finished",
G_CALLBACK (on_web_view_document_load_finished),
&data);
- g_signal_connect (web_view,
+ g_signal_connect (embed,
"navigation-policy-decision-requested",
G_CALLBACK (on_web_view_navigation_policy_decision_requested),
&data);
- scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_widget_set_size_request (scrolled_window, 500, 400);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_SHADOW_IN);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_container_add (GTK_CONTAINER (scrolled_window), web_view);
- gtk_container_add (GTK_CONTAINER (vbox), scrolled_window);
- gtk_widget_show_all (scrolled_window);
+ gtk_container_add (GTK_CONTAINER (vbox), web_view);
+ gtk_widget_show_all (web_view);
}
gtk_dialog_run (GTK_DIALOG (dialog));
diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
index b82f162..fac8623 100644
--- a/src/goabackend/goaoauthprovider.c
+++ b/src/goabackend/goaoauthprovider.c
@@ -26,12 +26,12 @@
#include <rest/oauth-proxy.h>
#include <libsoup/soup.h>
-#include <libsoup/soup-gnome.h>
#include <webkit/webkit.h>
#include <json-glib/json-glib.h>
#include "goalogging.h"
#include "goaprovider.h"
+#include "goawebview.h"
#include "goaoauthprovider.h"
/**
@@ -786,48 +786,24 @@ get_tokens_and_identity (GoaOAuthProvider *provider,
}
else
{
- GtkWidget *scrolled_window;
GtkWidget *web_view;
- SoupSession *webkit_soup_session;
- SoupCookieJar *cookie_jar;
-
- webkit_soup_session = webkit_get_default_session ();
- /* Get the proxy configuration from the GNOME settings */
- soup_session_add_feature_by_type (webkit_soup_session, SOUP_TYPE_PROXY_RESOLVER_GNOME);
-
- /* Ensure we use an empty non-persistent cookie to avoid login
- * credentials being reused...
- */
- soup_session_remove_feature_by_type (webkit_soup_session, SOUP_TYPE_COOKIE_JAR);
- cookie_jar = soup_cookie_jar_new ();
- soup_session_add_feature (webkit_soup_session, SOUP_SESSION_FEATURE (cookie_jar));
- g_object_unref (cookie_jar);
-
- /* TODO: we might need to add some more web browser UI to make this
- * work...
- */
- web_view = webkit_web_view_new ();
- webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), url);
- g_signal_connect (web_view,
+ GtkWidget *embed;
+
+ web_view = goa_web_view_new ();
+ embed = goa_web_view_get_view (GOA_WEB_VIEW (web_view));
+
+ webkit_web_view_load_uri (WEBKIT_WEB_VIEW (embed), url);
+ g_signal_connect (embed,
"document-load-finished",
G_CALLBACK (on_web_view_document_load_finished),
&data);
- g_signal_connect (web_view,
+ g_signal_connect (embed,
"navigation-policy-decision-requested",
G_CALLBACK (on_web_view_navigation_policy_decision_requested),
&data);
- scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_widget_set_size_request (scrolled_window, 500, 400);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_SHADOW_IN);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_container_add (GTK_CONTAINER (scrolled_window), web_view);
- gtk_container_add (GTK_CONTAINER (vbox), scrolled_window);
-
- gtk_widget_show_all (scrolled_window);
+ gtk_container_add (GTK_CONTAINER (vbox), web_view);
+ gtk_widget_show_all (web_view);
}
gtk_dialog_run (GTK_DIALOG (dialog));
if (data.oauth_verifier == NULL)
diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c
index 8cba458..294689d 100644
--- a/src/goabackend/goaprovider.c
+++ b/src/goabackend/goaprovider.c
@@ -936,6 +936,16 @@ goa_provider_delete_credentials_sync (GoaProvider *provider,
* Various utility routines.
*/
+/* ---------------------------------------------------------------------------------------------------- */
+
+gchar *
+goa_util_get_css (void)
+{
+ return g_strdup (PACKAGE_DATA_DIR "/" PACKAGE "/" PACKAGE ".css");
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
/**
* goa_util_add_row_widget:
* @table: A #GtkTable.
diff --git a/src/goabackend/goaprovider.h b/src/goabackend/goaprovider.h
index d1d65b8..64e8603 100644
--- a/src/goabackend/goaprovider.h
+++ b/src/goabackend/goaprovider.h
@@ -193,6 +193,8 @@ GtkWidget *goa_util_add_row_label (GtkTable *table,
const gchar *label_text,
const gchar *value_markup);
+gchar *goa_util_get_css (void);
+
gchar *
goa_util_lookup_keyfile_string (GoaObject *object,
const gchar *key);
diff --git a/src/goabackend/goawebview.c b/src/goabackend/goawebview.c
new file mode 100644
index 0000000..db053ff
--- /dev/null
+++ b/src/goabackend/goawebview.c
@@ -0,0 +1,194 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Debarshi Ray <debarshir gnome org>
+ */
+
+/* Based on code by the Epiphany team.
+ */
+
+#include "config.h"
+
+#include <libsoup/soup.h>
+#include <libsoup/soup-gnome.h>
+#include <webkit/webkit.h>
+
+#include "goawebview.h"
+
+struct _GoaWebViewPrivate
+{
+ GtkWidget *progress_bar;
+ GtkWidget *web_view;
+ gboolean status;
+ gulong clear_notify_progress_id;
+ gulong notify_progress_id;
+};
+
+#define GOA_WEB_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOA_TYPE_WEB_VIEW, GoaWebViewPrivate))
+
+G_DEFINE_TYPE (GoaWebView, goa_web_view, GTK_TYPE_OVERLAY)
+
+static gboolean
+web_view_clear_notify_progress_cb (gpointer user_data)
+{
+ GoaWebView *self = GOA_WEB_VIEW (user_data);
+ GoaWebViewPrivate *priv = self->priv;
+
+ gtk_widget_hide (priv->progress_bar);
+ priv->clear_notify_progress_id = 0;
+ return FALSE;
+}
+
+static gboolean
+web_view_is_loading (GoaWebView *self)
+{
+ GoaWebViewPrivate *priv = self->priv;
+ WebKitLoadStatus status;
+
+ status = webkit_web_view_get_load_status (WEBKIT_WEB_VIEW (priv->web_view));
+
+ if ((priv->status == WEBKIT_LOAD_FINISHED || priv->status == WEBKIT_LOAD_FAILED)
+ && status != WEBKIT_LOAD_PROVISIONAL)
+ return FALSE;
+
+ priv->status = status;
+ return status != WEBKIT_LOAD_FINISHED && status != WEBKIT_LOAD_FAILED;
+}
+
+static void
+web_view_notify_progress_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
+{
+ GoaWebView *self = GOA_WEB_VIEW (user_data);
+ GoaWebViewPrivate *priv = self->priv;
+ WebKitWebView *web_view = WEBKIT_WEB_VIEW (object);
+ gboolean loading;
+ const gchar *uri;
+ gdouble progress;
+
+ if (priv->clear_notify_progress_id != 0)
+ {
+ g_source_remove (priv->clear_notify_progress_id);
+ priv->clear_notify_progress_id = 0;
+ }
+
+ uri = webkit_web_view_get_uri (web_view);
+ if (!uri || g_str_equal (uri, "about:blank"))
+ return;
+
+ progress = webkit_web_view_get_progress (WEBKIT_WEB_VIEW (priv->web_view));
+ loading = web_view_is_loading (self);
+
+ if (progress == 1.0 || !loading)
+ priv->clear_notify_progress_id = g_timeout_add (500, web_view_clear_notify_progress_cb, self);
+ else
+ gtk_widget_show (priv->progress_bar);
+
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress_bar),
+ (loading || progress == 1.0) ? progress : 0.0);
+}
+
+static void
+goa_web_view_dispose (GObject *object)
+{
+ GoaWebView *self = GOA_WEB_VIEW (object);
+ GoaWebViewPrivate *priv = self->priv;
+
+ if (priv->clear_notify_progress_id != 0)
+ {
+ g_source_remove (priv->clear_notify_progress_id);
+ priv->clear_notify_progress_id = 0;
+ }
+
+ if (priv->notify_progress_id != 0)
+ {
+ g_signal_handler_disconnect (priv->web_view, priv->notify_progress_id);
+ priv->notify_progress_id = 0;
+ }
+
+ G_OBJECT_CLASS (goa_web_view_parent_class)->dispose (object);
+}
+
+static void
+goa_web_view_init (GoaWebView *self)
+{
+ GoaWebViewPrivate *priv;
+ GtkWidget *scrolled_window;
+ SoupCookieJar *cookie_jar;
+ SoupSession *session;
+
+ self->priv = GOA_WEB_VIEW_GET_PRIVATE (self);
+ priv = self->priv;
+
+ session = webkit_get_default_session ();
+
+ soup_session_add_feature_by_type (session, SOUP_TYPE_PROXY_RESOLVER_GNOME);
+
+ soup_session_remove_feature_by_type (session, SOUP_TYPE_COOKIE_JAR);
+ cookie_jar = soup_cookie_jar_new ();
+ soup_session_add_feature (session, SOUP_SESSION_FEATURE (cookie_jar));
+ g_object_unref (cookie_jar);
+
+ gtk_widget_set_name (GTK_WIDGET (self), "goa-overlay");
+
+ scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_set_size_request (scrolled_window, 500, 400);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_container_add (GTK_CONTAINER (self), scrolled_window);
+
+ priv->web_view = webkit_web_view_new ();
+ priv->status = WEBKIT_LOAD_PROVISIONAL;
+ gtk_container_add (GTK_CONTAINER (scrolled_window), priv->web_view);
+
+ priv->progress_bar = gtk_progress_bar_new ();
+ gtk_widget_set_name (priv->progress_bar, "goa-progress-bar");
+ gtk_widget_set_halign (priv->progress_bar, GTK_ALIGN_FILL);
+ gtk_widget_set_valign (priv->progress_bar, GTK_ALIGN_START);
+ gtk_overlay_add_overlay (GTK_OVERLAY (self), priv->progress_bar);
+
+ priv->notify_progress_id = g_signal_connect (priv->web_view,
+ "notify::progress",
+ G_CALLBACK (web_view_notify_progress_cb),
+ self);
+}
+
+static void
+goa_web_view_class_init (GoaWebViewClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->dispose = goa_web_view_dispose;
+
+ g_type_class_add_private (object_class, sizeof (GoaWebViewPrivate));
+}
+
+GtkWidget *
+goa_web_view_new (void)
+{
+ return g_object_new (GOA_TYPE_WEB_VIEW, NULL);
+}
+
+GtkWidget *
+goa_web_view_get_view (GoaWebView *self)
+{
+ return self->priv->web_view;
+}
diff --git a/src/goabackend/goawebview.h b/src/goabackend/goawebview.h
new file mode 100644
index 0000000..935de73
--- /dev/null
+++ b/src/goabackend/goawebview.h
@@ -0,0 +1,58 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Debarshi Ray <debarshir gnome org>
+ */
+
+#ifndef __GOA_WEB_VIEW_H__
+#define __GOA_WEB_VIEW_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GOA_TYPE_WEB_VIEW (goa_web_view_get_type ())
+#define GOA_WEB_VIEW(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GOA_TYPE_WEB_VIEW, GoaWebView))
+#define GOA_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOA_TYPE_WEB_VIEW, GoaWebViewClass))
+#define GOA_IS_WEB_VIEW(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GOA_TYPE_WEB_VIEW))
+#define GOA_IS_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOA_TYPE_WEB_VIEW))
+#define GOA_WEB_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOA_TYPE_WEB_VIEW, GoaWebViewClass))
+
+typedef struct _GoaWebView GoaWebView;
+typedef struct _GoaWebViewClass GoaWebViewClass;
+typedef struct _GoaWebViewPrivate GoaWebViewPrivate;
+
+struct _GoaWebView
+{
+ GtkOverlay parent_instance;
+ GoaWebViewPrivate *priv;
+};
+
+struct _GoaWebViewClass
+{
+ GtkOverlayClass parent_class;
+};
+
+GType goa_web_view_get_type (void) G_GNUC_CONST;
+GtkWidget *goa_web_view_new (void);
+GtkWidget *goa_web_view_get_view (GoaWebView *self);
+
+G_END_DECLS
+
+#endif /* __GOA_WEB_VIEW_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]