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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright © 2000, 2001, 2002, 2003, 2004 Marco Pesenti Gritti
* Copyright © 2003, 2004, 2005 Christian Persch
* Copyright © 2010 Igalia S.L.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "config.h"
#include "ephy-action-helper.h"
#include "ephy-embed-container.h"
#include "ephy-embed-shell.h"
#include "ephy-embed-utils.h"
#include "ephy-web-view.h"
#include "ephy-lockdown.h"
#include "ephy-extension.h"
#include "ephy-settings.h"
#include "ephy-prefs.h"
#include "ephy-debug.h"
#include <gtk/gtk.h>
#include <string.h>
#define LOCKDOWN_FLAG 1 << 8
static void ephy_lockdown_iface_init (EphyExtensionIface *iface);
static int
find_name (GtkActionGroup *action_group,
const char *name)
{
return strcmp (gtk_action_group_get_name (action_group), name);
}
static GtkActionGroup *
find_action_group (GtkUIManager *manager,
const char *name)
{
GList *list, *element;
list = gtk_ui_manager_get_action_groups (manager);
element = g_list_find_custom (list, name, (GCompareFunc) find_name);
g_return_val_if_fail (element != NULL, NULL);
return GTK_ACTION_GROUP (element->data);
}
static void
arbitrary_url_cb (GSettings *settings,
char *key,
EphyWindow *window)
{
EphyEmbed *embed;
char *address;
/* Restore the real web page address when disabling entry */
if (g_settings_get_boolean (settings, key))
{
embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
/* embed is NULL on startup */
if (embed == NULL)
return;
address = ephy_web_view_get_location (ephy_embed_get_web_view (embed), TRUE);
ephy_window_set_location (window, address);
ephy_web_view_set_typed_address (ephy_embed_get_web_view (embed), NULL);
g_free (address);
}
}
static void
fullscreen_cb (GSettings *settings,
char *key,
EphyWindow *window)
{
if (g_settings_get_boolean (settings, key))
gtk_window_fullscreen (GTK_WINDOW (window));
else
gtk_window_unfullscreen (GTK_WINDOW (window));
}
typedef struct {
char *key;
char *action;
char *prop;
} BindAction;
static const BindAction window_actions[] = {
{ EPHY_PREFS_LOCKDOWN_PRINTING, "FilePrint", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_PRINTING, "FilePrintPreview", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_PRINTING, "FilePrintSetup", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_PRINT_SETUP, "FilePrintSetup", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_COMMAND_LINE, "FilePrintSetup", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "GoBookmarks", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "FileBookmarkPage", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_ARBITRARY_URL, "GoLocation", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "FileSaveAs", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_HISTORY, "GoHistory", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_FULLSCREEN, "ViewFullscreen", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_FULLSCREEN, "TabsDetach", "sensitive" }
};
static const BindAction popup_actions[] = {
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "DownloadLink", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "DownloadLinkAs", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "SaveImageAs", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "OpenImage", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "BookmarkLink", "sensitive" }
};
static const BindAction special_toolbar_actions[] = {
{ EPHY_PREFS_LOCKDOWN_ARBITRARY_URL, "Location", "editable" },
{ EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationBack", "visible" },
{ EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationBack", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationForward", "visible" },
{ EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationForward", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_FULLSCREEN, "FileNewWindow", "sensitive" }
};
static gboolean
sensitive_get_mapping (GValue *value,
GVariant *variant,
gpointer data)
{
GtkAction *action;
gboolean active, before, after;
action = GTK_ACTION (data);
active = g_variant_get_boolean (variant);
before = gtk_action_get_sensitive (action);
ephy_action_change_sensitivity_flags (action, LOCKDOWN_FLAG, active);
after = gtk_action_get_sensitive (action);
/* Set (GtkAction::sensitive) to the value in GSettings _only if_
* the LOCKDOWN_FLAG had some real effect in the GtkAction */
g_value_set_boolean (value, (before != after) ? after : before);
return TRUE;
}
static void
bind_settings_and_actions (GSettings *settings,
GtkActionGroup *action_group,
const BindAction *actions,
int actions_n)
{
int i;
for (i = 0; i < actions_n; i++)
{
GtkAction *action;
action = gtk_action_group_get_action (action_group,
actions[i].action);
if (g_strcmp0 (actions[i].prop, "visible") == 0)
{
g_settings_bind (settings, actions[i].key,
action, actions[i].prop,
G_SETTINGS_BIND_GET |
G_SETTINGS_BIND_INVERT_BOOLEAN);
}
else
{
/* We need a custom get_mapping for 'sensitive'
* properties, see usage of
* ephy_action_change_sensitivity_flags in
* ephy-window.c. */
g_settings_bind_with_mapping (settings, actions[i].key,
action, actions[i].prop,
G_SETTINGS_BIND_GET,
sensitive_get_mapping,
NULL,
action, NULL);
}
}
}
static void
impl_attach_window (EphyExtension *extension,
EphyWindow *window)
{
GtkUIManager *manager;
GtkActionGroup *action_group;
GtkAction *action;
GSettings *settings;
g_signal_connect (EPHY_SETTINGS_LOCKDOWN,
"changed::" EPHY_PREFS_LOCKDOWN_FULLSCREEN,
G_CALLBACK (fullscreen_cb), window);
g_signal_connect (EPHY_SETTINGS_LOCKDOWN,
"changed::" EPHY_PREFS_LOCKDOWN_ARBITRARY_URL,
G_CALLBACK (arbitrary_url_cb), window);
/* Trigger an initial state on these elements. */
fullscreen_cb (EPHY_SETTINGS_LOCKDOWN,
EPHY_PREFS_LOCKDOWN_FULLSCREEN, window);
arbitrary_url_cb (EPHY_SETTINGS_LOCKDOWN,
EPHY_PREFS_LOCKDOWN_ARBITRARY_URL, window);
manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window));
action_group = find_action_group (manager, "WindowActions");
bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
action_group, window_actions,
G_N_ELEMENTS (window_actions));
action_group = find_action_group (manager, "PopupsActions");
bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
action_group, popup_actions,
G_N_ELEMENTS (popup_actions));
action = gtk_action_group_get_action (action_group,
"SetImageAsBackground");
settings = ephy_settings_get ("org.gnome.desktop.background");
g_settings_bind_writable (settings, "picture-filename",
action, "sensitive", FALSE);
action_group = find_action_group (manager, "SpecialToolbarActions");
bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
action_group, special_toolbar_actions,
G_N_ELEMENTS (special_toolbar_actions));
}
static void
ephy_lockdown_init (EphyLockdown *lockdown)
{
LOG ("EphyLockdown initialising");
}
G_DEFINE_TYPE_WITH_CODE (EphyLockdown, ephy_lockdown, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (EPHY_TYPE_EXTENSION,
ephy_lockdown_iface_init))
static void
ephy_lockdown_iface_init (EphyExtensionIface *iface)
{
iface->attach_window = impl_attach_window;
}
static void
ephy_lockdown_class_init (EphyLockdownClass *klass)
{
}
|