Implement -b, --blocked-uris command line option
Using a regular expression of blocked URIs makes it possible to restrict the locations that can be visited. Any URI matching the expression will be replaced with "http://.invalid". The option works in --app and normal mode.
This commit is contained in:
parent
b3efe80656
commit
bde7495e6c
1 changed files with 34 additions and 0 deletions
|
@ -1431,6 +1431,27 @@ signal_handler (int signal_id)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_soup_session_block_uris_cb (SoupSession* session,
|
||||||
|
SoupMessage* msg,
|
||||||
|
gchar* blocked_uris)
|
||||||
|
{
|
||||||
|
static GRegex* regex = NULL;
|
||||||
|
SoupURI* soup_uri;
|
||||||
|
gchar* uri;
|
||||||
|
if (!regex)
|
||||||
|
regex = g_regex_new (blocked_uris, 0, 0, NULL);
|
||||||
|
soup_uri = soup_message_get_uri (msg);
|
||||||
|
uri = soup_uri_to_string (soup_uri, FALSE);
|
||||||
|
if (g_regex_match (regex, uri, 0, 0))
|
||||||
|
{
|
||||||
|
soup_uri = soup_uri_new ("http://.invalid");
|
||||||
|
soup_message_set_uri (msg, soup_uri);
|
||||||
|
soup_uri_free (soup_uri);
|
||||||
|
}
|
||||||
|
g_free (uri);
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
MidoriBrowser* browser;
|
MidoriBrowser* browser;
|
||||||
guint timeout;
|
guint timeout;
|
||||||
|
@ -1508,6 +1529,7 @@ main (int argc,
|
||||||
gboolean execute;
|
gboolean execute;
|
||||||
gboolean version;
|
gboolean version;
|
||||||
gchar** uris;
|
gchar** uris;
|
||||||
|
gchar* block_uris;
|
||||||
gint inactivity_reset;
|
gint inactivity_reset;
|
||||||
MidoriApp* app;
|
MidoriApp* app;
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
@ -1534,6 +1556,8 @@ main (int argc,
|
||||||
N_("Display program version"), NULL },
|
N_("Display program version"), NULL },
|
||||||
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &uris,
|
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &uris,
|
||||||
N_("Addresses"), NULL },
|
N_("Addresses"), NULL },
|
||||||
|
{ "block-uris", 'b', 0, G_OPTION_ARG_STRING, &block_uris,
|
||||||
|
N_("Block URIs according to regular expression REGEX"), _("REGEX") },
|
||||||
#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
|
#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
|
||||||
{ "inactivity-reset", 'i', 0, G_OPTION_ARG_INT, &inactivity_reset,
|
{ "inactivity-reset", 'i', 0, G_OPTION_ARG_INT, &inactivity_reset,
|
||||||
N_("Reset Midori after SECONDS seconds of inactivity"), N_("SECONDS") },
|
N_("Reset Midori after SECONDS seconds of inactivity"), N_("SECONDS") },
|
||||||
|
@ -1613,6 +1637,7 @@ main (int argc,
|
||||||
execute = FALSE;
|
execute = FALSE;
|
||||||
version = FALSE;
|
version = FALSE;
|
||||||
uris = NULL;
|
uris = NULL;
|
||||||
|
block_uris = NULL;
|
||||||
inactivity_reset = 0;
|
inactivity_reset = 0;
|
||||||
error = NULL;
|
error = NULL;
|
||||||
if (!gtk_init_with_args (&argc, &argv, _("[Addresses]"), entries,
|
if (!gtk_init_with_args (&argc, &argv, _("[Addresses]"), entries,
|
||||||
|
@ -1722,6 +1747,10 @@ main (int argc,
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (block_uris)
|
||||||
|
g_signal_connect (webkit_get_default_session (), "request-queued",
|
||||||
|
G_CALLBACK (midori_soup_session_block_uris_cb),
|
||||||
|
g_strdup (block_uris));
|
||||||
midori_setup_inactivity_reset (browser, inactivity_reset, webapp);
|
midori_setup_inactivity_reset (browser, inactivity_reset, webapp);
|
||||||
midori_startup_timer ("App created: \t%f");
|
midori_startup_timer ("App created: \t%f");
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
@ -2063,6 +2092,11 @@ main (int argc,
|
||||||
|
|
||||||
if (execute)
|
if (execute)
|
||||||
g_object_set_data (G_OBJECT (app), "execute-command", uris);
|
g_object_set_data (G_OBJECT (app), "execute-command", uris);
|
||||||
|
if (block_uris)
|
||||||
|
g_signal_connect (webkit_get_default_session (), "request-queued",
|
||||||
|
G_CALLBACK (midori_soup_session_block_uris_cb),
|
||||||
|
g_strdup (block_uris));
|
||||||
|
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue