[epiphany] Decouple the page load from the tab creation



commit 0b9fdf677e37eb508e119bf236ad86aa6e0daf8b
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Thu Feb 13 12:59:00 2014 +0100

    Decouple the page load from the tab creation
    
    The flags used to decide whether to load the page and how are confusing,
    because they are mutually exclusive, which adds more complexity to
    ephy_shell_new_tab. Also, ephy_shell_new_tab doesn't always create a new
    tab, depending on the parameters and flags, it might reuse an existing
    empty tab. All this is easier to handle from the callers if we make
    ephy_shell_new_tab always create a new tab that is returned and callers
    can decide what to load in the new tab.

 src/bookmarks/ephy-bookmarks-editor.c |   56 ++++++------
 src/ephy-history-window.c             |   15 ++--
 src/ephy-navigation-history-action.c  |    3 -
 src/ephy-session.c                    |   47 +++++-----
 src/ephy-shell.c                      |  155 +++++++++++----------------------
 src/ephy-shell.h                      |   31 ++-----
 src/ephy-window.c                     |   44 ++++++----
 src/popup-commands.c                  |   32 ++++---
 src/window-commands.c                 |   10 ++-
 tests/ephy-shell-test.c               |   26 +++---
 10 files changed, 181 insertions(+), 238 deletions(-)
---
diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c
index 76e31b5..9db50c3 100644
--- a/src/bookmarks/ephy-bookmarks-editor.c
+++ b/src/bookmarks/ephy-bookmarks-editor.c
@@ -295,6 +295,17 @@ get_target_window (EphyBookmarksEditor *editor)
 }
 
 static void
