[epiphany/tgt: 1/10] Display documents inside ephy window using libevince



commit 9fffb001dc9a03b65326253746486de13122c8dc
Author: Javier M. Mellid <jmunhoz igalia com>
Date:   Mon Jul 8 14:51:32 2013 +0200

    Display documents inside ephy window using libevince
    
    This patch ports Carlos Garcia Campos' patch in order to support it in
    gnome-3-8 branch.
    
    As Carlos mentions, it adds a new widget EphyDocumentView to load
    documents using EvView. When the policy checker detects the document
    can't be shown inside a web view, and it's a document supported by
    evince, a download is started for the document. The EphyEmbed mode is
    set to DOCUMENT so that when the download finishes, a EphyDocumentView
    is created to load the downloaded document.
    
    In EphyWindow we consider documents as about:blank pages for now, so
    that all actions (search, copy, paste, etc.) are disabled.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=689992

 configure.ac               |    2 +
 embed/Makefile.am          |    5 +-
 embed/ephy-document-view.c |  112 +++++++++++++++++++++++++++++++++++++++
 embed/ephy-document-view.h |   60 +++++++++++++++++++++
 embed/ephy-embed-utils.c   |   26 +++++++++
 embed/ephy-embed-utils.h   |    1 +
 embed/ephy-embed.c         |  124 +++++++++++++++++++++++++++++---------------
 embed/ephy-embed.h         |   14 ++++-
 embed/ephy-web-view.c      |   16 +++++-
 src/ephy-main.c            |    3 +
 src/ephy-shell.c           |    6 ++-
 src/ephy-window.c          |   13 +++--
 12 files changed, 326 insertions(+), 56 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8120ece..7ba1c91 100644
