[gnome-online-accounts/wip/wk2: 4/4] Port to WebKit 2
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts/wip/wk2: 4/4] Port to WebKit 2
- Date: Fri, 27 Feb 2015 19:42:43 +0000 (UTC)
commit b2e4d06ce473bed1c3dc843cdeeceb29720b28fe
Author: Damián Nohales <damiannohales gmail com>
Date: Fri Jan 9 15:41:54 2015 -0300
Port to WebKit 2
https://bugzilla.gnome.org/show_bug.cgi?id=742680
configure.ac | 2 +-
data/Makefile.am | 4 -
data/goawebview.css | 3 -
src/goabackend/Makefile.am | 77 ++++++---
src/goabackend/goaoauth2provider.c | 68 ++++++--
src/goabackend/goaoauthprovider.c | 82 +++++++--
src/goabackend/goaoauthprovider.h | 4 +-
src/goabackend/goawebextension.c | 187 +++++++++++++++++++
src/goabackend/goawebextension.h | 45 +++++
src/goabackend/goawebextensionmain.c | 71 ++++++++
src/goabackend/goawebview.c | 329 ++++++++++++++++-----------------
src/goabackend/goawebview.h | 7 +-
12 files changed, 639 insertions(+), 240 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 807e253..cda6916 100644
--- a/configure.ac
+++ b/configure.ac
@@ -90,7 +90,7 @@ PKG_CHECK_MODULES(GTK, [gtk+-3.0 >= 3.11.1])
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
-PKG_CHECK_MODULES(WEBKIT_GTK, [webkitgtk-3.0 >= 2.1.90])
+PKG_CHECK_MODULES(WEBKIT_GTK, [webkit2gtk-4.0 >= 2.1.90])
AC_SUBST(WEBKIT_GTK_CFLAGS)
AC_SUBST(WEBKIT_GTK_LIBS)
diff --git a/data/Makefile.am b/data/Makefile.am
index cb30eb8..d5513ef 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -3,9 +3,6 @@ NULL =
SUBDIRS = icons
-cssdir = $(pkgdatadir)
-css_DATA = goawebview.css
-
gsettings_in_files = org.gnome.online-accounts.gschema.xml.in
gsettings_SCHEMAS = $(gsettings_in_files:.xml.in=.xml)
@@ -20,7 +17,6 @@ $(service_DATA): $(service_in_files) Makefile
@sed -e "s|\ libexecdir\@|$(libexecdir)|" $< > $@
EXTRA_DIST = \
- $(css_DATA) \
$(gsettings_in_files) \
$(service_in_files) \
dbus-interfaces.xml \
diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am
index 5ca8e5c..8c14774 100644
--- a/src/goabackend/Makefile.am
+++ b/src/goabackend/Makefile.am
@@ -19,6 +19,7 @@ AM_CPPFLAGS = \
-DPACKAGE_LOCALSTATE_DIR=\""$(localstatedir)"\" \
-DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
-DPACKAGE_LIB_DIR=\""$(libdir)"\" \
+ -DPACKAGE_WEB_EXTENSIONS_DIR=\""$(libdir)/goa-1.0/web-extensions"\" \
-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT \
$(WARN_CFLAGS) \
$(NULL)
@@ -99,29 +100,6 @@ libgoa_backend_1_0_la_SOURCES = \
$(top_builddir)/src/goaidentity/org.freedesktop.realmd.c \
$(NULL)
-BUILT_SOURCES = \
- $(libgoa_backend_1_0_la_built_sources) \
- $(NULL)
-
-EXTRA_DIST += \
- goadleynaservermanager.xml \
- goadleynaservermediadevice.xml \
- $(NULL)
-
-goadleynaservermanager.h goadleynaservermanager.c: goadleynaservermanager.xml
- $(AM_V_GEN)gdbus-codegen \
- --c-namespace DleynaServer \
- --generate-c-code goadleynaservermanager \
- --interface-prefix com.intel.dLeynaServer. \
- $<
-
-goadleynaservermediadevice.h goadleynaservermediadevice.c: goadleynaservermediadevice.xml
- $(AM_V_GEN)gdbus-codegen \
- --c-namespace DleynaServer \
- --generate-c-code goadleynaservermediadevice \
- --interface-prefix com.intel.dLeynaServer. \
- $<
-
if BUILD_KERBEROS
libgoa_backend_1_0_la_SOURCES += \
goakerberosprovider.h goakerberosprovider.c
@@ -162,6 +140,59 @@ libgoa_backend_1_0_la_LDFLAGS = \
# ----------------------------------------------------------------------------------------------------
+webextension_LTLIBRARIES = libgoawebextension.la
+
+webextensiondir = $(libdir)/goa-1.0/web-extensions
+
+libgoawebextension_la_SOURCES = \
+ goawebextension.h goawebextension.c \
+ goawebextensionmain.c \
+ $(NULL)
+
+libgoawebextension_la_CFLAGS = \
+ $(REST_CFLAGS) \
+ $(WEBKIT_GTK_CFLAGS) \
+ $(NULL)
+
+libgoawebextension_la_LIBADD = \
+ libgoa-backend-1.0.la \
+ $(REST_LIBS) \
+ $(WEBKIT_GTK_LIBS) \
+ $(NULL)
+
+libgoawebextension_la_LDFLAGS = \
+ -avoid-version \
+ -module \
+ -no-undefined \
+ $(NULL)
+
+# ----------------------------------------------------------------------------------------------------
+
+BUILT_SOURCES = \
+ $(libgoa_backend_1_0_la_built_sources) \
+ $(NULL)
+
+EXTRA_DIST += \
+ goadleynaservermanager.xml \
+ goadleynaservermediadevice.xml \
+ $(NULL)
+
+goadleynaservermanager.h goadleynaservermanager.c: goadleynaservermanager.xml
+ $(AM_V_GEN)gdbus-codegen \
+ --c-namespace DleynaServer \
+ --generate-c-code goadleynaservermanager \
+ --interface-prefix com.intel.dLeynaServer. \
+ $<
+
+goadleynaservermediadevice.h goadleynaservermediadevice.c: goadleynaservermediadevice.xml
+ $(AM_V_GEN)gdbus-codegen \
+ --c-namespace DleynaServer \
+ --generate-c-code goadleynaservermediadevice \
+ --interface-prefix com.intel.dLeynaServer. \
+ $<
+
+# ----------------------------------------------------------------------------------------------------
+
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = goa-backend-1.0.pc
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 560b0ed..34e5b80 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -23,7 +23,7 @@
#include <rest/oauth2-proxy.h>
#include <libsoup/soup.h>
#include <json-glib/json-glib.h>
-#include <webkit/webkit.h>
+#include <webkit2/webkit2.h>
#include "goaprovider.h"
#include "goautils.h"
@@ -78,6 +78,8 @@ struct _GoaOAuth2ProviderPrivate
gchar *identity;
gchar *presentation_identity;
gchar *password;
+
+ gboolean load_failed;
};
#define GOA_OAUTH2_PROVIDER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOA_TYPE_OAUTH2_PROVIDER,
GoaOAuth2ProviderPrivate))
@@ -794,16 +796,33 @@ on_form_submit (WebKitDOMNode *element, WebKitDOMEvent *event, gpointer user_dat
priv->password_node = NULL;
}
+static gboolean
+on_web_view_load_failed (WebKitWebView *web_view,
+ WebKitLoadEvent load_event,
+ gchar *failing_uri,
+ gpointer error,
+ gpointer user_data)
+{
+ GoaOAuth2Provider *provider = user_data;
+ provider->priv->load_failed = TRUE;
+}
+
static void
-on_web_view_document_load_finished (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data)
+on_web_view_load_chaged (WebKitWebView *web_view, WebKitLoadEvent *load_event, gpointer user_data)
{
GoaOAuth2Provider *provider = GOA_OAUTH2_PROVIDER (user_data);
GoaOAuth2ProviderPrivate *priv = provider->priv;
+
+ if (load_event != WEBKIT_LOAD_FINISHED || priv->load_failed)
+ return;
+
+#if 0 /* TODO: DOM Parsing */
WebKitDOMDocument *document;
WebKitDOMNodeList *elements;
gulong element_count;
gulong i;
+ // Find a way to replace webkit_web_view_get_dom_document
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (web_view));
elements = webkit_dom_document_get_elements_by_tag_name (document, "*");
element_count = webkit_dom_node_list_get_length (elements);
@@ -846,20 +865,21 @@ on_web_view_document_load_finished (WebKitWebView *web_view, WebKitWebFrame *fra
}
}
}
+#endif
}
static gboolean
-on_web_view_navigation_policy_decision_requested (WebKitWebView *webView,
- WebKitWebFrame *frame,
- WebKitNetworkRequest *request,
- WebKitWebNavigationAction *navigation_action,
- WebKitWebPolicyDecision *policy_decision,
- gpointer user_data)
+on_web_view_decide_policy (WebKitWebView *web_view,
+ WebKitPolicyDecision *decision,
+ WebKitPolicyDecisionType decision_type,
+ gpointer user_data)
{
GoaOAuth2Provider *provider = GOA_OAUTH2_PROVIDER (user_data);
GoaOAuth2ProviderPrivate *priv = provider->priv;
GHashTable *key_value_pairs;
- SoupMessage *message;
+ WebKitNavigationPolicyDecision *navigation_decision;
+ WebKitNavigationAction *action;
+ WebKitURIRequest *request;
SoupURI *uri;
const gchar *fragment;
const gchar *oauth2_error;
@@ -868,15 +888,20 @@ on_web_view_navigation_policy_decision_requested (WebKitWebView *web
const gchar *requested_uri;
gint response_id = GTK_RESPONSE_NONE;
+ if (decision_type != WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION)
+ goto default_behaviour;
+
/* TODO: use oauth2_proxy_extract_access_token() */
- requested_uri = webkit_network_request_get_uri (request);
+ navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision);
+ action = webkit_navigation_policy_decision_get_navigation_action (navigation_decision);
+ request = webkit_navigation_action_get_request (action);
+ requested_uri = webkit_uri_request_get_uri (request);
redirect_uri = goa_oauth2_provider_get_redirect_uri (provider);
if (!g_str_has_prefix (requested_uri, redirect_uri))
goto default_behaviour;
- message = webkit_network_request_get_message (request);
- uri = soup_message_get_uri (message);
+ uri = soup_uri_new (requested_uri);
fragment = soup_uri_get_fragment (uri);
query = soup_uri_get_query (uri);
@@ -974,7 +999,7 @@ on_web_view_navigation_policy_decision_requested (WebKitWebView *web
ignore_request:
g_assert (response_id != GTK_RESPONSE_NONE);
gtk_dialog_response (priv->dialog, response_id);
- webkit_web_policy_decision_ignore (policy_decision);
+ webkit_policy_decision_ignore (decision);
return TRUE;
default_behaviour:
@@ -1048,7 +1073,7 @@ get_tokens_and_identity (GoaOAuth2Provider *provider,
gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
gtk_container_add (GTK_CONTAINER (vbox), grid);
- web_view = goa_web_view_new ();
+ web_view = goa_web_view_new (GOA_PROVIDER (provider), existing_identity);
gtk_widget_set_hexpand (web_view, TRUE);
gtk_widget_set_vexpand (web_view, TRUE);
embed = goa_web_view_get_view (GOA_WEB_VIEW (web_view));
@@ -1062,10 +1087,18 @@ get_tokens_and_identity (GoaOAuth2Provider *provider,
goa_web_view_fake_mobile (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),
provider);
+ provider->priv->load_failed = FALSE;
+ g_signal_connect (embed,
+ "load-failed",
+ G_CALLBACK (on_web_view_load_failed),
+ provider);
+ g_signal_connect (embed,
+ "load-changed",
+ G_CALLBACK (on_web_view_load_chaged),
+ provider);
g_signal_connect (embed,
- "navigation-policy-decision-requested",
- G_CALLBACK (on_web_view_navigation_policy_decision_requested),
+ "decide-policy",
+ G_CALLBACK (on_web_view_decide_policy),
provider);
gtk_container_add (GTK_CONTAINER (grid), web_view);
@@ -1738,6 +1771,7 @@ static void
goa_oauth2_provider_init (GoaOAuth2Provider *provider)
{
provider->priv = GOA_OAUTH2_PROVIDER_GET_PRIVATE (provider);
+ provider->priv->load_failed = FALSE;
}
static void
diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
index 1928036..e26646f 100644
--- a/src/goabackend/goaoauthprovider.c
+++ b/src/goabackend/goaoauthprovider.c
@@ -23,7 +23,7 @@
#include <rest/oauth-proxy.h>
#include <libsoup/soup.h>
#include <json-glib/json-glib.h>
-#include <webkit/webkit.h>
+#include <webkit2/webkit2.h>
#include "goaprovider.h"
#include "goautils.h"
@@ -64,6 +64,13 @@
* need to be implemented - this type implements these methods.
*/
+struct _GoaOAuthProviderPrivate
+{
+ gboolean load_failed;
+};
+
+#define GOA_OAUTH_PROVIDER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOA_TYPE_OAUTH_PROVIDER,
GoaOAuthProviderPrivate))
+
G_LOCK_DEFINE_STATIC (provider_lock);
G_DEFINE_ABSTRACT_TYPE (GoaOAuthProvider, goa_oauth_provider, GOA_TYPE_PROVIDER);
@@ -657,16 +664,33 @@ on_form_submit (WebKitDOMNode *element, WebKitDOMEvent *event, gpointer user_dat
data->password_node = NULL;
}
+static gboolean
+on_web_view_load_failed (WebKitWebView *web_view,
+ WebKitLoadEvent load_event,
+ gchar *failing_uri,
+ gpointer error,
+ gpointer user_data)
+{
+ IdentifyData *data = user_data;
+ data->provider->priv->load_failed = TRUE;
+}
+
static void
-on_web_view_document_load_finished (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data)
+on_web_view_load_chaged (WebKitWebView *web_view, WebKitLoadEvent *load_event, gpointer user_data)
{
IdentifyData *data = user_data;
GoaOAuthProvider *provider = data->provider;
+
+ if (load_event != WEBKIT_LOAD_FINISHED || provider->priv->load_failed)
+ return;
+
+#if 0 /* TODO: DOM Parsing */
WebKitDOMDocument *document;
WebKitDOMNodeList *elements;
gulong element_count;
gulong i;
+ // Find a way to replace webkit_web_view_get_dom_document
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (web_view));
elements = webkit_dom_document_get_elements_by_tag_name (document, "*");
element_count = webkit_dom_node_list_get_length (elements);
@@ -709,32 +733,38 @@ on_web_view_document_load_finished (WebKitWebView *web_view, WebKitWebFrame *fra
}
}
}
+#endif
}
static gboolean
-on_web_view_navigation_policy_decision_requested (WebKitWebView *webView,
- WebKitWebFrame *frame,
- WebKitNetworkRequest *request,
- WebKitWebNavigationAction *navigation_action,
- WebKitWebPolicyDecision *policy_decision,
- gpointer user_data)
+on_web_view_decide_policy (WebKitWebView *web_view,
+ WebKitPolicyDecision *decision,
+ WebKitPolicyDecisionType decision_type,
+ gpointer user_data)
{
IdentifyData *data = user_data;
+ WebKitNavigationPolicyDecision *navigation_decision;
+ WebKitNavigationAction *action;
+ WebKitURIRequest *request;
const gchar *redirect_uri;
const gchar *requested_uri;
+ if (decision_type != WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION)
+ return FALSE;
+
/* TODO: use oauth_proxy_extract_access_token() */
- requested_uri = webkit_network_request_get_uri (request);
+ navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision);
+ action = webkit_navigation_policy_decision_get_navigation_action (navigation_decision);
+ request = webkit_navigation_action_get_request (action);
+ requested_uri = webkit_uri_request_get_uri (request);
redirect_uri = goa_oauth_provider_get_callback_uri (data->provider);
if (g_str_has_prefix (requested_uri, redirect_uri))
{
- SoupMessage *message;
SoupURI *uri;
GHashTable *key_value_pairs;
- message = webkit_network_request_get_message (request);
- uri = soup_message_get_uri (message);
+ uri = soup_uri_new (requested_uri);
key_value_pairs = soup_form_decode (uri->query);
/* TODO: error handling? */
@@ -744,12 +774,15 @@ on_web_view_navigation_policy_decision_requested (WebKitWebView *web
gtk_dialog_response (data->dialog, GTK_RESPONSE_OK);
}
g_hash_table_unref (key_value_pairs);
- webkit_web_policy_decision_ignore (policy_decision);
- return TRUE; /* ignore the request */
+
+ /* ignore the request */
+ webkit_policy_decision_ignore (decision);
+ return TRUE;
}
else
{
- return FALSE; /* make default behavior apply */
+ /* make default behavior apply */
+ return FALSE;
}
}
@@ -887,7 +920,7 @@ get_tokens_and_identity (GoaOAuthProvider *provider,
goa_oauth_provider_get_authorization_uri
(provider),
escaped_request_token);
- web_view = goa_web_view_new ();
+ web_view = goa_web_view_new (GOA_PROVIDER (provider), existing_identity);
gtk_widget_set_hexpand (web_view, TRUE);
gtk_widget_set_vexpand (web_view, TRUE);
embed = goa_web_view_get_view (GOA_WEB_VIEW (web_view));
@@ -896,10 +929,18 @@ get_tokens_and_identity (GoaOAuthProvider *provider,
goa_web_view_fake_mobile (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);
+ provider->priv->load_failed = FALSE;
+ g_signal_connect (embed,
+ "load-failed",
+ G_CALLBACK (on_web_view_load_failed),
+ &data);
+ g_signal_connect (embed,
+ "load-changed",
+ G_CALLBACK (on_web_view_load_chaged),
+ &data);
g_signal_connect (embed,
- "navigation-policy-decision-requested",
- G_CALLBACK (on_web_view_navigation_policy_decision_requested),
+ "decide-policy",
+ G_CALLBACK (on_web_view_decide_policy),
&data);
gtk_container_add (GTK_CONTAINER (grid), web_view);
@@ -1678,8 +1719,9 @@ goa_oauth_provider_ensure_credentials_sync (GoaProvider *_provider,
/* ---------------------------------------------------------------------------------------------------- */
static void
-goa_oauth_provider_init (GoaOAuthProvider *client)
+goa_oauth_provider_init (GoaOAuthProvider *provider)
{
+ provider->priv = GOA_OAUTH_PROVIDER_GET_PRIVATE (provider);
}
static void
diff --git a/src/goabackend/goaoauthprovider.h b/src/goabackend/goaoauthprovider.h
index a0764fc..4acb90f 100644
--- a/src/goabackend/goaoauthprovider.h
+++ b/src/goabackend/goaoauthprovider.h
@@ -120,8 +120,10 @@ struct _GoaOAuthProviderClass
WebKitDOMHTMLInputElement *element);
/*< private >*/
+ GoaOAuthProviderPrivate *priv;
+
/* Padding for future expansion */
- gpointer goa_reserved[29];
+ gpointer goa_reserved[28];
};
GType goa_oauth_provider_get_type (void) G_GNUC_CONST;
diff --git a/src/goabackend/goawebextension.c b/src/goabackend/goawebextension.c
new file mode 100644
index 0000000..529cab5
--- /dev/null
+++ b/src/goabackend/goawebextension.c
@@ -0,0 +1,187 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2015 Damián Nohales
+ * Copyright (C) 2015 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "goaoauthprovider.h"
+#include "goaoauth2provider.h"
+#include "goaprovider.h"
+#include "goawebextension.h"
+
+struct _GoaWebExtension
+{
+ GObject parent;
+ GoaProvider *provider;
+ WebKitWebExtension *wk_extension;
+ gchar *existing_identity;
+ gchar *provider_type;
+};
+
+struct _GoaWebExtensionClass
+{
+ GObjectClass parent;
+};
+
+enum
+{
+ PROP_0,
+ PROP_EXISTING_IDENTITY,
+ PROP_PROVIDER_TYPE,
+ PROP_WK_EXTENSION
+};
+
+G_DEFINE_TYPE (GoaWebExtension, goa_web_extension, G_TYPE_OBJECT)
+
+static void
+web_extension_page_created_cb (GoaWebExtension *self, WebKitWebPage *web_page)
+{
+ WebKitDOMDocument *document;
+ WebKitDOMNodeList *elements;
+ gulong element_count;
+ gulong i;
+
+ g_message ("web_extension_page_created_cb");
+
+ document = webkit_web_page_get_dom_document (web_page);
+ elements = webkit_dom_document_get_elements_by_tag_name (document, "*");
+ element_count = webkit_dom_node_list_get_length (elements);
+
+ for (i = 0; i < element_count; i++)
+ {
+ WebKitDOMNode *element = webkit_dom_node_list_item (elements, i);
+
+ if (self->existing_identity != NULL
+ && self->existing_identity[0] != '\0'
+ && WEBKIT_DOM_IS_HTML_INPUT_ELEMENT (element))
+ {
+ if ((GOA_IS_OAUTH_PROVIDER (self->provider)
+ && goa_oauth_provider_is_identity_node (GOA_OAUTH_PROVIDER (self->provider),
+ WEBKIT_DOM_HTML_INPUT_ELEMENT (element)))
+ || (GOA_IS_OAUTH2_PROVIDER (self->provider)
+ && goa_oauth_provider_is_identity_node (GOA_OAUTH_PROVIDER (self->provider),
+ WEBKIT_DOM_HTML_INPUT_ELEMENT (element))))
+ {
+ webkit_dom_html_input_element_set_value (WEBKIT_DOM_HTML_INPUT_ELEMENT (element),
+ self->existing_identity);
+ webkit_dom_html_input_element_set_read_only (WEBKIT_DOM_HTML_INPUT_ELEMENT (element), TRUE);
+ }
+ }
+ }
+}
+
+static void
+goa_web_extension_constructed (GObject *object)
+{
+ GoaWebExtension *self = GOA_WEB_EXTENSION (object);
+
+ G_OBJECT_CLASS (goa_web_extension_parent_class)->constructed (object);
+
+ self->provider = goa_provider_get_for_provider_type (self->provider_type);
+
+ g_signal_connect_object (self->wk_extension,
+ "page-created",
+ G_CALLBACK (web_extension_page_created_cb),
+ self,
+ G_CONNECT_SWAPPED);
+}
+
+static void
+goa_web_extension_dispose (GObject *object)
+{
+ GoaWebExtension *self = GOA_WEB_EXTENSION (object);
+
+ g_clear_object (&self->provider);
+ g_clear_object (&self->wk_extension);
+
+ G_OBJECT_CLASS (goa_web_extension_parent_class)->dispose (object);
+}
+
+static void
+goa_web_extension_finalize (GObject *object)
+{
+ GoaWebExtension *self = GOA_WEB_EXTENSION (object);
+
+ g_free (self->existing_identity);
+ g_free (self->provider_type);
+
+ G_OBJECT_CLASS (goa_web_extension_parent_class)->finalize (object);
+}
+
+static void
+goa_web_extension_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ GoaWebExtension *self = GOA_WEB_EXTENSION (object);
+
+ switch (prop_id)
+ {
+ case PROP_EXISTING_IDENTITY:
+ self->existing_identity = g_value_dup_string (value);
+ break;
+
+ case PROP_PROVIDER_TYPE:
+ self->provider_type = g_value_dup_string (value);
+ break;
+
+ case PROP_WK_EXTENSION:
+ self->wk_extension = WEBKIT_WEB_EXTENSION (g_value_dup_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+goa_web_extension_class_init (GoaWebExtensionClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructed = goa_web_extension_constructed;
+ object_class->dispose = goa_web_extension_dispose;
+ object_class->finalize = goa_web_extension_finalize;
+ object_class->set_property = goa_web_extension_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_WK_EXTENSION,
+ g_param_spec_object ("wk-extension",
+ "A WebKitWebExtension",
+ "The associated WebKitWebExtension",
+ WEBKIT_TYPE_WEB_EXTENSION,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+goa_web_extension_init (GoaWebExtension *self)
+{
+}
+
+GoaWebExtension *
+goa_web_extension_new (WebKitWebExtension *wk_extension,
+ const gchar *provider_type,
+ const gchar *existing_identity)
+{
+ return g_object_new (GOA_TYPE_WEB_EXTENSION,
+ "existing-identity", existing_identity,
+ "provider-type", provider_type,
+ "wk-extension", wk_extension,
+ NULL);
+}
diff --git a/src/goabackend/goawebextension.h b/src/goabackend/goawebextension.h
new file mode 100644
index 0000000..029cb21
--- /dev/null
+++ b/src/goabackend/goawebextension.h
@@ -0,0 +1,45 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2015 Damián Nohales
+ * Copyright (C) 2015 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GOA_WEB_EXTENSION_H__
+#define __GOA_WEB_EXTENSION_H__
+
+#include <glib-object.h>
+#include <webkit2/webkit-web-extension.h>
+
+G_BEGIN_DECLS
+
+#define GOA_TYPE_WEB_EXTENSION (goa_web_extension_get_type())
+#define GOA_WEB_EXTENSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOA_TYPE_WEB_EXTENSION,
GoaWebExtension))
+#define GOA_WEB_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOA_TYPE_WEB_EXTENSION,
GoaWebExtensionClass))
+#define GOA_IS_WEB_EXTENSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOA_TYPE_WEB_EXTENSION))
+#define GOA_IS_WEB_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOA_TYPE_WEB_EXTENSION))
+#define GOA_WEB_EXTENSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOA_TYPE_WEB_EXTENSION,
GoaWebExtensionClass))
+
+typedef struct _GoaWebExtension GoaWebExtension;
+typedef struct _GoaWebExtensionClass GoaWebExtensionClass;
+
+GType goa_web_extension_get_type (void);
+GoaWebExtension *goa_web_extension_new (WebKitWebExtension *wk_extension,
+ const gchar *provider_type,
+ const gchar *existing_identity);
+
+G_END_DECLS
+
+#endif /* __GOA_WEB_EXTENSION_H__ */
diff --git a/src/goabackend/goawebextensionmain.c b/src/goabackend/goawebextensionmain.c
new file mode 100644
index 0000000..6d7b546
--- /dev/null
+++ b/src/goabackend/goawebextensionmain.c
@@ -0,0 +1,71 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2015 Damián Nohales
+ * Copyright (C) 2015 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+
+#include <gmodule.h>
+#include <glib/gprintf.h>
+#include <webkit2/webkit-web-extension.h>
+
+#include "goawebextension.h"
+
+static GoaWebExtension *the_extension;
+
+/* Silence -Wmissing-prototypes */
+void webkit_web_extension_initialize_with_user_data (WebKitWebExtension *wk_extension, GVariant *user_data);
+
+static void
+on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+}
+
+static void
+on_name_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+}
+
+G_MODULE_EXPORT void
+webkit_web_extension_initialize_with_user_data (WebKitWebExtension *wk_extension, GVariant *user_data)
+{
+ const gchar *existing_identity;
+ const gchar *provider_type;
+
+ g_message ("webkit_web_extension_initialize_with_user_data");
+ g_printf ("webkit_web_extension_initialize_with_user_data\n");
+ fprintf (stderr, "webkit_web_extension_initialize_with_user_data\n");
+ g_variant_get (user_data, "(&s&s)", &provider_type, &existing_identity);
+
+ the_extension = goa_web_extension_new (wk_extension, provider_type, existing_identity);
+ g_bus_own_name (G_BUS_TYPE_SESSION,
+ "org.gnome.OnlineAccounts.WebExtension",
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ on_bus_acquired,
+ on_name_acquired,
+ NULL,
+ the_extension,
+ NULL);
+}
+
+static void __attribute__((destructor))
+goa_web_extension_shutdown (void)
+{
+ g_clear_object (&the_extension);
+}
diff --git a/src/goabackend/goawebview.c b/src/goabackend/goawebview.c
index 0c7c75c..96d9d60 100644
--- a/src/goabackend/goawebview.c
+++ b/src/goabackend/goawebview.c
@@ -1,6 +1,7 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
- * Copyright (C) 2012, 2013, 2014 Red Hat, Inc.
+ * Copyright (C) 2015 Damián Nohales
+ * Copyright (C) 2012, 2013, 2014, 2015 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
@@ -24,22 +25,32 @@
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <libsoup/soup.h>
-#include <webkit/webkit.h>
+#include <webkit2/webkit2.h>
#include "goawebview.h"
#include "nautilus-floating-bar.h"
struct _GoaWebViewPrivate
{
+ GoaProvider *provider;
GtkWidget *floating_bar;
GtkWidget *progress_bar;
GtkWidget *web_view;
- gboolean status;
+ SoupCookieJar *cookie_jar;
+ WebKitWebContext *context;
+ gchar *existing_identity;
gulong clear_notify_progress_id;
gulong notify_load_status_id;
gulong notify_progress_id;
};
+enum
+{
+ PROP_0,
+ PROP_EXISTING_IDENTITY,
+ PROP_PROVIDER
+};
+
#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)
@@ -89,58 +100,38 @@ web_view_floating_bar_update (GoaWebView *self, const gchar *text)
gtk_widget_show (priv->floating_bar);
}
-static gboolean
-web_view_is_loading (GoaWebView *self)
+static void
+web_view_initialize_web_extensions_cb (GoaWebView *self)
{
GoaWebViewPrivate *priv = self->priv;
- WebKitLoadStatus status;
+ GVariant *data;
+ const gchar *existing_identity;
+ const gchar *provider_type;
- status = webkit_web_view_get_load_status (WEBKIT_WEB_VIEW (priv->web_view));
+ webkit_web_context_set_web_extensions_directory (priv->context, PACKAGE_WEB_EXTENSIONS_DIR);
- 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;
+ provider_type = goa_provider_get_provider_type (priv->provider);
+ existing_identity = (priv->existing_identity == NULL) ? "" : priv->existing_identity;
+ data = g_variant_new ("(ss)", provider_type, existing_identity);
+ webkit_web_context_set_web_extensions_initialization_user_data (priv->context, data);
}
static void
-web_view_log_printer (SoupLogger *logger,
- SoupLoggerLogLevel level,
- gchar direction,
- const gchar *data,
- gpointer user_data)
-{
- gchar *message;
-
- message = g_strdup_printf ("%c %s", direction, data);
- g_log_default_handler ("goa", G_LOG_LEVEL_DEBUG, message, NULL);
- g_free (message);
-}
-
-static void
-web_view_notify_load_status_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
+web_view_load_changed_cb (WebKitWebView *web_view,
+ WebKitLoadEvent load_event,
+ gpointer user_data)
{
GoaWebView *self = GOA_WEB_VIEW (user_data);
- WebKitWebView *web_view = WEBKIT_WEB_VIEW (object);
- WebKitLoadStatus status;
- status = webkit_web_view_get_load_status (web_view);
- switch (status)
+ switch (load_event)
{
- case WEBKIT_LOAD_PROVISIONAL:
+ case WEBKIT_LOAD_STARTED:
+ case WEBKIT_LOAD_COMMITTED:
{
- WebKitNetworkRequest *request;
- WebKitWebDataSource *source;
- WebKitWebFrame *frame;
const gchar *uri;
gchar *title;
- frame = webkit_web_view_get_main_frame (web_view);
- source = webkit_web_frame_get_provisional_data_source (frame);
- request = webkit_web_data_source_get_initial_request (source);
- uri = webkit_network_request_get_uri (request);
+ uri = webkit_web_view_get_uri (web_view);
title = web_view_create_loading_title (uri);
web_view_floating_bar_update (self, title);
@@ -148,7 +139,10 @@ web_view_notify_load_status_cb (GObject *object, GParamSpec *pspec, gpointer use
break;
}
- case WEBKIT_LOAD_FAILED:
+ case WEBKIT_LOAD_REDIRECTED:
+ /* TODO: Update the loading uri */
+ break;
+
case WEBKIT_LOAD_FINISHED:
web_view_floating_bar_update (self, NULL);
break;
@@ -159,7 +153,9 @@ web_view_notify_load_status_cb (GObject *object, GParamSpec *pspec, gpointer use
}
static void
-web_view_notify_progress_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
+web_view_notify_estimated_load_progress_cb (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
{
GoaWebView *self = GOA_WEB_VIEW (user_data);
GoaWebViewPrivate *priv = self->priv;
@@ -178,8 +174,8 @@ web_view_notify_progress_cb (GObject *object, GParamSpec *pspec, gpointer user_d
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);
+ progress = webkit_web_view_get_estimated_load_progress (web_view);
+ loading = webkit_web_view_is_loading (web_view);
if (progress == 1.0 || !loading)
priv->clear_notify_progress_id = g_timeout_add (500, web_view_clear_notify_progress_cb, self);
@@ -191,11 +187,79 @@ web_view_notify_progress_cb (GObject *object, GParamSpec *pspec, gpointer user_d
}
static void
+goa_web_view_constructed (GObject *object)
+{
+ GoaWebView *self = GOA_WEB_VIEW (object);
+ GoaWebViewPrivate *priv = self->priv;
+ WebKitCookieManager *cookie_manager;
+ gchar *jar_file;
+
+ G_OBJECT_CLASS (goa_web_view_parent_class)->constructed (object);
+
+ priv->context = g_object_new (WEBKIT_TYPE_WEB_CONTEXT, NULL);
+ g_signal_connect_swapped (priv->context,
+ "initialize-web-extensions",
+ G_CALLBACK (web_view_initialize_web_extensions_cb),
+ self);
+
+ cookie_manager = webkit_web_context_get_cookie_manager (priv->context);
+ jar_file = g_build_filename (g_get_user_cache_dir (), "goa-1.0", "cookies.sqlite", NULL);
+ priv->cookie_jar = soup_cookie_jar_db_new (jar_file, FALSE);
+ webkit_cookie_manager_set_persistent_storage (cookie_manager, jar_file,
WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE);
+ webkit_cookie_manager_delete_all_cookies (cookie_manager);
+ g_free (jar_file);
+
+ priv->web_view = webkit_web_view_new_with_context (priv->context);
+ gtk_widget_set_size_request (priv->web_view, 500, 400);
+ gtk_container_add (GTK_CONTAINER (self), priv->web_view);
+
+#ifdef GOA_INSPECTOR_ENABLED
+ {
+ WebKitSettings *settings;
+ WebKitWebInspector *inspector;
+
+ /* Setup the inspector */
+ settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (priv->web_view));
+ g_object_set (settings, "enable-developer-extras", TRUE, NULL);
+
+ inspector = webkit_web_view_get_inspector (WEBKIT_WEB_VIEW (priv->web_view));
+ webkit_web_inspector_show (inspector);
+ }
+#endif /* GOA_INSPECTOR_ENABLED */
+
+ /* statusbar is hidden by default */
+ priv->floating_bar = nautilus_floating_bar_new (NULL, FALSE);
+ gtk_widget_set_halign (priv->floating_bar, GTK_ALIGN_START);
+ gtk_widget_set_valign (priv->floating_bar, GTK_ALIGN_END);
+ gtk_widget_set_no_show_all (priv->floating_bar, TRUE);
+ gtk_overlay_add_overlay (GTK_OVERLAY (self), priv->floating_bar);
+
+ priv->progress_bar = gtk_progress_bar_new ();
+ gtk_style_context_add_class (gtk_widget_get_style_context (priv->progress_bar),
+ GTK_STYLE_CLASS_OSD);
+ 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::estimated-load-progress",
+ G_CALLBACK (web_view_notify_estimated_load_progress_cb),
+ self);
+ priv->notify_load_status_id = g_signal_connect (priv->web_view,
+ "load_changed",
+ G_CALLBACK (web_view_load_changed_cb),
+ self);
+}
+
+static void
goa_web_view_dispose (GObject *object)
{
GoaWebView *self = GOA_WEB_VIEW (object);
GoaWebViewPrivate *priv = self->priv;
+ g_clear_object (&priv->cookie_jar);
+ g_clear_object (&priv->context);
+
if (priv->clear_notify_progress_id != 0)
{
g_source_remove (priv->clear_notify_progress_id);
@@ -217,133 +281,43 @@ goa_web_view_dispose (GObject *object)
G_OBJECT_CLASS (goa_web_view_parent_class)->dispose (object);
}
-#ifdef GOA_INSPECTOR_ENABLED
-static WebKitWebView *
-web_inspector_inspect_web_view_cb (WebKitWebInspector *inspector,
- WebKitWebView *web_view,
- gpointer user_data)
+static void
+goa_web_view_finalize (GObject *object)
{
- GtkWidget *inspector_web_view;
- GtkWidget *scrolled_window;
- GtkWidget *window;
-
- inspector_web_view = webkit_web_view_new ();
-
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_window_resize (GTK_WINDOW (window), 800, 600);
-
- scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
-
- gtk_container_add (GTK_CONTAINER (window), scrolled_window);
- gtk_container_add (GTK_CONTAINER (scrolled_window), inspector_web_view);
+ GoaWebView *self = GOA_WEB_VIEW (object);
- g_object_set_data (G_OBJECT (inspector), "window", window);
+ g_free (self->priv->existing_identity);
- return WEBKIT_WEB_VIEW (inspector_web_view);
+ G_OBJECT_CLASS (goa_web_view_parent_class)->finalize (object);
}
-static gboolean
-web_inspector_show_window_cb (WebKitWebInspector *inspector,
- gpointer user_data)
+static void
+goa_web_view_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
- GtkWidget *window;
- GtkWindowGroup *group;
+ GoaWebView *self = GOA_WEB_VIEW (object);
+ GoaWebViewPrivate *priv = self->priv;
- group = gtk_window_group_new ();
+ switch (prop_id)
+ {
+ case PROP_EXISTING_IDENTITY:
+ priv->existing_identity = g_value_dup_string (value);
+ break;
- window = g_object_get_data (G_OBJECT (inspector), "window");
- gtk_window_group_add_window (group, GTK_WINDOW (window));
- gtk_widget_show_all (window);
- gtk_window_present (GTK_WINDOW (window));
+ case PROP_PROVIDER:
+ priv->provider = GOA_PROVIDER (g_value_get_object (value));
+ g_object_add_weak_pointer (G_OBJECT (priv->provider), (gpointer *) &priv->provider);
+ break;
- g_object_unref (group);
- return GDK_EVENT_STOP;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
-#endif /* GOA_INSPECTOR_ENABLED */
static void
goa_web_view_init (GoaWebView *self)
{
- GoaWebViewPrivate *priv;
- GtkWidget *scrolled_window;
- SoupCookieJar *cookie_jar;
- SoupLogger *logger;
- SoupSession *session;
- WebKitWebSettings *settings;
-
self->priv = GOA_WEB_VIEW_GET_PRIVATE (self);
- priv = self->priv;
-
- session = webkit_get_default_session ();
- g_object_set (session, SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE, SOUP_SESSION_SSL_STRICT, TRUE, NULL);
-
- soup_session_add_feature_by_type (session, SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
- g_object_set (session, "accept-language-auto", TRUE, NULL);
-
- 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);
-
- logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, -1);
- soup_logger_set_printer (logger, web_view_log_printer, NULL, NULL);
- soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger));
- g_object_unref (logger);
-
- 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);
-
- settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (priv->web_view));
- g_object_set (settings, "user-stylesheet-uri", "file://" PACKAGE_DATA_DIR "/goawebview.css", NULL);
-
-#ifdef GOA_INSPECTOR_ENABLED
- {
- WebKitWebInspector *inspector;
-
- /* Setup the inspector */
- g_object_set (settings, "enable-developer-extras", TRUE, NULL);
- inspector = webkit_web_view_get_inspector (WEBKIT_WEB_VIEW (priv->web_view));
- webkit_web_inspector_show (WEBKIT_WEB_INSPECTOR (inspector));
-
- g_signal_connect (inspector, "inspect-web-view", G_CALLBACK (web_inspector_inspect_web_view_cb), NULL);
- g_signal_connect (inspector, "show-window", G_CALLBACK (web_inspector_show_window_cb), NULL);
- }
-#endif /* GOA_INSPECTOR_ENABLED */
-
- /* statusbar is hidden by default */
- priv->floating_bar = nautilus_floating_bar_new (NULL, FALSE);
- gtk_widget_set_halign (priv->floating_bar, GTK_ALIGN_START);
- gtk_widget_set_valign (priv->floating_bar, GTK_ALIGN_END);
- gtk_widget_set_no_show_all (priv->floating_bar, TRUE);
- gtk_overlay_add_overlay (GTK_OVERLAY (self), priv->floating_bar);
-
- priv->progress_bar = gtk_progress_bar_new ();
- gtk_style_context_add_class (gtk_widget_get_style_context (priv->progress_bar),
- GTK_STYLE_CLASS_OSD);
- 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);
- priv->notify_load_status_id = g_signal_connect (priv->web_view,
- "notify::load-status",
- G_CALLBACK (web_view_notify_load_status_cb),
- self);
}
static void
@@ -352,15 +326,38 @@ goa_web_view_class_init (GoaWebViewClass *klass)
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
+ object_class->constructed = goa_web_view_constructed;
object_class->dispose = goa_web_view_dispose;
+ object_class->finalize = goa_web_view_finalize;
+ object_class->set_property = goa_web_view_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_EXISTING_IDENTITY,
+ g_param_spec_string ("existing-identity",
+ "A GoaAccount identity",
+ "The user name with which we want to prefill the
form",
+ NULL,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_PROVIDER,
+ g_param_spec_object ("provider",
+ "A GoaProvider",
+ "The provider that is represented by this view",
+ GOA_TYPE_PROVIDER,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
g_type_class_add_private (object_class, sizeof (GoaWebViewPrivate));
}
GtkWidget *
-goa_web_view_new (void)
+goa_web_view_new (GoaProvider *provider, const gchar *existing_identity)
{
- return g_object_new (GOA_TYPE_WEB_VIEW, NULL);
+ return g_object_new (GOA_TYPE_WEB_VIEW, "provider", provider, "existing-identity", existing_identity,
NULL);
}
GtkWidget *
@@ -372,7 +369,7 @@ goa_web_view_get_view (GoaWebView *self)
void
goa_web_view_fake_mobile (GoaWebView *self)
{
- WebKitWebSettings *settings;
+ WebKitSettings *settings;
settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (self->priv->web_view));
@@ -389,26 +386,20 @@ goa_web_view_fake_mobile (GoaWebView *self)
* Also note that the user agents of some mobile browsers may
* not work. eg., Nokia N9.
*/
- g_object_set (G_OBJECT (settings),
- "user-agent", "Mozilla/5.0 (GNOME; not Android) "
- "AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile",
- NULL);
+ webkit_settings_set_user_agent (settings,
+ "Mozilla/5.0 (GNOME; not Android) "
+ "AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile");
}
void
goa_web_view_add_cookies (GoaWebView *self,
GSList *cookies)
{
- SoupCookieJar *cookie_jar;
- SoupSession *session;
GSList *l;
- session = webkit_get_default_session ();
- cookie_jar = SOUP_COOKIE_JAR (soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR));
-
for (l = cookies; l != NULL; l = l->next)
{
SoupCookie *cookie = l->data;
- soup_cookie_jar_add_cookie (cookie_jar, soup_cookie_copy (cookie));
+ soup_cookie_jar_add_cookie (self->priv->cookie_jar, soup_cookie_copy (cookie));
}
}
diff --git a/src/goabackend/goawebview.h b/src/goabackend/goawebview.h
index 633afaa..31989a0 100644
--- a/src/goabackend/goawebview.h
+++ b/src/goabackend/goawebview.h
@@ -1,6 +1,6 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
- * Copyright (C) 2012 Red Hat, Inc.
+ * Copyright (C) 2012, 2015 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
@@ -21,6 +21,8 @@
#include <gtk/gtk.h>
+#include "goaprovider.h"
+
G_BEGIN_DECLS
#define GOA_TYPE_WEB_VIEW (goa_web_view_get_type ())
@@ -46,7 +48,8 @@ struct _GoaWebViewClass
};
GType goa_web_view_get_type (void) G_GNUC_CONST;
-GtkWidget *goa_web_view_new (void);
+GtkWidget *goa_web_view_new (GoaProvider *provider,
+ const gchar *existing_identity);
GtkWidget *goa_web_view_get_view (GoaWebView *self);
void goa_web_view_fake_mobile (GoaWebView *self);
void goa_web_view_add_cookies (GoaWebView *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]