~ubuntu-branches/ubuntu/trusty/epiphany-browser/trusty

« back to all changes in this revision

Viewing changes to .pc/03_dbus.patch/src/ephy-main.c

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2011-11-21 17:15:18 UTC
  • mfrom: (1.6.3) (98.2.3 sid)
  • Revision ID: package-import@ubuntu.com-20111121171518-0f07y0i5rvb2wrix
Tags: 3.2.1-2ubuntu1
* Resynchronize on Debian, remaining diffs:
* debian/branding.conf.in: set the branding to Ubuntu.
* debian/epiphany-browser-data.gsettings-override:
  - set startpage and search to Ubuntu
* debian/patches/80_ubuntu_search_url.patch: use Ubuntu search
* debian/patches/81_ubuntu_force_update_bookmarks_menu.patch:
  - update the bookmarks menu every time the internal structure
    is changed (needed for the indicator application menu to work correctly).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright © 2000-2002 Marco Pesenti Gritti
3
 
 *  Copyright © 2006, 2008 Christian Persch
4
 
 *
5
 
 *  This program is free software; you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation; either version 2, or (at your option)
8
 
 *  any later version.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 
 *
19
 
 */
20
 
 
21
 
#include "config.h"
22
 
 
23
 
#include "ephy-settings.h"
24
 
#include "ephy-shell.h"
25
 
#include "ephy-file-helpers.h"
26
 
#include "ephy-object-helpers.h"
27
 
#include "ephy-state.h"
28
 
#include "ephy-debug.h"
29
 
#include "ephy-stock-icons.h"
30
 
#include "ephy-dbus-client-bindings.h"
31
 
#include "ephy-activation.h"
32
 
#include "ephy-session.h"
33
 
#include "ephy-shell.h"
34
 
#include "ephy-prefs.h"
35
 
#include "ephy-profile-utils.h"
36
 
#include "ephy-debug.h"
37
 
#include "eggsmclient.h"
38
 
 
39
 
#include <libxml/xmlversion.h>
40
 
 
41
 
#include <glib/gi18n.h>
42
 
 
43
 
#include <gdk/gdkx.h>
44
 
#include <gtk/gtk.h>
45
 
 
46
 
#include <errno.h>
47
 
#include <string.h>
48
 
 
49
 
#ifdef ENABLE_INTROSPECTION
50
 
#include <girepository.h>
51
 
#endif
52
 
 
53
 
static GQuark startup_error_quark = 0;
54
 
#define STARTUP_ERROR_QUARK     (startup_error_quark)
55
 
 
56
 
static gboolean open_in_new_tab = FALSE;
57
 
static gboolean open_in_new_window = FALSE;
58
 
static gboolean open_as_bookmarks_editor = FALSE;
59
 
/*static gboolean reload_plugins = FALSE;*/
60
 
 
61
 
static char *session_filename = NULL;
62
 
static char *bookmark_url = NULL;
63
 
static char *bookmarks_file = NULL;
64
 
static char **arguments = NULL;
65
 
 
66
 
/* Only set from options in debug builds */
67
 
static gboolean private_instance = FALSE;
68
 
static gboolean keep_temp_directory = FALSE;
69
 
static char *profile_directory = NULL;
70
 
 
71
 
static gboolean
72
 
option_version_cb (const gchar *option_name,
73
 
                   const gchar *value,
74
 
                   gpointer     data,
75
 
                   GError     **error)
76
 
{
77
 
  g_print ("%s %s\n", _("GNOME Web Browser"), VERSION);
78
 
 
79
 
  exit (EXIT_SUCCESS);
80
 
 return FALSE;
81
 
}
82
 
 
83
 
static const GOptionEntry option_entries[] =
84
 