+load_bookmark_in_tab (EphyNode *node,
+                      EphyEmbed *embed)
+{
+        const char *location;
+
+        location = ephy_node_get_property_string (node,
+                                                  EPHY_NODE_BMK_PROP_LOCATION);
+        ephy_web_view_load_url (ephy_embed_get_web_view (embed), location);
+}
+
+static void
 cmd_open_bookmarks_in_tabs (GtkAction *action,
                            EphyBookmarksEditor *editor)
 {
@@ -309,14 +320,12 @@ cmd_open_bookmarks_in_tabs (GtkAction *action,
        {
                EphyNode *node = l->data;
                EphyEmbed *new_embed;
-               const char *location;
-
-               location = ephy_node_get_property_string (node,
-                                               EPHY_NODE_BMK_PROP_LOCATION);
 
                new_embed = ephy_shell_new_tab (ephy_shell_get_default (),
-                                               window, NULL, location,
-                                               EPHY_NEW_TAB_OPEN_PAGE);
+                                               window, NULL,
+                                               0);
+                load_bookmark_in_tab (node, new_embed);
+
                /* if there was no target window, a new one was opened. Get it
                 * from the new tab so we open the remaining links in the
                 * same window. See bug 138343.
@@ -345,14 +354,11 @@ cmd_open_bookmarks_in_browser (GtkAction *action,
        for (l = selection; l; l = l->next)
        {
                EphyNode *node = l->data;
-               const char *location;
-
-               location = ephy_node_get_property_string (node,
-                                               EPHY_NODE_BMK_PROP_LOCATION);
+                EphyEmbed *embed;
 
-               ephy_shell_new_tab (ephy_shell_get_default (),
-                                   window, NULL, location,
-                                   EPHY_NEW_TAB_OPEN_PAGE);
+                embed = ephy_shell_new_tab (ephy_shell_get_default (),
+                                            window, NULL, 0);
+                load_bookmark_in_tab (node, embed);
        }
 
        g_list_free (selection);
@@ -1038,15 +1044,11 @@ ephy_bookmarks_editor_node_activated_cb (GtkWidget *view,
                                         EphyNode *node,
                                         EphyBookmarksEditor *editor)
 {
-       const char *location;
+        EphyEmbed *embed;
 
-       location = ephy_node_get_property_string
-               (node, EPHY_NODE_BMK_PROP_LOCATION);
-       g_return_if_fail (location != NULL);
-
-       ephy_shell_new_tab (ephy_shell_get_default (),
-                           NULL, NULL, location,
-                           EPHY_NEW_TAB_OPEN_PAGE);
+       embed = ephy_shell_new_tab (ephy_shell_get_default (),
+                                    NULL, NULL, 0);
+        load_bookmark_in_tab (node, embed);
 }
 
 static void
@@ -1055,17 +1057,13 @@ ephy_bookmarks_editor_node_middle_clicked_cb (GtkWidget *view,
                                              EphyBookmarksEditor *editor)
 {
        EphyWindow *window;
-       const char *location;
+        EphyEmbed *embed;
 
        window = EPHY_WINDOW (get_target_window (editor));
 
-       location = ephy_node_get_property_string
-               (node, EPHY_NODE_BMK_PROP_LOCATION);
-       g_return_if_fail (location != NULL);
-
-       ephy_shell_new_tab (ephy_shell_get_default (),
-                           window, NULL, location,
-                           EPHY_NEW_TAB_OPEN_PAGE);
+       embed = ephy_shell_new_tab (ephy_shell_get_default (),
+                                    window, NULL, 0);
+        load_bookmark_in_tab (node, embed);
 }
 
 static void
diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c
index ddc26f3..03af3c7 100644
--- a/src/ephy-history-window.c
+++ b/src/ephy-history-window.c
@@ -307,9 +307,11 @@ open_selected (EphyHistoryWindow *self)
        window = EPHY_WINDOW (get_target_window (self));
        for (l = selection; l; l = l->next) {
                EphyHistoryURL *url = l->data;
-               ephy_shell_new_tab (ephy_shell_get_default (),
-                                   window, NULL, url->url,
-                                   EPHY_NEW_TAB_OPEN_PAGE);
+               EphyEmbed *embed;
+
+               embed = ephy_shell_new_tab (ephy_shell_get_default (),
+                                           window, NULL, 0);
+               ephy_web_view_load_url (ephy_embed_get_web_view (embed), url->url);
        }
 
        g_list_free_full (selection, (GDestroyNotify) ephy_history_url_free);
@@ -421,15 +423,16 @@ on_treeview_row_activated (GtkTreeView *view,
 {
        EphyWindow *window;
        EphyHistoryURL *url;
+       EphyEmbed *embed;
 
        window = EPHY_WINDOW (get_target_window (self));
        url = get_url_from_path (gtk_tree_view_get_model (view),
                                 path);
        g_return_if_fail (url != NULL);
 
-       ephy_shell_new_tab (ephy_shell_get_default (),
-                           window, NULL, url->url,
-                           EPHY_NEW_TAB_OPEN_PAGE);
+       embed = ephy_shell_new_tab (ephy_shell_get_default (),
+                                   window, NULL, 0);
+       ephy_web_view_load_url (ephy_embed_get_web_view (embed), url->url);
        ephy_history_url_free (url);
 }
 
diff --git a/src/ephy-navigation-history-action.c b/src/ephy-navigation-history-action.c
index ca6fa15..2028053 100644
--- a/src/ephy-navigation-history-action.c
+++ b/src/ephy-navigation-history-action.c
@@ -115,7 +115,6 @@ action_activate (GtkAction *action)
       embed = ephy_shell_new_tab (ephy_shell_get_default (),
                                   EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (embed))),
                                   NULL,
-                                  NULL,
                                   0);
 
       web_view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
@@ -143,7 +142,6 @@ action_activate (GtkAction *action)
       embed = ephy_shell_new_tab (ephy_shell_get_default (),
                                   EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (embed))),
                                   embed,
-                                  NULL,
                                   0);
 
       web_view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
@@ -327,7 +325,6 @@ middle_click_handle_on_history_menu_item (EphyNavigationHistoryAction *action,
   new_embed = ephy_shell_new_tab (ephy_shell_get_default (),
                                   EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (embed))),
                                   embed,
-                                  NULL,
                                   0);
   g_return_if_fail (new_embed != NULL);
 
diff --git a/src/ephy-session.c b/src/ephy-session.c
index bcff252..44b1768 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -231,9 +231,7 @@ ephy_session_undo_close_tab (EphySession *session)
        EphySessionPrivate *priv;
        EphyEmbed *embed, *new_tab;
        ClosedTab *tab;
-       EphyNewTabFlags flags = EPHY_NEW_TAB_OPEN_PAGE
-               | EPHY_NEW_TAB_PRESENT_WINDOW
-               | EPHY_NEW_TAB_JUMP;
+       EphyNewTabFlags flags = EPHY_NEW_TAB_PRESENT_WINDOW | EPHY_NEW_TAB_JUMP;
 
        g_return_if_fail (EPHY_IS_SESSION (session));
 
@@ -264,7 +262,7 @@ ephy_session_undo_close_tab (EphySession *session)
 
                window = gtk_widget_get_toplevel (GTK_WIDGET (*tab->parent_location));
                new_tab = ephy_shell_new_tab (ephy_shell_get_default (),
-                                             EPHY_WINDOW (window), embed, tab->url,
+                                             EPHY_WINDOW (window), embed,
                                              flags);
                post_restore_cleanup (priv->closed_tabs, tab, FALSE);
        }
@@ -274,7 +272,7 @@ ephy_session_undo_close_tab (EphySession *session)
                EphyWindow *window = ephy_window_new ();
 
                new_tab = ephy_shell_new_tab (ephy_shell_get_default (),
-                                             window, NULL, tab->url, flags);
+                                             window, NULL, flags);
 
                /* FIXME: This makes the assumption that the notebook
                   is the parent of the returned EphyEmbed. */
@@ -283,6 +281,8 @@ ephy_session_undo_close_tab (EphySession *session)
                post_restore_cleanup (priv->closed_tabs, tab, TRUE);
        }
 
+       ephy_web_view_load_url (ephy_embed_get_web_view (new_tab), tab->url);
+       gtk_widget_grab_focus (GTK_WIDGET (new_tab));
        closed_tab_free (tab);
 
        if (g_queue_is_empty (priv->closed_tabs))
@@ -387,13 +387,15 @@ session_maybe_open_window (EphySession *session,
        if (ephy_shell_get_n_windows (shell) == 0)
        {
                EphyWindow *window = ephy_window_new ();
+               EphyEmbed *embed;
 
-               ephy_shell_new_tab_full (shell,
-                                        NULL /* related view */,
-                                        window, NULL /* tab */,
-                                        NULL /* NetworkRequest */,
-                                        EPHY_NEW_TAB_HOME_PAGE,
-                                        user_time);
+               embed = ephy_shell_new_tab_full (shell,
+                                                NULL /* related view */,
+                                                window, NULL /* tab */,
+                                                0,
+                                                user_time);
+               ephy_web_view_load_homepage (ephy_embed_get_web_view (embed));
+               ephy_window_activate_location (window);
        }
 }
 
@@ -908,7 +910,7 @@ confirm_before_recover (EphyWindow *window, const char *url, const char *title)
        EphyEmbed *embed;
 
        embed = ephy_shell_new_tab (ephy_shell_get_default (),
-                                   window, NULL, NULL,
+                                   window, NULL,
                                    EPHY_NEW_TAB_APPEND_LAST);
 
        ephy_web_view_load_error_page (ephy_embed_get_web_view (embed), url,
@@ -1058,22 +1060,21 @@ session_parse_embed (SessionParserContext *context,
 
                flags = EPHY_NEW_TAB_APPEND_LAST;
 
-               if (delay_loading)
-               {
-                       flags |= EPHY_NEW_TAB_DELAYED_OPEN_PAGE;
-               }
-               else
-               {
-                       flags |= EPHY_NEW_TAB_OPEN_PAGE;
-               }
-
                embed = ephy_shell_new_tab (ephy_shell_get_default (),
-                                           context->window, NULL, url, flags);
+                                           context->window, NULL, flags);
 
+               web_view = ephy_embed_get_web_view (embed);
                if (delay_loading)
                {
-                       web_view = ephy_embed_get_web_view (embed);
+                       WebKitURIRequest *request = webkit_uri_request_new (url);
+
+                       ephy_embed_set_delayed_load_request (embed, request);
                        ephy_web_view_set_placeholder (web_view, url, title);
+                       g_object_unref (request);
+               }
+               else
+               {
+                       ephy_web_view_load_url (web_view, url);
                }
        }
        else if (was_loading && url != NULL)
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index c3fad21..7bc94d7 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -648,7 +648,6 @@ ephy_shell_get_default (void)
  * @shell: a #EphyShell
  * @window: the target #EphyWindow or %NULL
  * @previous_embed: the referrer embed, or %NULL
- * @request: a #WebKitNetworkRequest to load or %NULL
  * @user_time: a timestamp, or 0
  *
  * Create a new tab and the parent window when necessary.
@@ -661,32 +660,23 @@ ephy_shell_new_tab_full (EphyShell *shell,
                          WebKitWebView *related_view,
                          EphyWindow *window,
                          EphyEmbed *previous_embed,
-                         WebKitURIRequest *request,
                          EphyNewTabFlags flags,
                          guint32 user_time)
 {
   EphyEmbedShell *embed_shell;
+  GtkWidget *web_view;
   EphyEmbed *embed = NULL;
-  gboolean open_page = FALSE;
-  gboolean delayed_open_page = FALSE;
   gboolean jump_to = FALSE;
-  gboolean active_is_blank = FALSE;
-  gboolean is_empty = FALSE;
   int position = -1;
 
   g_return_val_if_fail (EPHY_IS_SHELL (shell), NULL);
   g_return_val_if_fail (EPHY_IS_WINDOW (window), NULL);
   g_return_val_if_fail (EPHY_IS_EMBED (previous_embed) || !previous_embed, NULL);
-  g_return_val_if_fail (WEBKIT_IS_URI_REQUEST (request) || !request, NULL);
 
   embed_shell = EPHY_EMBED_SHELL (shell);
 
-  if (flags & EPHY_NEW_TAB_OPEN_PAGE) open_page = TRUE;
-  if (flags & EPHY_NEW_TAB_DELAYED_OPEN_PAGE) delayed_open_page = TRUE;
   if (flags & EPHY_NEW_TAB_JUMP) jump_to = TRUE;
 
-  g_return_val_if_fail ((open_page || delayed_open_page) == (gboolean)(request != NULL), NULL);
-
   LOG ("Opening new tab window %p parent-embed %p jump-to:%s",
        window, previous_embed, jump_to ? "t" : "f");
 
@@ -703,32 +693,14 @@ ephy_shell_new_tab_full (EphyShell *shell,
   if (flags & EPHY_NEW_TAB_FIRST)
     position = 0;
 
-  if (flags & EPHY_NEW_TAB_FROM_EXTERNAL && position == -1) {
-    /* If the active embed is blank, use that to open the url and jump to it */
-    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_web_view_is_overview (view)) &&
-          ephy_web_view_is_loading (view) == FALSE) {
-        active_is_blank = TRUE;
-      }
-    }
-  }
-
-  if (active_is_blank == FALSE) {
-    GtkWidget *web_view;
+  if (related_view)
+    web_view = ephy_web_view_new_with_related_view (related_view);
+  else
+    web_view = ephy_web_view_new ();
 
-    if (related_view)
-      web_view = ephy_web_view_new_with_related_view (related_view);
-    else
-      web_view = ephy_web_view_new ();
-
-    embed = EPHY_EMBED (g_object_new (EPHY_TYPE_EMBED, "web-view", web_view, NULL));
-    g_assert (embed != NULL);
-    gtk_widget_show (GTK_WIDGET (embed));
-
-    ephy_embed_container_add_child (EPHY_EMBED_CONTAINER (window), embed, position, jump_to);
-  }
+  embed = EPHY_EMBED (g_object_new (EPHY_TYPE_EMBED, "web-view", web_view, NULL));
+  gtk_widget_show (GTK_WIDGET (embed));
+  ephy_embed_container_add_child (EPHY_EMBED_CONTAINER (window), embed, position, jump_to);
 
   ephy_gui_window_update_user_time (GTK_WIDGET (window), user_time);
 