--- a/configure.ac
+++ b/configure.ac
@@ -131,6 +131,8 @@ PKG_CHECK_MODULES([DEPENDENCIES], [
                  gcr-3 >= $GCR_REQUIRED
                  avahi-gobject >= $AVAHI_REQUIRED
                  avahi-client >= $AVAHI_REQUIRED
+                 evince-view-3.0
+                 evince-document-3.0
                  ])
 
 PKG_CHECK_MODULES(WEB_EXTENSION, [
diff --git a/embed/Makefile.am b/embed/Makefile.am
index c859888..3014706 100644
--- a/embed/Makefile.am
+++ b/embed/Makefile.am
@@ -13,7 +13,8 @@ NOINST_H_FILES = \
        ephy-encoding.h                 \
        ephy-encodings.h                \
        ephy-file-monitor.h             \
-       ephy-request-about.h
+       ephy-request-about.h            \
+       ephy-document-view.h
 
 INST_H_FILES = \
        ephy-download.h                 \
@@ -27,7 +28,6 @@ INST_H_FILES = \
        ephy-overview.h                 \
        ephy-web-view.h
 
-
 BUILT_SOURCES = \
        ephy-embed-type-builtins.c      \
        ephy-embed-type-builtins.h
@@ -49,6 +49,7 @@ libephyembed_la_SOURCES = \
        ephy-request-about.c            \
        ephy-embed-prefs.c              \
        ephy-web-view.c                 \
+       ephy-document-view.c            \
        $(INST_H_FILES)                 \
        $(NOINST_H_FILES)
 
diff --git a/embed/ephy-document-view.c b/embed/ephy-document-view.c
new file mode 100644
index 0000000..e1c511a
--- /dev/null
+++ b/embed/ephy-document-view.c
@@ -0,0 +1,112 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/* vim: set sw=2 ts=2 sts=2 et: */
+/*
+ *  Copyright © 2013 Igalia S.L.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "ephy-document-view.h"
+
+#include <evince-view.h>
+
+struct _EphyDocumentViewPrivate
+{
+  GtkWidget *ev_view;
+  EvDocumentModel *model;
+};
+
+G_DEFINE_TYPE (EphyDocumentView, ephy_document_view, GTK_TYPE_SCROLLED_WINDOW)
+
+static void
+ephy_document_view_finalize (GObject* object)
+{
+  EphyDocumentView *view = EPHY_DOCUMENT_VIEW (object);
+
+  g_clear_object (&view->priv->model);
+
+  G_OBJECT_CLASS (ephy_document_view_parent_class)->finalize (object);
+}
+
+static void
+ephy_document_view_constructed (GObject* object)
+{
+  EphyDocumentView *view = EPHY_DOCUMENT_VIEW (object);
+
+  G_OBJECT_CLASS (ephy_document_view_parent_class)->constructed (object);
+
+  view->priv->ev_view = ev_view_new ();
+  view->priv->model = ev_document_model_new ();
+  ev_view_set_model (EV_VIEW (view->priv->ev_view), view->priv->model);
+
+  gtk_container_add (GTK_CONTAINER (view), view->priv->ev_view);
+  gtk_widget_show (view->priv->ev_view);
+}
+
+static void
+ephy_document_view_class_init (EphyDocumentViewClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->constructed = ephy_document_view_constructed;
+  object_class->finalize = ephy_document_view_finalize;
+
+  g_type_class_add_private (object_class, sizeof (EphyDocumentViewPrivate));
+}
+
+static void
+ephy_document_view_init (EphyDocumentView *view)
+{
+  view->priv = G_TYPE_INSTANCE_GET_PRIVATE (view, EPHY_TYPE_DOCUMENT_VIEW, EphyDocumentViewPrivate);
+}
+
+GtkWidget *
+ephy_document_view_new (void)
+{
+  return g_object_new (EPHY_TYPE_DOCUMENT_VIEW,
+                       "hadjustment", NULL,
+                       "vadjustment", NULL,
+                       NULL);
+}
+
+static void
+document_load_job_finished (EvJob *job,
+                            EvDocumentModel *model)
+{
+  if (ev_job_is_failed (job)) {
+    /* FIXME: Error reporting */
+    g_warning ("Failed to load document");
+  } else
+    ev_document_model_set_document (model, job->document);
+  g_object_unref (job);
+}
+
+void
+ephy_document_view_load_uri (EphyDocumentView *view,
+                             const char *uri)
+{
+  EvJob *job;
+
+  g_return_if_fail (EPHY_DOCUMENT_VIEW (view));
+  g_return_if_fail (uri != NULL);
+
+  job = ev_job_load_new (uri);
+  g_signal_connect (job, "finished",
+                    G_CALLBACK (document_load_job_finished),
+                    view->priv->model);
+  ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE);
+}
diff --git a/embed/ephy-document-view.h b/embed/ephy-document-view.h
new file mode 100644
index 0000000..27a3c4d
--- /dev/null
+++ b/embed/ephy-document-view.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/* vim: set sw=2 ts=2 sts=2 et: */
+/*
+ *  Copyright © 2013 Igalia S.L.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef _EPHY_DOCUMENT_VIEW_H
+#define _EPHY_DOCUMENT_VIEW_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_DOCUMENT_VIEW            (ephy_document_view_get_type())
+#define EPHY_DOCUMENT_VIEW(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_DOCUMENT_VIEW, 
EphyDocumentView))
+#define EPHY_IS_DOCUMENT_VIEW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_DOCUMENT_VIEW))
+#define EPHY_DOCUMENT_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_DOCUMENT_VIEW, 
EphyDocumentViewClass))
+#define EPHY_IS_DOCUMENT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_DOCUMENT_VIEW))
+#define EPHY_DOCUMENT_VIEW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_DOCUMENT_VIEW, 
EphyDocumentViewClass))
+
+typedef struct _EphyDocumentView            EphyDocumentView;
+typedef struct _EphyDocumentViewClass       EphyDocumentViewClass;
+typedef struct _EphyDocumentViewPrivate     EphyDocumentViewPrivate;
+
+struct _EphyDocumentView {
+  GtkScrolledWindow parent;
+
+  /*< private >*/
+  EphyDocumentViewPrivate *priv;
+};
+
+struct _EphyDocumentViewClass {
+  GtkScrolledWindowClass parent_class;
+
+};
+
+GType       ephy_document_view_get_type (void) G_GNUC_CONST;
+
+GtkWidget *ephy_document_view_new       (void);
+void       ephy_document_view_load_uri  (EphyDocumentView *view,
+                                         const char       *uri);
+
+G_END_DECLS
+
+#endif /* _EPHY_DOCUMENT_VIEW_H */
diff --git a/embed/ephy-embed-utils.c b/embed/ephy-embed-utils.c
index 5b1760b..444842e 100644
--- a/embed/ephy-embed-utils.c
+++ b/embed/ephy-embed-utils.c
@@ -27,6 +27,7 @@
 #include "ephy-about-handler.h"
 #include "ephy-string.h"
 
+#include <evince-document.h>
 #include <string.h>
 #include <glib/gi18n.h>
 #include <libsoup/soup.h>
@@ -187,3 +188,28 @@ ephy_embed_utils_is_no_show_address (const char *address)
 
   return FALSE;
 }
+
+gboolean
+ephy_embed_utils_mime_type_is_supported_document (const char *mime_type)
+{
+  GList *doc_types = ev_backends_manager_get_all_types_info ();
+  GList *l;
+  gboolean found = FALSE;
+
+  for (l = doc_types; l && !found; l = l->next) {
+    EvTypeInfo *info = (EvTypeInfo *) l->data;
+    char **mime_types = info->mime_types;
+    guint i;
+
+    for (i = 0; info->mime_types[i]; ++i) {
+      if (g_ascii_strcasecmp (mime_type, info->mime_types[i]) == 0) {
+        found = TRUE;
+        break;
+      }
+    }
+  }
+
+  g_list_free (doc_types);
+
+  return found;
+}
diff --git a/embed/ephy-embed-utils.h b/embed/ephy-embed-utils.h
index 5575c1a..ee38e4f 100644
--- a/embed/ephy-embed-utils.h
+++ b/embed/ephy-embed-utils.h
@@ -48,6 +48,7 @@ gboolean ephy_embed_utils_address_is_existing_absolute_filename (const char *add
 char*    ephy_embed_utils_normalize_address                     (const char *address);
 gboolean ephy_embed_utils_url_is_empty                          (const char *location);
 gboolean ephy_embed_utils_is_no_show_address                    (const char *address);
+gboolean ephy_embed_utils_mime_type_is_supported_document       (const char *mime_type);
 
 G_END_DECLS
 
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index c9b8bf4..cb1b6d4 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -29,15 +29,18 @@
 #ifndef HAVE_WEBKIT2
 #include "ephy-adblock-manager.h"
 #endif
+#include "ephy-document-view.h"
 #include "ephy-debug.h"
 #include "ephy-download.h"
 #include "ephy-embed-prefs.h"
 #include "ephy-embed-shell.h"
+#include "ephy-embed-type-builtins.h"
 #include "ephy-prefs.h"
 #include "ephy-settings.h"
 #include "ephy-web-view.h"
 #include "nautilus-floating-bar.h"
 
+#include <evince-view.h>
 #include <glib/gi18n.h>
 #ifdef HAVE_WEBKIT2
 #include <webkit2/webkit2.h>
@@ -68,6 +71,7 @@ typedef struct {
 struct _EphyEmbedPrivate
 {
   GtkBox *top_widgets_vbox;
+  EphyEmbedMode mode;
 #ifndef HAVE_WEBKIT2
   GtkScrolledWindow *scrolled_window;
   GtkWidget *inspector_window;
@@ -90,7 +94,7 @@ struct _EphyEmbedPrivate
 #endif
 
   GtkWidget *overview;
-  guint overview_mode : 1;
+  GtkWidget *document_view;
   GSList *messages;
   GSList *keys;
 
@@ -115,7 +119,7 @@ struct _EphyEmbedPrivate
 enum
 {
   PROP_0,
-  PROP_OVERVIEW_MODE,
+  PROP_MODE,
 };
 
 G_DEFINE_TYPE (EphyEmbed, ephy_embed, GTK_TYPE_BOX)
@@ -300,20 +304,8 @@ load_changed_cb (WebKitWebView *web_view,
                  WebKitLoadEvent load_event,
                  EphyEmbed *embed)
 {
-  switch (load_event) {
-  case WEBKIT_LOAD_STARTED: {
-    const char *uri;
-
-    uri = webkit_web_view_get_uri (web_view);
-    ephy_embed_set_overview_mode (embed, g_strcmp0 (uri, "ephy-about:overview") == 0);
-    break;
-  }
-  case WEBKIT_LOAD_COMMITTED:
+ if (load_event == WEBKIT_LOAD_COMMITTED)
     ephy_embed_destroy_top_widgets (embed);
-    break;
-  default:
-    break;
-  }
 }
 #else
 static void
@@ -322,13 +314,9 @@ load_status_changed_cb (WebKitWebView *web_view,
                         EphyEmbed *embed)
 {
   WebKitLoadStatus status = webkit_web_view_get_load_status (web_view);
-  const char *address;
 
-  if (status == WEBKIT_LOAD_COMMITTED) {
+  if (status == WEBKIT_LOAD_COMMITTED)
     ephy_embed_destroy_top_widgets (embed);
-    address = ephy_web_view_get_address (EPHY_WEB_VIEW (web_view));
-    ephy_embed_set_overview_mode (embed, strcmp (address, "ephy-about:overview") == 0);
-  }
 }
 #endif
 
@@ -488,8 +476,8 @@ ephy_embed_set_property (GObject *object,
 
   switch (prop_id)
   {
-  case PROP_OVERVIEW_MODE:
-    ephy_embed_set_overview_mode (embed, g_value_get_boolean (value));
+  case PROP_MODE:
+    ephy_embed_set_mode (embed, g_value_get_enum (value));
     break;
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -507,8 +495,8 @@ ephy_embed_get_property (GObject *object,
 
   switch (prop_id)
   {
-  case PROP_OVERVIEW_MODE:
-    g_value_set_boolean (value, ephy_embed_get_overview_mode (embed));
+  case PROP_MODE:
+    g_value_set_enum (value, ephy_embed_get_mode (embed));
     break;
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -535,12 +523,13 @@ ephy_embed_class_init (EphyEmbedClass *klass)
  * If %TRUE activates the overview mode in this #EphyEmbed.
  **/
   g_object_class_install_property (object_class,
-                                   PROP_OVERVIEW_MODE,
-                                   g_param_spec_boolean ("overview-mode",
-                                                         "Overview mode",
-                                                         "Whether the embed is showing the overview",
-                                                         FALSE,
-                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+                                   PROP_MODE,
+                                   g_param_spec_enum ("mode",
+                                   "Mode",
+                                   "The embed mode",
+                                   EPHY_TYPE_EMBED_MODE,
+                                   EPHY_EMBED_MODE_WEB_VIEW,
+                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
   g_type_class_add_private (G_OBJECT_CLASS (klass), sizeof(EphyEmbedPrivate));
 }
@@ -664,6 +653,31 @@ ephy_embed_auto_download_url (EphyEmbed *embed, const char *url)
   ephy_download_set_action (download, EPHY_DOWNLOAD_ACTION_OPEN);
 }
 
+static void
+document_download_finished_cb (WebKitDownload *download,
+                               EphyEmbed *embed)
+{
+ const char *document_uri = webkit_download_get_destination (download);
+ if (!embed->priv->document_view) {
+    embed->priv->document_view = ephy_document_view_new ();
+    gtk_box_pack_start (GTK_BOX (embed),
+                        embed->priv->document_view,
+                        TRUE, TRUE, 0);
+    gtk_widget_show (embed->priv->document_view);
+  }
+
+  ephy_document_view_load_uri (EPHY_DOCUMENT_VIEW (embed->priv->document_view),
+                               document_uri);
+}
+
+void
+ephy_embed_download_started (EphyEmbed *embed,
+                             WebKitDownload *download)
+{
+    if (embed->priv->mode == EPHY_EMBED_MODE_DOCUMENT)
+      g_signal_connect (download, "finished", G_CALLBACK (document_download_finished_cb), embed);
+}
+
 #ifndef HAVE_WEBKIT2
 static gboolean
 download_requested_cb (WebKitWebView *web_view,
@@ -686,6 +700,8 @@ download_requested_cb (WebKitWebView *web_view,
   ed = ephy_download_new_for_download (download, window);
   ephy_download_set_auto_destination (ed);
 
+  ephy_embed_download_started (embed, download);
+
   return TRUE;
 }
 #endif
@@ -972,10 +988,6 @@ ephy_embed_constructed (GObject *object)
     gtk_widget_set_halign (priv->overview, GTK_ALIGN_FILL);
     gtk_widget_set_valign (priv->overview, GTK_ALIGN_FILL);
     gtk_overlay_add_overlay (GTK_OVERLAY (overlay), priv->overview);
-
-    g_object_bind_property (embed, "overview-mode",
-                            priv->overview, "visible",
-                            G_BINDING_SYNC_CREATE);
   }
 
   /* Floating message popup for fullscreen mode. */
@@ -1028,6 +1040,7 @@ ephy_embed_constructed (GObject *object)
   gtk_widget_show (GTK_WIDGET (priv->top_widgets_vbox));
   gtk_widget_show (GTK_WIDGET (web_view));
   gtk_widget_show_all (paned);
+  gtk_widget_hide (priv->overview);
 
 #ifdef HAVE_WEBKIT2
   g_object_connect (web_view,
@@ -1210,28 +1223,55 @@ ephy_embed_remove_top_widget (EphyEmbed *embed, GtkWidget *widget)
 }
 
 void
-ephy_embed_set_overview_mode (EphyEmbed *embed, gboolean overview_mode)
+ephy_embed_set_mode (EphyEmbed *embed, EphyEmbedMode mode)
 {
   EphyEmbedPrivate *priv;
+  gboolean show_document, show_overview, show_paned;
 
   g_return_if_fail (EPHY_IS_EMBED (embed));
 
   priv = embed->priv;
 
-  if (priv->overview_mode == overview_mode)
+  if (priv->mode == mode)
     return;
 
-  priv->overview_mode = overview_mode;
+  switch (mode) {
+  case EPHY_EMBED_MODE_WEB_VIEW:
+    show_document = FALSE;
+    show_overview = FALSE;
+    show_paned = TRUE;
+    break;
+  case EPHY_EMBED_MODE_OVERVIEW:
+    show_document = FALSE;
+    show_overview = TRUE;
+    show_paned = TRUE;
+    break;
+  case EPHY_EMBED_MODE_DOCUMENT:
+    show_document = TRUE;
+    show_overview = FALSE;
+    show_paned = FALSE;
+    break;
+  default:
+    g_assert_not_reached ();
+  }
+
+  priv->mode = mode;
 
-  g_object_notify (G_OBJECT (embed), "overview-mode");
+  gtk_widget_set_visible (GTK_WIDGET (priv->paned), show_paned);
+  if (priv->overview)
+    gtk_widget_set_visible (priv->overview, show_overview);
+  if (priv->document_view)
+    gtk_widget_set_visible (priv->document_view, show_document);
+
+  g_object_notify (G_OBJECT (embed), "mode");
 }
 
-gboolean
-ephy_embed_get_overview_mode (EphyEmbed *embed)
+EphyEmbedMode
+ephy_embed_get_mode (EphyEmbed *embed)
 {
-  g_return_val_if_fail (EPHY_IS_EMBED (embed), FALSE);
+  g_return_val_if_fail (EPHY_IS_EMBED (embed), EPHY_EMBED_MODE_WEB_VIEW);
 
-  return embed->priv->overview_mode;
+  return embed->priv->mode;
 }
 
 /**
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index 5802cbe..76b8720 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -36,6 +36,12 @@ G_BEGIN_DECLS
 #define EPHY_IS_EMBED_CLASS(k)        (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_EMBED))
 #define EPHY_EMBED_GET_CLASS(o)       (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_EMBED, EphyEmbedClass))
 
+typedef enum {
+  EPHY_EMBED_MODE_WEB_VIEW,
+  EPHY_EMBED_MODE_OVERVIEW,
+  EPHY_EMBED_MODE_DOCUMENT
+} EphyEmbedMode;
+
 typedef struct _EphyEmbedClass EphyEmbedClass;
 typedef struct _EphyEmbed EphyEmbed;
 typedef struct _EphyEmbedPrivate EphyEmbedPrivate;
@@ -69,10 +75,12 @@ void         ephy_embed_set_delayed_load_request (EphyEmbed *embed,
                                                   WebKitNetworkRequest *request);
 #endif
 gboolean     ephy_embed_has_load_pending         (EphyEmbed *embed);
-void         ephy_embed_set_overview_mode        (EphyEmbed *embed,
-                                                  gboolean   overview_mode);
-gboolean     ephy_embed_get_overview_mode        (EphyEmbed *embed);
+void         ephy_embed_set_mode                 (EphyEmbed *embed,
+                                                  EphyEmbedMode mode);
+EphyEmbedMode ephy_embed_get_mode                (EphyEmbed *embed);
 EphyOverview*ephy_embed_get_overview             (EphyEmbed *embed);
+void         ephy_embed_download_started         (EphyEmbed *embed,
+                                                  WebKitDownload *download);
 
 G_END_DECLS
 
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 6b6e108..e6ab2e8 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1776,6 +1776,11 @@ decide_policy_cb (WebKitWebView *web_view,
   if (g_strcmp0 (webkit_web_resource_get_uri (main_resource), request_uri) != 0)
     return FALSE;
 
+  if (ephy_embed_utils_mime_type_is_supported_document(mime_type)) {
+    EphyEmbed *embed = EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (web_view);
+    ephy_embed_set_mode (embed, EPHY_EMBED_MODE_DOCUMENT);
+  }
+
   webkit_policy_decision_download (decision);
 
   return TRUE;
@@ -2113,6 +2118,7 @@ load_changed_cb (WebKitWebView *web_view,
 
   switch (load_event) {
   case WEBKIT_LOAD_STARTED: {
+    EphyEmbed *embed = EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (web_view);
     const char *loading_uri = NULL;
 
     priv->load_failed = FALSE;
@@ -2120,6 +2126,9 @@ load_changed_cb (WebKitWebView *web_view,
     loading_uri = webkit_web_view_get_uri (web_view);
     g_signal_emit_by_name (view, "new-document-now", loading_uri);
 
+    ephy_embed_set_mode (embed, g_strcmp0 (loading_uri, "ephy-about:overview") == 0 ?
+                         EPHY_EMBED_MODE_OVERVIEW : EPHY_EMBED_MODE_WEB_VIEW);
+
     if (ephy_embed_utils_is_no_show_address (loading_uri))
       ephy_web_view_freeze_history (view);
 
@@ -2278,11 +2287,14 @@ load_status_cb (WebKitWebView *web_view,
     WebKitWebFrame *frame;
     WebKitNetworkResponse *response;
     SoupMessage *message;
+    EphyEmbed *embed = EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (web_view);
 
     /* Title and location. */
     uri = webkit_web_view_get_uri (web_view);
-    ephy_web_view_location_changed (view,
-                                    uri);
+    ephy_web_view_location_changed (view, uri);
+
+    ephy_embed_set_mode (embed, strcmp (uri, "ephy-about:overview") == 0 ?
+                         EPHY_EMBED_MODE_OVERVIEW : EPHY_EMBED_MODE_WEB_VIEW);
 
     /* Security status. */
     frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW(view));
diff --git a/src/ephy-main.c b/src/ephy-main.c
index 80d076b..2db239b 100644
--- a/src/ephy-main.c
+++ b/src/ephy-main.c
@@ -33,6 +33,7 @@
 #include "ephy-string.h"
 #include "ephy-web-app-utils.h"
 
+#include <evince-document.h>
 #include <errno.h>
 #include <gdk/gdkx.h>
 #include <glib/gi18n.h>
@@ -457,6 +458,7 @@ main (int argc,
     gtk_window_set_default_icon_name ("web-browser");
   }
 
+  ev_init();
   _ephy_shell_create_instance (mode);
 
   startup_flags = get_startup_flags ();
@@ -478,6 +480,7 @@ main (int argc,
     notify_uninit ();
 
   ephy_initial_state_save ();
+  ev_shutdown ();
   ephy_settings_shutdown ();
   ephy_file_helpers_shutdown ();
   xmlCleanupParser ();
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 208c3da..860aa87 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -574,6 +574,7 @@ download_started_cb (WebKitWebContext *web_context,
 {
   GtkWindow *window = NULL;
   WebKitWebView *web_view;
+  EphyEmbed *embed;
   gboolean ephy_download_set;
 
   /* Is download locked down? */
@@ -605,6 +606,9 @@ download_started_cb (WebKitWebContext *web_context,
     window = gtk_application_get_active_window (GTK_APPLICATION (shell));
 
   ephy_download_new_for_download (download, window);
+  embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
+  if (embed)
+    ephy_embed_download_started (embed, download);
 }
 #endif
 
@@ -786,7 +790,7 @@ ephy_shell_new_tab_full (EphyShell *shell,
     embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
     if (embed != NULL) {
       EphyWebView *view = ephy_embed_get_web_view (embed);
-      if ((ephy_web_view_get_is_blank (view) || ephy_embed_get_overview_mode (embed)) &&
+      if ((ephy_web_view_get_is_blank (view) || ephy_embed_get_mode (embed) == EPHY_EMBED_MODE_OVERVIEW) &&
           ephy_web_view_is_loading (view) == FALSE) {
         active_is_blank = TRUE;
       }
diff --git a/src/ephy-window.c b/src/ephy-window.c
index a183122..4695fa9 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -2258,13 +2258,14 @@ ephy_window_mouse_target_changed_cb (WebKitWebView *web_view,
 #endif
 
 static void
-sync_embed_is_overview (EphyEmbed *embed, GParamSpec *pspec, EphyWindow *window)
+sync_embed_mode (EphyEmbed *embed, GParamSpec *pspec, EphyWindow *window)
 {
        if (window->priv->closing) return;
 
+       /* For now we can consider documents as about:blank */
        _ephy_window_set_default_actions_sensitive (window,
                                                    SENS_FLAG_IS_BLANK,
-                                                   ephy_embed_get_overview_mode (embed));;
+                                                   ephy_embed_get_mode (embed) != EPHY_EMBED_MODE_WEB_VIEW);
 }
 
 static void
@@ -2787,7 +2788,7 @@ ephy_window_connect_active_embed (EphyWindow *window)
        sync_tab_icon           (view, NULL, window);
        sync_tab_popup_windows  (view, NULL, window);
        sync_tab_popups_allowed (view, NULL, window);
-       sync_embed_is_overview  (embed, NULL, window);
+       sync_embed_mode         (embed, NULL, window);
 
        sync_tab_zoom           (web_view, NULL, window);
 
@@ -2873,8 +2874,8 @@ ephy_window_connect_active_embed (EphyWindow *window)
                                 G_CALLBACK (ephy_window_dom_mouse_click_cb),
                                 window, G_CONNECT_AFTER);
 #endif
-       g_signal_connect_object (embed, "notify::overview-mode",
-                                G_CALLBACK (sync_embed_is_overview),
+       g_signal_connect_object (embed, "notify::mode",
+                                G_CALLBACK (sync_embed_mode),
                                 window, 0);
 
        shell_mode = ephy_embed_shell_get_mode (EPHY_EMBED_SHELL (ephy_embed_shell_get_default ()));
@@ -2969,7 +2970,7 @@ ephy_window_disconnect_active_embed (EphyWindow *window)
                                              window);
 
        g_signal_handlers_disconnect_by_func (embed,
-                                             G_CALLBACK (sync_embed_is_overview),
+                                             G_CALLBACK (sync_embed_mode),
                                              window);
 
        shell_mode = ephy_embed_shell_get_mode (EPHY_EMBED_SHELL (ephy_embed_shell_get_default ()));


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