{
85
 
        { "new-tab", 'n', 0, G_OPTION_ARG_NONE, &open_in_new_tab,
86
 
          N_("Open a new tab in an existing browser window"), NULL },
87
 
        { "new-window", 0, 0, G_OPTION_ARG_NONE, &open_in_new_window,
88
 
          N_("Open a new browser window"), NULL },
89
 
        { "bookmarks-editor", 'b', 0, G_OPTION_ARG_NONE, &open_as_bookmarks_editor,
90
 
          N_("Launch the bookmarks editor"), NULL },
91
 
        { "import-bookmarks", '\0', 0, G_OPTION_ARG_FILENAME, &bookmarks_file,
92
 
          N_("Import bookmarks from the given file"), N_("FILE") },
93
 
        { "load-session", 'l', 0, G_OPTION_ARG_FILENAME, &session_filename,
94
 
          N_("Load the given session file"), N_("FILE") },
95
 
        { "add-bookmark", 't', 0, G_OPTION_ARG_STRING, &bookmark_url,
96
 
          N_("Add a bookmark"), N_("URL") },
97
 
        { "private-instance", 'p', 0, G_OPTION_ARG_NONE, &private_instance,
98
 
          N_("Start a private instance"), NULL },
99
 
        { "profile", 0, 0, G_OPTION_ARG_STRING, &profile_directory,
100
 
          N_("Profile directory to use in the private instance"), N_("DIR") },
101
 
        { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &arguments,
102
 
          "", N_("URL …")},
103
 
        { "version", 0, G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN, 
104
 
          G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL },
105
 
        { NULL }
106
 
};
107
 
 
108
 
#ifdef GNOME_ENABLE_DEBUG
109
 
static GOptionEntry debug_option_entries[] =
110
 
{
111
 
        { "keep-tempdir", 0, 0, G_OPTION_ARG_NONE, &keep_temp_directory,
112
 
          "Don't delete the temporary directory on exit", NULL },
113
 
        { NULL }
114
 
};
115
 
#endif /* GNOME_ENABLE_DEBUG */
116
 
 
117
 
/* adapted from gtk+/gdk/x11/gdkdisplay-x11.c */
118
 
static guint32
119
 
get_startup_id (void)
120
 
{
121
 
        const char *startup_id, *time_str;
122
 
        guint32 retval = 0;
123
 
 
124
 
        startup_id = g_getenv ("DESKTOP_STARTUP_ID");
125
 
        if (startup_id == NULL) return 0;
126
 
 
127
 
        /* Find the launch time from the startup_id, if it's there.  Newer spec
128
 
        * states that the startup_id is of the form <unique>_TIME<timestamp>
129
 
        */
130
 
        time_str = g_strrstr (startup_id, "_TIME");
131
 
        if (time_str != NULL)
132
 
        {
133
 
                gulong value;
134
 
                gchar *end;
135
 
                errno = 0;
136
 
        
137
 
                /* Skip past the "_TIME" part */
138
 
                time_str += 5;
139
 
        
140
 
                value = strtoul (time_str, &end, 0);
141
 
                if (end != time_str && errno == 0)
142
 
                {
143
 
                        retval = (guint32) value;
144
 
                }
145
 
        }
146
 
 
147
 
        return retval;
148
 
}
149
 
 
150
 
/* Copied from libnautilus/nautilus-program-choosing.c; Needed in case
151
 
 * we have no DESKTOP_STARTUP_ID (with its accompanying timestamp).
152
 
 */
153
 
static Time
154
 
slowly_and_stupidly_obtain_timestamp (Display *xdisplay)
155
 
{
156
 
        Window xwindow;
157
 
        XEvent event;
158
 
        
159
 
        {
160
 
                XSetWindowAttributes attrs;
161
 
                Atom atom_name;
162
 
                Atom atom_type;
163
 
                char* name;
164
 
                
165
 
                attrs.override_redirect = True;
166
 
                attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
167
 
                
168
 
                xwindow =
169
 
                        XCreateWindow (xdisplay,
170
 
                                       RootWindow (xdisplay, 0),
171
 
                                       -100, -100, 1, 1,
172
 
                                       0,
173
 
                                       CopyFromParent,
174
 
                                       CopyFromParent,
175
 
                                       CopyFromParent,
176
 
                                       CWOverrideRedirect | CWEventMask,
177
 
                                       &attrs);
178
 
                
179
 
                atom_name = XInternAtom (xdisplay, "WM_NAME", TRUE);
180
 
                g_assert (atom_name != None);
181
 
                atom_type = XInternAtom (xdisplay, "STRING", TRUE);
182
 
                g_assert (atom_type != None);
183
 
                
184
 
                name = "Fake Window";
185
 
                XChangeProperty (xdisplay, 
186
 
                                 xwindow, atom_name,
187
 
                                 atom_type,
188
 
                                 8, PropModeReplace, (unsigned char *)name, strlen (name));
189
 
        }
190
 
        
191
 
        XWindowEvent (xdisplay,
192
 
                      xwindow,
193
 
                      PropertyChangeMask,
194
 
                      &event);
195
 
        
196
 
        XDestroyWindow(xdisplay, xwindow);
197
 
        
198
 
        return event.xproperty.time;
199
 
}
200
 
 
201
 
