commit 145c60b441d337c0cbe726c59f199ee32c39e77a
Author: alex <alex@livonia.localdomain>
Date:   Tue Jan 26 21:31:29 2010 +0100

    ephy-web-view.c: refactored the load status callback
    
    This patch uses the ephy-embed.c callback code and refactors it in
    just one method in the ephy-web-view that handles all the status
    changes for this object. The net states enum was removed, now ephy
    uses the same enum WebKitGTK defines.
    
    Bug #593743

diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index fe81fd2..1ecf4dc 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -62,7 +62,6 @@ struct EphyEmbedPrivate
   WebKitWebView *web_view;
   EphyHistory *history;
   GtkWidget *inspector_window;
-  char *loading_uri;
   guint is_setting_zoom : 1;
   GSList *destroy_on_transition_list;
 };
@@ -196,85 +195,21 @@ load_status_changed_cb (WebKitWebView *view,
                         GParamSpec *spec,
                         EphyEmbed *embed)
 {
-  EphyEmbedPrivate *priv = embed->priv;
   WebKitLoadStatus status = webkit_web_view_get_load_status (view);
 
   if (status == WEBKIT_LOAD_COMMITTED) {
     const gchar* uri;
-    EphyWebViewSecurityLevel security_level;
 
     uri = webkit_web_view_get_uri (view);
 
     ephy_embed_destroy_top_widgets (embed);
 
-    if (g_strcmp0 (uri, priv->loading_uri) != 0) {
-      g_free (priv->loading_uri);
-      priv->loading_uri = g_strdup (uri);
-    }
-
-    ephy_web_view_location_changed (EPHY_WEB_VIEW (view),
-                                    uri);
     restore_zoom_level (embed, uri);
     ephy_history_add_page (embed->priv->history,
                            uri,
                            FALSE,
                            FALSE);
 
-    /*
-     * FIXME: as a temporary workaround while soup lacks the needed
-     * security API, determine security level based on the existence of
-     * a 'https' prefix for the URI
-     */
-    if (uri && g_str_has_prefix (uri, "https"))
-      security_level = EPHY_WEB_VIEW_STATE_IS_SECURE_HIGH;
-    else
-      security_level = EPHY_WEB_VIEW_STATE_IS_UNKNOWN;
-
-    ephy_web_view_set_security_level (EPHY_WEB_VIEW (view), security_level);
-  } else if (status == WEBKIT_LOAD_PROVISIONAL || status == WEBKIT_LOAD_FINISHED) {
-    EphyWebViewNetState estate = EPHY_WEB_VIEW_STATE_UNKNOWN;
-    char *loading_uri = NULL;
-
-    if (status == WEBKIT_LOAD_PROVISIONAL) {
-      WebKitWebFrame *frame;
-      WebKitWebDataSource *source;
-      WebKitNetworkRequest *request;
-
-      frame = webkit_web_view_get_main_frame (view);
-      source = webkit_web_frame_get_provisional_data_source (frame);
-      request = webkit_web_data_source_get_initial_request (source);
-      loading_uri = g_strdup (webkit_network_request_get_uri (request));
-
-      /* We also store the URI we are currently loading here, because
-       * we will want to use it in WEBKIT_LOAD_FINISHED, because if a
-       * load fails we may never get to committed */
-      priv->loading_uri = g_strdup (loading_uri);
-
-      estate = (EphyWebViewNetState) (estate |
-                                      EPHY_WEB_VIEW_STATE_START |
-                                      EPHY_WEB_VIEW_STATE_NEGOTIATING |
-                                      EPHY_WEB_VIEW_STATE_IS_REQUEST |
-                                      EPHY_WEB_VIEW_STATE_IS_NETWORK);
-      
-      g_signal_emit_by_name (EPHY_WEB_VIEW (view), "new-document-now", loading_uri);
-    } else if (status == WEBKIT_LOAD_FINISHED) {
-      loading_uri = priv->loading_uri;
-
-      /* Will be freed bellow */
-      priv->loading_uri = NULL;
-
-      estate = (EphyWebViewNetState) (estate |
-                                      EPHY_WEB_VIEW_STATE_STOP |
-                                      EPHY_WEB_VIEW_STATE_IS_DOCUMENT |
-                                      EPHY_WEB_VIEW_STATE_IS_NETWORK);
-    }
-
-    ephy_web_view_update_from_net_state (EPHY_WEB_VIEW (view),
-                                         loading_uri,
-                                         (EphyWebViewNetState)estate);
-
-    g_free (loading_uri);
-
   }
 }
 
