[Xfce4-commits] <midori:master> Check resources to see if a file has subresources

Christian Dywan noreply at xfce.org
Fri Oct 5 00:50:01 CEST 2012


Updating branch refs/heads/master
         to 81ab79c12969f927bebaad756b88d3a3451f59ef (commit)
       from bd1d4f8cc00cc62b826e2d786aed75b0275020dd (commit)

commit 81ab79c12969f927bebaad756b88d3a3451f59ef
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Oct 1 00:04:30 2012 +0200

    Check resources to see if a file has subresources

 katze/katze-net.c         |    2 +-
 midori/main.c             |    3 ++-
 midori/midori-browser.c   |   19 +++++++------------
 midori/midori-dialog.vala |   10 +++++++++-
 midori/midori-view.c      |   14 ++++++++++----
 midori/midori-view.h      |    3 +++
 tests/browser.c           |   13 +++++++++----
 7 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/katze/katze-net.c b/katze/katze-net.c
index 10b55bf..b17e368 100644
--- a/katze/katze-net.c
+++ b/katze/katze-net.c
@@ -96,7 +96,7 @@ katze_net_get_cached_path (KatzeNet*    net,
 
     if (subfolder)
     {
-        gchar* cache_path = g_build_filename (midori_paths_get_cache_dir (), subfolder, NULL);
+        gchar* cache_path = g_build_filename (midori_paths_get_cache_dir_for_reading (), subfolder, NULL);
         katze_mkdir_with_parents (cache_path, 0700);
         cached_path = g_build_filename (cache_path, cached_filename, NULL);
         g_free (cache_path);
diff --git a/midori/main.c b/midori/main.c
index dabe6c8..e56d4a3 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -1480,7 +1480,8 @@ static void
 signal_handler (int signal_id)
 {
     signal (signal_id, 0);
-    midori_app_quit_cb (NULL, NULL);
+    if (!midori_paths_is_readonly ())
+        midori_app_quit_cb (NULL, NULL);
     if (kill (getpid (), signal_id))
       exit (1);
 }
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 1f8c424..48efcb8 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -995,15 +995,10 @@ midori_browser_prepare_download (MidoriBrowser*  browser,
 }
 
 static void
-midori_browser_save_resources (MidoriView*  view,
+midori_browser_save_resources (GList*       resources,
                                const gchar* folder)
 {
-    WebKitWebView* web_view = WEBKIT_WEB_VIEW (midori_view_get_web_view (view));
-    WebKitWebFrame* frame = webkit_web_view_get_main_frame (web_view);
-    WebKitWebDataSource* data_source = webkit_web_frame_get_data_source (frame);
-    GList* resources = webkit_web_data_source_get_subresources (data_source);
     GList* list;
-
     katze_mkdir_with_parents (folder, 0700);
 
     for (list = resources; list; list = g_list_next (list))
@@ -1034,7 +1029,6 @@ midori_browser_save_resources (MidoriView*  view,
         g_free (sub_filename);
         g_free (sub_path);
     }
-    g_list_free (resources);
 }
 
 void
@@ -1046,6 +1040,7 @@ midori_browser_save_uri (MidoriBrowser* browser,
     GtkWidget* dialog;
     const gchar* title = midori_view_get_display_title (view);
     gchar* filename;
+    GList* resources = midori_view_get_subresources (view);
     gboolean file_only = TRUE;
     GtkWidget* checkbox = NULL;
 
@@ -1056,7 +1051,7 @@ midori_browser_save_uri (MidoriBrowser* browser,
     if (uri == NULL)
         uri = midori_view_get_display_uri (view);
 
-    if (midori_view_can_view_source (view))
+    if (resources != NULL && g_list_nth_data (resources, 1) != NULL)
     {
         file_only = FALSE;
         checkbox = gtk_check_button_new_with_mnemonic (_("Save associated _resources"));
@@ -1090,21 +1085,21 @@ midori_browser_save_uri (MidoriBrowser* browser,
     {
         filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
         if (checkbox != NULL)
-            file_only = !file_only && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox));
-        if (!file_only && !g_str_equal (title, uri))
+            file_only = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox));
+        if (!file_only)
         {
             gchar* fullname = g_strconcat (filename, ".html", NULL);
             midori_view_save_source (view, uri, fullname);
             g_free (fullname);
+            midori_browser_save_resources (resources, filename);
         }
         else
             midori_view_save_source (view, uri, filename);
-        if (!file_only)
-            midori_browser_save_resources (view, filename);
         katze_assign (last_dir,
             gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog)));
     }
     gtk_widget_destroy (dialog);
+    g_list_free (resources);
 }
 
 static void
