html.c 17.1 KB
Newer Older
Victor Ananjesky's avatar
Victor Ananjesky committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * This file is part of YAD.
 *
 * YAD is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * YAD is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with YAD. If not, see <http://www.gnu.org/licenses/>.
 *
17
 * Copyright (C) 2008-2023, Victor Ananjevsky <victor@sanana.kiev.ua>
Victor Ananjesky's avatar
Victor Ananjesky committed
18 19 20 21 22 23 24
 */

#include <limits.h>
#include <stdlib.h>

#include "yad.h"

25
#include <webkit2/webkit2.h>
Victor Ananjesky's avatar
Victor Ananjesky committed
26 27

static WebKitWebView *view;
28 29
static WebKitFindController *find_ctl = NULL;;
static YadSearchBar *search_bar = NULL;
Victor Ananjesky's avatar
Victor Ananjesky committed
30 31 32

static GString *inbuf;

33
static gboolean is_loaded = FALSE;
34
static gboolean uri_cmd = FALSE;
Victor Ananjesky's avatar
Victor Ananjesky committed
35 36 37 38 39

#ifndef PATH_MAX
#define PATH_MAX 4096
#endif

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
/* searching */
static void
do_find_next (GtkWidget *w, gpointer d)
{
  webkit_find_controller_search_next (find_ctl);
}

static void
do_find_prev (GtkWidget *w, gpointer d)
{
  webkit_find_controller_search_previous (find_ctl);
}

static void
search_changed_cb (GtkWidget *w, gpointer d)
{
  WebKitFindOptions fopts = WEBKIT_FIND_OPTIONS_WRAP_AROUND;

  if (!find_ctl)
    find_ctl = webkit_web_view_get_find_controller (view);
  search_bar->new_search = TRUE;
  search_bar->str = gtk_entry_get_text (GTK_ENTRY (search_bar->entry));

  if (!search_bar->case_sensitive)
    fopts |= WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE;

  webkit_find_controller_search (find_ctl, search_bar->str, fopts, G_MAXUINT);
}

static void
stop_search_cb (GtkWidget *w, YadSearchBar *sb)
{
  if (find_ctl)
    {
      webkit_find_controller_search_finish (find_ctl);
      find_ctl = NULL;
    }

  gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (search_bar->bar), FALSE);
  gtk_widget_grab_focus (GTK_WIDGET (view));
  ignore_esc = FALSE;
}

Victor Ananjesky's avatar
Victor Ananjesky committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96
static void
load_uri (const gchar * uri)
{
  gchar *addr = NULL;

  if (!uri || !uri[0])
    return;

  if (g_file_test (uri, G_FILE_TEST_EXISTS))
    {
      if (g_path_is_absolute (uri))
        addr = g_filename_to_uri (uri, NULL, NULL);
      else
        {
97
          gchar *afn = realpath (uri, NULL);
Victor Ananjesky's avatar
Victor Ananjesky committed
98 99 100 101 102 103 104
          addr = g_filename_to_uri (afn, NULL, NULL);
          g_free (afn);
        }
    }
  else
    {
      if (g_uri_parse_scheme (uri) == NULL)
105
        addr = g_strdup_printf ("https://%s", uri);
Victor Ananjesky's avatar
Victor Ananjesky committed
106 107 108 109
      else
        addr = g_strdup (uri);
    }

110
  is_loaded = FALSE;
Victor Ananjevsky's avatar
Victor Ananjevsky committed
111 112
  webkit_web_view_load_uri (view, addr);
  g_free (addr);
Victor Ananjesky's avatar
Victor Ananjesky committed
113 114
}

115 116 117 118 119 120 121 122 123 124
static void
loaded_cb (WebKitWebView *v, WebKitLoadEvent ev, gpointer d)
{
  if (ev == WEBKIT_LOAD_FINISHED)
    is_loaded = TRUE;
}