@@ -338,8 +273,6 @@ ephy_embed_finalize (GObject *object)
   EphyEmbed *embed = EPHY_EMBED (object);
   GSList *list;
 
-  g_free (embed->priv->loading_uri);
-
   list = embed->priv->destroy_on_transition_list;
   for (; list; list = list->next) {
     GtkWidget *widget = GTK_WIDGET (list->data);
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 25f0f63..152098f 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1937,18 +1937,137 @@ mime_type_policy_decision_requested_cb (WebKitWebView *web_view,
 }
 
 static void
+update_navigation_flags (EphyWebView *view)
+{
+  EphyWebViewPrivate *priv = view->priv;
+  guint flags = 0;
+  WebKitWebView *web_view = WEBKIT_WEB_VIEW (view);
+
+  if (ephy_web_view_can_go_up (view)) {
+    flags |= EPHY_WEB_VIEW_NAV_UP;
+  }
+
+  if (webkit_web_view_can_go_back (web_view)) {
+    flags |= EPHY_WEB_VIEW_NAV_BACK;
+  }
+
+  if (webkit_web_view_can_go_forward (web_view)) {
+    flags |= EPHY_WEB_VIEW_NAV_FORWARD;
+  }
+
+  if (priv->nav_flags != (EphyWebViewNavigationFlags)flags) {
+    priv->nav_flags = (EphyWebViewNavigationFlags)flags;
+
+    g_object_notify (G_OBJECT (view), "navigation");
+  }
+}
+
+static void
 load_status_cb (WebKitWebView *web_view,
                 GParamSpec *pspec,
                 gpointer user_data)
 {
   WebKitLoadStatus status = webkit_web_view_get_load_status (web_view);
+  EphyWebView *eview = EPHY_WEB_VIEW (web_view);
+  EphyWebViewPrivate *priv = eview->priv;
+  GObject *object = G_OBJECT (web_view);
+
+  switch (status)
+  {
+  /* FIXME: add REDIRECTING and NEGOTIATING states to WebKitGTK */
+  case WEBKIT_LOAD_PROVISIONAL:
+    {
+      gchar *loading_uri = NULL;
+      WebKitWebFrame *frame;
+      WebKitWebDataSource *source;
+      WebKitNetworkRequest *request;
+
+      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);
+      loading_uri = g_strdup (webkit_network_request_get_uri (request));
+
+      g_signal_emit_by_name (eview, "new-document-now", loading_uri);
+
+      g_object_freeze_notify (object);
+
+      if (priv->expire_address_now) {
+        ephy_web_view_set_address (eview, loading_uri);
+      }
+      g_free (priv->status_message);
+      priv->status_message = g_strdup (priv->loading_title);
+      g_object_notify (object, "status-message");
+
+      ephy_web_view_set_title (eview, NULL);
+      ephy_web_view_set_loading_title (eview, loading_uri, TRUE);
+      priv->expire_address_now = TRUE;
+
+      g_object_thaw_notify (object);
+
+      g_free (loading_uri);
+    }
+    break;
+  case WEBKIT_LOAD_COMMITTED:
+    {
+      const gchar* uri;
+      EphyWebViewSecurityLevel security_level;
+
+      uri = webkit_web_view_get_uri (web_view);
+      ephy_web_view_location_changed (eview,
+                                      uri);
+
+      ephy_web_view_set_title (eview, NULL);
+
+      /*
+       * FIXME: as a temporary workaround while soup lacks the needed
+       * security API, determine security level based on the existence of
+       * a 'https' prefix for the URI
+       */
+      if (uri && g_str_has_prefix (uri, "https"))
+        security_level = EPHY_WEB_VIEW_STATE_IS_SECURE_HIGH;
+      else
+        security_level = EPHY_WEB_VIEW_STATE_IS_UNKNOWN;
+
+      ephy_web_view_set_security_level (EPHY_WEB_VIEW (web_view), security_level);
+    }
+    break;
+  case WEBKIT_LOAD_FINISHED:
+    g_object_freeze_notify (object);
+
+    g_free (priv->status_message);
+    priv->status_message = NULL;
+    g_object_notify (object, "status-message");
+    ephy_web_view_set_loading_title (eview, NULL, FALSE);
+
+    g_object_thaw_notify (object);
+
+    if (ephy_web_view_get_is_blank (eview))
+      g_object_notify (object, "embed-title");
 
-  if (status == WEBKIT_LOAD_FINISHED) {
     if (ephy_has_private_profile () == FALSE &&
         eel_gconf_get_boolean (CONF_PRIVACY_REMEMBER_PASSWORDS))
-      _ephy_web_view_hook_into_forms (EPHY_WEB_VIEW (web_view));
+      _ephy_web_view_hook_into_forms (eview);
 
-    _ephy_web_view_hook_into_links (EPHY_WEB_VIEW (web_view));
+    _ephy_web_view_hook_into_links (eview);
+    break;
+  case WEBKIT_LOAD_FAILED:
+    g_object_freeze_notify (object);
+
+    g_free (priv->status_message);
+    ephy_web_view_set_link_message (eview, NULL);
+    _ephy_web_view_set_icon_address (eview, NULL);
+    ephy_web_view_set_title (eview, _("Problem loading page"));
+    ephy_web_view_set_loading_title (eview, NULL, FALSE);
+    priv->status_message = NULL;
+    g_object_notify (object, "status-message");
+
+    update_navigation_flags (eview);
+
+    g_object_thaw_notify (object);
+    break;
+  default:
+    break;
   }
 }
 
@@ -2310,144 +2429,6 @@ ephy_web_view_get_title (EphyWebView *view)
   return view->priv->title;
 }
 
-static void
-ensure_page_info (EphyWebView *view, const char *address)
-{
-  EphyWebViewPrivate *priv = view->priv;
-
-  if ((priv->address == NULL || priv->address[0] == '\0') &&
-      priv->expire_address_now == TRUE) {
-    ephy_web_view_set_address (view, address);
-  }
-
-  /* FIXME huh?? */
-  if (priv->title == NULL || priv->title[0] == '\0') {
-    ephy_web_view_set_title (view, NULL);
-  }
-}
-
-static void
-update_net_state_message (EphyWebView *view, const char *uri, EphyWebViewNetState flags)
-{
-  const char *msg = NULL;
-  char *host = NULL;
-
-  if (uri != NULL)
-    host = ephy_string_get_host_name (uri);
-
-  if (host == NULL) goto out;
-
-  /* IS_REQUEST and IS_NETWORK can be both set */
-  if (flags & EPHY_WEB_VIEW_STATE_IS_REQUEST) {
-    if (flags & EPHY_WEB_VIEW_STATE_REDIRECTING) {
-      msg = _ ("Redirecting to “%s”…");
-    } else if (flags & EPHY_WEB_VIEW_STATE_TRANSFERRING) {
-      msg = _ ("Transferring data from “%s”…");
-    } else if (flags & EPHY_WEB_VIEW_STATE_NEGOTIATING) {
-      msg = _ ("Waiting for authorization from “%s”…");
-    }
-  }
-
-  if (flags & EPHY_WEB_VIEW_STATE_IS_NETWORK) {
-    if (flags & EPHY_WEB_VIEW_STATE_START) {
-      msg = _ ("Loading “%s”…");
-    }
-  }
-
-  if ((flags & EPHY_WEB_VIEW_STATE_IS_NETWORK) &&
-      (flags & EPHY_WEB_VIEW_STATE_STOP)) {
-    g_free (view->priv->status_message);
-    view->priv->status_message = NULL;
-    g_object_notify (G_OBJECT (view), "status-message");
-
-  } else if (msg != NULL) {
-    g_free (view->priv->status_message);
-    g_free (view->priv->loading_title);
-    view->priv->status_message = g_strdup_printf (msg, host);
-    view->priv->loading_title = g_strdup_printf (msg, host);
-    g_object_notify (G_OBJECT (view), "status-message");
-    g_object_notify (G_OBJECT (view), "embed-title");
-  }
-
- out:
-    g_free (host);
-}
-
-static void
-update_navigation_flags (EphyWebView *view)
-{
-  EphyWebViewPrivate *priv = view->priv;
-  guint flags = 0;
-  WebKitWebView *web_view = WEBKIT_WEB_VIEW (view);
-
-  if (ephy_web_view_can_go_up (view)) {
-    flags |= EPHY_WEB_VIEW_NAV_UP;
-  }
-
-  if (webkit_web_view_can_go_back (web_view)) {
-    flags |= EPHY_WEB_VIEW_NAV_BACK;
-  }
-
-  if (webkit_web_view_can_go_forward (web_view)) {
-    flags |= EPHY_WEB_VIEW_NAV_FORWARD;
-  }
-
-  if (priv->nav_flags != (EphyWebViewNavigationFlags)flags) {
-    priv->nav_flags = (EphyWebViewNavigationFlags)flags;
-
-    g_object_notify (G_OBJECT (view), "navigation");
-  }
-}
-
-/**
- * ephy_web_view_update_from_net_state:
- * @view: an #EphyWebView
- * @uri: the uri associated with @view
- * @state: an #EphyWebViewNetState
- *
- * Update @view at @uri with info from @state.
- **/
-void
-ephy_web_view_update_from_net_state (EphyWebView *view,
-                                     const char *uri,
-                                     EphyWebViewNetState state)
-{
-  EphyWebViewPrivate *priv = view->priv;
-
-  update_net_state_message (view, uri, state);
-
-  if (state & EPHY_WEB_VIEW_STATE_IS_NETWORK) {
-    if (state & EPHY_WEB_VIEW_STATE_START) {
-      GObject *object = G_OBJECT (view);
-
-      g_object_freeze_notify (object);
-
-      ensure_page_info (view, uri);
-
-      priv->expire_address_now = TRUE;
-
-      g_object_notify (object, "embed-title");
-
-      g_object_thaw_notify (object);
-    } else if (state & EPHY_WEB_VIEW_STATE_STOP) {
-      GObject *object = G_OBJECT (view);
-
-      g_object_freeze_notify (object);
-
-      g_free (priv->loading_title);
-      priv->loading_title = NULL;
-
-      priv->expire_address_now = TRUE;
-
-      g_object_notify (object, "embed-title");
-
-      g_object_thaw_notify (object);
-    }
-
-    update_navigation_flags (view);
-  }
-}
-
 /**
  * ephy_web_view_set_loading_title:
  * @view: an #EphyWebView
diff --git a/embed/ephy-web-view.h b/embed/ephy-web-view.h
index 37852bc..058b72f 100644
--- a/embed/ephy-web-view.h
+++ b/embed/ephy-web-view.h
@@ -54,22 +54,6 @@ typedef enum
 
 typedef enum
 {
-	EPHY_WEB_VIEW_STATE_UNKNOWN		= 0,
-	EPHY_WEB_VIEW_STATE_START		= 1 << 0,
-	EPHY_WEB_VIEW_STATE_REDIRECTING		= 1 << 1,
-	EPHY_WEB_VIEW_STATE_TRANSFERRING	= 1 << 2,
-	EPHY_WEB_VIEW_STATE_NEGOTIATING		= 1 << 3,
-	EPHY_WEB_VIEW_STATE_STOP		= 1 << 4,
-
-	EPHY_WEB_VIEW_STATE_IS_REQUEST	= 1 << 5,
-	EPHY_WEB_VIEW_STATE_IS_DOCUMENT	= 1 << 6,
-	EPHY_WEB_VIEW_STATE_IS_NETWORK	= 1 << 7,
-	EPHY_WEB_VIEW_STATE_IS_WINDOW	= 1 << 8,
-	EPHY_WEB_VIEW_STATE_RESTORING	= 1 << 9
-} EphyWebViewNetState;
-
-typedef enum
-{
 	EPHY_WEB_VIEW_CHROME_MENUBAR		= 1 << 0,
 	EPHY_WEB_VIEW_CHROME_TOOLBAR		= 1 << 1,
 	EPHY_WEB_VIEW_CHROME_STATUSBAR		= 1 << 2,
@@ -208,9 +192,6 @@ const char *               ephy_web_view_get_title_composite     (EphyWebView
 /* These should be private */
 void                       ephy_web_view_set_address             (EphyWebView                     *view,
                                                                   const char                      *address);
-void                       ephy_web_view_update_from_net_state   (EphyWebView                     *view,
-                                                                  const char                      *uri,
-                                                                  EphyWebViewNetState              state);
 void                       ephy_web_view_location_changed        (EphyWebView                     *view,
                                                                   const char                      *location);
 void                       ephy_web_view_set_loading_title       (EphyWebView                     *view,