@@ -737,38 +709,6 @@ ephy_shell_new_tab_full (EphyShell *shell,
     gtk_widget_show (GTK_WIDGET (window));
   }
 
-  if (flags & EPHY_NEW_TAB_HOME_PAGE ||
-      flags & EPHY_NEW_TAB_NEW_PAGE) {
-    EphyWebView *view = ephy_embed_get_web_view (embed);
-    ephy_web_view_set_typed_address (view, "");
-    ephy_window_activate_location (window);
-    ephy_web_view_load_homepage (view);
-    is_empty = TRUE;
-  } else if (open_page) {
-    ephy_web_view_load_request (ephy_embed_get_web_view (embed),
-                                request);
-
-    is_empty = ephy_embed_utils_url_is_empty (webkit_uri_request_get_uri (request));
-  } else if (delayed_open_page)
-      ephy_embed_set_delayed_load_request (embed, request);
-
-  /* Make sure the initial focus is somewhere sensible and not, for
-   * example, on the reload button.
-   */
-  if (jump_to) {
-    /* If the location entry is blank, focus that, except if the
-     * page was a copy */
-    if (is_empty) {
-      /* empty page, focus location entry */
-      ephy_window_activate_location (window);
-    } else if ((flags & EPHY_NEW_TAB_DONT_SHOW_WINDOW) == 0 && embed != NULL &&
-               ephy_embed_shell_get_mode (embed_shell) != EPHY_EMBED_SHELL_MODE_TEST) {
-      /* non-empty page, focus the page. but make sure the widget is realised first! */
-      gtk_widget_realize (GTK_WIDGET (embed));
-      gtk_widget_grab_focus (GTK_WIDGET (embed));
-    }
-  }
-
   if (flags & EPHY_NEW_TAB_PRESENT_WINDOW &&
       ephy_embed_shell_get_mode (EPHY_EMBED_SHELL (embed_shell)) != EPHY_EMBED_SHELL_MODE_TEST)
     gtk_window_present_with_time (GTK_WINDOW (window), user_time);