static gboolean
policy_cb (WebKitWebView *v, WebKitPolicyDecision *pd, WebKitPolicyDecisionType pt, gpointer d)
{
125 126 127 128 129 130
  const gchar *uri;

  if (!is_loaded)
    return FALSE;

  if (!options.html_data.browser)
131 132 133 134 135 136
    {
      WebKitNavigationAction *act = webkit_navigation_policy_decision_get_navigation_action (WEBKIT_NAVIGATION_POLICY_DECISION (pd));
      if (webkit_navigation_action_get_navigation_type (act) == WEBKIT_NAVIGATION_TYPE_LINK_CLICKED)
        {
          WebKitURIRequest *r = webkit_navigation_action_get_request (act);

137
          uri = webkit_uri_request_get_uri (r);
138 139
          if (strncmp (uri, "about:blank#", 11) == 0)
            webkit_policy_decision_use (pd);
140
          else
141 142 143 144 145 146 147
            {
              webkit_policy_decision_ignore (pd);
              if (options.html_data.print_uri)
                g_printf ("%s\n", uri);
              else
                g_app_info_launch_default_for_uri (uri, NULL, NULL);
            }
148
        }
149 150
      else
        webkit_policy_decision_ignore (pd);
151
    }
152
  else if (uri_cmd && options.data.uri_handler && options.data.uri_handler[0])
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    {
      gchar *v1, *v2, *cmd;
      gint status;

      if (pt == WEBKIT_POLICY_DECISION_TYPE_RESPONSE)
        {
          WebKitURIRequest *r = webkit_response_policy_decision_get_request (WEBKIT_RESPONSE_POLICY_DECISION (pd));
          uri =  webkit_uri_request_get_uri (r);
          v1 = g_strdup ("");
          v2 = g_strdup ("");
        }
      else
        {
          WebKitNavigationAction *act = webkit_navigation_policy_decision_get_navigation_action (WEBKIT_NAVIGATION_POLICY_DECISION (pd));
          WebKitURIRequest *r = webkit_navigation_action_get_request (act);
          uri =  webkit_uri_request_get_uri (r);
          v1 = g_strdup_printf ("%d", webkit_navigation_action_get_mouse_button (act));
          v2 = g_strdup_printf ("%d", webkit_navigation_action_get_modifiers (act));
        }

      g_setenv ("YAD_HTML_BUTTON", v1, TRUE);
      g_setenv ("YAD_HTML_STATE", v2, TRUE);

176 177 178 179
      if (g_strstr_len (options.data.uri_handler, -1, "%s") != NULL)
        cmd = g_strdup_printf (options.data.uri_handler, uri);
      else
        cmd = g_strdup_printf ("%s '%s'", options.data.uri_handler, uri);
180
      status = run_command_sync (cmd, NULL);
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
      g_free (cmd);

      g_unsetenv ("YAD_HTML_BUTTON");
      g_unsetenv ("YAD_HTML_STATE");

      g_free (v1);
      g_free (v2);

      /* actial exit code in a highest byte */
      switch (status >> 8)
        {
        case 0:
          webkit_policy_decision_use (pd);
          break;
        case 1:
          webkit_policy_decision_ignore (pd);
          break;
        case 2:
          if (pt == WEBKIT_POLICY_DECISION_TYPE_RESPONSE)
            webkit_policy_decision_download (pd);
          else
            webkit_policy_decision_use (pd);
          break;
        default:
          g_printerr ("yad: wrong return code (%d) from uri handler\n", status >> 8);
          return FALSE;
        }
    }
209 210 211 212 213 214
  else
    return FALSE;

  return TRUE;
}

Victor Ananjesky's avatar
Victor Ananjesky committed
215
static void
Victor Ananjevsky's avatar
Victor Ananjevsky committed
216
select_file_cb (GtkEntry *entry, GtkEntryIconPosition pos, GdkEventButton *ev, gpointer d)
Victor Ananjesky's avatar
Victor Ananjesky committed
217 218 219 220 221 222 223 224 225 226
{
  GtkWidget *dlg;
  static gchar *dir = NULL;

  if (ev->button != 1 || pos != GTK_ENTRY_ICON_SECONDARY)
    return;

  dlg = gtk_file_chooser_dialog_new (_("YAD - Select File"),
                                     GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (entry))),
                                     GTK_FILE_CHOOSER_ACTION_OPEN,
Victor Ananjevsky's avatar
Victor Ananjevsky committed
227
                                     _("Cancel"), GTK_RESPONSE_CANCEL,
