Merge lp:~gero-bare/midori/webkit2download-bug-1173744 into lp:midori

Proposed by Gero.Bare
Status: Rejected
Rejected by: Cris Dywan
Proposed branch: lp:~gero-bare/midori/webkit2download-bug-1173744
Merge into: lp:midori
Diff against target: 935 lines (+381/-122)
8 files modified
extensions/CMakeLists.txt (+0/-1)
extensions/external-download-manager.vala (+28/-4)
midori/midori-browser.c (+72/-7)
midori/midori-download.vala (+58/-16)
midori/midori-view.c (+200/-85)
midori/midori-view.h (+7/-2)
midori/webkit2gtk-3.0.vapi (+6/-1)
tests/browser.c (+10/-6)
To merge this branch: bzr merge lp:~gero-bare/midori/webkit2download-bug-1173744
Reviewer Review Type Date Requested Status
gue5t gue5t Needs Fixing
Review via email: mp+217346@code.launchpad.net

This proposal supersedes a proposal from 2014-04-21.

Commit message

Fill in caps of WebKit2 file saving, external download manager and transfers

Description of the change

This branch add the download feature, adds external-download-manager and change the save page mechanism to asynchronous in midori-webkit2.

This branch breaks the download test in webkit2 only. Need further refactoring.
The branch has been build several times in webkit2 and webkit. I think that I didn't broke anything else so far.

I'm eager to listen comments.

To post a comment you must log in.
Revision history for this message
gue5t gue5t (gue5t) wrote : Posted in a previous version of this proposal

Cool, we do need downloads working right with wk2. :)

That said, there are numerous whitespace/style issues in the patch: added and removed blank lines, use of tab characters in files which are indented with spaces, inconsistent presence of spaces around '=', and a couple merge conflicts in the source.

The phrasing of the Aria2 error message could be clarified, and it might also do to add a comment why we are comparing against 200. Are we showing an error dialog if the website returns a non-200 status code to Aria2 (this would be poor form), or is communication between Midori and Aria2 using HTTP (please forgive my ignorance on this point)?

review: Needs Fixing
Revision history for this message
Gero.Bare (gero-bare) wrote : Posted in a previous version of this proposal

Ok I'm working on it. I will try my best shoot.
Sorry about the tabs... I didn't check my configuration.

Yeah Aria2, this was a headache. I lost few hours till I discovered that I
not only needed the extension working and aria2 working, it sould be
running with rpc... According to the current current plug-in aria2 was
working, but I never saw the download in the Transfer nor in my file
system. After I discovered that I was receiving a null response, the
plug-in never warn me about it.

Aria2 works as a command line downloader, but also as a download manager
with an http service. You can use the later connecting you through the port
6800 by using XML or json. This is a very cool feature because you can
manage downloads via Internet. But I'm not very good using the XML service.
Probably there's a better solution.

2014-04-21 11:32 GMT-03:00 gue5t gue5t <email address hidden>:

> Review: Needs Fixing
>
> Cool, we do need downloads working right with wk2. :)
>
> That said, there are numerous whitespace/style issues in the patch: added
> and removed blank lines, use of tab characters in files which are indented
> with spaces, inconsistent presence of spaces around '=', and a couple merge
> conflicts in the source.
>
> The phrasing of the Aria2 error message could be clarified, and it might
> also do to add a comment why we are comparing against 200. Are we showing
> an error dialog if the website returns a non-200 status code to Aria2 (this
> would be poor form), or is communication between Midori and Aria2 using
> HTTP (please forgive my ignorance on this point)?
> --
>
> https://code.launchpad.net/~gero-bare/midori/webkit2download-bug-1173744/+merge/216574
> You are the owner of lp:~gero-bare/midori/webkit2download-bug-1173744.
>

Revision history for this message
gue5t gue5t (gue5t) wrote :

The code doesn't seem to compile at present: it needs ifdef guards moved to the outside of midori_browser_save_resources to avoid an unused function warning, it needs the unused variable file_only to be removed from midori_browser_save_midori_view, and the uri in midori_browser_save_midori_view is declared "gchar * uri" instead of "const gchar* uri".

In addition, please double-check code style; several instances of newlines are removed without code changes and tabs are added to extensions/external-download-manager.vala which is indented with spaces.

Aside the compilation (I worked around locally) and style issues, the code works well except that the "action icon" on downloads doesn't change to the "clean" broom when the download is stopped with webkit2. Almost there!

Finally, make sure you don't remove "external-download-manager.vala" from CMakeLists.txt in the final version of the branch.