static void
202
 
unref_proxy_reply_cb (DBusGProxy *proxy,
203
 
                      GError *error,
204
 
                      gpointer user_data)
205
 
{
206
 
        if (error != NULL)
207
 
        {
208
 
                g_warning ("An error occurred while calling remote method: %s", error->message);
209
 
                g_error_free (error);
210
 
        }
211
 
 
212
 
        g_object_unref (proxy);
213
 
 
214
 
        if (gtk_main_level ())
215
 
        {
216
 
                gtk_main_quit ();
217
 
        }
218
 
}
219
 
 
220
 
static gboolean
221
 
open_urls (DBusGProxy *proxy,
222
 
           guint32 user_time,
223
 
           GError **error)
224
 
{
225
 
        static const char *empty_arguments[] = { "", NULL };
226
 
        GString *options;
227
 
        char **uris;
228
 
 
229
 
        options = g_string_sized_new (64);
230
 
 
231
 
        if (open_in_new_window)
232
 
        {
233
 
                g_string_append (options, "new-window,");
234
 
        }
235
 
        if (open_in_new_tab)
236
 
        {
237
 
                g_string_append (options, "new-tab,");
238
 
        }
239
 
 
240
 
        if (arguments == NULL)
241
 
        {
242
 
                uris = (char **) empty_arguments;
243
 
        }
244
 
        else
245
 
        {
246
 
                uris = (char **) arguments;
247
 
        }
248
 
 
249
 
        org_gnome_Epiphany_load_ur_ilist_async
250
 
                (proxy, (const char **) uris, options->str, user_time,
251
 
                 unref_proxy_reply_cb, NULL);
252
 
        
253
 
        if (arguments != NULL)
254
 
        {
255
 
                g_strfreev (arguments);
256
 
                arguments = NULL;
257
 
        }
258
 
 
259
 
        g_string_free (options, TRUE);
260
 
 
261
 
        return TRUE;
262
 
}
263
 
 
264
 
static gboolean
265
 
call_dbus_proxy (DBusGProxy *proxy,
266
 
                 guint32 user_time,
267
 
                 GError **error)
268
 
{
269
 
        EphyShell *shell;
270
 
        gboolean retval = TRUE;
271
 
 
272
 
        shell = ephy_shell_get_default ();
273
 
 
274
 
        if (open_as_bookmarks_editor)
275
 
        {
276
 
                org_gnome_Epiphany_open_bookmarks_editor_async
277
 
                        (proxy, user_time,
278
 
                         unref_proxy_reply_cb, shell);
279
 
        }
280
 
        else if (session_filename != NULL)
281
 
        {
282
 
                org_gnome_Epiphany_load_session_async
283
 
                        (proxy, session_filename, user_time,
284
 
                         unref_proxy_reply_cb, shell);
285
 
 
286
 
                g_free (session_filename);
287
 
                session_filename = NULL;
288
 
        }
289
 
        else
290
 
        {
291
 
                retval = open_urls (proxy, user_time, error);
292
 
        }
293
 
 
294
 
        /* FIXME why? */
295
 
        dbus_g_connection_flush (ephy_dbus_get_bus (ephy_dbus_get_default (), EPHY_DBUS_SESSION));
296
 
 
297
 
        return retval;
298
 
}
299
 
 
300
 
static void
301
 
queue_commands (guint32 user_time)
302
 
{
303
 
        EphyShell *shell;
304
 
        EphySession *session;
305
 
 
306
 
        shell = ephy_shell_get_default ();
307
 
        g_assert (shell != NULL);
308
 
 
309
 
        session = EPHY_SESSION (ephy_shell_get_session (shell));
310
 
        g_assert (session != NULL);
311
 
 
312
 
        /* We only get here when starting a new instance, so we 
313
 
         * first need to autoresume!
314
 
         */
315
 
        ephy_session_queue_command (session,
316
 
                                    EPHY_SESSION_CMD_RESUME_SESSION,
317
 
                                    NULL, NULL, user_time, TRUE);
318
 
 
319
 
        if (open_as_bookmarks_editor)
320
 
        {
321
 
                ephy_session_queue_command (session,
322
 
                                            EPHY_SESSION_CMD_OPEN_BOOKMARKS_EDITOR,
323
 
                                            NULL, NULL, user_time, FALSE);
324
 
        }
325
 
        else if (session_filename != NULL)
326
 
        {
327
 
                ephy_session_queue_command (session,
328
 
                                            EPHY_SESSION_CMD_LOAD_SESSION,
329
 
                                            session_filename, NULL,
330
 
                                            user_time, FALSE);
331
 
 
332
 
                g_free (session_filename);
333
 
                session_filename = NULL;
334
 
        }
335
 
        /* Don't queue any window openings if no extra arguments given,
336
 
         * since session autoresume will open one for us.
337
 
         */
338
 
        else if (arguments != NULL)
339
 
        {
340
 
                GString *options;
341
 
 
342
 
                options = g_string_sized_new (64);
343
 
 
344
 
                if (open_in_new_window)
345
 
                {
346
 
                        g_string_append (options, "new-window,");
347
 
                }
348
 
                if (open_in_new_tab)
349
 
                {
350
 
                        g_string_append (options, "new-tab,external,");
351
 
                }
352
 
 
353
 
                ephy_session_queue_command (session,
354
 
                                            EPHY_SESSION_CMD_OPEN_URIS,
355
 
                                            options->str,
356
 
                                            arguments,
357
 
                                            user_time, FALSE);
358
 
 
359
 
                g_strfreev (arguments);
360
 
                arguments = NULL;
361
 
        }
362
 
}
363
 
 
364
 
static void
365
 
show_error_message (GError **error)
366
 
{
367
 
        GtkWidget *dialog;
368
 
 
369
 
        /* FIXME better texts!!! */
370
 
        dialog = gtk_message_dialog_new (NULL,
371
 
                                         GTK_DIALOG_MODAL,
372
 
                                         GTK_MESSAGE_ERROR,
373
 
                                         GTK_BUTTONS_CLOSE,
374
 
                                         _("Could not start GNOME Web Browser"));
375
 
        gtk_message_dialog_format_secondary_text
376
 
                (GTK_MESSAGE_DIALOG (dialog),
377
 
                 _("Startup failed because of the following error:\n%s"),
378
 
                 (*error)->message);
379
 
 
380
 
        g_clear_error (error);
381
 
 
382
 
        gtk_dialog_run (GTK_DIALOG (dialog));
383
 
}
384
 
 
385
 
static gchar *
386
 
get_accels_filename (void)
387
 
{
388
 
        const char *home;
389
 
 
390
 
        home = g_get_home_dir();
391
 
        if (!home)
392
 
                return NULL;
393
 
        return g_build_filename (home, GNOME_DOT_GNOME, "accels", PACKAGE, NULL);
394
 
}
395
 
 
396
 
static void
397
 
load_accels (void)
398
 
{
399
 
        char *filename;
400
 
 
401
 
        filename = get_accels_filename ();
402
 
        if (!filename)
403
 
                return;
404
 
 
405
 
        gtk_accel_map_load (filename);
406
 
        g_free (filename);
407
 
}
408
 
 
409
 
static void
410
 
save_accels (void)
411
 
{
412
 
        char *filename;
413
 
 
414
 
        filename = get_accels_filename ();
415
 
        if (!filename)
416
 
                return;
417
 
 
418
 
        gtk_accel_map_save (filename);
419
 
        g_free (filename);
420
 
}
421
 
 
422
 
static void
423
 
shell_quit_cb (EphyShell *shell, gpointer data)
424
 
{
425
 
        gtk_main_quit ();
426
 
}
427
 
 
428
 
int
429
 
main (int argc,
430
 
      char *argv[])
431
 
