gtkieembed r211 - in trunk: . src



Author: hiikezoe
Date: Wed Feb  4 02:43:14 2009
New Revision: 211
URL: http://svn.gnome.org/viewvc/gtkieembed?rev=211&view=rev

Log:
2009-02-04  Hiroyuki Ikezoe  <poincare ikezoe net>

	* src/ie-bridge.cpp (_ie_bridge_set_whole_history): Load the first
	page in histroy if the browser has not been loaded any page and wait
	for DISPID_DOCUMENTCOMPLETE event to avoid crash.
	And try to remove the current item.



Modified:
   trunk/ChangeLog
   trunk/src/ie-bridge.cpp

Modified: trunk/src/ie-bridge.cpp
==============================================================================
--- trunk/src/ie-bridge.cpp	(original)
+++ trunk/src/ie-bridge.cpp	Wed Feb  4 02:43:14 2009
@@ -52,6 +52,7 @@
     gboolean can_go_forward;
     gboolean can_go_back;
     gboolean ready;
+    gboolean is_setting_history;
 
     IWebBrowser2 *web_browser;
     IEBrowserEventDispatcher *browser_event_dispatcher;
@@ -59,6 +60,9 @@
     IHTMLDocument2 *current_document;
     DWORD browser_event_cookie;
     DWORD document_event_cookie;
+#ifdef HAVE_TLOGSTG_H
+    ITravelLogEntry *old_current_entry;
+#endif
 };
 
 #define IE_BRIDGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_IE_BRIDGE, IEBridgePriv))
@@ -219,7 +223,11 @@
     priv->browser_event_cookie = 0;
     priv->document_event_cookie = 0;
     priv->ready = FALSE;
+    priv->is_setting_history = FALSE;
 
+#ifdef HAVE_TLOGSTG_H
+    priv->old_current_entry = NULL;
+#endif
     priv->document_event_dispatcher = new IEDocumentEventDispatcher (ie);
 }
 
@@ -234,6 +242,13 @@
         priv->browser_event_dispatcher = NULL;
     }
 
+#ifdef HAVE_TLOGSTG_H
+    if (priv->old_current_entry) {
+        priv->old_current_entry->Release ();
+        priv->old_current_entry = NULL;
+    }
+#endif
+
     if (priv->document_event_cookie) {
         _ie_bridge_disconnect_document_event_dispatcher (IE_BRIDGE (object));
     }
@@ -1301,8 +1316,10 @@
                                  NULL, NULL, NULL);
     utf16_title = g_utf8_to_utf16 (gtk_ie_embed_history_item_get_title (item), -1,
                                    NULL, NULL, NULL);
+
     travel_log->CreateEntry ((LPOLESTR) utf16_uri, (LPOLESTR) utf16_title,
                              NULL, FALSE, &entry);
+
     g_free (utf16_uri);
     g_free (utf16_title);
 
@@ -1361,6 +1378,38 @@
 #endif
 }
 
+#ifdef HAVE_TLOGSTG_H
+static void
+cb_new_entry_loaded (GtkIEEmbed *embed, gpointer data)
+{
+    IEBridgePriv *priv = IE_BRIDGE_GET_PRIVATE (data);
+    ITravelLogStg *travel_log = NULL;
+    ITravelLogEntry *entry = NULL;
+
+    g_signal_handlers_disconnect_by_func (priv->widget,
+                                          (gpointer)cb_new_entry_loaded,
+                                          data);
+    priv->is_setting_history = FALSE;
+
+    travel_log = _get_travel_log (IE_BRIDGE (data));
+    if (!travel_log)
+        return;
+
+    travel_log->RemoveEntry (priv->old_current_entry);
+    entry->Release ();
+}
+
+static void
+wait_for_loading_first_page (IEBridge *ie, const GList *history)
+{
+    GtkIEEmbedHistoryItem *item = GTK_IE_EMBED_HISTORY_ITEM (history->data);
+    _ie_bridge_load_url (ie, gtk_ie_embed_history_item_get_uri(item));
+    while (!_ie_bridge_is_ready (ie))
+        g_main_context_iteration (NULL, FALSE);
+}
+
+#endif
+
 void
 _ie_bridge_set_whole_history (IEBridge *ie,
                               const GList *history,
@@ -1374,24 +1423,38 @@
     ITravelLogEntry *old_current_entry = NULL;
     IEnumTravelLogEntry *enum_entry = NULL;
     guint count;
+    gboolean not_ready = FALSE;
+
+    if (!history)
+        return;
 
     travel_log = _get_travel_log (ie);
     if (!travel_log)
         return;
 
-    travel_log->EnumEntries (TLEF_ABSOLUTE, &enum_entry);
-    remove_entries_from_travel_log (travel_log, enum_entry);
-    enum_entry->Release ();
-
-    /* current entry can not be removed so we remove it after create new entries */
-    travel_log->GetRelativeEntry (0, &old_current_entry);
+    /* Load a page if the browser has not been loaded any page to avoid crash */
+    if (!_ie_bridge_is_ready (ie)) {
+        not_ready = TRUE;
+        wait_for_loading_first_page (ie, history);
+    } else {
+        travel_log->EnumEntries (TLEF_ABSOLUTE, &enum_entry);
+        if (enum_entry) {
+            remove_entries_from_travel_log (travel_log, enum_entry);
+            enum_entry->Release ();
+        }
+        /* current entry can not be removed so we remove it after create new entries */
+        travel_log->GetRelativeEntry (0, &old_current_entry);
+    }
 
     count = g_list_length ((GList *)history);
-    for (list = g_list_last ((GList *)history); list; list = g_list_previous (list)) {
+    if (not_ready)
+        count--;
+
+    for (list = g_list_last ((GList *)history); count > 0 && list; list = g_list_previous (list)) {
         GtkIEEmbedHistoryItem *item = GTK_IE_EMBED_HISTORY_ITEM (list->data);
         entry = create_travel_log_entry_from_history_item (travel_log, item);
 
-        if (count == current_position)
+        if (count + (not_ready ? 1 : 0 )== current_position)
             current_entry = entry;
         else
             entry->Release ();
@@ -1403,10 +1466,14 @@
         current_entry->Release ();
     }
 
-    if (old_current_entry) {
-        /* FIXME remove current entry after navigation to a new entry completed. */
-        /* travel_log->RemoveEntry (old_current_entry); */
-        old_current_entry->Release ();
+    if (!not_ready) {
+        IEBridgePriv *priv = IE_BRIDGE_GET_PRIVATE (ie);
+        priv->old_current_entry = old_current_entry;
+        g_signal_connect (priv->widget, "net-stop",
+                          G_CALLBACK (cb_new_entry_loaded), ie);
+
+        while (priv->is_setting_history) 
+            g_main_context_iteration (NULL, FALSE);
     }
     travel_log->Release ();
 #endif



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