review: Needs Fixing

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'extensions/CMakeLists.txt'
2--- extensions/CMakeLists.txt 2014-03-02 16:09:22 +0000
3+++ extensions/CMakeLists.txt 2014-04-26 18:11:30 +0000
4@@ -18,7 +18,6 @@
5 "cookie-permissions"
6 "addons.c"
7 "formhistory"
8- "external-download-manager.vala"
9 "nojs"
10 "nsplugin-manager.vala"
11 )
12
13=== modified file 'extensions/external-download-manager.vala'
14--- extensions/external-download-manager.vala 2014-02-18 21:15:56 +0000
15+++ extensions/external-download-manager.vala 2014-04-26 18:11:30 +0000
16@@ -41,12 +41,17 @@
17
18 if (download_type == Midori.DownloadType.SAVE) {
19 var dlReq = new DownloadRequest ();
20+ #if HAVE_WEBKIT2
21+ dlReq.uri = download.request.get_uri ();
22+ weak MessageHeaders headers =download.request.get_http_headers();
23+ #else
24 dlReq.uri = download.get_uri ();
25-
26 var request = download.get_network_request ();
27 var message = request.get_message ();
28 weak MessageHeaders headers = message.request_headers;
29-
30+ #endif
31+
32+
33 dlReq.auth = headers.get ("Authorization");
34 dlReq.referer = headers.get ("Referer");
35 dlReq.cookie_header = this.cookie_jar.get_cookies (new Soup.URI (dlReq.uri), true);
36@@ -102,7 +107,11 @@
37 }
38
39 construct {
40+ #if HAVE_WEBKIT2
41+ var session= new Session();
42+ #else
43 var session = WebKit.get_default_session ();
44+ #endif
45 this.cookie_jar = session.get_feature (typeof (CookieJar)) as CookieJar;
46 }
47 }
48@@ -159,7 +168,23 @@
49 typeof(HashTable), options);
50 var session = new SessionSync ();
51 session.send_message (message);
52-
53+
54+ /* Check if the plug-in actually recieved an reply.
55+ * The parse method do not warns us about it. And the exception
56+ * never is launched.*/
57+ if(message.status_code != 200){
58+ var dialog = new MessageDialog (null, DialogFlags.MODAL,
59+ MessageType.ERROR, ButtonsType.CLOSE,
60+ _("The plug-in was unable to connect with aria2:\n" +
61+ "Please make sure that aria2 is running with rpc enabled ie: aria2c --enable-rpc\n" +
62+ "If it's so, check it also is using the port 6800.\n" +
63+ "Lastly Check the configuration of your firewall.\n" +
64+ "Whitelist aria2 and the port 6800 if they aren't."
65+ ));
66+ dialog.response.connect ((a) => { dialog.destroy (); });
67+ dialog.run ();
68+
69+ }
70 try {
71 Value v;
72 XMLRPC.parse_method_response ((string) message.response_body.flatten ().data, -1, out v);
73@@ -344,4 +369,3 @@
74 extensions.add_item (new EDM.CommandLine ());
75 return extensions;
76 }
77-
78
79=== modified file 'midori/midori-browser.c'
80--- midori/midori-browser.c 2014-04-16 21:00:49 +0000
81+++ midori/midori-browser.c 2014-04-26 18:11:30 +0000
82@@ -152,7 +152,11 @@
83
84 static void
85 midori_browser_finalize (GObject* object);
86-
87+#ifdef HAVE_WEBKIT2
88+void download_created_destination_cb (WebKitDownload *download,
89+ gchar *destination,
90+ gpointer user_data);
91+#endif
92 static void
93 midori_browser_set_property (GObject* object,
94 guint prop_id,
95@@ -1246,15 +1250,16 @@
96 const gchar* uri)
97
98 {
99-#ifndef HAVE_WEBKIT2
100 if (!midori_download_has_enough_space (download, uri, FALSE))
101 return FALSE;
102+#ifdef HAVE_WEBKIT2
103+ webkit_download_set_destination (download, uri);
104+#else
105 webkit_download_set_destination_uri (download, uri);
106+#endif
107 g_signal_emit (browser, signals[ADD_DOWNLOAD], 0, download);
108 return TRUE;
109-#else
110- return FALSE;
111-#endif
112+
113 }
114
115 static void
116@@ -1296,6 +1301,7 @@
117 #endif
118 }
119
120+#ifndef HAVE_WEBKIT2
121 void
122 midori_browser_save_uri (MidoriBrowser* browser,
123 MidoriView* view,
124@@ -1308,7 +1314,6 @@
125 GList* resources = midori_view_get_resources (view);
126 gboolean file_only = TRUE;
127 GtkWidget* checkbox = NULL;
128-
129 dialog = (GtkWidget*)midori_file_chooser_dialog_new (_("Save file as"),
130 GTK_WINDOW (browser), GTK_FILE_CHOOSER_ACTION_SAVE);
131 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
132@@ -1366,6 +1371,57 @@
133 gtk_widget_destroy (dialog);
134 g_list_free (resources);
135 }
136+#else
137+void
138+midori_browser_save_midori_view (MidoriBrowser* browser,
139+ MidoriView* view)
140+{
141+ static gchar* last_dir = NULL;
142+ GtkWidget* dialog;
143+ const gchar* title = midori_view_get_display_title (view);
144+ gchar* filename;
145+ gboolean file_only = TRUE;
146+
147+ dialog = (GtkWidget*)midori_file_chooser_dialog_new (_("Save file as"),
148+ GTK_WINDOW (browser), GTK_FILE_CHOOSER_ACTION_SAVE);
149+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
150+ if (last_dir && *last_dir)
151+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), last_dir);
152+ else
153+ {
154+ gchar * uri = midori_view_get_display_uri (view);
155+ gchar* dirname = midori_uri_get_folder (uri);
156+ if (dirname == NULL)
157+ dirname = katze_object_get_string (browser->settings, "download-folder");
158+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), dirname);
159+ g_free (dirname);
160+ }
161+ filename = midori_download_clean_filename (title);
162+
163+
164+ gchar* suggested_filename = g_strconcat (filename, ".mhtml", NULL);
165+
166+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), suggested_filename);
167+ g_free (filename);
168+ g_free (suggested_filename);
169+ if (midori_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
170+ {
171+ char *uri;
172+ uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
173+ if (uri != NULL)
174+ {
175+ if (uri != NULL)
176+ {
177+ midori_view_save_source (view, uri,false);
178+ }
179+ g_free (uri);
180+ }
181+ katze_assign (last_dir,
182+ gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog)));
183+ }
184+ gtk_widget_destroy (dialog);
185+}
186+#endif
187
188 static void
189 midori_browser_speed_dial_refresh_cb (MidoriSpeedDial* dial,
190@@ -1699,7 +1755,6 @@
191 g_signal_connect (dialog, "destroy",
192 G_CALLBACK (gtk_widget_destroyed), &dialog);
193 }
194-
195 filename = midori_download_get_suggested_filename (download);
196 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
197 g_free (filename);
198@@ -1752,6 +1807,12 @@
199 return handled;
200 }
201
202+void download_created_destination_cb (WebKitDownload *download,
203+ gchar *destination,
204+ gpointer user_data){
205+ g_print("%s: destination %s",G_STRFUNC,destination);
206+}
207+
208 static void
209 midori_view_search_text_cb (GtkWidget* view,
210 gboolean found,
211@@ -2627,7 +2688,11 @@
212 MidoriBrowser* browser)
213 {
214 GtkWidget* view = midori_browser_get_current_tab (browser);
215+ #ifndef HAVE_WEBKIT2
216 midori_browser_save_uri (browser, MIDORI_VIEW (view), NULL);
217+ #else
218+ midori_browser_save_midori_view (browser, MIDORI_VIEW (view));
219+ #endif
220 }
221
222 static void
223
224=== modified file 'midori/midori-download.vala'
225--- midori/midori-download.vala 2014-03-06 22:22:37 +0000
226+++ midori/midori-download.vala 2014-04-26 18:11:30 +0000
227@@ -10,9 +10,7 @@
228 */
229
230 namespace Sokoke {
231-#if !HAVE_WEBKIT2
232 extern static bool message_dialog (Gtk.MessageType type, string short, string detailed, bool modal);
233-#endif
234 }
235
236 namespace Midori {
237@@ -28,6 +26,8 @@
238 return false;
239 }
240 #else
241+ if (download.estimated_progress == 1)
242+ return true;
243 return false;
244 #endif
245 }
246@@ -40,6 +40,14 @@
247 download.set_data<int> ("midori-download-type", type);
248 }
249
250+#if HAVE_WEBKIT2
251+ public static string get_filename (WebKit.Download download) {
252+ return download.get_data<string> ("midori-download-filename");
253+ }
254+ public static void set_filename (WebKit.Download download, string name) {
255+ download.set_data<string> ("midori-download-filename", name);
256+ }
257+#endif
258 public static double get_progress (WebKit.Download download) {
259 #if !HAVE_WEBKIT2
260 /* Avoid a bug in WebKit */
261@@ -47,7 +55,7 @@
262 return 0.0;
263 return download.progress;
264 #else
265- return 0.0;
266+ return download.estimated_progress;
267 #endif
268 }
269
270@@ -110,39 +118,57 @@
271
272 return "%s\n%s %s%s".printf (filename, size, speed, eta);
273 #else
274- return "";
275+ string filename = Midori.Download.get_basename_for_display(download.destination);
276+
277+ string size = "%s".printf (format_size (download.get_received_data_length()));
278+ string speed = "";
279+ speed = format_size ((uint64)((download.get_received_data_length()*1.0)/download.elapsed_time));
280+ speed = _(" (%s/s)").printf (speed);
281+ string progress = "%d%%".printf((int)(download.get_estimated_progress()*100));
282+ if (is_finished (download))
283+ return "%s\n %s".printf (filename,size);
284+ return "%s\n %s - %s".printf (filename,speed,progress);
285 #endif
286 }
287
288 public static string get_content_type (WebKit.Download download, string? mime_type) {
289-#if !HAVE_WEBKIT2
290+#if HAVE_WEBKIT2
291+ string? content_type = ContentType.guess (download.response.suggested_filename == null?
292+ download.destination : download.response.suggested_filename,
293+ null,null);
294+#else
295 string? content_type = ContentType.guess (download.suggested_filename, null, null);
296+#endif
297 if (content_type == null) {
298 content_type = ContentType.from_mime_type (mime_type);
299 if (content_type == null)
300 content_type = ContentType.from_mime_type ("application/octet-stream");
301 }
302 return content_type;
303-#else
304- return ContentType.from_mime_type ("application/octet-stream");
305-#endif
306 }
307
308 public static bool has_wrong_checksum (WebKit.Download download) {
309-#if !HAVE_WEBKIT2
310 int status = download.get_data<int> ("checksum-status");
311 if (status == 0) {
312 /* Link Fingerprint */
313+ #if HAVE_WEBKIT2
314+ string? original_uri = download.request.uri;
315+ #else
316 string? original_uri = download.network_request.get_data<string> ("midori-original-uri");
317 if (original_uri == null)
318 original_uri = download.get_uri ();
319+ #endif
320 string? fingerprint;
321 ChecksumType checksum_type = URI.get_fingerprint (original_uri, out fingerprint, null);
322 /* By default, no wrong checksum */
323 status = 2;
324 if (fingerprint != null) {
325 try {
326+ #if HAVE_WEBKIT2
327+ string filename = Filename.from_uri (download.destination);
328+ #else
329 string filename = Filename.from_uri (download.destination_uri);
330+ #endif
331 string contents;
332 size_t length;
333 bool y = FileUtils.get_contents (filename, out contents, out length);
334@@ -158,9 +184,7 @@
335 download.set_data<int> ("checksum-status", status);
336 }
337 return status == 1;
338-#else
339- return false;
340-#endif
341+
342 }
343
344 public static bool action_clear (WebKit.Download download, Gtk.Widget widget) throws Error {
345@@ -181,6 +205,14 @@
346 warn_if_reached ();
347 break;
348 }
349+ #else
350+
351+ if(download.estimated_progress<1){
352+ download.cancel ();
353+ }else{
354+ if (open (download, widget))
355+ return true;
356+ }
357 #endif
358 return false;
359 }
360@@ -205,13 +237,17 @@
361 return Gtk.Stock.MISSING_IMAGE;
362 }
363 #else
364- return Gtk.Stock.MISSING_IMAGE;
365+ if (download.estimated_progress == 1)
366+ if (has_wrong_checksum (download))
367+ return Gtk.Stock.DIALOG_WARNING;
368+ else
369+ return Gtk.Stock.OPEN;
370+ return Gtk.Stock.CANCEL;
371 #endif
372 }
373
374 /* returns whether an application was successfully launched to handle the file */
375 public static bool open (WebKit.Download download, Gtk.Widget widget) throws Error {
376-#if !HAVE_WEBKIT2
377 if (has_wrong_checksum (download)) {
378 Sokoke.message_dialog (Gtk.MessageType.WARNING,
379 _("The downloaded file is erroneous."),
380@@ -223,9 +259,12 @@
381 Tab? tab = null;
382 browser.get ("tab", &tab);
383 if (tab != null)
384+ #if HAVE_WEBKIT2
385+ return tab.open_uri (download.destination);
386+ #else
387 return tab.open_uri (download.destination_uri);
388+ #endif
389 }
390-#endif
391 return false;
392 }
393
394@@ -257,7 +296,10 @@
395 https://d19vezwu8eufl6.cloudfront.net/nlp/slides%2F03-01-FormalizingNB.pdf */
396 return clean_filename (download.get_suggested_filename ());
397 #else
398- return "";
399+ string name = get_filename(download);
400+ if (name == null)
401+ return "";
402+ return name;
403 #endif
404 }
405
406
407=== modified file 'midori/midori-view.c'
408--- midori/midori-view.c 2014-04-16 23:19:21 +0000
409+++ midori/midori-view.c 2014-04-26 18:11:30 +0000
410@@ -67,9 +67,13 @@
411 gpointer user_data);
412
413 static void
414-midori_view_download_requested_cb (WebKitWebContext* context,
415- WebKitDownload* download,
416- gpointer user_data);
417+midori_view_download_started_cb (WebKitWebContext* context,
418+ WebKitDownload* download,
419+ MidoriView * view);
420+static gboolean
421+midori_view_download_query_action (MidoriView* view,
422+ WebKitDownload* download,
423+ const gchar * suggested_filename );
424 #endif
425
426 static gboolean
427@@ -378,16 +382,6 @@
428 "The associated settings",
429 MIDORI_TYPE_WEB_SETTINGS,
430 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
431-
432- #ifdef HAVE_WEBKIT2
433- WebKitWebContext* context = webkit_web_context_get_default ();
434- webkit_web_context_register_uri_scheme (context,
435- "res", midori_view_uri_scheme_res, NULL, NULL);
436- webkit_web_context_register_uri_scheme (context,
437- "stock", midori_view_uri_scheme_res, NULL, NULL);
438- g_signal_connect (context, "download-started",
439- (GCallback)midori_view_download_requested_cb, NULL);
440- #endif
441 }
442
443 static void
444@@ -1988,14 +1982,17 @@
445 {
446 #ifdef HAVE_WEBKIT2
447 WebKitDownload* download = webkit_web_view_download_uri (WEBKIT_WEB_VIEW (view->web_view), uri);
448+ WebKitWebContext * web_context = webkit_web_view_get_context(WEBKIT_WEB_VIEW (view->web_view));
449+ midori_download_set_type (download, type);
450+ g_signal_emit_by_name(web_context,"download-started",download,view);
451 #else
452 WebKitNetworkRequest* request = webkit_network_request_new (uri);
453 WebKitDownload* download = webkit_download_new (request);
454 g_object_unref (request);
455-#endif
456+ midori_download_set_type (download, type);
457 gboolean handled;
458- midori_download_set_type (download, type);
459 g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
460+ #endif
461 }
462
463 static void
464@@ -2712,14 +2709,80 @@
465 }
466 #endif
467
468+gint
469+midori_save_dialog(const gchar* title,
470+ const gchar * hostname,
471+ const GString* details,
472+ const gchar *content_type)
473+{
474+ GIcon* icon;
475+ GtkWidget* image;
476+ GdkScreen* screen;
477+ GtkWidget* dialog= NULL;
478+ GtkIconTheme* icon_theme;
479+ gint response;
480+ dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
481+ _("Open or download file from %s"), hostname);
482+ icon = g_content_type_get_icon (content_type);
483+ g_themed_icon_append_name (G_THEMED_ICON (icon), "text-html");
484+ image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
485+ gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
486+ g_object_unref (icon);
487+ gtk_widget_show (image);
488+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
489+ "%s", details->str);
490+ screen = gtk_widget_get_screen (dialog);
491+
492+ gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
493+ if (screen)
494+ {
495+ icon_theme = gtk_icon_theme_get_for_screen (screen);
496+ if (gtk_icon_theme_has_icon (icon_theme, MIDORI_STOCK_TRANSFER))
497+ gtk_window_set_icon_name (GTK_WINDOW (dialog), MIDORI_STOCK_TRANSFER);
498+ else
499+ gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_OPEN);
500+ }
501+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
502+ GTK_STOCK_SAVE, MIDORI_DOWNLOAD_SAVE,
503+ GTK_STOCK_SAVE_AS, MIDORI_DOWNLOAD_SAVE_AS,
504+ GTK_STOCK_CANCEL, MIDORI_DOWNLOAD_CANCEL,
505+ GTK_STOCK_OPEN, MIDORI_DOWNLOAD_OPEN,
506+ NULL);
507+
508+ response = midori_dialog_run (GTK_DIALOG (dialog));
509+
510+ gtk_widget_destroy (dialog);
511+ if (response == GTK_RESPONSE_DELETE_EVENT)
512+ response = MIDORI_DOWNLOAD_CANCEL;
513+ return response;
514+}
515+
516 #ifdef HAVE_WEBKIT2
517+static gboolean
518+midori_view_download_decide_destination_cb (WebKitDownload* download,
519+ const gchar * suggested_filename,
520+ MidoriView* view)
521+{
522+ if(!midori_view_download_query_action(view,download,suggested_filename)){
523+ webkit_download_cancel (download);
524+ }
525+ return TRUE; //we must return TRUE because we handled the signal
526+}
527+
528 static void
529-midori_view_download_requested_cb (WebKitWebContext* context,
530- WebKitDownload* download,
531- gpointer user_data)
532-{
533- WebKitWebView* web_view = webkit_download_get_web_view (download);
534- MidoriView* view = midori_view_get_for_widget (GTK_WIDGET (web_view));
535+midori_view_download_started_cb (WebKitWebContext* context,
536+ WebKitDownload* download,
537+ MidoriView *view)
538+{
539+ g_signal_connect (download, "decide-destination",
540+ G_CALLBACK (midori_view_download_decide_destination_cb), view);
541+}
542+
543+static gboolean
544+midori_view_download_query_action (MidoriView* view,
545+ WebKitDownload* download,
546+ const gchar * suggested_filename)
547+{
548 #else
549 static gboolean
550 midori_view_download_requested_cb (GtkWidget* web_view,
551@@ -2727,42 +2790,36 @@
552 MidoriView* view)
553 {
554 #endif
555- gchar* opener_uri;
556+ gboolean handled = TRUE;
557 gchar* hostname;
558- GtkWidget* dialog;
559 gchar* content_type;
560 gchar* description;
561+ gchar* title;
562+ gint response;
563 GString* details;
564- GIcon* icon;
565- GtkWidget* image;
566- gchar* title;
567- GdkScreen* screen;
568- GtkIconTheme* icon_theme;
569- gint response;
570- gboolean handled;
571-
572 /* Opener may differ from displaying view:
573 http://lcamtuf.coredump.cx/fldl/ http://lcamtuf.coredump.cx/switch/ */
574- opener_uri = g_object_get_data (G_OBJECT (view), "opener-uri");
575+ const gchar* opener_uri = g_object_get_data (G_OBJECT (view), "opener-uri");
576 hostname = midori_uri_parse_hostname (
577 opener_uri ? opener_uri : midori_view_get_display_uri (view), NULL);
578- dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
579- _("Open or download file from %s"), hostname);
580- g_free (hostname);
581+
582+ #ifdef HAVE_WEBKIT2
583+ content_type = g_content_type_guess (suggested_filename, NULL ,
584+ 0 ,NULL);
585+ if (!content_type)
586+ content_type = g_strdup("application/octet-stream");
587+ midori_download_set_filename (download, g_strdup (suggested_filename));
588+ #else
589 content_type = midori_download_get_content_type (download,
590 g_object_get_data (G_OBJECT (view), "download-mime-type"));
591+ #endif
592 description = g_content_type_get_description (content_type);
593- icon = g_content_type_get_icon (content_type);
594- g_themed_icon_append_name (G_THEMED_ICON (icon), "text-html");
595- image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
596- g_object_unref (icon);
597- gtk_widget_show (image);
598- gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
599
600 details = g_string_sized_new (20 * 4);
601 #ifdef HAVE_WEBKIT2
602+ const gchar * suggestion = webkit_uri_response_get_suggested_filename (webkit_download_get_response (download));
603 g_string_append_printf (details, _("File Name: %s"),
604- webkit_uri_response_get_suggested_filename (webkit_download_get_response (download)));
605+ suggestion ? suggestion : suggested_filename);
606 #else
607 g_string_append_printf (details, _("File Name: %s"),
608 webkit_download_get_suggested_filename (download));
609@@ -2774,8 +2831,6 @@
610 else
611 g_string_append_printf (details, _("File Type: %s ('%s')"), description, content_type);
612 g_string_append_c (details, '\n');
613- g_free (description);
614- g_free (content_type);
615
616 #ifndef HAVE_WEBKIT2
617 /* Link Fingerprint */
618@@ -2816,53 +2871,22 @@
619 }
620 #endif
621
622- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
623- "%s", details->str);
624- g_string_free (details, TRUE);
625-
626- gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
627 #ifdef HAVE_WEBKIT2
628 /* i18n: A file open dialog title, ie. "Open http://fila.com/manual.tgz" */
629 title = g_strdup_printf (_("Open %s"), webkit_uri_request_get_uri (webkit_download_get_request (download)));
630 #else
631 title = g_strdup_printf (_("Open %s"), webkit_download_get_uri (download));
632 #endif
633- gtk_window_set_title (GTK_WINDOW (dialog), title);
634+ response = midori_save_dialog (title,
635+ hostname, details, content_type); //We prompt a dialog
636 g_free (title);
637- screen = gtk_widget_get_screen (dialog);
638- if (screen)
639- {
640- icon_theme = gtk_icon_theme_get_for_screen (screen);
641- if (gtk_icon_theme_has_icon (icon_theme, MIDORI_STOCK_TRANSFER))
642- gtk_window_set_icon_name (GTK_WINDOW (dialog), MIDORI_STOCK_TRANSFER);
643- else
644- gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_OPEN);
645- }
646- gtk_dialog_add_buttons (GTK_DIALOG (dialog),
647- GTK_STOCK_SAVE, MIDORI_DOWNLOAD_SAVE,
648- GTK_STOCK_SAVE_AS, MIDORI_DOWNLOAD_SAVE_AS,
649- GTK_STOCK_CANCEL, MIDORI_DOWNLOAD_CANCEL,
650- GTK_STOCK_OPEN, MIDORI_DOWNLOAD_OPEN,
651- NULL);
652-
653- response = midori_dialog_run (GTK_DIALOG (dialog));
654- gtk_widget_destroy (dialog);
655- if (response == GTK_RESPONSE_DELETE_EVENT)
656- response = MIDORI_DOWNLOAD_CANCEL;
657+ g_free (hostname);
658+ g_free (description);
659+ g_free (content_type);
660+ g_string_free (details, TRUE);
661 midori_download_set_type (download, response);
662-
663- /* TODO
664- g_object_connect (download,
665- "signal::decide-destination", download_decide_destination_cb, view,
666- "signal::created-destination", download_created_destination_cb, view,
667- "signal::finished", download_finished_cb, view,
668- "signal::failed", download_failed_cb, view,
669- NULL);
670- */
671 g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
672-#ifndef HAVE_WEBKIT2
673 return handled;
674-#endif
675 }
676
677 #ifndef HAVE_WEBKIT2
678@@ -3602,6 +3626,13 @@
679 g_signal_connect (view->web_view, "web-process-crashed",
680 (GCallback)midori_view_web_view_crashed_cb, view);
681 view->scrolled_window = view->web_view;
682+ WebKitWebContext* context = webkit_web_view_get_context (WEBKIT_WEB_VIEW (view->web_view));
683+ webkit_web_context_register_uri_scheme (context,
684+ "res", midori_view_uri_scheme_res, NULL, NULL);
685+ webkit_web_context_register_uri_scheme (context,
686+ "stock", midori_view_uri_scheme_res, NULL, NULL);
687+ g_signal_connect (context, "download-started",
688+ G_CALLBACK (midori_view_download_started_cb), view);
689 #endif
690
691 #if GTK_CHECK_VERSION(3, 2, 0)
692@@ -4287,6 +4318,59 @@
693 || !g_str_has_prefix (midori_tab_get_mime_type (MIDORI_TAB (view)), "image/"));
694 }
695
696+#ifdef HAVE_WEBKIT2
697+static void
698+midori_web_resource_get_data_cb (WebKitWebResource *resource,
699+ GAsyncResult *result,
700+ GOutputStream *output_stream)
701+{
702+ guchar *data;
703+ gsize data_length;
704+ GInputStream *input_stream;
705+ GError *error = NULL;
706+
707+ data = webkit_web_resource_get_data_finish (resource, result, &data_length, &error);
708+ if (!data) {
709+ g_printerr ("Failed to save page: %s", error->message);
710+ g_error_free (error);
711+ g_object_unref (output_stream);
712+
713+ return;
714+ }
715+
716+ input_stream = g_memory_input_stream_new_from_data (data, data_length, g_free);
717+ g_output_stream_splice_async (output_stream, input_stream,
718+ G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
719+ G_PRIORITY_DEFAULT,
720+ NULL, NULL, NULL);
721+ g_object_unref (input_stream);
722+ g_object_unref (output_stream);
723+}
724+
725+static void
726+midori_web_view_save_main_resource_cb (GFile *file,
727+ GAsyncResult *result,
728+ WebKitWebView *view)
729+{
730+ GFileOutputStream *output_stream;
731+ WebKitWebResource *resource;
732+ GError *error = NULL;
733+
734+ output_stream = g_file_replace_finish (file, result, &error);
735+ if (!output_stream) {
736+ g_printerr ("Failed to save page: %s", error->message);
737+ g_error_free (error);
738+ return;
739+ }
740+
741+ resource = webkit_web_view_get_main_resource (view);
742+ webkit_web_resource_get_data (resource, NULL,
743+ (GAsyncReadyCallback)midori_web_resource_get_data_cb,
744+ output_stream);
745+}
746+#endif
747+
748+#ifndef HAVE_WEBKIT2
749 /**
750 * midori_view_save_source:
751 * @view: a #MidoriView
752@@ -4305,7 +4389,6 @@
753 const gchar* outfile,
754 gboolean use_dom)
755 {
756-#ifndef HAVE_WEBKIT2
757 WebKitWebFrame *frame;
758 WebKitWebDataSource *data_source;
759 const GString *data;
760@@ -4375,10 +4458,43 @@
761 close (fd);
762 }
763 return unique_filename;
764+}
765 #else
766- return NULL;
767+/**
768+ * midori_view_save_source:
769+ * @view: a #MidoriView
770+ * @uri: an alternative destination URI, or %NULL
771+ *
772+ * Saves the data in the view to disk.
773+ *
774+ * Return value: the destination filename
775+ *
776+ * Since: 0.4.4
777+ **/
778+void
779+midori_view_save_source (MidoriView* view,
780+ const gchar* uri,
781+ gboolean use_dom)
782+{
783+ GFile *file;
784+ char * converted = NULL;
785+ WebKitWebView * web_view = WEBKIT_WEB_VIEW(view->web_view);
786+ g_return_if_fail (uri);
787+ converted = g_filename_to_utf8 (uri, -1, NULL, NULL, NULL);
788+ file = g_file_new_for_uri (converted);
789+ if (g_str_has_suffix (uri, ".mhtml"))
790+ webkit_web_view_save_to_file (WEBKIT_WEB_VIEW (web_view), file, WEBKIT_SAVE_MODE_MHTML,
791+ NULL, NULL, NULL);
792+ else
793+ g_file_replace_async (file, NULL, FALSE,
794+ G_FILE_CREATE_REPLACE_DESTINATION | G_FILE_CREATE_PRIVATE,
795+ G_PRIORITY_DEFAULT, NULL,
796+ (GAsyncReadyCallback)midori_web_view_save_main_resource_cb,
797+ web_view);
798+ g_free (converted);
799+ g_object_unref (file);
800+}
801 #endif
802-}
803
804 /**
805 * midori_view_reload:
806@@ -4808,4 +4924,3 @@
807 midori_tab_set_fg_color (MIDORI_TAB (view), fg_color);
808 midori_tab_set_bg_color (MIDORI_TAB (view), bg_color);
809 }
810-
811
812=== modified file 'midori/midori-view.h'
813--- midori/midori-view.h 2014-04-05 19:15:34 +0000
814+++ midori/midori-view.h 2014-04-26 18:11:30 +0000
815@@ -183,13 +183,18 @@
816
817 gboolean
818 midori_view_can_view_source (MidoriView* view);
819-
820+#ifndef HAVE_WEBKIT2
821 gchar*
822 midori_view_save_source (MidoriView* view,
823 const gchar* uri,
824 const gchar* outfile,
825 gboolean use_dom);
826-
827+#else
828+void
829+midori_view_save_source (MidoriView* view,
830+ const gchar* uri,
831+ gboolean use_dom);
832+#endif
833 void
834 midori_view_search_text (MidoriView* view,
835 const gchar* text,
836
837=== modified file 'midori/webkit2gtk-3.0.vapi'
838--- midori/webkit2gtk-3.0.vapi 2014-03-14 22:22:29 +0000
839+++ midori/webkit2gtk-3.0.vapi 2014-04-26 18:11:30 +0000
840@@ -81,7 +81,7 @@
841 public async Cairo.Surface? get_favicon (string page_uri, GLib.Cancellable? cancellable) throws GLib.Error;
842 public string? get_favicon_uri (string page_uri);
843 public void clear ();
844- }
845+ }
846 [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_download_get_type ()")]
847 public class Download : GLib.Object {
848 [CCode (has_construct_function = false)]
849@@ -95,8 +95,10 @@
850 public unowned WebKit.URIResponse get_response ();
851 public void set_destination (string uri);
852 public string destination { get; }
853+ public double elapsed_time{get;}
854 public double estimated_progress { get; }
855 public WebKit.URIResponse response { get; }
856+ public WebKit.URIRequest request{get;}
857 public signal bool created_destination (string destination);
858 public virtual signal bool decide_destination (string suggested_filename);
859 public signal void failed (void* error);
860@@ -395,6 +397,7 @@
861 public URIRequest (string uri);
862 public unowned string get_uri ();
863 public string uri { get; construct; }
864+ public unowned Soup.MessageHeaders get_http_headers();
865 }
866 [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_uri_response_get_type ()")]
867 public class URIResponse : GLib.Object {
868@@ -403,12 +406,14 @@
869 public uint64 get_content_length ();
870 public bool get_https_status (out unowned GLib.TlsCertificate certificate, out GLib.TlsCertificateFlags errors);
871 public unowned string get_mime_type ();
872+ public unowned string get_suggested_filename ();
873 public uint get_status_code ();
874 public unowned string get_uri ();
875 public uint64 content_length { get; }
876 public string mime_type { get; }
877 public uint status_code { get; }
878 public string uri { get; }
879+ public string suggested_filename { get; }
880 }
881 [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_uri_scheme_request_get_type ()")]
882 public class URISchemeRequest : GLib.Object {
883
884=== modified file 'tests/browser.c'
885--- tests/browser.c 2013-11-04 16:08:35 +0000
886+++ tests/browser.c 2014-04-26 18:11:30 +0000
887@@ -11,6 +11,7 @@
888
889 #include "midori.h"
890
891+#ifndef HAVE_WEBKIT2
892 static void
893 browser_create (void)
894 {
895@@ -42,13 +43,13 @@
896 midori_test_set_file_chooser_filename (temporary_filename);
897 midori_settings_set_download_folder (MIDORI_SETTINGS (settings), temporary_downloads);
898 midori_browser_save_uri (browser, MIDORI_VIEW (view), NULL);
899-
900+
901 filename = midori_view_save_source (MIDORI_VIEW (view), NULL, NULL, FALSE);
902 filename2 = g_filename_from_uri (uri, NULL, NULL);
903 g_assert_cmpstr (filename, ==, filename2);
904 g_free (filename);
905 g_free (filename2);
906-
907+
908 /* View source for local file: should NOT use temporary file */
909 view = midori_browser_add_uri (browser, uri);
910 midori_browser_set_current_tab (browser, view);
911@@ -61,7 +62,7 @@
912 g_object_unref (settings);
913 g_object_unref (app);
914 }
915-
916+#endif
917 static void
918 browser_tooltips (void)
919 {
920@@ -168,9 +169,12 @@
921 #ifndef HAVE_WEBKIT2
922 g_object_set_data (G_OBJECT (webkit_get_default_session ()),
923 "midori-session-initialized", (void*)1);
924- #endif
925-
926- g_test_add_func ("/browser/create", browser_create);
927+ g_test_add_func ("/browser/create", browser_create);
928+ #endif
929+
930+
931+
932+
933 g_test_add_func ("/browser/tooltips", browser_tooltips);
934 g_test_add_func ("/browser/site_data", browser_site_data);
935 g_test_add_func ("/browser/block_uris", browser_block_uris);

Subscribers

People subscribed via source and target branches

to all changes: