Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Cody Garver | ||||
Approved revision: | 6739 | ||||
Merged at revision: | 6762 | ||||
Proposed branch: | lp:~evfool/midori/lp1173744 | ||||
Merge into: | lp:midori | ||||
Diff against target: |
893 lines (+342/-131) 6 files modified
extensions/external-download-manager.vala (+26/-2) midori/midori-browser.c (+52/-19) midori/midori-download.vala (+58/-16) midori/midori-view.c (+196/-91) midori/webkit2gtk-3.0.vapi (+6/-1) tests/browser.c (+4/-2) |
||||
To merge this branch: | bzr merge lp:~evfool/midori/lp1173744 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Cody Garver (community) | Approve | ||
gue5t gue5t | Pending | ||
Review via email: mp+225449@code.launchpad.net |
Commit message
Fix webkit2 downloads based on older branch
Description of the change
Fix webkit2 downloads based on older branch.
Additionally fixed based on the review [1]:
* code style fixes
* use spaces instead of tabs
* fixed build errors
The only thing I did not fix was the button change on download cancel (the button of canceled download does not change to the broom), as changing that would require several changes in the Transfer class from transfers.vala, a class being moved to the core in another branch, so it would need fixing in both places (https:/
[1] https:/
[2] https:/
Corentin Noël (tintou) wrote : | # |
Rico Tzschichholz (ricotz) wrote : | # |
I would be curious about the (not-needed?) interface changes, like:
* midori_
* midori_
Danielle Foré (danrabbit) wrote : | # |
I've been using this branch for the past couple days and I can confirm that it does fix the downloads issue and I haven't seen/had any additional problems/
Robert Roth (evfool) wrote : | # |
@Rico: The interface changes are from the parent branch, but I could fix them:
* could you please be more specific about the first point, I don't understand what do you mean by "midori_
* Should I remove the return value from the doc comment or should I re-add the return value to match the comment?
Rico Tzschichholz (ricotz) wrote : | # |
@evfool: I am not familiar with the midori source, but for the sake of compatibility I would not change the name of internal functions while compiling against webkit1 or webkit2 if possible. So given I was just browsing through the diff here this pretty much looks like duplicating code while leading to the need to fix things on the caller-side as well. If the interface of a method is really not fitting then change it properly for all flavors if possible. In case of part of the API I would avoid it completely if things are suppose to stay stable.
Robert Roth (evfool) wrote : | # |
Thanks Rico, updated the branch, different API was not needed indeed.
RabbitBot (rabbitbot-a) wrote : | # |
Voting does not meet specified criteria. Required: Approve >= 1. Got: 2 Pending.
Cody Garver (codygarver) : | # |
Preview Diff
1 | === modified file 'extensions/external-download-manager.vala' |
2 | --- extensions/external-download-manager.vala 2014-02-18 21:15:56 +0000 |
3 | +++ extensions/external-download-manager.vala 2014-07-26 22:58:18 +0000 |
4 | @@ -41,11 +41,16 @@ |
5 | |
6 | if (download_type == Midori.DownloadType.SAVE) { |
7 | var dlReq = new DownloadRequest (); |
8 | + |
9 | + #if HAVE_WEBKIT2 |
10 | + dlReq.uri = download.request.get_uri (); |
11 | + weak MessageHeaders headers = download.request.get_http_headers (); |
12 | + #else |
13 | dlReq.uri = download.get_uri (); |
14 | - |
15 | var request = download.get_network_request (); |
16 | var message = request.get_message (); |
17 | weak MessageHeaders headers = message.request_headers; |
18 | + #endif |
19 | |
20 | dlReq.auth = headers.get ("Authorization"); |
21 | dlReq.referer = headers.get ("Referer"); |
22 | @@ -102,7 +107,11 @@ |
23 | } |
24 | |
25 | construct { |
26 | + #if HAVE_WEBKIT2 |
27 | + var session= new Session (); |
28 | + #else |
29 | var session = WebKit.get_default_session (); |
30 | + #endif |
31 | this.cookie_jar = session.get_feature (typeof (CookieJar)) as CookieJar; |
32 | } |
33 | } |
34 | @@ -160,6 +169,22 @@ |
35 | var session = new SessionSync (); |
36 | session.send_message (message); |
37 | |
38 | + /* Check if the plug-in actually recieved an reply. |
39 | + * The parse method do not warns us about it. And the exception |
40 | + * never is launched.*/ |
41 | + if (message.status_code != 200) { |
42 | + var dialog = new MessageDialog (null, DialogFlags.MODAL, |
43 | + MessageType.ERROR, ButtonsType.CLOSE, |
44 | + _("The plug-in was unable to connect with aria2:\n" + |
45 | + "Please make sure that aria2 is running with rpc enabled ie: aria2c --enable-rpc\n" + |
46 | + "If it's so, check it also is using the port 6800.\n" + |
47 | + "Lastly Check the configuration of your firewall.\n" + |
48 | + "Whitelist aria2 and the port 6800 if they aren't." |
49 | + )); |
50 | + dialog.response.connect ((a) => { dialog.destroy (); }); |
51 | + dialog.run (); |
52 | + } |
53 | + |
54 | try { |
55 | Value v; |
56 | XMLRPC.parse_method_response ((string) message.response_body.flatten ().data, -1, out v); |
57 | @@ -344,4 +369,3 @@ |
58 | extensions.add_item (new EDM.CommandLine ()); |
59 | return extensions; |
60 | } |
61 | - |
62 | |
63 | === modified file 'midori/midori-browser.c' |
64 | --- midori/midori-browser.c 2014-07-24 07:20:50 +0000 |
65 | +++ midori/midori-browser.c 2014-07-26 22:58:18 +0000 |
66 | @@ -153,6 +153,12 @@ |
67 | static void |
68 | midori_browser_finalize (GObject* object); |
69 | |
70 | +#ifdef HAVE_WEBKIT2 |
71 | +void download_created_destination_cb (WebKitDownload *download, |
72 | + gchar *destination, |
73 | + gpointer user_data); |
74 | +#endif |
75 | + |
76 | static void |
77 | midori_browser_set_property (GObject* object, |
78 | guint prop_id, |
79 | @@ -1246,22 +1252,23 @@ |
80 | const gchar* uri) |
81 | |
82 | { |
83 | -#ifndef HAVE_WEBKIT2 |
84 | if (!midori_download_has_enough_space (download, uri, FALSE)) |
85 | return FALSE; |
86 | + |
87 | +#ifdef HAVE_WEBKIT2 |
88 | + webkit_download_set_destination (download, uri); |
89 | +#else |
90 | webkit_download_set_destination_uri (download, uri); |
91 | +#endif |
92 | g_signal_emit (browser, signals[ADD_DOWNLOAD], 0, download); |
93 | return TRUE; |
94 | -#else |
95 | - return FALSE; |
96 | -#endif |
97 | } |
98 | |
99 | +#ifndef HAVE_WEBKIT2 |
100 | static void |
101 | midori_browser_save_resources (GList* resources, |
102 | const gchar* folder) |
103 | { |
104 | -#ifndef HAVE_WEBKIT2 |
105 | GList* list; |
106 | katze_mkdir_with_parents (folder, 0700); |
107 | |
108 | @@ -1293,8 +1300,8 @@ |
109 | g_free (sub_filename); |
110 | g_free (sub_path); |
111 | } |
112 | +} |
113 | #endif |
114 | -} |
115 | |
116 | void |
117 | midori_browser_save_uri (MidoriBrowser* browser, |
118 | @@ -1305,9 +1312,6 @@ |
119 | GtkWidget* dialog; |
120 | const gchar* title = midori_view_get_display_title (view); |
121 | gchar* filename; |
122 | - GList* resources = midori_view_get_resources (view); |
123 | - gboolean file_only = TRUE; |
124 | - GtkWidget* checkbox = NULL; |
125 | |
126 | dialog = (GtkWidget*)midori_file_chooser_dialog_new (_("Save file as"), |
127 | GTK_WINDOW (browser), GTK_FILE_CHOOSER_ACTION_SAVE); |
128 | @@ -1316,14 +1320,6 @@ |
129 | if (uri == NULL) |
130 | uri = midori_view_get_display_uri (view); |
131 | |
132 | - if (resources != NULL && g_list_nth_data (resources, 1) != NULL) |
133 | - { |
134 | - file_only = FALSE; |
135 | - checkbox = gtk_check_button_new_with_mnemonic (_("Save associated _resources")); |
136 | - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE); |
137 | - gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), checkbox); |
138 | - } |
139 | - |
140 | if (last_dir && *last_dir) |
141 | gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), last_dir); |
142 | else |
143 | @@ -1335,6 +1331,19 @@ |
144 | g_free (dirname); |
145 | } |
146 | |
147 | +#ifndef HAVE_WEBKIT2 |
148 | + GList* resources = midori_view_get_resources (view); |
149 | + gboolean file_only = TRUE; |
150 | + GtkWidget* checkbox = NULL; |
151 | + |
152 | + if (resources != NULL && g_list_nth_data (resources, 1) != NULL) |
153 | + { |
154 | + file_only = FALSE; |
155 | + checkbox = gtk_check_button_new_with_mnemonic (_("Save associated _resources")); |
156 | + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE); |
157 | + gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), checkbox); |
158 | + } |
159 | + |
160 | if (!file_only && !g_str_equal (title, uri)) |
161 | filename = midori_download_clean_filename (title); |
162 | else |
163 | @@ -1363,8 +1372,27 @@ |
164 | katze_assign (last_dir, |
165 | gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog))); |
166 | } |
167 | - gtk_widget_destroy (dialog); |
168 | g_list_free (resources); |
169 | +#else |
170 | + filename = midori_download_clean_filename (title); |
171 | + gchar* suggested_filename = g_strconcat (filename, ".mht", NULL); |
172 | + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), suggested_filename); |
173 | + |
174 | + g_free (filename); |
175 | + g_free (suggested_filename); |
176 | + if (midori_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) |
177 | + { |
178 | + char *uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog)); |
179 | + if (uri != NULL) |
180 | + { |
181 | + midori_view_save_source (view, uri, NULL, false); |
182 | + g_free (uri); |
183 | + } |
184 | + katze_assign (last_dir, |
185 | + gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog))); |
186 | + } |
187 | +#endif |
188 | + gtk_widget_destroy (dialog); |
189 | } |
190 | |
191 | static void |
192 | @@ -1699,7 +1727,6 @@ |
193 | g_signal_connect (dialog, "destroy", |
194 | G_CALLBACK (gtk_widget_destroyed), &dialog); |
195 | } |
196 | - |
197 | filename = midori_download_get_suggested_filename (download); |
198 | gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename); |
199 | g_free (filename); |
200 | @@ -1752,6 +1779,12 @@ |
201 | return handled; |
202 | } |
203 | |
204 | +void download_created_destination_cb (WebKitDownload *download, |
205 | + gchar *destination, |
206 | + gpointer user_data){ |
207 | + g_print("%s: destination %s",G_STRFUNC,destination); |
208 | +} |
209 | + |
210 | static void |
211 | midori_view_search_text_cb (GtkWidget* view, |
212 | gboolean found, |
213 | |
214 | === modified file 'midori/midori-download.vala' |
215 | --- midori/midori-download.vala 2014-03-06 22:22:37 +0000 |
216 | +++ midori/midori-download.vala 2014-07-26 22:58:18 +0000 |
217 | @@ -10,9 +10,7 @@ |
218 | */ |
219 | |
220 | namespace Sokoke { |
221 | -#if !HAVE_WEBKIT2 |
222 | extern static bool message_dialog (Gtk.MessageType type, string short, string detailed, bool modal); |
223 | -#endif |
224 | } |
225 | |
226 | namespace Midori { |
227 | @@ -28,6 +26,8 @@ |
228 | return false; |
229 | } |
230 | #else |
231 | + if (download.estimated_progress == 1) |
232 | + return true; |
233 | return false; |
234 | #endif |
235 | } |
236 | @@ -40,6 +40,14 @@ |
237 | download.set_data<int> ("midori-download-type", type); |
238 | } |
239 | |
240 | +#if HAVE_WEBKIT2 |
241 | + public static string get_filename (WebKit.Download download) { |
242 | + return download.get_data<string> ("midori-download-filename"); |
243 | + } |
244 | + public static void set_filename (WebKit.Download download, string name) { |
245 | + download.set_data<string> ("midori-download-filename", name); |
246 | + } |
247 | +#endif |
248 | public static double get_progress (WebKit.Download download) { |
249 | #if !HAVE_WEBKIT2 |
250 | /* Avoid a bug in WebKit */ |
251 | @@ -47,7 +55,7 @@ |
252 | return 0.0; |
253 | return download.progress; |
254 | #else |
255 | - return 0.0; |
256 | + return download.estimated_progress; |
257 | #endif |
258 | } |
259 | |
260 | @@ -110,39 +118,57 @@ |
261 | |
262 | return "%s\n%s %s%s".printf (filename, size, speed, eta); |
263 | #else |
264 | - return ""; |
265 | + string filename = Midori.Download.get_basename_for_display (download.destination); |
266 | + |
267 | + string size = "%s".printf (format_size (download.get_received_data_length ())); |
268 | + string speed = ""; |
269 | + speed = format_size ((uint64)((download.get_received_data_length () * 1.0) / download.elapsed_time)); |
270 | + speed = _(" (%s/s)").printf (speed); |
271 | + string progress = "%d%%".printf( (int) (download.get_estimated_progress ()*100)); |
272 | + if (is_finished (download)) |
273 | + return "%s\n %s".printf (filename, size); |
274 | + return "%s\n %s - %s".printf (filename, speed, progress); |
275 | #endif |
276 | } |
277 | |
278 | public static string get_content_type (WebKit.Download download, string? mime_type) { |
279 | -#if !HAVE_WEBKIT2 |
280 | +#if HAVE_WEBKIT2 |
281 | + string? content_type = ContentType.guess (download.response.suggested_filename == null ? |
282 | + download.destination : download.response.suggested_filename, |
283 | + null, null); |
284 | +#else |
285 | string? content_type = ContentType.guess (download.suggested_filename, null, null); |
286 | +#endif |
287 | if (content_type == null) { |
288 | content_type = ContentType.from_mime_type (mime_type); |
289 | if (content_type == null) |
290 | content_type = ContentType.from_mime_type ("application/octet-stream"); |
291 | } |
292 | return content_type; |
293 | -#else |
294 | - return ContentType.from_mime_type ("application/octet-stream"); |
295 | -#endif |
296 | } |
297 | |
298 | public static bool has_wrong_checksum (WebKit.Download download) { |
299 | -#if !HAVE_WEBKIT2 |
300 | int status = download.get_data<int> ("checksum-status"); |
301 | if (status == 0) { |
302 | /* Link Fingerprint */ |
303 | + #if HAVE_WEBKIT2 |
304 | + string? original_uri = download.request.uri; |
305 | + #else |
306 | string? original_uri = download.network_request.get_data<string> ("midori-original-uri"); |
307 | if (original_uri == null) |
308 | original_uri = download.get_uri (); |
309 | + #endif |
310 | string? fingerprint; |
311 | ChecksumType checksum_type = URI.get_fingerprint (original_uri, out fingerprint, null); |
312 | /* By default, no wrong checksum */ |
313 | status = 2; |
314 | if (fingerprint != null) { |
315 | try { |
316 | + #if HAVE_WEBKIT2 |
317 | + string filename = Filename.from_uri (download.destination); |
318 | + #else |
319 | string filename = Filename.from_uri (download.destination_uri); |
320 | + #endif |
321 | string contents; |
322 | size_t length; |
323 | bool y = FileUtils.get_contents (filename, out contents, out length); |
324 | @@ -158,9 +184,7 @@ |
325 | download.set_data<int> ("checksum-status", status); |
326 | } |
327 | return status == 1; |
328 | -#else |
329 | - return false; |
330 | -#endif |
331 | + |
332 | } |
333 | |
334 | public static bool action_clear (WebKit.Download download, Gtk.Widget widget) throws Error { |
335 | @@ -181,6 +205,14 @@ |
336 | warn_if_reached (); |
337 | break; |
338 | } |
339 | + #else |
340 | + |
341 | + if (download.estimated_progress < 1) { |
342 | + download.cancel (); |
343 | + } else { |
344 | + if (open (download, widget)) |
345 | + return true; |
346 | + } |
347 | #endif |
348 | return false; |
349 | } |
350 | @@ -205,13 +237,17 @@ |
351 | return Gtk.Stock.MISSING_IMAGE; |
352 | } |
353 | #else |
354 | - return Gtk.Stock.MISSING_IMAGE; |
355 | + if (download.estimated_progress == 1) |
356 | + if (has_wrong_checksum (download)) |
357 | + return Gtk.Stock.DIALOG_WARNING; |
358 | + else |
359 | + return Gtk.Stock.OPEN; |
360 | + return Gtk.Stock.CANCEL; |
361 | #endif |
362 | } |
363 | |
364 | /* returns whether an application was successfully launched to handle the file */ |
365 | public static bool open (WebKit.Download download, Gtk.Widget widget) throws Error { |
366 | -#if !HAVE_WEBKIT2 |
367 | if (has_wrong_checksum (download)) { |
368 | Sokoke.message_dialog (Gtk.MessageType.WARNING, |
369 | _("The downloaded file is erroneous."), |
370 | @@ -223,9 +259,12 @@ |
371 | Tab? tab = null; |
372 | browser.get ("tab", &tab); |
373 | if (tab != null) |
374 | + #if HAVE_WEBKIT2 |
375 | + return tab.open_uri (download.destination); |
376 | + #else |
377 | return tab.open_uri (download.destination_uri); |
378 | + #endif |
379 | } |
380 | -#endif |
381 | return false; |
382 | } |
383 | |
384 | @@ -257,7 +296,10 @@ |
385 | https://d19vezwu8eufl6.cloudfront.net/nlp/slides%2F03-01-FormalizingNB.pdf */ |
386 | return clean_filename (download.get_suggested_filename ()); |
387 | #else |
388 | - return ""; |
389 | + string name = get_filename (download); |
390 | + if (name == null) |
391 | + return ""; |
392 | + return name; |
393 | #endif |
394 | } |
395 | |
396 | |
397 | === modified file 'midori/midori-view.c' |
398 | --- midori/midori-view.c 2014-07-20 23:53:06 +0000 |
399 | +++ midori/midori-view.c 2014-07-26 22:58:18 +0000 |
400 | @@ -67,9 +67,13 @@ |
401 | gpointer user_data); |
402 | |
403 | static void |
404 | -midori_view_download_requested_cb (WebKitWebContext* context, |
405 | - WebKitDownload* download, |
406 | - gpointer user_data); |
407 | +midori_view_download_started_cb (WebKitWebContext* context, |
408 | + WebKitDownload* download, |
409 | + MidoriView * view); |
410 | +static gboolean |
411 | +midori_view_download_query_action (MidoriView* view, |
412 | + WebKitDownload* download, |
413 | + const gchar * suggested_filename ); |
414 | #endif |
415 | |
416 | static gboolean |
417 | @@ -378,16 +382,6 @@ |
418 | "The associated settings", |
419 | MIDORI_TYPE_WEB_SETTINGS, |
420 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
421 | - |
422 | - #ifdef HAVE_WEBKIT2 |
423 | - WebKitWebContext* context = webkit_web_context_get_default (); |
424 | - webkit_web_context_register_uri_scheme (context, |
425 | - "res", midori_view_uri_scheme_res, NULL, NULL); |
426 | - webkit_web_context_register_uri_scheme (context, |
427 | - "stock", midori_view_uri_scheme_res, NULL, NULL); |
428 | - g_signal_connect (context, "download-started", |
429 | - (GCallback)midori_view_download_requested_cb, NULL); |
430 | - #endif |
431 | } |
432 | |
433 | static void |
434 | @@ -2008,14 +2002,17 @@ |
435 | { |
436 | #ifdef HAVE_WEBKIT2 |
437 | WebKitDownload* download = webkit_web_view_download_uri (WEBKIT_WEB_VIEW (view->web_view), uri); |
438 | + WebKitWebContext * web_context = webkit_web_view_get_context (WEBKIT_WEB_VIEW (view->web_view)); |
439 | + midori_download_set_type (download, type); |
440 | + g_signal_emit_by_name (web_context, "download-started", download, view); |
441 | #else |
442 | WebKitNetworkRequest* request = webkit_network_request_new (uri); |
443 | WebKitDownload* download = webkit_download_new (request); |
444 | g_object_unref (request); |
445 | -#endif |
446 | + midori_download_set_type (download, type); |
447 | gboolean handled; |
448 | - midori_download_set_type (download, type); |
449 | g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled); |
450 | + #endif |
451 | } |
452 | |
453 | static void |
454 | @@ -2732,14 +2729,80 @@ |
455 | } |
456 | #endif |
457 | |
458 | +gint |
459 | +midori_save_dialog (const gchar* title, |
460 | + const gchar * hostname, |
461 | + const GString* details, |
462 | + const gchar *content_type) |
463 | +{ |
464 | + GIcon* icon; |
465 | + GtkWidget* image; |
466 | + GdkScreen* screen; |
467 | + GtkWidget* dialog= NULL; |
468 | + GtkIconTheme* icon_theme; |
469 | + gint response; |
470 | + dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, |
471 | + _("Open or download file from %s"), hostname); |
472 | + icon = g_content_type_get_icon (content_type); |
473 | + g_themed_icon_append_name (G_THEMED_ICON (icon), "text-html"); |
474 | + image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG); |
475 | + gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image); |
476 | + g_object_unref (icon); |
477 | + gtk_widget_show (image); |
478 | + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), |
479 | + "%s", details->str); |
480 | + screen = gtk_widget_get_screen (dialog); |
481 | + |
482 | + gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE); |
483 | + if (screen) |
484 | + { |
485 | + icon_theme = gtk_icon_theme_get_for_screen (screen); |
486 | + if (gtk_icon_theme_has_icon (icon_theme, MIDORI_STOCK_TRANSFER)) |
487 | + gtk_window_set_icon_name (GTK_WINDOW (dialog), MIDORI_STOCK_TRANSFER); |
488 | + else |
489 | + gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_OPEN); |
490 | + } |
491 | + gtk_dialog_add_buttons (GTK_DIALOG (dialog), |
492 | + GTK_STOCK_SAVE, MIDORI_DOWNLOAD_SAVE, |
493 | + GTK_STOCK_SAVE_AS, MIDORI_DOWNLOAD_SAVE_AS, |
494 | + GTK_STOCK_CANCEL, MIDORI_DOWNLOAD_CANCEL, |
495 | + GTK_STOCK_OPEN, MIDORI_DOWNLOAD_OPEN, |
496 | + NULL); |
497 | + |
498 | + response = midori_dialog_run (GTK_DIALOG (dialog)); |
499 | + |
500 | + gtk_widget_destroy (dialog); |
501 | + if (response == GTK_RESPONSE_DELETE_EVENT) |
502 | + response = MIDORI_DOWNLOAD_CANCEL; |
503 | + return response; |
504 | +} |
505 | + |
506 | #ifdef HAVE_WEBKIT2 |
507 | +static gboolean |
508 | +midori_view_download_decide_destination_cb (WebKitDownload* download, |
509 | + const gchar * suggested_filename, |
510 | + MidoriView* view) |
511 | +{ |
512 | + if(!midori_view_download_query_action (view, download, suggested_filename)) { |
513 | + webkit_download_cancel (download); |
514 | + } |
515 | + return TRUE; //we must return TRUE because we handled the signal |
516 | +} |
517 | + |
518 | static void |
519 | -midori_view_download_requested_cb (WebKitWebContext* context, |
520 | - WebKitDownload* download, |
521 | - gpointer user_data) |
522 | -{ |
523 | - WebKitWebView* web_view = webkit_download_get_web_view (download); |
524 | - MidoriView* view = midori_view_get_for_widget (GTK_WIDGET (web_view)); |
525 | +midori_view_download_started_cb (WebKitWebContext* context, |
526 | + WebKitDownload* download, |
527 | + MidoriView *view) |
528 | +{ |
529 | + g_signal_connect (download, "decide-destination", |
530 | + G_CALLBACK (midori_view_download_decide_destination_cb), view); |
531 | +} |
532 | + |
533 | +static gboolean |
534 | +midori_view_download_query_action (MidoriView* view, |
535 | + WebKitDownload* download, |
536 | + const gchar * suggested_filename) |
537 | +{ |
538 | #else |
539 | static gboolean |
540 | midori_view_download_requested_cb (GtkWidget* web_view, |
541 | @@ -2747,42 +2810,36 @@ |
542 | MidoriView* view) |
543 | { |
544 | #endif |
545 | - gchar* opener_uri; |
546 | + gboolean handled = TRUE; |
547 | gchar* hostname; |
548 | - GtkWidget* dialog; |
549 | gchar* content_type; |
550 | gchar* description; |
551 | + gchar* title; |
552 | + gint response; |
553 | GString* details; |
554 | - GIcon* icon; |
555 | - GtkWidget* image; |
556 | - gchar* title; |
557 | - GdkScreen* screen; |
558 | - GtkIconTheme* icon_theme; |
559 | - gint response; |
560 | - gboolean handled; |
561 | - |
562 | /* Opener may differ from displaying view: |
563 | http://lcamtuf.coredump.cx/fldl/ http://lcamtuf.coredump.cx/switch/ */ |
564 | - opener_uri = g_object_get_data (G_OBJECT (view), "opener-uri"); |
565 | + const gchar* opener_uri = g_object_get_data (G_OBJECT (view), "opener-uri"); |
566 | hostname = midori_uri_parse_hostname ( |
567 | opener_uri ? opener_uri : midori_view_get_display_uri (view), NULL); |
568 | - dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, |
569 | - _("Open or download file from %s"), hostname); |
570 | - g_free (hostname); |
571 | + |
572 | + #ifdef HAVE_WEBKIT2 |
573 | + content_type = g_content_type_guess (suggested_filename, NULL , |
574 | + 0 ,NULL); |
575 | + if (!content_type) |
576 | + content_type = g_strdup ("application/octet-stream"); |
577 | + midori_download_set_filename (download, g_strdup (suggested_filename)); |
578 | + #else |
579 | content_type = midori_download_get_content_type (download, |
580 | g_object_get_data (G_OBJECT (view), "download-mime-type")); |
581 | + #endif |
582 | description = g_content_type_get_description (content_type); |
583 | - icon = g_content_type_get_icon (content_type); |
584 | - g_themed_icon_append_name (G_THEMED_ICON (icon), "text-html"); |
585 | - image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG); |
586 | - g_object_unref (icon); |
587 | - gtk_widget_show (image); |
588 | - gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image); |
589 | |
590 | details = g_string_sized_new (20 * 4); |
591 | #ifdef HAVE_WEBKIT2 |
592 | + const gchar * suggestion = webkit_uri_response_get_suggested_filename (webkit_download_get_response (download)); |
593 | g_string_append_printf (details, _("File Name: %s"), |
594 | - webkit_uri_response_get_suggested_filename (webkit_download_get_response (download))); |
595 | + suggestion ? suggestion : suggested_filename); |
596 | #else |
597 | g_string_append_printf (details, _("File Name: %s"), |
598 | webkit_download_get_suggested_filename (download)); |
599 | @@ -2794,8 +2851,6 @@ |
600 | else |
601 | g_string_append_printf (details, _("File Type: %s ('%s')"), description, content_type); |
602 | g_string_append_c (details, '\n'); |
603 | - g_free (description); |
604 | - g_free (content_type); |
605 | |
606 | #ifndef HAVE_WEBKIT2 |
607 | /* Link Fingerprint */ |
608 | @@ -2836,53 +2891,22 @@ |
609 | } |
610 | #endif |
611 | |
612 | - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), |
613 | - "%s", details->str); |
614 | - g_string_free (details, TRUE); |
615 | - |
616 | - gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE); |
617 | #ifdef HAVE_WEBKIT2 |
618 | /* i18n: A file open dialog title, ie. "Open http://fila.com/manual.tgz" */ |
619 | title = g_strdup_printf (_("Open %s"), webkit_uri_request_get_uri (webkit_download_get_request (download))); |
620 | #else |
621 | title = g_strdup_printf (_("Open %s"), webkit_download_get_uri (download)); |
622 | #endif |
623 | - gtk_window_set_title (GTK_WINDOW (dialog), title); |
624 | + response = midori_save_dialog (title, |
625 | + hostname, details, content_type); //We prompt a dialog |
626 | g_free (title); |
627 | - screen = gtk_widget_get_screen (dialog); |
628 | - if (screen) |
629 | - { |
630 | - icon_theme = gtk_icon_theme_get_for_screen (screen); |
631 | - if (gtk_icon_theme_has_icon (icon_theme, MIDORI_STOCK_TRANSFER)) |
632 | - gtk_window_set_icon_name (GTK_WINDOW (dialog), MIDORI_STOCK_TRANSFER); |
633 | - else |
634 | - gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_OPEN); |
635 | - } |
636 | - gtk_dialog_add_buttons (GTK_DIALOG (dialog), |
637 | - GTK_STOCK_SAVE, MIDORI_DOWNLOAD_SAVE, |
638 | - GTK_STOCK_SAVE_AS, MIDORI_DOWNLOAD_SAVE_AS, |
639 | - GTK_STOCK_CANCEL, MIDORI_DOWNLOAD_CANCEL, |
640 | - GTK_STOCK_OPEN, MIDORI_DOWNLOAD_OPEN, |
641 | - NULL); |
642 | - |
643 | - response = midori_dialog_run (GTK_DIALOG (dialog)); |
644 | - gtk_widget_destroy (dialog); |
645 | - if (response == GTK_RESPONSE_DELETE_EVENT) |
646 | - response = MIDORI_DOWNLOAD_CANCEL; |
647 | + g_free (hostname); |
648 | + g_free (description); |
649 | + g_free (content_type); |
650 | + g_string_free (details, TRUE); |
651 | midori_download_set_type (download, response); |
652 | - |
653 | - /* TODO |
654 | - g_object_connect (download, |
655 | - "signal::decide-destination", download_decide_destination_cb, view, |
656 | - "signal::created-destination", download_created_destination_cb, view, |
657 | - "signal::finished", download_finished_cb, view, |
658 | - "signal::failed", download_failed_cb, view, |
659 | - NULL); |
660 | - */ |
661 | g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled); |
662 | -#ifndef HAVE_WEBKIT2 |
663 | return handled; |
664 | -#endif |
665 | } |
666 | |
667 | #ifndef HAVE_WEBKIT2 |
668 | @@ -3622,6 +3646,13 @@ |
669 | g_signal_connect (view->web_view, "web-process-crashed", |
670 | (GCallback)midori_view_web_view_crashed_cb, view); |
671 | view->scrolled_window = view->web_view; |
672 | + WebKitWebContext* context = webkit_web_view_get_context (WEBKIT_WEB_VIEW (view->web_view)); |
673 | + webkit_web_context_register_uri_scheme (context, |
674 | + "res", midori_view_uri_scheme_res, NULL, NULL); |
675 | + webkit_web_context_register_uri_scheme (context, |
676 | + "stock", midori_view_uri_scheme_res, NULL, NULL); |
677 | + g_signal_connect (context, "download-started", |
678 | + G_CALLBACK (midori_view_download_started_cb), view); |
679 | #endif |
680 | |
681 | #if GTK_CHECK_VERSION(3, 2, 0) |
682 | @@ -4307,6 +4338,58 @@ |
683 | || !g_str_has_prefix (midori_tab_get_mime_type (MIDORI_TAB (view)), "image/")); |
684 | } |
685 | |
686 | +#ifdef HAVE_WEBKIT2 |
687 | +static void |
688 | +midori_web_resource_get_data_cb (WebKitWebResource *resource, |
689 | + GAsyncResult *result, |
690 | + GOutputStream *output_stream) |
691 | +{ |
692 | + guchar *data; |
693 | + gsize data_length; |
694 | + GInputStream *input_stream; |
695 | + GError *error = NULL; |
696 | + |
697 | + data = webkit_web_resource_get_data_finish (resource, result, &data_length, &error); |
698 | + if (!data) { |
699 | + g_printerr ("Failed to save page: %s", error->message); |
700 | + g_error_free (error); |
701 | + g_object_unref (output_stream); |
702 | + |
703 | + return; |
704 | + } |
705 | + |
706 | + input_stream = g_memory_input_stream_new_from_data (data, data_length, g_free); |
707 | + g_output_stream_splice_async (output_stream, input_stream, |
708 | + G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, |
709 | + G_PRIORITY_DEFAULT, |
710 | + NULL, NULL, NULL); |
711 | + g_object_unref (input_stream); |
712 | + g_object_unref (output_stream); |
713 | +} |
714 | + |
715 | +static void |
716 | +midori_web_view_save_main_resource_cb (GFile *file, |
717 | + GAsyncResult *result, |
718 | + WebKitWebView *view) |
719 | +{ |
720 | + GFileOutputStream *output_stream; |
721 | + WebKitWebResource *resource; |
722 | + GError *error = NULL; |
723 | + |
724 | + output_stream = g_file_replace_finish (file, result, &error); |
725 | + if (!output_stream) { |
726 | + g_printerr ("Failed to save page: %s", error->message); |
727 | + g_error_free (error); |
728 | + return; |
729 | + } |
730 | + |
731 | + resource = webkit_web_view_get_main_resource (view); |
732 | + webkit_web_resource_get_data (resource, NULL, |
733 | + (GAsyncReadyCallback)midori_web_resource_get_data_cb, |
734 | + output_stream); |
735 | +} |
736 | +#endif |
737 | + |
738 | /** |
739 | * midori_view_save_source: |
740 | * @view: a #MidoriView |
741 | @@ -4325,6 +4408,14 @@ |
742 | const gchar* outfile, |
743 | gboolean use_dom) |
744 | { |
745 | + g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL); |
746 | + |
747 | + if (uri == NULL) |
748 | + uri = midori_view_get_display_uri (view); |
749 | + |
750 | + if (g_str_has_prefix (uri, "file:///")) |
751 | + return g_filename_from_uri (uri, NULL, NULL); |
752 | + |
753 | #ifndef HAVE_WEBKIT2 |
754 | WebKitWebFrame *frame; |
755 | WebKitWebDataSource *data_source; |
756 | @@ -4334,8 +4425,6 @@ |
757 | FILE* fp; |
758 | size_t ret; |
759 | |
760 | - g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL); |
761 | - |
762 | frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view)); |
763 | |
764 | if (use_dom) |
765 | @@ -4356,12 +4445,6 @@ |
766 | data = webkit_web_data_source_get_data (data_source); |
767 | } |
768 | |
769 | - if (uri == NULL) |
770 | - uri = midori_view_get_display_uri (view); |
771 | - |
772 | - if (g_str_has_prefix (uri, "file:///")) |
773 | - return g_filename_from_uri (uri, NULL, NULL); |
774 | - |
775 | if (!outfile) |
776 | { |
777 | gchar* extension = midori_download_get_extension_for_uri (uri, NULL); |
778 | @@ -4396,7 +4479,30 @@ |
779 | } |
780 | return unique_filename; |
781 | #else |
782 | - return NULL; |
783 | + GFile *file; |
784 | + char *converted = NULL; |
785 | + WebKitWebView * web_view = WEBKIT_WEB_VIEW (view->web_view); |
786 | + g_return_if_fail (uri); |
787 | + |
788 | + if (!outfile) |
789 | + converted = g_filename_to_utf8 (uri, -1, NULL, NULL, NULL); |
790 | + else |
791 | + converted = g_strdup (outfile); |
792 | + |
793 | + file = g_file_new_for_uri (converted); |
794 | + |
795 | + if (g_str_has_suffix (uri, ".mht")) |
796 | + webkit_web_view_save_to_file (WEBKIT_WEB_VIEW (web_view), file, WEBKIT_SAVE_MODE_MHTML, |
797 | + NULL, NULL, NULL); |
798 | + else |
799 | + g_file_replace_async (file, NULL, FALSE, |
800 | + G_FILE_CREATE_REPLACE_DESTINATION | G_FILE_CREATE_PRIVATE, |
801 | + G_PRIORITY_DEFAULT, NULL, |
802 | + (GAsyncReadyCallback)midori_web_view_save_main_resource_cb, |
803 | + web_view); |
804 | + g_free (converted); |
805 | + g_object_unref (file); |
806 | + return converted; |
807 | #endif |
808 | } |
809 | |
810 | @@ -4828,4 +4934,3 @@ |
811 | midori_tab_set_fg_color (MIDORI_TAB (view), fg_color); |
812 | midori_tab_set_bg_color (MIDORI_TAB (view), bg_color); |
813 | } |
814 | - |
815 | |
816 | === modified file 'midori/webkit2gtk-3.0.vapi' |
817 | --- midori/webkit2gtk-3.0.vapi 2014-03-14 22:22:29 +0000 |
818 | +++ midori/webkit2gtk-3.0.vapi 2014-07-26 22:58:18 +0000 |
819 | @@ -81,7 +81,7 @@ |
820 | public async Cairo.Surface? get_favicon (string page_uri, GLib.Cancellable? cancellable) throws GLib.Error; |
821 | public string? get_favicon_uri (string page_uri); |
822 | public void clear (); |
823 | - } |
824 | + } |
825 | [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_download_get_type ()")] |
826 | public class Download : GLib.Object { |
827 | [CCode (has_construct_function = false)] |
828 | @@ -95,8 +95,10 @@ |
829 | public unowned WebKit.URIResponse get_response (); |
830 | public void set_destination (string uri); |
831 | public string destination { get; } |
832 | + public double elapsed_time{ get; } |
833 | public double estimated_progress { get; } |
834 | public WebKit.URIResponse response { get; } |
835 | + public WebKit.URIRequest request{ get; } |
836 | public signal bool created_destination (string destination); |
837 | public virtual signal bool decide_destination (string suggested_filename); |
838 | public signal void failed (void* error); |
839 | @@ -395,6 +397,7 @@ |
840 | public URIRequest (string uri); |
841 | public unowned string get_uri (); |
842 | public string uri { get; construct; } |
843 | + public unowned Soup.MessageHeaders get_http_headers (); |
844 | } |
845 | [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_uri_response_get_type ()")] |
846 | public class URIResponse : GLib.Object { |
847 | @@ -403,12 +406,14 @@ |
848 | public uint64 get_content_length (); |
849 | public bool get_https_status (out unowned GLib.TlsCertificate certificate, out GLib.TlsCertificateFlags errors); |
850 | public unowned string get_mime_type (); |
851 | + public unowned string get_suggested_filename (); |
852 | public uint get_status_code (); |
853 | public unowned string get_uri (); |
854 | public uint64 content_length { get; } |
855 | public string mime_type { get; } |
856 | public uint status_code { get; } |
857 | public string uri { get; } |
858 | + public string suggested_filename { get; } |
859 | } |
860 | [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_uri_scheme_request_get_type ()")] |
861 | public class URISchemeRequest : GLib.Object { |
862 | |
863 | === modified file 'tests/browser.c' |
864 | --- tests/browser.c 2013-11-04 16:08:35 +0000 |
865 | +++ tests/browser.c 2014-07-26 22:58:18 +0000 |
866 | @@ -11,6 +11,7 @@ |
867 | |
868 | #include "midori.h" |
869 | |
870 | +#ifndef HAVE_WEBKIT2 |
871 | static void |
872 | browser_create (void) |
873 | { |
874 | @@ -61,6 +62,7 @@ |
875 | g_object_unref (settings); |
876 | g_object_unref (app); |
877 | } |
878 | +#endif |
879 | |
880 | static void |
881 | browser_tooltips (void) |
882 | @@ -168,9 +170,9 @@ |
883 | #ifndef HAVE_WEBKIT2 |
884 | g_object_set_data (G_OBJECT (webkit_get_default_session ()), |
885 | "midori-session-initialized", (void*)1); |
886 | - #endif |
887 | - |
888 | g_test_add_func ("/browser/create", browser_create); |
889 | + #endif |
890 | + |
891 | g_test_add_func ("/browser/tooltips", browser_tooltips); |
892 | g_test_add_func ("/browser/site_data", browser_site_data); |
893 | g_test_add_func ("/browser/block_uris", browser_block_uris); |
I don't see anything wrong with the code, but the code style is sometimes not following the Midori's code style.
I've pointed out some fixes to do.