File: window-commands-don-t-take-snapshot-when-saving-PNG-image.patch

package info (click to toggle)
epiphany-browser 48.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,172 kB
  • sloc: ansic: 75,495; javascript: 7,332; xml: 686; python: 177; sh: 77; makefile: 14
file content (102 lines) | stat: -rw-r--r-- 3,511 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
From: Michael Catanzaro <mcatanzaro@redhat.com>
Date: Thu, 26 Jun 2025 17:27:48 -0500
Subject: window-commands: don't take snapshot when saving PNG image

We have an easter egg that allows users to save a screenshot of the web
page by changing the file suffix to ".png" on the save dialog. This is
fun, but we don't want to do that when the main resource is a PNG image.
In that case, we surely want to save the actual PNG image.

(cherry picked from commit 03ef91d5a0a1a2cce3c4839f6145cae47574f71b)

Co-authored-by: Michael Catanzaro <mcatanzaro@redhat.com>
Origin: upstream, 48.6, commit:de5672a7397521a6333e13e2de10018b0a4775e6
---
 src/window-commands.c | 44 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 36 insertions(+), 8 deletions(-)

diff --git a/src/window-commands.c b/src/window-commands.c
index 871346a..8f5f773 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -2479,11 +2479,33 @@ take_snapshot (EphyEmbed *embed,
                                 g_filename_from_uri (file, NULL, NULL));
 }
 
+typedef struct {
+  EphyEmbed *embed;
+  char *suggested_filename;
+} SaveDialogAsyncData;
+
+static SaveDialogAsyncData *
+save_dialog_async_data_new (EphyEmbed  *embed,
+                            const char *suggested_filename)
+{
+  SaveDialogAsyncData *data = g_new (SaveDialogAsyncData, 1);
+  data->embed = g_object_ref (embed);
+  data->suggested_filename = g_strdup (suggested_filename);
+  return data;
+}
 
 static void
-save_dialog_cb (GtkFileDialog *dialog,
-                GAsyncResult  *result,
-                EphyEmbed     *embed)
+save_dialog_async_data_free (SaveDialogAsyncData *data)
+{
+  g_object_unref (data->embed);
+  g_free (data->suggested_filename);
+  g_free (data);
+}
+
+static void
+save_dialog_cb (GtkFileDialog       *dialog,
+                GAsyncResult        *result,
+                SaveDialogAsyncData *data)
 {
   g_autoptr (GFile) file = NULL;
   g_autoptr (GFile) current_file = NULL;
@@ -2494,17 +2516,20 @@ save_dialog_cb (GtkFileDialog *dialog,
   file = gtk_file_dialog_save_finish (dialog, result, NULL);
 
   if (!file)
-    return;
+    goto out;
 
   uri = g_file_get_uri (file);
   if (uri != NULL) {
     converted = g_filename_to_utf8 (uri, -1, NULL, NULL, NULL);
 
     if (converted != NULL) {
-      if (g_str_has_suffix (converted, ".png")) {
-        take_snapshot (embed, converted);
+      /* Easter egg: allow power users to take a screenshot of anything that's
+       * not a PNG by changing the suffix to .png.
+       */
+      if (g_str_has_suffix (converted, ".png") && !g_str_has_suffix (data->suggested_filename, ".png")) {
+        take_snapshot (data->embed, converted);
       } else {
-        EphyWebView *web_view = ephy_embed_get_web_view (embed);
+        EphyWebView *web_view = ephy_embed_get_web_view (data->embed);
         ephy_web_view_save (web_view, converted);
       }
     }
@@ -2515,6 +2540,9 @@ save_dialog_cb (GtkFileDialog *dialog,
   g_settings_set_string (EPHY_SETTINGS_WEB,
                          EPHY_PREFS_WEB_LAST_DOWNLOAD_DIRECTORY,
                          current_path);
+
+out:
+  save_dialog_async_data_free (data);
 }
 
 void
@@ -2565,7 +2593,7 @@ window_cmd_save_as (GSimpleAction *action,
                         GTK_WINDOW (window),
                         NULL,
                         (GAsyncReadyCallback)save_dialog_cb,
-                        embed);
+                        save_dialog_async_data_new (embed, suggested_filename));
 }
 
 void