[gnome-online-accounts/wip/wk2: 3/3] Port to WebKit 2



commit c4231132b45c6c6e2fe3c0832cee959967f1e5b7
Author: Damián Nohales <damiannohales gmail com>
Date:   Fri Jan 9 16:06:59 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/goaoauth2provider.c |   64 +++++++++---
 src/goabackend/goaoauth2provider.h |    3 +-
 src/goabackend/goaoauthprovider.c  |   78 +++++++++++----
 src/goabackend/goaoauthprovider.h  |    7 +-
 src/goabackend/goawebview.c        |  189 ++++++++---------------------------
 8 files changed, 160 insertions(+), 190 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/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 594c173..688ba33 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -77,6 +77,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))
@@ -793,16 +795,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);
@@ -845,20 +864,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;
@@ -867,15 +887,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);
 
@@ -973,7 +998,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:
@@ -1061,10 +1086,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);
@@ -1737,6 +1770,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/goaoauth2provider.h b/src/goabackend/goaoauth2provider.h
index 65c46cf..6b90d3b 100644
--- a/src/goabackend/goaoauth2provider.h
+++ b/src/goabackend/goaoauth2provider.h
@@ -25,7 +25,8 @@
 
 #include <goabackend/goaprovider.h>
 #include <goabackend/goaprovider-priv.h>
-#include <webkit/webkit.h>
+#include <webkit2/webkit2.h>
+#include <webkitdom/webkitdom.h>
 
 G_BEGIN_DECLS
 
diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
index 9c95bae..e3c552f 100644
--- a/src/goabackend/goaoauthprovider.c
+++ b/src/goabackend/goaoauthprovider.c
@@ -63,6 +63,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);
@@ -656,16 +663,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);
@@ -708,32 +732,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? */
@@ -743,12 +773,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;
     }
 }
 
@@ -895,10 +928,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);
@@ -1677,8 +1718,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 f39d2b1..9fedb03 100644
--- a/src/goabackend/goaoauthprovider.h
+++ b/src/goabackend/goaoauthprovider.h
@@ -26,7 +26,8 @@
 #include <goabackend/goaprovider.h>
 #include <goabackend/goaprovider-priv.h>
 #include <rest/rest-proxy-call.h>
-#include <webkit/webkit.h>
+#include <webkit2/webkit2.h>
+#include <webkitdom/webkitdom.h>
 
 G_BEGIN_DECLS
 
@@ -120,8 +121,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/goawebview.c b/src/goabackend/goawebview.c
index c662b00..ae5d74f 100644
--- a/src/goabackend/goawebview.c
+++ b/src/goabackend/goawebview.c
@@ -24,7 +24,7 @@
 #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"
@@ -34,6 +34,7 @@ struct _GoaWebViewPrivate
   GtkWidget *floating_bar;
   GtkWidget *progress_bar;
   GtkWidget *web_view;
+  SoupCookieJar *cookie_jar;
   gulong clear_notify_progress_id;
   gulong notify_load_status_id;
   gulong notify_progress_id;
@@ -88,58 +89,22 @@ web_view_floating_bar_update (GoaWebView *self, const gchar *text)
     gtk_widget_show (priv->floating_bar);
 }
 
-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_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);
@@ -147,7 +112,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;
@@ -158,7 +126,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;
@@ -177,8 +147,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);
@@ -195,6 +165,8 @@ goa_web_view_dispose (GObject *object)
   GoaWebView *self = GOA_WEB_VIEW (object);
   GoaWebViewPrivate *priv = self->priv;
 
+  g_clear_object (&priv->cookie_jar);
+
   if (priv->clear_notify_progress_id != 0)
     {
       g_source_remove (priv->clear_notify_progress_id);
@@ -216,107 +188,38 @@ 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)
-{
-  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);
-
-  g_object_set_data (G_OBJECT (inspector), "window", window);
-
-  return WEBKIT_WEB_VIEW (inspector_web_view);
-}
-
-static gboolean
-web_inspector_show_window_cb (WebKitWebInspector *inspector,
-                              gpointer            user_data)
-{
-  GtkWidget *window;
-  GtkWindowGroup *group;
-
-  group = gtk_window_group_new ();
-
-  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));
-
-  g_object_unref (group);
-  return GDK_EVENT_STOP;
-}
-#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;
+  WebKitCookieManager *cookie_manager;
+  WebKitWebContext *context;
+  gchar *jar_file;
 
   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);
+  context = webkit_web_context_get_default ();
+  cookie_manager = webkit_web_context_get_cookie_manager (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);
+  g_free (jar_file);
 
   priv->web_view = webkit_web_view_new ();
-  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);
+  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 (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);
+    inspector = webkit_web_view_get_inspector (WEBKIT_WEB_VIEW (priv->web_view));
+    webkit_web_inspector_show (inspector);
   }
 #endif /* GOA_INSPECTOR_ENABLED */
 
@@ -335,12 +238,12 @@ goa_web_view_init (GoaWebView *self)
   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),
+                                               "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,
-                                                  "notify::load-status",
-                                                  G_CALLBACK (web_view_notify_load_status_cb),
+                                                  "load_changed",
+                                                  G_CALLBACK (web_view_load_changed_cb),
                                                   self);
 }
 
@@ -370,7 +273,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));
 
@@ -387,26 +290,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));
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]