228
                                     _("OK"), GTK_RESPONSE_ACCEPT,
Victor Ananjevsky's avatar
Victor Ananjevsky committed
229
                                     NULL);
Victor Ananjesky's avatar
Victor Ananjesky committed
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
  if (dir)
    gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dlg), dir);

  if (gtk_dialog_run (GTK_DIALOG (dlg)) == GTK_RESPONSE_ACCEPT)
    {
      gchar *uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dlg));
      gtk_entry_set_text (entry, uri);
      g_free (uri);

      /* keep current dir */
      g_free (dir);
      dir = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dlg));
    }

  gtk_widget_destroy (dlg);
}

static void
Victor Ananjevsky's avatar
Victor Ananjevsky committed
248
do_open_cb (GtkWidget *w, GtkDialog *dlg)
Victor Ananjesky's avatar
Victor Ananjesky committed
249 250 251 252 253
{
  gtk_dialog_response (dlg, GTK_RESPONSE_ACCEPT);
}

static void
254
open_cb (GSimpleAction *act, GVariant *param, gpointer d)
Victor Ananjesky's avatar
Victor Ananjesky committed
255 256 257
{
  GtkWidget *dlg, *cnt, *lbl, *entry;

258
  dlg = gtk_dialog_new_with_buttons (_("Open URI"), GTK_WINDOW (d),
Victor Ananjesky's avatar
Victor Ananjesky committed
259
                                     GTK_DIALOG_DESTROY_WITH_PARENT,
Victor Ananjevsky's avatar
Victor Ananjevsky committed
260 261 262
                                     _("Cancel"), GTK_RESPONSE_REJECT,
                                     _("Open"), GTK_RESPONSE_ACCEPT,
                                     NULL);
Victor Ananjesky's avatar
Victor Ananjesky committed
263 264 265 266 267
  gtk_window_set_default_size (GTK_WINDOW (dlg), 350, -1);

  cnt = gtk_dialog_get_content_area (GTK_DIALOG (dlg));

  lbl = gtk_label_new (_("Enter URI or file name:"));
268
  gtk_label_set_xalign (GTK_LABEL (lbl), 0.0);
Victor Ananjesky's avatar
Victor Ananjesky committed
269 270 271 272
  gtk_widget_show (lbl);
  gtk_box_pack_start (GTK_BOX (cnt), lbl, TRUE, FALSE, 2);

  entry = gtk_entry_new ();
273
  gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, "document-open");
Victor Ananjesky's avatar
Victor Ananjesky committed
274 275 276 277 278 279 280 281 282 283 284 285
  gtk_widget_show (entry);
  gtk_box_pack_start (GTK_BOX (cnt), entry, TRUE, FALSE, 2);

  g_signal_connect (G_OBJECT (entry), "icon-press", G_CALLBACK (select_file_cb), NULL);
  g_signal_connect (G_OBJECT (entry), "activate", G_CALLBACK (do_open_cb), dlg);

  if (gtk_dialog_run (GTK_DIALOG (dlg)) == GTK_RESPONSE_ACCEPT)
    load_uri (gtk_entry_get_text (GTK_ENTRY (entry)));

  gtk_widget_destroy (dlg);
}

286 287 288 289 290 291
static void
quit_cb (GSimpleAction *act, GVariant *param, gpointer d)
{
  yad_exit (options.data.def_resp);
}