{
432
 
        GOptionContext *option_context;
433
 
        GOptionGroup *option_group;
434
 
        DBusGProxy *proxy;
435
 
        GError *error = NULL;
436
 
        guint32 user_time;
437
 
        gboolean arbitrary_url;
438
 
 
439
 
#ifdef ENABLE_NLS
440
 
        /* Initialize the i18n stuff */
441
 
        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
442
 
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
443
 
        textdomain (GETTEXT_PACKAGE);
444
 
#endif
445
 
 
446
 
        /* Threads have to be initialised before calling ANY glib function */
447
 
        g_thread_init (NULL);
448
 
        dbus_g_thread_init ();
449
 
 
450
 
        /* check libxml2 API version epiphany was compiled with against the
451
 
         * version we're running with.
452
 
         */
453
 
        LIBXML_TEST_VERSION;
454
 
 
455
 
        /* sets name to help matching with the .desktop file */
456
 
        g_set_prgname ("epiphany-browser");
457
 
 
458
 
        /* If we're given -remote arguments, translate them */
459
 
        if (argc >= 2 &&
460
 
            strcmp (argv[1], "-remote") == 0)
461
 
        {
462
 
                const char *opening, *closing;
463
 
                char *command, *argument;
464
 
                char **arguments;
465
 
 
466
 
                if (argc != 3)
467
 
                {
468
 
                        g_print ("-remote allows exactly one argument\n");
469
 
                        exit (1);
470
 
                }
471
 
 
472
 
                opening = strchr (argv[2], '(');
473
 
                closing = strchr (argv[2], ')');
474
 
 
475
 
                if (opening == NULL ||
476
 
                    closing == NULL ||
477
 
                    opening == argv[2] ||
478
 
                    opening + 1 >= closing)
479
 
                {
480
 
                        g_print ("Invalid argument for -remote\n");
481
 
                        exit (1);
482
 
                }
483
 
 
484
 
                command = g_strstrip (g_strndup (argv[2], opening - argv[2]));
485
 
 
486
 
                /* See http://lxr.mozilla.org/seamonkey/source/xpfe/components/xremote/src/XRemoteService.cpp
487
 
                 * for the commands that mozilla supports; we'll just support openURL here.
488
 
                 */
489
 
                if (g_ascii_strcasecmp (command, "openURL") != 0)
490
 
                {
491
 
                        g_print ("-remote command \"%s\" not supported\n", command);
492
 
                        g_free (command);
493
 
                        exit (1);
494
 
                }
495
 
 
496
 
                g_free (command);
497
 
 
498
 
                argument = g_strstrip (g_strndup (opening + 1, closing - opening - 1));
499
 
                arguments = g_strsplit (argument, ",", -1);
500
 
                g_free (argument);
501
 
                if (arguments == NULL)
502
 
                {
503
 
                        g_print ("Invalid argument for -remote\n");
504
 
 
505
 
                        exit (1);
506
 
                }
507
 
 
508
 
                /* replace arguments */
509
 
                argv[1] = g_strstrip (g_strdup (arguments[0]));
510
 
                argc = 2;
511
 
 
512
 
                g_strfreev (arguments);
513
 
        }
514
 
 
515
 
        /* Initialise our debug helpers */
516
 
        ephy_debug_init ();
517
 
 
518
 
        /* get this early, since gdk will unset the env var */
519
 
        user_time = get_startup_id ();
520
 
 
521
 
        option_context = g_option_context_new ("");
522
 
        option_group = g_option_group_new ("epiphany-browser",
523
 
                                           N_("GNOME Web Browser"),
524
 
                                           N_("GNOME Web Browser options"),
525
 
                                           NULL, NULL);
526
 
 
527
 
        g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE);
528
 
 
529
 
        g_option_group_add_entries (option_group, option_entries);
530
 
 
531
 
        g_option_context_set_main_group (option_context, option_group);
532
 
 
533
 
#ifdef ENABLE_INTROSPECTION
534
 
        g_option_context_add_group (option_context, g_irepository_get_option_group ());
535
 
#endif
536
 
 
537
 
        g_option_context_add_group (option_context, gtk_get_option_group (TRUE));
538
 
        g_option_context_add_group (option_context, egg_sm_client_get_option_group ());
539
 
 
540
 