@@ -781,7 +721,6 @@ ephy_shell_new_tab_full (EphyShell *shell,
  * @shell: a #EphyShell
  * @parent_window: the target #EphyWindow or %NULL
  * @previous_embed: the referrer embed, or %NULL
- * @url: an url to load or %NULL
  *
  * Create a new tab and the parent window when necessary.
  * Use this function to open urls in new window/tabs.
@@ -792,20 +731,11 @@ EphyEmbed *
 ephy_shell_new_tab (EphyShell *shell,
                     EphyWindow *parent_window,
                     EphyEmbed *previous_embed,
-                    const char *url,
                     EphyNewTabFlags flags)
 {
-  EphyEmbed *embed;
-  WebKitURIRequest *request = url ? webkit_uri_request_new (url) : NULL;
-
-  embed = ephy_shell_new_tab_full (shell, NULL, parent_window,
-                                   previous_embed, request, flags,
-                                   0);
-
-  if (request)
-    g_object_unref (request);
-
-  return embed;
+  return ephy_shell_new_tab_full (shell, NULL, parent_window,
+                                  previous_embed, flags,
+                                  0);
 }
 
 /**
@@ -1029,6 +959,15 @@ ephy_shell_close_all_windows (EphyShell *shell)
   return retval;
 }
 
+static gboolean
+tab_is_empty (EphyEmbed *embed)
+{
+  EphyWebView *view = ephy_embed_get_web_view (embed);
+
+  return ((ephy_web_view_get_is_blank (view) || ephy_web_view_is_overview (view)) &&
+          !ephy_web_view_is_loading (view));
+}
+
 typedef struct {
   EphyShell *shell;
   EphySession *session;
@@ -1038,6 +977,7 @@ typedef struct {
   guint32 user_time;
   EphyEmbed *previous_embed;
   guint current_uri;
+  gboolean reuse_empty_tab;
 } OpenURIsData;
 
 static OpenURIsData *
@@ -1067,8 +1007,9 @@ open_uris_data_new (EphyShell *shell,
   if (startup_flags & EPHY_STARTUP_NEW_WINDOW && !fullscreen_lockdown) {
     data->window = ephy_window_new ();
   } else if (startup_flags & EPHY_STARTUP_NEW_TAB || (new_windows_in_tabs && have_uris)) {
-    data->flags |= EPHY_NEW_TAB_JUMP | EPHY_NEW_TAB_PRESENT_WINDOW | EPHY_NEW_TAB_FROM_EXTERNAL;
+    data->flags |= EPHY_NEW_TAB_JUMP | EPHY_NEW_TAB_PRESENT_WINDOW;
     data->window = ephy_shell_get_main_window (shell);
+    data->reuse_empty_tab = TRUE;
   } else if (!have_uris) {
     data->window = ephy_window_new ();
   }
@@ -1091,34 +1032,40 @@ open_uris_data_free (OpenURIsData *data)
 static gboolean
 ephy_shell_open_uris_idle (OpenURIsData *data)
 {
-  EphyEmbed *embed;
-  EphyNewTabFlags page_flags;
+  EphyEmbed *embed = NULL;
+  EphyNewTabFlags page_flags = 0;
+  gboolean reusing_empty_tab = FALSE;
   const char *url;
-  WebKitURIRequest *request = NULL;
-
-  url = data->uris[data->current_uri];
-  if (url[0] == '\0') {
-    page_flags = EPHY_NEW_TAB_HOME_PAGE;
-  } else {
-    page_flags = EPHY_NEW_TAB_OPEN_PAGE;
-    if (data->previous_embed)
-      page_flags |= EPHY_NEW_TAB_APPEND_AFTER;
-    request = webkit_uri_request_new (url);
-  }
 
   if (!data->window)
     data->window = ephy_window_new ();
+  else if (data->previous_embed)
+    page_flags |= EPHY_NEW_TAB_APPEND_AFTER;
+  else if (data->reuse_empty_tab) {
+    embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (data->window));
+    reusing_empty_tab = tab_is_empty (embed);
+  }
+
+  if (!reusing_empty_tab) {
+    embed = ephy_shell_new_tab_full (ephy_shell_get_default (),
+                                     NULL,
+                                     data->window,
+                                     data->previous_embed,
+                                     data->flags | page_flags,
+                                     data->user_time);
+  }
 
-  embed = ephy_shell_new_tab_full (ephy_shell_get_default (),
-                                   NULL,
-                                   data->window,
-                                   data->previous_embed,
-                                   request,
-                                   data->flags | page_flags,
-                                   data->user_time);
+  url = data->uris[data->current_uri];
+  if (url[0] != '\0') {
+    ephy_web_view_load_url (ephy_embed_get_web_view (embed), url);
 
-  if (request)
-    g_object_unref (request);
+    /* When reusing an empty tab, the focus is in the location entry */
+    if (reusing_empty_tab || data->flags & EPHY_NEW_TAB_JUMP)
+      gtk_widget_grab_focus (GTK_WIDGET (embed));
+  } else {
+    ephy_web_view_load_homepage (ephy_embed_get_web_view (embed));
+    ephy_window_activate_location (data->window);
+  }
 
   data->current_uri++;
   data->previous_embed = embed;
diff --git a/src/ephy-shell.h b/src/ephy-shell.h
index a370c38..0ab78f3 100644
--- a/src/ephy-shell.h
+++ b/src/ephy-shell.h
@@ -52,20 +52,12 @@ typedef struct _EphyShellPrivate  EphyShellPrivate;
 
 /**
  * EphyNewTabFlags:
- * @EPHY_NEW_TAB_HOME_PAGE: loads the home page in the new tab.
- * @EPHY_NEW_TAB_NEW_PAGE: legacy synonym for @EPHY_NEW_TAB_HOME_PAGE.
- * @EPHY_NEW_TAB_OPEN_PAGE: opens the provided network-request.
- * @EPHY_NEW_TAB_DELAYED_OPEN_PAGE: store the provided network-request
- *        so that it will be opened when the tab is switched to.
- * @EPHY_NEW_TAB_FULLSCREEN_MODE: calls gtk_window_fullscreen on the
- *        parent window of the new tab.
  * @EPHY_NEW_TAB_DONT_SHOW_WINDOW: do not show the window where the new
  *        tab is attached.
  * @EPHY_NEW_TAB_APPEND_LAST: appends the new tab at the end of the
  *        notebook.
  * @EPHY_NEW_TAB_APPEND_AFTER: appends the new tab right after the
  *        current one in the notebook.
- * @EPHY_NEW_TAB_JUMP: jumps to the new tab immediately.
  * @EPHY_NEW_TAB_FROM_EXTERNAL: tries to open the new tab in the current
  *        active tab if it is currently not loading anything and is
  *        blank.
@@ -74,24 +66,15 @@ typedef struct _EphyShellPrivate  EphyShellPrivate;
  * Controls how new tabs/windows are created and handled.
  */
 typedef enum {
-  /* Page types */
-  EPHY_NEW_TAB_HOME_PAGE    = 1 << 0,
-  EPHY_NEW_TAB_NEW_PAGE   = 1 << 1,
-  EPHY_NEW_TAB_OPEN_PAGE    = 1 << 2,
-  EPHY_NEW_TAB_DELAYED_OPEN_PAGE    = 1 << 3,
-
   /* Page mode */
-  EPHY_NEW_TAB_DONT_SHOW_WINDOW = 1 << 4,
-  EPHY_NEW_TAB_PRESENT_WINDOW     = 1 << 5,
+  EPHY_NEW_TAB_DONT_SHOW_WINDOW = 1 << 0,
+  EPHY_NEW_TAB_PRESENT_WINDOW     = 1 << 1,
 
   /* Tabs */
-  EPHY_NEW_TAB_FIRST        = 1 << 6,
-  EPHY_NEW_TAB_APPEND_LAST  = 1 << 7,
-  EPHY_NEW_TAB_APPEND_AFTER = 1 << 8,
-  EPHY_NEW_TAB_JUMP   = 1 << 10,
-
-  /* The way to load */
-  EPHY_NEW_TAB_FROM_EXTERNAL      = 1 << 9,
+  EPHY_NEW_TAB_FIRST        = 1 << 2,
+  EPHY_NEW_TAB_APPEND_LAST  = 1 << 3,
+  EPHY_NEW_TAB_APPEND_AFTER = 1 << 4,
+  EPHY_NEW_TAB_JUMP   = 1 << 5,
 } EphyNewTabFlags;
 
 typedef enum {
@@ -131,14 +114,12 @@ EphyShell      *ephy_shell_get_default                  (void);
 EphyEmbed      *ephy_shell_new_tab                      (EphyShell *shell,
                                                          EphyWindow *parent_window,
                                                          EphyEmbed *previous_embed,
-                                                         const char *url,
                                                          EphyNewTabFlags flags);
 
 EphyEmbed      *ephy_shell_new_tab_full                 (EphyShell *shell,
                                                          WebKitWebView *related_view,
                                                          EphyWindow *parent_window,
                                                          EphyEmbed *previous_embed,
-                                                         WebKitURIRequest *request,
                                                          EphyNewTabFlags flags,
                                                          guint32 user_time);
 
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 2ac9230..ce5927c 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -547,13 +547,14 @@ ephy_window_open_link (EphyLink *link,
                      EPHY_LINK_NEW_TAB | 
                      EPHY_LINK_NEW_WINDOW))
        {
-               EphyNewTabFlags ntflags = EPHY_NEW_TAB_OPEN_PAGE;
+               EphyNewTabFlags ntflags = 0;
                EphyWindow *target_window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (embed)));
 
                if (flags & EPHY_LINK_JUMP_TO)
                {
                        ntflags |= EPHY_NEW_TAB_JUMP;
                }
