28
28
#include "ephy-embed-container.h"
29
29
#include "ephy-embed-shell.h"
30
30
#include "ephy-embed-utils.h"
31
#include "ephy-extension.h"
32
31
#include "ephy-prefs.h"
33
32
#include "ephy-private.h"
34
33
#include "ephy-settings.h"
35
#include "ephy-web-view.h"
37
35
#include <gtk/gtk.h>
40
37
#define LOCKDOWN_FLAG 1 << 8
42
static void ephy_lockdown_iface_init (EphyExtensionIface *iface);
45
40
find_name (GtkActionGroup *action_group,
48
return strcmp (gtk_action_group_get_name (action_group), name);
43
return g_strcmp0 (gtk_action_group_get_name (action_group), name);
51
46
static GtkActionGroup *
52
47
find_action_group (GtkUIManager *manager,
55
GList *list, *element;
57
list = gtk_ui_manager_get_action_groups (manager);
58
element = g_list_find_custom (list, name, (GCompareFunc) find_name);
59
g_return_val_if_fail (element != NULL, NULL);
61
return GTK_ACTION_GROUP (element->data);
50
GList *list, *element;
52
list = gtk_ui_manager_get_action_groups (manager);
53
element = g_list_find_custom (list, name, (GCompareFunc) find_name);
54
g_return_val_if_fail (element != NULL, NULL);
56
return GTK_ACTION_GROUP (element->data);
65
60
arbitrary_url_cb (GSettings *settings,
72
/* Restore the real web page address when disabling entry */
73
if (g_settings_get_boolean (settings, key))
75
embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
76
/* embed is NULL on startup */
80
address = ephy_web_view_get_address (ephy_embed_get_web_view (embed));
81
ephy_window_set_location (window, address);
82
ephy_web_view_set_typed_address (ephy_embed_get_web_view (embed), NULL);
67
/* Restore the real web page address when disabling entry */
68
if (g_settings_get_boolean (settings, key)) {
69
embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
70
/* embed is NULL on startup */
74
address = ephy_web_view_get_address (ephy_embed_get_web_view (embed));
75
ephy_window_set_location (window, address);
76
ephy_web_view_set_typed_address (ephy_embed_get_web_view (embed), NULL);
87
81
fullscreen_cb (GSettings *settings,
91
if (g_settings_get_boolean (settings, key))
92
gtk_window_fullscreen (GTK_WINDOW (window));
94
gtk_window_unfullscreen (GTK_WINDOW (window));
85
if (g_settings_get_boolean (settings, key))
86
gtk_window_fullscreen (GTK_WINDOW (window));
88
gtk_window_unfullscreen (GTK_WINDOW (window));
103
97
static const BindAction window_actions[] = {
104
{ EPHY_PREFS_LOCKDOWN_PRINTING, "FilePrint", "sensitive" },
106
{ EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "FileBookmarkPage", "sensitive" },
108
{ EPHY_PREFS_LOCKDOWN_ARBITRARY_URL, "GoLocation", "sensitive" },
109
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "FileSaveAs", "sensitive" },
111
{ EPHY_PREFS_LOCKDOWN_FULLSCREEN, "ViewFullscreen", "sensitive" },
112
{ EPHY_PREFS_LOCKDOWN_FULLSCREEN, "TabsDetach", "sensitive" }
98
{ EPHY_PREFS_LOCKDOWN_PRINTING, "FilePrint", "sensitive" },
100
{ EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "FileBookmarkPage", "sensitive" },
102
{ EPHY_PREFS_LOCKDOWN_ARBITRARY_URL, "GoLocation", "sensitive" },
103
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "FileSaveAs", "sensitive" },
105
{ EPHY_PREFS_LOCKDOWN_FULLSCREEN, "ViewFullscreen", "sensitive" },
106
{ EPHY_PREFS_LOCKDOWN_FULLSCREEN, "TabsDetach", "sensitive" }
115
109
static const BindAction popup_actions[] = {
116
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "DownloadLink", "sensitive" },
117
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "DownloadLinkAs", "sensitive" },
118
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "SaveImageAs", "sensitive" },
119
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "OpenImage", "sensitive" },
120
{ EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "BookmarkLink", "sensitive" }
110
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "DownloadLink", "sensitive" },
111
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "DownloadLinkAs", "sensitive" },
112
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "SaveImageAs", "sensitive" },
113
{ EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "OpenImage", "sensitive" },
114
{ EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "BookmarkLink", "sensitive" }
123
117
static const BindAction special_toolbar_actions[] = {
124
{ EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationBack", "visible" },
125
{ EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationBack", "sensitive" },
126
{ EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationForward", "visible" },
127
{ EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationForward", "sensitive" },
118
{ EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationBack", "visible" },
119
{ EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationBack", "sensitive" },
120
{ EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationForward", "visible" },
121
{ EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationForward", "sensitive" },
131
125
sensitive_get_mapping (GValue *value,
136
gboolean active, before, after;
138
action = GTK_ACTION (data);
139
active = g_variant_get_boolean (variant);
141
before = gtk_action_get_sensitive (action);
142
ephy_action_change_sensitivity_flags (action, LOCKDOWN_FLAG, active);
143
after = gtk_action_get_sensitive (action);
145
/* Set (GtkAction::sensitive) to the value in GSettings _only if_
146
* the LOCKDOWN_FLAG had some real effect in the GtkAction */
147
g_value_set_boolean (value, (before != after) ? after : before);
130
gboolean active, before, after;
132
action = GTK_ACTION (data);
133
active = g_variant_get_boolean (variant);
135
before = gtk_action_get_sensitive (action);
136
ephy_action_change_sensitivity_flags (action, LOCKDOWN_FLAG, active);
137
after = gtk_action_get_sensitive (action);
139
/* Set (GtkAction::sensitive) to the value in GSettings _only if_
140
* the LOCKDOWN_FLAG had some real effect in the GtkAction */
141
g_value_set_boolean (value, (before != after) ? after : before);
153
147
bind_settings_and_actions (GSettings *settings,
154
GtkActionGroup *action_group,
155
const BindAction *actions,
148
GtkActionGroup *action_group,
149
const BindAction *actions,
160
for (i = 0; i < actions_n; i++)
164
action = gtk_action_group_get_action (action_group,
167
if (g_strcmp0 (actions[i].prop, "visible") == 0)
169
g_settings_bind (settings, actions[i].key,
170
action, actions[i].prop,
171
G_SETTINGS_BIND_GET |
172
G_SETTINGS_BIND_INVERT_BOOLEAN);
176
/* We need a custom get_mapping for 'sensitive'
177
* properties, see usage of
178
* ephy_action_change_sensitivity_flags in
180
g_settings_bind_with_mapping (settings, actions[i].key,
181
action, actions[i].prop,
183
sensitive_get_mapping,
154
for (i = 0; i < actions_n; i++) {
157
action = gtk_action_group_get_action (action_group,
160
if (g_strcmp0 (actions[i].prop, "visible") == 0) {
161
g_settings_bind (settings, actions[i].key,
162
action, actions[i].prop,
163
G_SETTINGS_BIND_GET |
164
G_SETTINGS_BIND_INVERT_BOOLEAN);
166
/* We need a custom get_mapping for 'sensitive'
167
* properties, see usage of
168
* ephy_action_change_sensitivity_flags in
170
g_settings_bind_with_mapping (settings, actions[i].key,
171
action, actions[i].prop,
173
sensitive_get_mapping,
191
181
bind_location_controller (GSettings *settings,
192
EphyLocationController *controller)
182
EphyLocationController *controller)
194
g_settings_bind (settings, EPHY_PREFS_LOCKDOWN_ARBITRARY_URL,
195
controller, "editable",
196
G_SETTINGS_BIND_GET |
197
G_SETTINGS_BIND_INVERT_BOOLEAN);
184
g_settings_bind (settings, EPHY_PREFS_LOCKDOWN_ARBITRARY_URL,
185
controller, "editable",
186
G_SETTINGS_BIND_GET |
187
G_SETTINGS_BIND_INVERT_BOOLEAN);
201
impl_attach_window (EphyExtension *extension,
191
window_added_cb (GtkApplication *application,
193
EphyLockdown *lockdown)
204
GtkUIManager *manager;
205
GtkActionGroup *action_group;
208
EphyLocationController *location_controller;
210
g_signal_connect (EPHY_SETTINGS_LOCKDOWN,
211
"changed::" EPHY_PREFS_LOCKDOWN_FULLSCREEN,
212
G_CALLBACK (fullscreen_cb), window);
213
g_signal_connect (EPHY_SETTINGS_LOCKDOWN,
214
"changed::" EPHY_PREFS_LOCKDOWN_ARBITRARY_URL,
215
G_CALLBACK (arbitrary_url_cb), window);
217
/* Trigger an initial state on these elements. */
218
fullscreen_cb (EPHY_SETTINGS_LOCKDOWN,
219
EPHY_PREFS_LOCKDOWN_FULLSCREEN, window);
220
arbitrary_url_cb (EPHY_SETTINGS_LOCKDOWN,
221
EPHY_PREFS_LOCKDOWN_ARBITRARY_URL, window);
223
manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window));
225
action_group = find_action_group (manager, "WindowActions");
226
bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
227
action_group, window_actions,
228
G_N_ELEMENTS (window_actions));
230
action_group = find_action_group (manager, "PopupsActions");
231
bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
232
action_group, popup_actions,
233
G_N_ELEMENTS (popup_actions));
235
action = gtk_action_group_get_action (action_group,
236
"SetImageAsBackground");
237
settings = ephy_settings_get ("org.gnome.desktop.background");
238
g_settings_bind_writable (settings, "picture-filename",
239
action, "sensitive", FALSE);
241
action_group = find_action_group (manager, "SpecialToolbarActions");
242
bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
243
action_group, special_toolbar_actions,
244
G_N_ELEMENTS (special_toolbar_actions));
246
location_controller = ephy_window_get_location_controller (window);
247
bind_location_controller (EPHY_SETTINGS_LOCKDOWN, location_controller);
195
GtkUIManager *manager;
196
GtkActionGroup *action_group;
199
EphyLocationController *location_controller;
201
if (!EPHY_IS_WINDOW (window))
204
g_signal_connect (EPHY_SETTINGS_LOCKDOWN,
205
"changed::" EPHY_PREFS_LOCKDOWN_FULLSCREEN,
206
G_CALLBACK (fullscreen_cb), window);
207
g_signal_connect (EPHY_SETTINGS_LOCKDOWN,
208
"changed::" EPHY_PREFS_LOCKDOWN_ARBITRARY_URL,
209
G_CALLBACK (arbitrary_url_cb), window);
211
/* Trigger an initial state on these elements. */
212
fullscreen_cb (EPHY_SETTINGS_LOCKDOWN,
213
EPHY_PREFS_LOCKDOWN_FULLSCREEN, EPHY_WINDOW (window));
214
arbitrary_url_cb (EPHY_SETTINGS_LOCKDOWN,
215
EPHY_PREFS_LOCKDOWN_ARBITRARY_URL, EPHY_WINDOW (window));
217
manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (EPHY_WINDOW (window)));
219
action_group = find_action_group (manager, "WindowActions");
220
bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
221
action_group, window_actions,
222
G_N_ELEMENTS (window_actions));
224
action_group = find_action_group (manager, "PopupsActions");
225
bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
226
action_group, popup_actions,
227
G_N_ELEMENTS (popup_actions));
229
action = gtk_action_group_get_action (action_group,
230
"SetImageAsBackground");
231
settings = ephy_settings_get ("org.gnome.desktop.background");
232
g_settings_bind_writable (settings, "picture-filename",
233
action, "sensitive", FALSE);
235
action_group = find_action_group (manager, "SpecialToolbarActions");
236
bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
237
action_group, special_toolbar_actions,
238
G_N_ELEMENTS (special_toolbar_actions));
240
location_controller = ephy_window_get_location_controller (EPHY_WINDOW (window));
241
bind_location_controller (EPHY_SETTINGS_LOCKDOWN, location_controller);
244
G_DEFINE_TYPE (EphyLockdown, ephy_lockdown, G_TYPE_OBJECT)
251
247
ephy_lockdown_init (EphyLockdown *lockdown)
253
LOG ("EphyLockdown initialising");
256
G_DEFINE_TYPE_WITH_CODE (EphyLockdown, ephy_lockdown, G_TYPE_OBJECT,
257
G_IMPLEMENT_INTERFACE (EPHY_TYPE_EXTENSION,
258
ephy_lockdown_iface_init))
261
ephy_lockdown_iface_init (EphyExtensionIface *iface)
263
iface->attach_window = impl_attach_window;
251
LOG ("EphyLockdown initialising");
253
shell = ephy_shell_get_default ();
255
g_signal_connect (shell, "window-added",
256
G_CALLBACK (window_added_cb), lockdown);