Victor Ananjesky's avatar
Victor Ananjesky committed
292
static gboolean
293
menu_cb (WebKitWebView *view, WebKitContextMenu *menu, GdkEvent *ev, WebKitHitTestResult *hit, gpointer d)
Victor Ananjesky's avatar
Victor Ananjesky committed
294
{
295 296 297
  WebKitContextMenuItem *mi;
  GSimpleAction *act;

298 299 300 301
  if (options.common_data.file_op)
    {
      mi = webkit_context_menu_item_new_separator ();
      webkit_context_menu_prepend (menu, mi);
302

303 304
      act = g_simple_action_new ("open", NULL);
      g_signal_connect (G_OBJECT (act), "activate", G_CALLBACK (open_cb), d);
305

306 307 308
      mi = webkit_context_menu_item_new_from_gaction (G_ACTION (act), _("Open URI"), NULL);
      webkit_context_menu_prepend (menu, mi);
    }
309 310 311 312 313

  mi = webkit_context_menu_item_new_separator ();
  webkit_context_menu_append (menu, mi);

  act = g_simple_action_new ("quit", NULL);
314
  g_signal_connect (G_OBJECT (act), "activate", G_CALLBACK (quit_cb), d);
Victor Ananjevsky's avatar
Victor Ananjevsky committed
315

316 317
  mi = webkit_context_menu_item_new_from_gaction (G_ACTION (act), _("Quit"), NULL);
  webkit_context_menu_append (menu, mi);
Victor Ananjesky's avatar
Victor Ananjesky committed
318 319 320 321

  return FALSE;
}

322 323 324 325 326 327 328 329
static gboolean
key_press_cb (GtkWidget *w, GdkEventKey *key, gpointer d)
{
  if ((key->state & GDK_CONTROL_MASK) && (key->keyval == GDK_KEY_O || key->keyval == GDK_KEY_o))
    {
      open_cb (NULL, NULL, d);
      return TRUE;
    }
330 331 332 333 334
  else if ((key->state & GDK_CONTROL_MASK) && (key->keyval == GDK_KEY_Q || key->keyval == GDK_KEY_q))
    {
      yad_exit (options.data.def_resp);
      return TRUE;
    }
335 336 337 338 339 340 341 342 343
  else if ((key->state & GDK_CONTROL_MASK) && (key->keyval == GDK_KEY_F || key->keyval == GDK_KEY_f))
    {
      if (search_bar == NULL)
        return FALSE;

      ignore_esc = TRUE;
      gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (search_bar->bar), TRUE);
      return gtk_search_bar_handle_event (GTK_SEARCH_BAR (search_bar->bar), (GdkEvent *) key);
    }
344 345 346 347

  return FALSE;
}

Victor Ananjesky's avatar
Victor Ananjesky committed
348 349 350 351 352 353 354 355 356 357 358
static void
title_cb (GObject *obj, GParamSpec *spec, GtkWindow *dlg)
{
  const gchar *title = webkit_web_view_get_title (view);
  if (title)
    gtk_window_set_title (dlg, title);
}

static void
icon_cb (GObject *obj, GParamSpec *spec, GtkWindow *dlg)
{
359
  GdkPixbuf *pb = gdk_pixbuf_get_from_surface (webkit_web_view_get_favicon (view), 0, 0, -1, -1);
Victor Ananjevsky's avatar
Victor Ananjevsky committed
360

Victor Ananjesky's avatar
Victor Ananjesky committed
361 362 363 364 365 366 367 368
  if (pb)
    {
      gtk_window_set_icon (dlg, pb);
      g_object_unref (pb);
    }
}

static gboolean
369
handle_stdin (GIOChannel *ch, GIOCondition cond, gpointer d)
Victor Ananjesky's avatar
Victor Ananjesky committed
370
{
371
  if ((cond == G_IO_IN) || (cond == G_IO_IN + G_IO_HUP))
Victor Ananjesky's avatar
Victor Ananjesky committed
372
    {
373 374
       GError *err = NULL;
      GString *string = g_string_new (NULL);
Victor Ananjesky's avatar
Victor Ananjesky committed
375

376 377
      while (ch->is_readable != TRUE)
        usleep (100);
Victor Ananjesky's avatar
Victor Ananjesky committed
378

379 380 381
      do
        {
          gint status;
Victor Ananjesky's avatar
Victor Ananjesky committed
382

383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
          do
            status = g_io_channel_read_line_string (ch, string, NULL, &err);
          while (status == G_IO_STATUS_AGAIN);

          if (status != G_IO_STATUS_NORMAL)
            {
              if (err)
                {
                  g_printerr ("yad_html_handle_stdin(): %s\n", err->message);
                  g_error_free (err);
                  err = NULL;
                }
              /* stop handling */
              g_io_channel_shutdown (ch, TRUE, NULL);
              return FALSE;
            }

          if (string->str[0] == '\014' )
            g_string_truncate (inbuf, 0);
          else
            g_string_append (inbuf, string->str);
        }
      while (g_io_channel_get_buffer_condition (ch) == G_IO_IN);
      g_string_free (string, TRUE);

      if (inbuf->len)
        {
          GBytes *data = g_bytes_new (inbuf->str, inbuf->len);
          is_loaded = FALSE;
          webkit_web_view_load_bytes (view, data, options.common_data.mime, options.html_data.encoding, NULL);
          g_bytes_unref (data);
        }
Victor Ananjesky's avatar
Victor Ananjesky committed
415 416
    }

417 418 419 420 421 422 423
  if ((cond != G_IO_IN) && (cond != G_IO_IN + G_IO_HUP))
    {
      g_io_channel_shutdown (ch, TRUE, NULL);
      return FALSE;
    }

  return TRUE;
Victor Ananjesky's avatar
Victor Ananjesky committed
424 425
}