+
                if (flags & EPHY_LINK_NEW_WINDOW ||
                    (flags & EPHY_LINK_NEW_TAB && priv->is_popup))
                {
@@ -563,15 +564,23 @@ ephy_window_open_link (EphyLink *link,
                if (flags & EPHY_LINK_NEW_TAB_APPEND_AFTER)
                        ntflags |= EPHY_NEW_TAB_APPEND_AFTER;
 
-               if (flags & EPHY_LINK_HOME_PAGE)
-               {
-                       ntflags |= EPHY_NEW_TAB_HOME_PAGE;
-               }
-
                new_embed = ephy_shell_new_tab
                                (ephy_shell_get_default (),
                                 target_window,
-                                embed, address, ntflags);
+                                embed, ntflags);
+               if (flags & EPHY_LINK_HOME_PAGE)
+               {
+                       ephy_web_view_load_homepage (ephy_embed_get_web_view (new_embed));
+                       ephy_window_activate_location (window);
+               }
+               else
+               {
+                       ephy_web_view_load_url (ephy_embed_get_web_view (new_embed), address);
+                       if (flags & EPHY_LINK_JUMP_TO)
+                       {
+                               gtk_widget_grab_focus (GTK_WIDGET (new_embed));
+                       }
+               }
        }
        else
        {
@@ -2041,9 +2050,10 @@ create_web_view_cb (WebKitWebView *web_view,
                                         web_view,
                                         target_window,
                                         EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (web_view),
-                                        NULL,
                                         flags,
                                         0);
+       if (target_window == window)
+               gtk_widget_grab_focus (GTK_WIDGET (embed));
 
        new_web_view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
        g_signal_connect (new_web_view, "ready-to-show",
@@ -2162,12 +2172,12 @@ decide_policy_cb (WebKitWebView *web_view,
        {
                gint button;
                gint state;
-               EphyNewTabFlags flags;
+               EphyEmbed *new_embed;
+               EphyNewTabFlags flags = 0;
                EphyWindow *target_window = window;
 
                button = webkit_navigation_policy_decision_get_mouse_button (navigation_decision);
                state = webkit_navigation_policy_decision_get_modifiers (navigation_decision);
-               flags = EPHY_NEW_TAB_OPEN_PAGE;
 
                ephy_web_view_set_visit_type (EPHY_WEB_VIEW (web_view),
                                              EPHY_PAGE_VISIT_LINK);
@@ -2205,13 +2215,13 @@ decide_policy_cb (WebKitWebView *web_view,
                embed = ephy_embed_container_get_active_child
                        (EPHY_EMBED_CONTAINER (window));
 
-               ephy_shell_new_tab_full (ephy_shell_get_default (),
-                                        NULL,
-                                        target_window,
-                                        embed,
-                                        request,
-                                        flags,
-                                        0);
+               new_embed = ephy_shell_new_tab_full (ephy_shell_get_default (),
+                                                    NULL,
+                                                    target_window,
+                                                    embed,
+                                                    flags,
+                                                    0);
+               ephy_web_view_load_request (ephy_embed_get_web_view (new_embed), request);
 
                webkit_policy_decision_ignore (decision);
 
diff --git a/src/popup-commands.c b/src/popup-commands.c
index 861a70d..bcc55bb 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -45,6 +45,7 @@ popup_cmd_link_in_new_window (GtkAction *action,
        EphyWindow *new_window;
        EphyEmbedEvent *event;
        EphyEmbed *embed;
+       EphyEmbed *new_embed;
        GValue value = { 0, };
 
        embed = ephy_embed_container_get_active_child 
@@ -56,10 +57,11 @@ popup_cmd_link_in_new_window (GtkAction *action,
        new_window = ephy_window_new ();
        ephy_embed_event_get_property (event, "link-uri", &value);
 
-       ephy_shell_new_tab (ephy_shell_get_default (),
-                           new_window, embed,
-                           g_value_get_string (&value),
-                           EPHY_NEW_TAB_OPEN_PAGE);
+       new_embed = ephy_shell_new_tab (ephy_shell_get_default (),
+                                       new_window, embed,
+                                       0);
+       ephy_web_view_load_url (ephy_embed_get_web_view (new_embed),
+                               g_value_get_string (&value));
        g_value_unset (&value);
 }
 
@@ -69,6 +71,7 @@ popup_cmd_link_in_new_tab (GtkAction *action,
 {
        EphyEmbedEvent *event;
        EphyEmbed *embed;
+       EphyEmbed *new_embed;
        GValue value = { 0, };
 
        embed = ephy_embed_container_get_active_child
@@ -79,11 +82,11 @@ popup_cmd_link_in_new_tab (GtkAction *action,
 
        ephy_embed_event_get_property (event, "link-uri", &value);
 
-       ephy_shell_new_tab (ephy_shell_get_default (),
-                           window, embed,
-                           g_value_get_string (&value),
-                           EPHY_NEW_TAB_OPEN_PAGE |
-                           EPHY_NEW_TAB_APPEND_AFTER);
+       new_embed = ephy_shell_new_tab (ephy_shell_get_default (),
+                                       window, embed,
+                                       EPHY_NEW_TAB_APPEND_AFTER);
+       ephy_web_view_load_url (ephy_embed_get_web_view (new_embed),
+                               g_value_get_string (&value));
        g_value_unset (&value);
 }
 
@@ -312,6 +315,7 @@ popup_cmd_view_image_in_new_tab (GtkAction *action,
        EphyEmbedEvent *event;
        GValue value = { 0, };
        EphyEmbed *embed;
+       EphyEmbed *new_embed;
 
        event = ephy_window_get_context_event (window);
        g_return_if_fail (event != NULL);
@@ -321,11 +325,11 @@ popup_cmd_view_image_in_new_tab (GtkAction *action,
 
        ephy_embed_event_get_property (event, "image-uri", &value);
 
-       ephy_shell_new_tab (ephy_shell_get_default (),
-                           window, embed,
-                           g_value_get_string (&value),
-                           EPHY_NEW_TAB_OPEN_PAGE |
-                           EPHY_NEW_TAB_APPEND_AFTER);
+       new_embed = ephy_shell_new_tab (ephy_shell_get_default (),
+                                       window, embed,
+                                       EPHY_NEW_TAB_APPEND_AFTER);
+       ephy_web_view_load_url (ephy_embed_get_web_view (new_embed),
+                               g_value_get_string (&value));
        g_value_unset (&value);
 }
 
diff --git a/src/window-commands.c b/src/window-commands.c
index a1d38a4..4c6c411 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -906,11 +906,13 @@ void
 window_cmd_file_new_window (GtkAction *action,
                            EphyWindow *window)
 {
+       EphyEmbed *embed;
        EphyWindow *new_window = ephy_window_new ();
 
-       ephy_shell_new_tab (ephy_shell_get_default (),
-                           new_window, NULL, NULL,
-                           EPHY_NEW_TAB_HOME_PAGE);
+       embed = ephy_shell_new_tab (ephy_shell_get_default (),
+                                   new_window, NULL, 0);
+       ephy_web_view_load_homepage (ephy_embed_get_web_view (embed));
+       ephy_window_activate_location (window);
 }
 
 void
@@ -1190,13 +1192,13 @@ view_source_embedded (const char *uri, EphyEmbed *embed)
                        (ephy_shell_get_default (),
                         EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (embed))),
                         embed,
-                        NULL,
                         EPHY_NEW_TAB_JUMP | EPHY_NEW_TAB_APPEND_AFTER);
 
        webkit_web_view_set_view_mode
                (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (new_embed), WEBKIT_VIEW_MODE_SOURCE);
        webkit_web_view_load_uri
                (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (new_embed), uri);
+       gtk_widget_grab_focus (GTK_WIDGET (new_embed));
 }
 
 
diff --git a/tests/ephy-shell-test.c b/tests/ephy-shell-test.c
index 079a47f..8e09a6c 100644
--- a/tests/ephy-shell-test.c
+++ b/tests/ephy-shell-test.c
@@ -60,7 +60,6 @@ test_ephy_shell_basic_embeds (void)
                    NULL, /* related view */
                    window,
                    NULL, /* embed */
-                   NULL, /* network-request */
                    EPHY_NEW_TAB_DONT_SHOW_WINDOW, /* flags */
                    gtk_get_current_event_time ());
   g_assert (EPHY_IS_EMBED (embed1));
@@ -77,7 +76,6 @@ test_ephy_shell_basic_embeds (void)
                    NULL, /* related view */
                    window, /* window */
                    NULL, /* embed */
-                   NULL, /* network-request */
                    EPHY_NEW_TAB_DONT_SHOW_WINDOW, /* flags */
                    gtk_get_current_event_time ());
   g_assert (EPHY_IS_EMBED (embed2));
@@ -103,7 +101,7 @@ test_ephy_shell_parent_windows (void)
 
   /* parent-window provided */
   embed = ephy_shell_new_tab
-                  (ephy_shell, EPHY_WINDOW (window), NULL, NULL,
+                  (ephy_shell, EPHY_WINDOW (window), NULL,
                    EPHY_NEW_TAB_DONT_SHOW_WINDOW);
 
   g_assert (EPHY_IS_EMBED (embed));
@@ -114,7 +112,7 @@ test_ephy_shell_parent_windows (void)
   /* Another new-window */
   window2 = GTK_WIDGET (ephy_window_new ());
   embed = ephy_shell_new_tab
-                  (ephy_shell, EPHY_WINDOW (window2), NULL, NULL,
+                  (ephy_shell, EPHY_WINDOW (window2), NULL,
                    EPHY_NEW_TAB_DONT_SHOW_WINDOW);
 
   /* The parent window should be a completely new one. */
@@ -142,8 +140,9 @@ test_ephy_shell_tab_load (void)
 
   /* homepage is "about:blank" for now, see embed/ephy-web-view.c */
   embed = ephy_shell_new_tab
-                  (ephy_shell, EPHY_WINDOW (window), NULL, NULL,
-                   EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_HOME_PAGE);
+                  (ephy_shell, EPHY_WINDOW (window), NULL,
+                   EPHY_NEW_TAB_DONT_SHOW_WINDOW);
+  ephy_web_view_load_homepage (ephy_embed_get_web_view (embed));
 
   g_assert (EPHY_IS_EMBED (embed));
 
@@ -160,8 +159,9 @@ test_ephy_shell_tab_load (void)
 
   /* open-page "about:epiphany" for testing. */
   embed = ephy_shell_new_tab
-                  (ephy_shell, EPHY_WINDOW (window), NULL, "about:epiphany",
-                   EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_OPEN_PAGE);
+                  (ephy_shell, EPHY_WINDOW (window), NULL,
+                   EPHY_NEW_TAB_DONT_SHOW_WINDOW);
+  ephy_web_view_load_url (ephy_embed_get_web_view (embed), "about:epiphany");
 
   g_assert (EPHY_IS_EMBED (embed));
 
@@ -195,29 +195,29 @@ test_ephy_shell_tab_append (void)
   window = GTK_WIDGET (ephy_window_new ());
   notebook = ephy_window_get_notebook (EPHY_WINDOW (window));
 
-  embed1 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), NULL, NULL,
+  embed1 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), NULL,
                                EPHY_NEW_TAB_DONT_SHOW_WINDOW);
   g_assert_cmpint (get_notebook_page_num (notebook, embed1), ==, 0);
 
-  embed2 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), embed1, NULL,
+  embed2 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), embed1,
                                EPHY_NEW_TAB_DONT_SHOW_WINDOW);
   g_assert_cmpint (get_notebook_page_num (notebook, embed1), ==, 0);
   g_assert_cmpint (get_notebook_page_num (notebook, embed2), ==, 1);
 
-  embed3 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), embed1, NULL,
+  embed3 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), embed1,
                                EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_APPEND_AFTER);
   g_assert_cmpint (get_notebook_page_num (notebook, embed1), ==, 0);
   g_assert_cmpint (get_notebook_page_num (notebook, embed3), ==, 1);
   g_assert_cmpint (get_notebook_page_num (notebook, embed2), ==, 2);
 
-  embed4 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), embed1, NULL,
+  embed4 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), embed1,
                                EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_APPEND_LAST);
   g_assert_cmpint (get_notebook_page_num (notebook, embed1), ==, 0);
   g_assert_cmpint (get_notebook_page_num (notebook, embed3), ==, 1);
   g_assert_cmpint (get_notebook_page_num (notebook, embed2), ==, 2);
   g_assert_cmpint (get_notebook_page_num (notebook, embed4), ==, 3);
 
-  embed5 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), embed3, NULL,
+  embed5 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), embed3,
                                EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_APPEND_AFTER);
   g_assert_cmpint (get_notebook_page_num (notebook, embed1), ==, 0);
   g_assert_cmpint (get_notebook_page_num (notebook, embed3), ==, 1);


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