X-Git-Url: http://git.maemo.org/git/?p=browser-switch;a=blobdiff_plain;f=launcher.c;h=a2aec7195ffa386eeec32ef5435424778e75bb6a;hp=e77e965f8e25d44946b89dd24b04bf4aee8cdb97;hb=d9eaacdb0796bfa089b4dea6fb5f1ad1d9835c44;hpb=20b61c36b9d9d871a80caf35c18a4be5f72035f0 diff --git a/launcher.c b/launcher.c index e77e965..a2aec71 100644 --- a/launcher.c +++ b/launcher.c @@ -32,8 +32,7 @@ #include "launcher.h" #include "dbus-server-bindings.h" -#define DEFAULT_BROWSER "/usr/bin/tear" -#define LAUNCH_DEFAULT_BROWSER launch_tear +#define LAUNCH_DEFAULT_BROWSER launch_microb static void launch_tear(struct swb_context *ctx, char *uri) { int status; @@ -46,6 +45,12 @@ static void launch_tear(struct swb_context *ctx, char *uri) { printf("launch_tear with uri '%s'\n", uri); + /* We should be able to just call the D-Bus service to open Tear ... + but if Tear's not open, that cuases D-Bus to star Tear and then pass + it the OpenAddress call, which results in two browser windows. + Properly fixing this probably requires Tear to provide a D-Bus + method that opens an address in an existing window, but for now work + around by just invoking Tear with exec() if it's not running. */ status = system("pidof tear > /dev/null"); if (WIFEXITED(status) && !WEXITSTATUS(status)) { if (!tear_proxy) @@ -78,12 +83,16 @@ void launch_microb(struct swb_context *ctx, char *uri) { if (!uri) uri = "new_window"; + printf("launch_microb with uri '%s'\n", uri); + + /* Launch browserd if it's not running */ status = system("pidof /usr/sbin/browserd > /dev/null"); if (WIFEXITED(status) && WEXITSTATUS(status)) { kill_browserd = 1; system("/usr/sbin/browserd -d"); } + /* Release the osso_browser D-Bus name so that MicroB can take it */ dbus_release_osso_browser_name(ctx); if ((pid = fork()) == -1) { @@ -95,6 +104,9 @@ void launch_microb(struct swb_context *ctx, char *uri) { waitpid(pid, &status, 0); } else { /* Child process */ + /* exec maemo-invoker directly instead of relying on the + /usr/bin/browser symlink, since /usr/bin/browser may have + been replaced with a shell script calling us via D-Bus */ if (!strcmp(uri, "new_window")) { execl("/usr/bin/maemo-invoker", "browser", (char *)NULL); @@ -104,6 +116,7 @@ void launch_microb(struct swb_context *ctx, char *uri) { } } + /* Kill off browserd if we started it */ if (kill_browserd) system("kill `pidof /usr/sbin/browserd`"); @@ -123,9 +136,11 @@ static void launch_other_browser(struct swb_context *ctx, char *uri) { if (!uri || !strcmp(uri, "new_window")) uri = ""; - urilen = strlen(uri); - if (urilen > 0) { - /* Quote the URI */ + + printf("launch_other_browser with uri '%s'\n", uri); + + if ((urilen = strlen(uri)) > 0) { + /* Quote the URI to prevent the shell from interpreting it */ /* urilen+3 = length of URI + 2x \' + \0 */ if (!(quoted_uri = calloc(urilen+3, sizeof(char)))) exit(1); @@ -187,6 +202,10 @@ static void launch_other_browser(struct swb_context *ctx, char *uri) { execl("/bin/sh", "/bin/sh", "-c", command, (char *)NULL); } +/* Use launch_other_browser as the default browser launcher, with the string + passed in as the other_browser_cmd + Resulting other_browser_cmd is always safe to free(), even if a pointer + to a string constant is passed in */ static void use_other_browser_cmd(struct swb_context *ctx, char *cmd) { size_t len = strlen(cmd); @@ -207,12 +226,8 @@ void update_default_browser(struct swb_context *ctx, char *default_browser) { return; if (!default_browser) { - /* No default_browser configured -- use DEFAULT_BROWSER if - installed, otherwise launch MicroB */ - if (!access(DEFAULT_BROWSER, X_OK)) - ctx->default_browser_launcher = LAUNCH_DEFAULT_BROWSER; - else - ctx->default_browser_launcher = launch_microb; + /* No default_browser configured -- use built-in default */ + ctx->default_browser_launcher = LAUNCH_DEFAULT_BROWSER; return; } @@ -221,6 +236,8 @@ void update_default_browser(struct swb_context *ctx, char *default_browser) { else if (!strcmp(default_browser, "microb")) ctx->default_browser_launcher = launch_microb; else if (!strcmp(default_browser, "fennec")) + /* Cheat and reuse launch_other_browser, since we don't appear + to need to do anything special */ use_other_browser_cmd(ctx, "fennec %s"); else if (!strcmp(default_browser, "midori")) use_other_browser_cmd(ctx, "midori %s");