From dd4ec633bf146b525016734d628eb00896008d89 Mon Sep 17 00:00:00 2001 From: Steven Luo Date: Sat, 29 May 2010 22:53:19 -0700 Subject: [PATCH] Don't use a browser as the default browser if it's not installed Add locations for the known browsers' binaries, and check to see if the binary is installed before using a browser as the default. --- launcher.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/launcher.c b/launcher.c index e042f78..935db63 100644 --- a/launcher.c +++ b/launcher.c @@ -51,6 +51,7 @@ struct browser_launcher { char *name; void (*launcher)(struct swb_context *, char *); char *other_browser_cmd; + char *binary; }; #ifdef FREMANTLE @@ -602,12 +603,12 @@ static void launch_other_browser(struct swb_context *ctx, char *uri) { /* The list of known browsers and how to launch them */ static struct browser_launcher browser_launchers[] = { - { "microb", launch_microb, NULL }, /* First entry is the default! */ - { "tear", launch_tear, NULL }, - { "fennec", NULL, "fennec %s" }, - { "opera", NULL, "opera %s" }, - { "midori", NULL, "midori %s" }, - { NULL, NULL, NULL }, + { "microb", launch_microb, NULL, NULL }, /* First entry is the default! */ + { "tear", launch_tear, NULL, "/usr/bin/tear" }, + { "fennec", NULL, "fennec %s", "/usr/bin/fennec" }, + { "opera", NULL, "opera %s", "/usr/bin/opera" }, + { "midori", NULL, "midori %s", "/usr/bin/midori" }, + { NULL, NULL, NULL, NULL }, }; static void use_launcher_as_default(struct swb_context *ctx, @@ -653,8 +654,14 @@ void update_default_browser(struct swb_context *ctx, char *default_browser) { it matches */ for (browser = browser_launchers; browser->name; ++browser) if (!strcmp(default_browser, browser->name)) { - use_launcher_as_default(ctx, browser); - return; + /* Make sure the user's choice is installed on the + system */ + if (browser->binary && !access(browser->binary, X_OK)) { + use_launcher_as_default(ctx, browser); + return; + } else + log_msg("%s appears not to be installed\n", + default_browser); } /* Deal with default_browser = "other" */ -- 1.7.9.5