2 * dbus-server-bindings.c -- osso_browser D-Bus interface implementation
4 * Copyright (C) 2009 Steven Luo
5 * Derived from a Python implementation by Jason Simpson and Steven Luo
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
26 #include <dbus/dbus-glib.h>
28 #include "browser-switchboard.h"
30 #include "dbus-server-bindings.h"
32 extern struct swb_context ctx;
34 G_DEFINE_TYPE(OssoBrowser, osso_browser, G_TYPE_OBJECT);
35 static void osso_browser_init(OssoBrowser *obj)
39 static void osso_browser_class_init(OssoBrowserClass *klass)
43 #include "dbus-server-glue.h"
46 static void open_address(const char *uri) {
51 /* Not much to do in this case ... */
54 printf("open_address '%s'\n", uri);
56 /* URI begins with a '/' -- assume it points to a local file
57 and prefix with "file://" */
58 new_uri_len = strlen("file://") + strlen(uri) + 1;
59 if (!(new_uri = calloc(new_uri_len, sizeof(char))))
61 snprintf(new_uri, new_uri_len, "%s%s", "file://", uri);
63 launch_browser(&ctx, new_uri);
64 /* If launch_browser didn't exec something in this process,
65 we need to clean up after ourselves */
68 launch_browser(&ctx, (char *)uri);
74 * The com.nokia.osso_browser D-Bus interface
76 gboolean osso_browser_load_url(OssoBrowser *obj,
77 const char *uri, GError **error) {
82 gboolean osso_browser_mime_open(OssoBrowser *obj,
83 const char *uri, GError **error) {
88 gboolean osso_browser_open_new_window(OssoBrowser *obj,
89 const char *uri, GError **error) {
94 gboolean osso_browser_top_application(OssoBrowser *obj,
96 launch_microb(&ctx, "new_window");
100 /* This is a "undocumented", non-standard extension to the API, ONLY
101 for use by /usr/bin/browser wrapper to implement --url */
102 gboolean osso_browser_switchboard_launch_microb(OssoBrowser *obj,
103 const char *uri, GError **error) {
104 launch_microb(&ctx, (char *)uri);
109 /* Register the name com.nokia.osso_browser on the D-Bus session bus */
110 void dbus_request_osso_browser_name(struct swb_context *ctx) {
111 GError *error = NULL;
114 if (!ctx || !ctx->dbus_proxy)
117 if (!dbus_g_proxy_call(ctx->dbus_proxy, "RequestName", &error,
118 G_TYPE_STRING, "com.nokia.osso_browser",
119 G_TYPE_UINT, DBUS_NAME_FLAG_REPLACE_EXISTING|DBUS_NAME_FLAG_DO_NOT_QUEUE,
121 G_TYPE_UINT, &result,
123 printf("Couldn't acquire name com.nokia.osso_browser\n");
126 if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
127 printf("Couldn't acquire name com.nokia.osso_browser\n");
132 /* Release the name com.nokia.osso_browser on the D-Bus session bus */
133 void dbus_release_osso_browser_name(struct swb_context *ctx) {
134 GError *error = NULL;
137 if (!ctx || !ctx->dbus_proxy)
140 dbus_g_proxy_call(ctx->dbus_proxy, "ReleaseName", &error,
141 G_TYPE_STRING, "com.nokia.osso_browser",
143 G_TYPE_UINT, &result,