426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
static void
set_user_props (WebKitSettings *wk_settings)
{
  gint i;

  if (!options.html_data.wk_props)
    return;

  for (i = 0; options.html_data.wk_props[i] != NULL; i++)
    {
      gchar **prop = g_strsplit (options.html_data.wk_props[i], " ", 2);

      if (prop[0] && prop[1])
        {
          switch (prop[1][0])
            {
            case 'b':
              g_object_set (G_OBJECT (wk_settings), prop[0], (strcmp (prop[1] + 2, "true") == 0), NULL);
              break;
            case 'i':
              g_object_set (G_OBJECT (wk_settings), prop[0], atol (prop[1] + 2), NULL);
              break;
            case 's':
              g_object_set (G_OBJECT (wk_settings), prop[0], prop[1] + 2, NULL);
              break;
            default:
              if (options.debug)
                g_warning ("Wrong value '%s' for setting '%s'\n", prop[1], prop[0]);
            }
        }

      g_strfreev (prop);
    }
}

Victor Ananjesky's avatar
Victor Ananjesky committed
461 462 463
GtkWidget *
html_create_widget (GtkWidget * dlg)
{
464
  GtkWidget *w, *sw;
Victor Ananjevsky's avatar
Victor Ananjevsky committed
465
  WebKitSettings *wk_settings;
466
  WebKitUserContentManager *wk_cman;
467
  gchar *str;
Victor Ananjesky's avatar
Victor Ananjesky committed
468

469 470
  w = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);

Victor Ananjesky's avatar
Victor Ananjesky committed
471
  sw = gtk_scrolled_window_new (NULL, NULL);
472
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), options.data.hscroll_policy, options.data.vscroll_policy);
473
  gtk_box_pack_start (GTK_BOX (w), sw, TRUE, TRUE, 0);
Victor Ananjesky's avatar
Victor Ananjesky committed
474

475 476
  wk_cman = webkit_user_content_manager_new ();
  view = WEBKIT_WEB_VIEW (webkit_web_view_new_with_user_content_manager (wk_cman));
Victor Ananjesky's avatar
Victor Ananjesky committed
477 478
  gtk_container_add (GTK_CONTAINER (sw), GTK_WIDGET (view));

479
  g_signal_connect (view, "decide-policy", G_CALLBACK (policy_cb), NULL);
480
  g_signal_connect (view, "load-changed", G_CALLBACK (loaded_cb), NULL);
Victor Ananjesky's avatar
Victor Ananjesky committed
481

482 483 484 485 486 487 488
  wk_settings = webkit_settings_new ();

  g_object_set (G_OBJECT (wk_settings),
                "user-agent", options.html_data.user_agent,
                "default-charset", g_get_codeset (),
                NULL);

Victor Ananjesky's avatar
Victor Ananjesky committed
489 490
  if (options.html_data.browser)
    {
491 492
      g_signal_connect (view, "context-menu", G_CALLBACK (menu_cb), dlg);
      g_signal_connect (view, "key-press-event", G_CALLBACK (key_press_cb), dlg);
Victor Ananjesky's avatar
Victor Ananjesky committed
493 494
      if (!options.data.dialog_title)
        g_signal_connect (view, "notify::title", G_CALLBACK (title_cb), dlg);
495
      if (!options.data.window_icon)
496
        g_signal_connect (view, "notify::favicon", G_CALLBACK (icon_cb), dlg);
Victor Ananjesky's avatar
Victor Ananjesky committed
497
    }
498 499
  else
    {
500
      g_object_set (G_OBJECT (wk_settings),
501
                    "enable-write-console-messages-to-stdout", TRUE,
502 503 504 505 506 507 508 509
                    "enable-caret-browsing", FALSE,
                    "enable-developer-extras", FALSE,
                    "enable-html5-database", FALSE,
                    "enable-html5-local-storage", FALSE,
                    "enable-offline-web-application-cache", FALSE,
                    "enable-page-cache", FALSE,
                    "enable-plugins", FALSE,
                    NULL);
510
    }
Victor Ananjesky's avatar
Victor Ananjesky committed
511

512
  set_user_props (wk_settings);
513 514 515 516 517
  webkit_web_view_set_settings (view, wk_settings);

  /* add user defined css */
  if (options.html_data.user_style)
    {
518
      gchar *css = NULL;
519 520
      GError *err = NULL;

521
      if (g_file_test (options.html_data.user_style, G_FILE_TEST_EXISTS))
522
        {
523 524 525 526 527 528 529 530
          if (!g_file_get_contents (options.html_data.user_style, &css, NULL, &err))
            {
              g_printerr ("yad_html: unable to load user css file: %s\n", err->message);
              g_error_free (err);
            }
        }
      else
        css = g_strdup (options.html_data.user_style);
531

532 533 534
      if (css)
        {
          WebKitUserStyleSheet *wk_css;
535 536 537 538 539 540
          wk_css = webkit_user_style_sheet_new (css, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
                                                WEBKIT_USER_STYLE_LEVEL_USER, NULL, NULL);
          webkit_user_content_manager_add_style_sheet (wk_cman, wk_css);
          g_free (css);
        }
    }
541

Victor Ananjesky's avatar
Victor Ananjesky committed
542 543 544
  gtk_widget_show_all (sw);
  gtk_widget_grab_focus (GTK_WIDGET (view));

545 546 547 548 549 550 551 552 553 554 555 556 557
  /* create search bar */
  if (options.common_data.enable_search)
    {
      if ((search_bar = create_search_bar ()) != NULL)
        {
          gtk_box_pack_start (GTK_BOX (w), search_bar->bar, FALSE, FALSE, 0);
          g_signal_connect (G_OBJECT (search_bar->entry), "search-changed", G_CALLBACK (search_changed_cb), NULL);
          g_signal_connect (G_OBJECT (search_bar->entry), "stop-search", G_CALLBACK (stop_search_cb), NULL);
          g_signal_connect (G_OBJECT (search_bar->entry), "next-match", G_CALLBACK (do_find_next), NULL);
          g_signal_connect (G_OBJECT (search_bar->entry), "previous-match", G_CALLBACK (do_find_prev), NULL);
        }
    }

558 559 560 561 562 563 564 565 566 567
  /* check for user specified uri handler */
#ifndef STANDALONE
  str = g_settings_get_string (settings, "open-command");
#else
  str = g_strdup (OPEN_CMD);
#endif
  if (strcmp (options.data.uri_handler, str) != 0)
    uri_cmd = TRUE;
  g_free (str);

568
  /* load data */
Victor Ananjesky's avatar
Victor Ananjesky committed
569 570 571 572 573 574 575 576 577 578 579 580
  if (options.html_data.uri)
    load_uri (options.html_data.uri);
  else if (!options.html_data.browser)
    {
      GIOChannel *ch;

      inbuf = g_string_new (NULL);
      ch = g_io_channel_unix_new (0);
      g_io_channel_set_encoding (ch, NULL, NULL);
      g_io_channel_set_flags (ch, G_IO_FLAG_NONBLOCK, NULL);
      g_io_add_watch (ch, G_IO_IN | G_IO_HUP, handle_stdin, NULL);
    }
581
  else if (options.extra_data)
582
    load_uri (options.extra_data[0]);
Victor Ananjesky's avatar
Victor Ananjesky committed
583

584
  return w;
Victor Ananjesky's avatar
Victor Ananjesky committed
585
}