return;
if (!(g_file_test (filename, G_FILE_TEST_EXISTS)))
+ g_file_set_contents (filename, "", -1, NULL);
+
+ file = g_file_new_for_path (filename);
+ if ((stream = (GOutputStream*)g_file_append_to (file, 0, NULL, NULL)))
{
- /* FIXME: Is there are better ways to create a file? like touch */
- FILE* cffd;
- cffd = g_fopen (filename,"w");
- fclose (cffd);
+ g_output_stream_write (stream, chunk->data, chunk->length, NULL, NULL);
+ g_object_unref (stream);
}
- file = g_file_new_for_path (filename);
- stream = (GOutputStream*)g_file_append_to (file, 0, NULL, NULL);
- g_output_stream_write (stream, chunk->data, chunk->length, NULL, NULL);
- g_output_stream_close (stream, NULL, NULL);
g_object_unref (file);
}
SoupMessageHeaders *hdrs = msg->response_headers;
gint length;
+ /* Skip files downloaded by the user */
+ if (g_object_get_data (G_OBJECT (msg), "midori-web-cache-download"))
+ return;
+
/* Skip big files */
length = GPOINTER_TO_INT (soup_message_headers_get_one (hdrs, "Content-Length"));
if (length > MAXLENGTH)
}
if (!(g_strcmp0 (uri, webkit_web_frame_get_uri (web_frame))
- && g_strcmp0 (webkit_web_data_source_get_unreachable_uri (webkit_web_frame_get_data_source (web_frame)), uri)))
+ && g_strcmp0 (webkit_web_data_source_get_unreachable_uri (
+ webkit_web_frame_get_data_source (web_frame)), uri)))
{
web_cache_replace_frame_uri (extension, uri, web_frame);
g_free (filename);
#endif
}
+#if WEBKIT_CHECK_VERSION (1, 1, 3)
+static void
+web_cache_add_download_cb (MidoriBrowser* browser,
+ WebKitDownload* download,
+ MidoriExtension* extension)
+{
+ WebKitNetworkRequest* request = webkit_download_get_network_request (download);
+ SoupMessage* msg = webkit_network_request_get_message (request);
+ if (msg)
+ g_object_set_data (G_OBJECT (msg), "midori-web-cache-download",
+ (gpointer)0xdeadbeef);
+}
+#endif
+
static void
web_cache_deactivate_cb (MidoriExtension* extension,
MidoriBrowser* browser);
(GtkCallback)web_cache_add_tab_foreach_cb, extension);
g_signal_connect (browser, "add-tab",
G_CALLBACK (web_cache_add_tab_cb), extension);
+ #if WEBKIT_CHECK_VERSION (1, 1, 3)
+ g_signal_connect (browser, "add-download",
+ G_CALLBACK (web_cache_add_download_cb), extension);
+ #endif
g_signal_connect (extension, "deactivate",
G_CALLBACK (web_cache_deactivate_cb), browser);
}
MidoriExtension* extension)
{
GtkWidget* web_view = gtk_bin_get_child (GTK_BIN (view));
- MidoriBrowser* browser = midori_browser_get_for_widget (web_view);
- g_signal_handlers_disconnect_by_func (
- browser, web_cache_add_tab_cb, 0);
#if HAVE_WEBKIT_RESOURCE_REQUEST
g_signal_handlers_disconnect_by_func (
web_view, web_cache_resource_request_starting_cb, extension);
#endif
- g_signal_handlers_disconnect_by_func (
- webkit_get_default_session (), web_cache_session_request_queued_cb, extension);
}
static void
extension, web_cache_deactivate_cb, browser);
g_signal_handlers_disconnect_by_func (
app, web_cache_app_add_browser_cb, extension);
+ g_signal_handlers_disconnect_by_func (
+ browser, web_cache_add_tab_cb, extension);
+ #if WEBKIT_CHECK_VERSION (1, 1, 3)
+ g_signal_handlers_disconnect_by_func (
+ browser, web_cache_add_download_cb, extension);
+ #endif
midori_browser_foreach (browser, (GtkCallback)web_cache_deactivate_tabs, extension);
}