diff --git a/midori/midori-dialog.vala b/midori/midori-dialog.vala
index f0f5b71..55b6bad 100644
--- a/midori/midori-dialog.vala
+++ b/midori/midori-dialog.vala
@@ -15,6 +15,11 @@ namespace Midori {
         public void set_dialog_response (Gtk.ResponseType response) {
             test_response = response;
         }
+
+        internal static string? test_filename = null;
+        public void set_file_chooser_filename (string filename) {
+            test_filename = filename;
+        }
     }
 
     public class FileChooserDialog : Gtk.FileChooserDialog {
@@ -35,8 +40,11 @@ namespace Midori {
 
     namespace Dialog {
         public static new int run (Gtk.Dialog dialog) {
-            if (Test.test_response != Gtk.ResponseType.NONE)
+            if (Test.test_response != Gtk.ResponseType.NONE) {
+                if (Test.test_filename != null && dialog is Gtk.FileChooser)
+                    (dialog as Gtk.FileChooser).set_filename (Test.test_filename);
                 return Test.test_response;
+            }
             return dialog.run ();
         }
     }
diff --git a/midori/midori-view.c b/midori/midori-view.c
index f5c14eb..e06b302 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -2115,14 +2115,20 @@ midori_web_view_menu_image_new_tab_activate_cb (GtkWidget*  widget,
     g_free (uri);
 }
 
-static GString*
-midori_view_get_data_for_uri (MidoriView*  view,
-                              const gchar* uri)
+GList*
+midori_view_get_subresources (MidoriView* view)
 {
     WebKitWebView* web_view = WEBKIT_WEB_VIEW (view->web_view);
     WebKitWebFrame* frame = webkit_web_view_get_main_frame (web_view);
     WebKitWebDataSource* data_source = webkit_web_frame_get_data_source (frame);
-    GList* resources = webkit_web_data_source_get_subresources (data_source);
+    return webkit_web_data_source_get_subresources (data_source);
+}
+
+static GString*
+midori_view_get_data_for_uri (MidoriView*  view,
+                              const gchar* uri)
+{
+    GList* resources = midori_view_get_subresources (view);
     GList* list;
     GString* result;
 
diff --git a/midori/midori-view.h b/midori/midori-view.h
index eba73fd..1e6f9fc 100644
--- a/midori/midori-view.h
+++ b/midori/midori-view.h
@@ -258,6 +258,9 @@ const gchar*
 midori_view_fallback_extension         (MidoriView*        view,
                                         const gchar*       extension);
 
+GList*
+midori_view_get_subresources           (MidoriView* view);
+
 G_END_DECLS
 
 #endif /* __MIDORI_VIEW_H__ */
diff --git a/tests/browser.c b/tests/browser.c
index e4db491..73c36b3 100644
--- a/tests/browser.c
+++ b/tests/browser.c
@@ -31,6 +31,7 @@ browser_create (void)
     MidoriBrowser* browser;
     gint n;
     gchar* temporary_downloads;
+    gchar* temporary_filename;
     GtkWidget* view;
     GFile* file;
     gchar* uri;
@@ -42,22 +43,26 @@ browser_create (void)
     settings = midori_web_settings_new ();
     g_object_set (app, "speed-dial", dial, "settings", settings, NULL);
     browser = midori_app_create_browser (app);
-    n = midori_browser_add_uri (browser, "about:blank");
+    file = g_file_new_for_commandline_arg ("./data/about.css");
+    uri = g_file_get_uri (file);
+    g_object_unref (file);
+    n = midori_browser_add_uri (browser, uri);
     view = midori_browser_get_nth_tab (browser, n);
 
     midori_test_set_dialog_response (GTK_RESPONSE_OK);
     temporary_downloads = g_dir_make_tmp ("saveXXXXXX", NULL);
+    temporary_filename = g_build_filename (temporary_downloads, "test.html", NULL);
+    midori_test_set_file_chooser_filename (temporary_filename);
     midori_settings_set_download_folder (MIDORI_SETTINGS (settings), temporary_downloads);
     midori_browser_save_uri (browser, MIDORI_VIEW (view), NULL);
 
     /* View source for local file: should NOT use temporary file */
-    file = g_file_new_for_commandline_arg ("./data/error.html");
-    uri = g_file_get_uri (file);
-    g_object_unref (file);
     n = midori_browser_add_uri (browser, uri);
     midori_browser_set_current_page (browser, n);
     g_assert_cmpstr (uri, ==, midori_browser_get_current_uri (browser));
     g_free (uri);
+    g_free (temporary_downloads);
+    g_free (temporary_filename);
 
     gtk_widget_destroy (GTK_WIDGET (browser));
     g_object_unref (settings);


More information about the Xfce4-commits mailing list