#ifdef GNOME_ENABLE_DEBUG
541
 
        option_group = g_option_group_new ("debug",
542
 
                                           "Epiphany debug options",
543
 
                                           "Epiphany debug options",
544
 
                                           NULL, NULL);
545
 
        g_option_group_add_entries (option_group, debug_option_entries);
546
 
        g_option_context_add_group (option_context, option_group);
547
 
#endif /* GNOME_ENABLE_DEBUG */
548
 
 
549
 
        if (!g_option_context_parse (option_context, &argc, &argv, &error))
550
 
        {
551
 
                g_print ("Failed to parse arguments: %s\n", error->message);
552
 
                g_error_free (error);
553
 
                g_option_context_free (option_context);
554
 
                exit (1);
555
 
        }
556
 
        
557
 
        g_option_context_free (option_context);
558
 
 
559
 
        /* Some argument sanity checks*/
560
 
        if (arguments != NULL && (session_filename != NULL || open_as_bookmarks_editor))
561
 
        {
562
 
                g_print ("Cannot use --bookmarks-editor or --load-session with URL arguments\n");
563
 
                exit (1);
564
 
        }
565
 
 
566
 
        if (profile_directory != NULL && private_instance == FALSE)
567
 
        {
568
 
                g_print ("--profile can only be used in combination with --private-instance\n");
569
 
                exit (1);
570
 
        }
571
 
 
572
 
        arbitrary_url = g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
573
 
                                                EPHY_PREFS_LOCKDOWN_ARBITRARY_URL);
574
 
 
575
 
        if (arguments != NULL && arbitrary_url)
576
 
        {
577
 
                g_print ("URL loading is locked down\n");
578
 
                exit (1);
579
 
        }
580
 
 
581
 
        /* Make URIs from arguments, to support filename args */
582
 
        if (arguments != NULL)
583
 
        {
584
 
                guint i;
585
 
 
586
 
                for (i = 0; arguments[i] != NULL; ++i)
587
 
                {
588
 
                        char *uri, *path;
589
 
#ifdef PATH_MAX
590
 
                        char rpath[PATH_MAX];
591
 
#else
592
 
                        char *rpath = NULL;
593
 
#endif
594
 
 
595
 
                        path = realpath (arguments[i], rpath);
596
 
                        if (path != NULL)
597
 
                        {
598
 
                                uri = g_locale_to_utf8 (path, -1, 
599
 
                                                        NULL, NULL, &error);
600
 
#ifndef PATH_MAX
601
 
                                free (path);
602
 
#endif
603
 
                        }
604
 
                        else
605
 
                        {
606
 
                                uri = g_locale_to_utf8 (arguments[i], -1, 
607
 
                                                        NULL, NULL, &error);
608
 
                        }
609
 
 
610
 
                        if (uri != NULL)
611
 
                        {
612
 
                                g_free (arguments[i]);
613
 
 
614
 
                                /* If it's a file, use g_file_new_for_commandline_arg,
615
 
                                 * so we get the right escaping.
616
 
                                 */
617
 
                                if (path != NULL)
618
 
                                {
619
 
                                        GFile *file;
620
 
                                        file = g_file_new_for_commandline_arg (uri);
621
 
                                        arguments[i] = g_file_get_uri (file);
622
 
                                        g_object_unref (file);
623
 
                                        g_free (uri);
624
 
                                }
625
 
                                else
626
 
                                {
627
 
                                        arguments[i] = uri;
628
 
                                }
629
 
                        }
630
 
                        else
631
 
                        {
632
 
                                g_print ("Could not convert '%s' to UTF-8: %s!\n",
633
 
                                         arguments[i], error->message);
634
 
                                g_error_free (error);
635
 
                                exit (1);
636
 
                        }
637
 
                }
638
 
        }
639
 
 
640
 
        /* Get a timestamp manually if need be */
641
 
        if (user_time == 0)
642
 
        {
643
 
                user_time = slowly_and_stupidly_obtain_timestamp (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
644
 
        }
645
 
 
646
 
        /* sets the name to appear in the window list applet when grouping windows */
647
 
        g_set_application_name (_("Web Browser"));
648
 
 
649
 
        /* Set default window icon */
650
 
        gtk_window_set_default_icon_name (EPHY_STOCK_EPHY);
651
 
 
652
 
        /* sets WM_CLASS to help GNOME Shell windows matching */
653
 
        gdk_set_program_class ("epiphany");
654
 
 
655
 
        startup_error_quark = g_quark_from_static_string ("epiphany-startup-error");
656
 
 
657
 
        if (!_ephy_dbus_startup (!private_instance, &error))
658
 
        {
659
 
                _ephy_dbus_release ();
660
 
 
661
 
                show_error_message (&error);
662
 
 
663
 
                exit (1);
664
 
        }
665
 
 
666
 
        /* If we're remoting, no need to start up any further services,
667
 
         * just forward the call.
668
 
         */
669
 
        if (!private_instance &&
670
 
            !_ephy_dbus_is_name_owner ())
671
 
        {
672
 
                /* Create DBUS proxy */
673
 
                proxy = ephy_dbus_get_proxy (ephy_dbus_get_default (), EPHY_DBUS_SESSION);
674
 
                if (proxy == NULL)
675
 
                {
676
 
                        error = g_error_new (STARTUP_ERROR_QUARK,
677
 
                                             0,
678
 
                                             "Unable to get DBus proxy; aborting activation."); /* FIXME i18n */
679
 
 
680
 
                        _ephy_dbus_release ();
681
 
 
682
 
                        show_error_message (&error);
683
 
 
684
 
                        exit (1);
685
 
                }
686
 
 
687
 
                if (!call_dbus_proxy (proxy, user_time, &error))
688
 
                {
689
 
                        _ephy_dbus_release ();
690
 
 
691
 
                        show_error_message (&error);
692
 
 
693
 
                        exit (1);
694
 
                }
695
 
 
696
 
                /* Wait for the response */
697
 
                gtk_main ();
698
 
 
699
 
                _ephy_dbus_release ();
700
 
 
701
 
                gdk_notify_startup_complete ();
702
 
 
703
 
                exit (0);
704
 
        }
705
 
 
706
 
        /* We're not remoting; start our services */
707
 
        if (!ephy_file_helpers_init (profile_directory,
708
 
                                     private_instance,
709
 
                                     keep_temp_directory || profile_directory,
710
 
                                     &error))
711
 
        {
712
 
                _ephy_dbus_release ();
713
 
 
714
 
                show_error_message (&error);
715
 
 
716
 
                exit (1);
717
 
        }
718
 
 
719
 
        /* Migrate profile if we are not running a private instance */
720
 
        if (ephy_has_private_profile () == FALSE &&
721
 
            ephy_profile_utils_get_migration_version () < EPHY_PROFILE_MIGRATION_VERSION)
722
 
        {
723
 
                GError *error = NULL;
724
 
                char *argv[1] = { "ephy-profile-migrator" };
725
 
                char *envp[1] = { "EPHY_LOG_MODULES=ephy-profile" };
726
 
 
727
 
                g_spawn_sync (NULL, argv, envp, G_SPAWN_SEARCH_PATH,
728
 
                              NULL, NULL, NULL, NULL,
729
 
                              NULL, &error);
730
 
 
731
 
                if (error)
732
 
                {
733
 
                        LOG ("Failed to run migrator: %s", error->message);
734
 
                        g_error_free (error);
735
 
                }
736
 
        }
737
 
 
738
 
        ephy_stock_icons_init ();
739
 
        load_accels ();
740
 
 
741
 
        /* Work-around Flash Player crash */
742
 
        g_setenv ("XLIB_SKIP_ARGB_VISUALS", "1", FALSE);
743
 
 
744
 
        /* Now create the shell */
745
 
        _ephy_shell_create_instance ();
746
 
        g_signal_connect (ephy_shell, "quit", G_CALLBACK (shell_quit_cb), NULL);
747
 
 
748
 
        queue_commands (user_time);
749
 
 
750
 
        gtk_main ();
751
 
 
752
 
        /* Shutdown */
753
 
        g_object_unref (ephy_shell);
754
 
 
755
 
        save_accels ();
756
 
        ephy_state_save ();
757
 
        ephy_settings_shutdown ();
758
 
        ephy_file_helpers_shutdown ();
759
 
        xmlCleanupParser ();
760
 
 
761
 
        _ephy_dbus_release ();
762
 
 
763
 
        return 0;
764
 
}