ephy-web-view.c 87 KB
Newer Older
1
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set sw=2 ts=2 sts=2 et: */
3
/*
4
 *  Copyright © 2008, 2009 Gustavo Noronha Silva
5
 *  Copyright © 2009, 2010 Igalia S.L.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 *  This program 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 2, or (at your option)
 *  any later version.
 *
 *  This program 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "config.h"
Xan Lopez's avatar
Xan Lopez committed
24
#include "ephy-web-view.h"
25

26
#include "ephy-about-handler.h"
27 28 29
#include "ephy-debug.h"
#include "ephy-embed-container.h"
#include "ephy-embed-prefs.h"
30
#include "ephy-embed-private.h"
31 32 33
#include "ephy-embed-shell.h"
#include "ephy-embed-type-builtins.h"
#include "ephy-embed-utils.h"
Xan Lopez's avatar
Xan Lopez committed
34
#include "ephy-embed.h"
35
#include "ephy-favicon-helpers.h"
36
#include "ephy-file-helpers.h"
37
#include "ephy-file-monitor.h"
38
#include "ephy-form-auth-data.h"
Xan Lopez's avatar
Xan Lopez committed
39
#include "ephy-history-service.h"
40
#include "ephy-overview.h"
Xan Lopez's avatar
Xan Lopez committed
41
#include "ephy-prefs.h"
42
#include "ephy-settings.h"
43
#include "ephy-string.h"
Xan Lopez's avatar
Xan Lopez committed
44
#include "ephy-web-app-utils.h"
45
#include "ephy-web-dom-utils.h"
46 47
#include "ephy-zoom.h"

Xan Lopez's avatar
Xan Lopez committed
48 49 50 51
#include <gio/gio.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
Carlos Garcia Campos's avatar
Carlos Garcia Campos committed
52
#include <libsoup/soup.h>
Xan Lopez's avatar
Xan Lopez committed
53

Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
54 55 56 57 58 59 60 61
/**
 * SECTION:ephy-web-view
 * @short_description: Epiphany custom #WebkitWebView
 *
 * #EphyWebView wraps #WebkitWebView implementing custom functionality on top of
 * it.
 */

62 63 64 65
#define MAX_HIDDEN_POPUPS       5
#define MAX_TITLE_LENGTH        512 /* characters */
#define EMPTY_PAGE              _("Blank page") /* Title for the empty page */

66 67 68 69
#define EPHY_PAGE_TEMPLATE_ERROR         "/org/gnome/epiphany/page-templates/error.html"
#define EPHY_PAGE_TEMPLATE_RECOVERY      "/org/gnome/epiphany/page-templates/recovery.html"
#define EPHY_PAGE_TEMPLATE_PROCESS_CRASH "/org/gnome/epiphany/page-templates/process-crash.html"

70 71 72 73 74 75 76
struct _EphyWebViewPrivate {
  EphyWebViewSecurityLevel security_level;
  EphyWebViewDocumentType document_type;
  EphyWebViewNavigationFlags nav_flags;

  /* Flags */
  guint is_blank : 1;
77
  guint is_setting_zoom : 1;
78
  guint load_failed : 1;
79
  guint history_frozen : 1;
80 81 82 83 84 85 86 87 88

  char *address;
  char *typed_address;
  char *title;
  char *loading_title;
  char *status_message;
  char *link_message;
  GdkPixbuf *icon;

89 90
  /* Local file watch. */
  EphyFileMonitor *file_monitor;
91

92 93
  /* Regex to figure out if we're dealing with a wanna-be URI */
  GRegex *non_search_regex;
94
  GRegex *domain_regex;
95

96 97
  GSList *hidden_popups;
  GSList *shown_popups;
98 99

  GtkWidget *password_info_bar;
Xan Lopez's avatar
Xan Lopez committed
100

101
  EphyHistoryService *history_service;
102 103
  GCancellable *history_service_cancellable;

104 105
  guint snapshot_idle_id;

Xan Lopez's avatar
Xan Lopez committed
106
  EphyHistoryPageVisitType visit_type;
Xan Lopez's avatar
Xan Lopez committed
107 108

  gulong do_not_track_handler;
109 110 111 112

  /* TLS information. */
  GTlsCertificate *certificate;
  GTlsCertificateFlags tls_errors;
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
};

typedef struct {
  char *url;
  char *name;
  char *features;
} PopupInfo;

enum {
  PROP_0,
  PROP_ADDRESS,
  PROP_DOCUMENT_TYPE,
  PROP_HIDDEN_POPUP_COUNT,
  PROP_ICON,
  PROP_LINK_MESSAGE,
  PROP_NAVIGATION,
  PROP_POPUPS_ALLOWED,
  PROP_SECURITY,
  PROP_STATUS_MESSAGE,
  PROP_EMBED_TITLE,
  PROP_TYPED_ADDRESS,
134
  PROP_IS_BLANK,
135 136 137 138
};

#define EPHY_WEB_VIEW_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_WEB_VIEW, EphyWebViewPrivate))

139 140
G_DEFINE_TYPE (EphyWebView, ephy_web_view, WEBKIT_TYPE_WEB_VIEW)

141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
static guint
popup_blocker_n_hidden (EphyWebView *view)
{
  return g_slist_length (view->priv->hidden_popups);
}

static void
popups_manager_free_info (PopupInfo *popup)
{
  g_free (popup->url);
  g_free (popup->name);
  g_free (popup->features);
  g_slice_free (PopupInfo, popup);
}

static void
popups_manager_show (PopupInfo *popup,
                     EphyWebView *view)
{
  /* Only show popup with non NULL url */
  if (popup->url != NULL) {
162 163 164
    /* FIXME: we need a way of opening windows in here. This used to
     * be implemented in EphyEmbedSingle open_window method, but it's
     * been a no-op for a while. */
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
  }
  popups_manager_free_info (popup);
}

static void
popups_manager_show_all (EphyWebView *view)
{
  LOG ("popup_blocker_show_all: view %p", view);

  g_slist_foreach (view->priv->hidden_popups,
                   (GFunc)popups_manager_show, view);
  g_slist_free (view->priv->hidden_popups);
  view->priv->hidden_popups = NULL;

  g_object_notify (G_OBJECT (view), "hidden-popup-count");
}

static char *
popups_manager_new_window_info (EphyEmbedContainer *container)
{
  EphyEmbed *embed;
  EphyWebViewChrome chrome;
187
  GtkAllocation allocation;
188 189 190 191 192 193 194 195 196
  gboolean is_popup;
  char *features;

  g_object_get (container, "chrome", &chrome, "is-popup", &is_popup, NULL);
  g_return_val_if_fail (is_popup, g_strdup (""));

  embed = ephy_embed_container_get_active_child (container);
  g_return_val_if_fail (embed != NULL, g_strdup (""));

197 198
  gtk_widget_get_allocation (GTK_WIDGET (embed), &allocation);

199
  features = g_strdup_printf
200
             ("width=%d,height=%d,toolbar=%d",
201 202
              allocation.width,
              allocation.height,
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
              (chrome & EPHY_WEB_VIEW_CHROME_TOOLBAR) > 0);

  return features;
}

static void
popups_manager_add (EphyWebView *view,
                    const char *url,
                    const char *name,
                    const char *features)
{
  EphyWebViewPrivate *priv = view->priv;
  PopupInfo *popup;

  LOG ("popups_manager_add: view %p, url %s, features %s",
       view, url, features);

  popup = g_slice_new (PopupInfo);

  popup->url = g_strdup (url);
  popup->name = g_strdup (name);
  popup->features = g_strdup (features);

  priv->hidden_popups = g_slist_prepend (priv->hidden_popups, popup);

  if (popup_blocker_n_hidden (view) > MAX_HIDDEN_POPUPS) {/* bug #160863 */
    /* Remove the oldest popup */
    GSList *l = view->priv->hidden_popups;

    while (l->next->next != NULL) {
      l = l->next;
    }

    popup = (PopupInfo *)l->next->data;
    popups_manager_free_info (popup);

    l->next = NULL;
  } else {
    g_object_notify (G_OBJECT (view), "hidden-popup-count");
  }
}

static void
popups_manager_hide (EphyEmbedContainer *container,
                     EphyWebView *parent_view)
{
  EphyEmbed *embed;
250
  const char *location;
251 252 253 254 255
  char *features;

  embed = ephy_embed_container_get_active_child (container);
  g_return_if_fail (EPHY_IS_EMBED (embed));

256
  location = ephy_web_view_get_address (ephy_embed_get_web_view (embed));
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
  if (location == NULL) return;

  features = popups_manager_new_window_info (container);

  popups_manager_add (parent_view, location, "" /* FIXME? maybe _blank? */, features);

  gtk_widget_destroy (GTK_WIDGET (container));

  g_free (features);
}

static void
popups_manager_hide_all (EphyWebView *view)
{
  LOG ("popup_blocker_hide_all: view %p", view);

  g_slist_foreach (view->priv->shown_popups,
                   (GFunc)popups_manager_hide, view);
  g_slist_free (view->priv->shown_popups);
  view->priv->shown_popups = NULL;
}

static void
ephy_web_view_set_popups_allowed (EphyWebView *view,
                                  gboolean allowed)
{
  if (allowed) {
    popups_manager_show_all (view);
  } else {
    popups_manager_hide_all (view);
  }
}

static gboolean
ephy_web_view_get_popups_allowed (EphyWebView *view)
{
293
  const char *location;
294 295
  gboolean allow;

296
  location = ephy_web_view_get_address (view);
297 298
  if (location == NULL) return FALSE;/* FALSE, TRUE… same thing */

Xan Lopez's avatar
Xan Lopez committed
299 300
  allow = g_settings_get_boolean (EPHY_SETTINGS_WEB,
                                  EPHY_PREFS_WEB_ENABLE_POPUPS);
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
  return allow;
}

static gboolean
popups_manager_remove_window (EphyWebView *view,
                              EphyEmbedContainer *container)
{
  view->priv->shown_popups = g_slist_remove (view->priv->shown_popups,
                                              container);

  return FALSE;
}

static void
popups_manager_add_window (EphyWebView *view,
                           EphyEmbedContainer *container)
{
  LOG ("popups_manager_add_window: view %p, container %p", view, container);

  view->priv->shown_popups = g_slist_prepend (view->priv->shown_popups, container);

  g_signal_connect_swapped (container, "destroy",
                            G_CALLBACK (popups_manager_remove_window),
                            view);
}

static void
disconnect_popup (EphyEmbedContainer *container,
                  EphyWebView *view)
{
  g_signal_handlers_disconnect_by_func
  (container, G_CALLBACK (popups_manager_remove_window), view);
}

Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
335 336 337 338 339 340
/**
 * ephy_web_view_popups_manager_reset:
 * @view: an #EphyWebView
 *
 * Resets the state of the popups manager in @view.
 **/
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
void
ephy_web_view_popups_manager_reset (EphyWebView *view)
{
  g_slist_foreach (view->priv->hidden_popups,
                   (GFunc)popups_manager_free_info, NULL);
  g_slist_free (view->priv->hidden_popups);
  view->priv->hidden_popups = NULL;

  g_slist_foreach (view->priv->shown_popups,
                   (GFunc)disconnect_popup, view);
  g_slist_free (view->priv->shown_popups);
  view->priv->shown_popups = NULL;

  g_object_notify (G_OBJECT (view), "hidden-popup-count");
  g_object_notify (G_OBJECT (view), "popups-allowed");
}

static void
ephy_web_view_get_property (GObject *object,
                            guint prop_id,
                            GValue *value,
                            GParamSpec *pspec)
{
  EphyWebViewPrivate *priv = EPHY_WEB_VIEW (object)->priv;

  switch (prop_id) {
    case PROP_ADDRESS:
      g_value_set_string (value, priv->address);
      break;
    case PROP_EMBED_TITLE:
      g_value_set_string (value, priv->title);
      break;
    case PROP_TYPED_ADDRESS:
      g_value_set_string (value, priv->typed_address);
      break;
    case PROP_DOCUMENT_TYPE:
      g_value_set_enum (value, priv->document_type);
      break;
    case PROP_HIDDEN_POPUP_COUNT:
      g_value_set_int (value, popup_blocker_n_hidden
                       (EPHY_WEB_VIEW (object)));
      break;
    case PROP_ICON:
      g_value_set_object (value, priv->icon);
      break;
    case PROP_LINK_MESSAGE:
      g_value_set_string (value, priv->link_message);
      break;
    case PROP_NAVIGATION:
      g_value_set_flags (value, priv->nav_flags);
      break;
    case PROP_POPUPS_ALLOWED:
      g_value_set_boolean (value, ephy_web_view_get_popups_allowed
                           (EPHY_WEB_VIEW (object)));
      break;
    case PROP_SECURITY:
      g_value_set_enum (value, priv->security_level);
      break;
    case PROP_STATUS_MESSAGE:
      g_value_set_string (value, priv->status_message);
      break;
402 403 404
    case PROP_IS_BLANK:
      g_value_set_boolean (value, priv->is_blank);
      break;
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
    default:
      break;
  }
}

static void
ephy_web_view_set_property (GObject *object,
                            guint prop_id,
                            const GValue *value,
                            GParamSpec *pspec)
{
  switch (prop_id) {
    case PROP_POPUPS_ALLOWED:
      ephy_web_view_set_popups_allowed (EPHY_WEB_VIEW (object), g_value_get_boolean (value));
      break;
    case PROP_TYPED_ADDRESS:
421
      ephy_web_view_set_typed_address (EPHY_WEB_VIEW (object), g_value_get_string (value));
422 423 424 425 426 427 428 429 430 431 432
      break;
      break;
    case PROP_ADDRESS:
    case PROP_DOCUMENT_TYPE:
    case PROP_HIDDEN_POPUP_COUNT:
    case PROP_ICON:
    case PROP_LINK_MESSAGE:
    case PROP_NAVIGATION:
    case PROP_SECURITY:
    case PROP_STATUS_MESSAGE:
    case PROP_EMBED_TITLE:
433
    case PROP_IS_BLANK:
434 435 436 437 438 439 440
      /* read only */
      break;
    default:
      break;
  }
}

441 442 443
static gboolean
ephy_web_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
{
444 445
  EphyWebView *web_view = EPHY_WEB_VIEW (widget);
  gboolean key_handled = FALSE;
446

447
  key_handled = GTK_WIDGET_CLASS (ephy_web_view_parent_class)->key_press_event (widget, event);
448

449 450
  if (key_handled)
    return TRUE;
451

452
  g_signal_emit_by_name (web_view, "search-key-press", event, &key_handled);
453

454
  return key_handled;
455 456
}

457 458 459
static gboolean
ephy_web_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
{
460 461 462 463 464
  /* This are the special cases WebkitWebView doesn't handle but we have an
   * interest in handling. */

  /* We always show the browser context menu on control-rightclick. */
  if (event->button == 3 && event->state == GDK_CONTROL_MASK)
465
    return FALSE;
466

467 468 469 470 471 472 473 474 475 476 477
  /* Handle typical back/forward mouse buttons. */
  if (event->button == 8) {
    webkit_web_view_go_back (WEBKIT_WEB_VIEW (widget));
    return TRUE;
  }

  if (event->button == 9) {
    webkit_web_view_go_forward (WEBKIT_WEB_VIEW (widget));
    return TRUE;
  }

478
  /* Let WebKitWebView handle this. */
479
  return GTK_WIDGET_CLASS (ephy_web_view_parent_class)->button_press_event (widget, event);
480 481
}

482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
static GtkWidget *
ephy_web_view_create_form_auth_save_confirmation_info_bar (EphyWebView *web_view,
                                                           const char *hostname,
                                                           const char *username)
{
  GtkWidget *info_bar;
  GtkWidget *action_area;
  GtkWidget *content_area;
  GtkWidget *label;
  char *message;

  LOG ("Going to show infobar about %s", webkit_web_view_get_uri (WEBKIT_WEB_VIEW (web_view)));

  info_bar = gtk_info_bar_new_with_buttons (_("Not now"), GTK_RESPONSE_NO,
                                            _("Store password"), GTK_RESPONSE_YES,
                                            NULL);

  action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
  gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area),
                                  GTK_ORIENTATION_HORIZONTAL);

  label = gtk_label_new (NULL);
  /* Translators: The first %s is the username and the second one is the
   * hostname where this is happening. Example: gnome@gmail.com and
   * mail.google.com.
   */
  message = g_markup_printf_escaped (_("<big>Would you like to store the password for <b>%s</b> in <b>%s</b>?</big>"),
                                     username, hostname);
  gtk_label_set_markup (GTK_LABEL (label), message);
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
  g_free (message);

  content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
  gtk_container_add (GTK_CONTAINER (content_area), label);
  gtk_widget_show (label);

  ephy_embed_add_top_widget (EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (web_view),
                             info_bar, FALSE);

  /* We track the info_bar, so we only ever show one */
  if (web_view->priv->password_info_bar)
    gtk_widget_destroy (web_view->priv->password_info_bar);

  web_view->priv->password_info_bar = info_bar;
  g_object_add_weak_pointer (G_OBJECT (info_bar),
                             (gpointer *)&web_view->priv->password_info_bar);

  return info_bar;
}

532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
static void
update_navigation_flags (EphyWebView *view)
{
  EphyWebViewPrivate *priv = view->priv;
  guint flags = 0;
  WebKitWebView *web_view = WEBKIT_WEB_VIEW (view);

  if (webkit_web_view_can_go_back (web_view))
    flags |= EPHY_WEB_VIEW_NAV_BACK;

  if (webkit_web_view_can_go_forward (web_view))
    flags |= EPHY_WEB_VIEW_NAV_FORWARD;

  if (priv->nav_flags != (EphyWebViewNavigationFlags)flags) {
    priv->nav_flags = (EphyWebViewNavigationFlags)flags;

    g_object_notify (G_OBJECT (view), "navigation");
  }
}

552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
static void
ephy_web_view_freeze_history (EphyWebView *view)
{
  view->priv->history_frozen = TRUE;
}

static void
ephy_web_view_thaw_history (EphyWebView *view)
{
  view->priv->history_frozen = FALSE;
}

static gboolean
ephy_web_view_is_history_frozen (EphyWebView *view)
{
  return view->priv->history_frozen;
}


571 572 573
static void
ephy_web_view_clear_history (EphyWebView *view)
{
Carlos Garcia Campos's avatar
Carlos Garcia Campos committed
574
  /* TODO: WebKitBackForwardList is read-only in WebKit2 */
575 576
}

577 578 579 580 581 582 583
static void
ephy_web_view_history_cleared_cb (EphyHistoryService *history_service,
                                  EphyWebView *view)
{
  ephy_web_view_clear_history (view);
}

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
static void
_ephy_web_view_update_icon (EphyWebView *view)
{
  EphyWebViewPrivate *priv = view->priv;

  if (priv->icon != NULL) {
    g_object_unref (priv->icon);
    priv->icon = NULL;
  }

  if (priv->address) {
    cairo_surface_t *icon_surface = webkit_web_view_get_favicon (WEBKIT_WEB_VIEW (view));
    if (icon_surface)
      priv->icon = ephy_pixbuf_get_from_surface_scaled (icon_surface, FAVICON_SIZE, FAVICON_SIZE);
  }

  g_object_notify (G_OBJECT (view), "icon");
}

static void
icon_changed_cb (EphyWebView *view,
                 GParamSpec *pspec,
                 gpointer user_data)
{
  _ephy_web_view_update_icon (view);
}

611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
static void
form_auth_data_save_confirmation_response (GtkInfoBar *info_bar,
                                           gint response_id,
                                           gpointer user_data)
{
  GDBusProxy *web_extension;
  guint request_id = GPOINTER_TO_INT (user_data);

  gtk_widget_destroy (GTK_WIDGET (info_bar));

  web_extension = ephy_embed_shell_get_web_extension_proxy (ephy_embed_shell_get_default ());
  if (!web_extension)
    return;

  g_dbus_proxy_call (web_extension,
                     "FormAuthDataSaveConfirmationResponse",
                     g_variant_new ("(ub)", request_id, response_id == GTK_RESPONSE_YES),
                     G_DBUS_CALL_FLAGS_NONE,
                     -1, NULL, NULL, NULL);
}

static void
form_auth_data_save_requested (EphyEmbedShell *shell,
                               guint request_id,
                               guint64 page_id,
                               const char *hostname,
                               const char *username,
                               WebKitWebView *web_view)
{
  GtkWidget *info_bar;

  if (webkit_web_view_get_page_id (web_view) != page_id)
    return;

  info_bar = ephy_web_view_create_form_auth_save_confirmation_info_bar (EPHY_WEB_VIEW (web_view),
                                                                        hostname, username);
  g_signal_connect (info_bar, "response",
                    G_CALLBACK (form_auth_data_save_confirmation_response),
                    GINT_TO_POINTER (request_id));

  gtk_widget_show (info_bar);
}

654
static void
655
ephy_web_view_dispose (GObject *object)
656 657 658
{
  EphyWebViewPrivate *priv = EPHY_WEB_VIEW (object)->priv;

659 660 661 662
  g_signal_handlers_disconnect_by_func (priv->history_service,
                                        ephy_web_view_history_cleared_cb,
                                        EPHY_WEB_VIEW (object));

663
  g_signal_handlers_disconnect_by_func (object, icon_changed_cb, NULL);
664 665

  g_signal_handlers_disconnect_by_func (ephy_embed_shell_get_default (), form_auth_data_save_requested, object);
666

667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
  g_clear_object (&priv->file_monitor);

  g_clear_object (&priv->icon);

  if (priv->history_service_cancellable) {
    g_cancellable_cancel (priv->history_service_cancellable);
    g_clear_object (&priv->history_service_cancellable);
  }

  if (priv->snapshot_idle_id) {
    g_source_remove (priv->snapshot_idle_id);
    priv->snapshot_idle_id = 0;
  }

  g_clear_object(&priv->certificate);

  G_OBJECT_CLASS (ephy_web_view_parent_class)->dispose (object);
}

static void
ephy_web_view_finalize (GObject *object)
{
  EphyWebViewPrivate *priv = EPHY_WEB_VIEW (object)->priv;

691
  if (priv->non_search_regex) {
692 693 694 695
    g_regex_unref (priv->non_search_regex);
    priv->non_search_regex = NULL;
  }

696 697 698 699 700
  if (priv->domain_regex) {
    g_regex_unref (priv->domain_regex);
    priv->domain_regex = NULL;
  }

701 702 703 704 705 706 707 708 709 710 711 712
  ephy_web_view_popups_manager_reset (EPHY_WEB_VIEW (object));

  g_free (priv->address);
  g_free (priv->typed_address);
  g_free (priv->title);
  g_free (priv->status_message);
  g_free (priv->link_message);
  g_free (priv->loading_title);

  G_OBJECT_CLASS (ephy_web_view_parent_class)->finalize (object);
}

713 714 715 716 717
static char*
get_title_from_address (const char *address)
{
  if (g_str_has_prefix (address, "file://"))
    return g_strdup (address + 7);
718 719
  else if (!strcmp (address, EPHY_ABOUT_SCHEME":overview") ||
           !strcmp (address, "about:overview"))
720
    return g_strdup (EPHY_OVERVIEW_TITLE);
721 722 723 724
  else
    return ephy_string_get_host_name (address);
}

725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
static void
_ephy_web_view_set_is_blank (EphyWebView *view,
                             gboolean is_blank)
{
  EphyWebViewPrivate *priv = view->priv;

  if (priv->is_blank != is_blank) {
    priv->is_blank = is_blank;
    g_object_notify (G_OBJECT (view), "is-blank");
  }
}

static void
ephy_web_view_set_title (EphyWebView *view,
                         const char *view_title)
{
  EphyWebViewPrivate *priv = view->priv;
  char *title = g_strdup (view_title);

744
  if (title == NULL || g_strstrip (title)[0] == '\0') {
745
    g_free (title);
746
    title = priv->address ? get_title_from_address (priv->address) : NULL;
747 748 749 750 751 752 753 754 755 756 757 758 759

    if (title == NULL || title[0] == '\0') {
      g_free (title);
      title = g_strdup (EMPTY_PAGE);
    }
  }

  g_free (priv->title);
  priv->title = ephy_string_shorten (title, MAX_TITLE_LENGTH);

  g_object_notify (G_OBJECT (view), "embed-title");
}

Xan Lopez's avatar
Xan Lopez committed
760 761 762 763 764 765 766
static void
title_changed_cb (WebKitWebView *web_view,
                  GParamSpec *spec,
                  gpointer data)
{
  const char *uri;
  char *title;
767 768
  EphyWebView *webview  = EPHY_WEB_VIEW (web_view);
  EphyHistoryService *history = webview->priv->history_service;
769

Carlos Garcia Campos's avatar
Carlos Garcia Campos committed
770
  uri = webkit_web_view_get_uri (web_view);
771

Xan Lopez's avatar
Xan Lopez committed
772 773
  g_object_get (web_view, "title", &title, NULL);

774
  ephy_web_view_set_title (webview, title);
775 776 777
  
  if (!title && uri)
    title = get_title_from_address (uri);
778

779
  if (uri && title && !ephy_web_view_is_history_frozen (webview))
780
    ephy_history_service_set_url_title (history, uri, title, NULL, NULL, NULL);
781

Xan Lopez's avatar
Xan Lopez committed
782 783 784 785
  g_free (title);

}

Xan Lopez's avatar
Xan Lopez committed
786
/*
787
 * Sets the view location to be address. Note that this function might
788
 * also set the typed-address property to NULL.
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
 */
static void
ephy_web_view_set_address (EphyWebView *view,
                           const char *address)
{
  EphyWebViewPrivate *priv = view->priv;
  GObject *object = G_OBJECT (view);
  gboolean is_blank;

  g_free (priv->address);
  priv->address = g_strdup (address);

  is_blank = address == NULL ||
             strcmp (address, "about:blank") == 0;
  _ephy_web_view_set_is_blank (view, is_blank);

  if (ephy_web_view_is_loading (view) && priv->typed_address != NULL)
    ephy_web_view_set_typed_address (view, NULL);

  g_object_notify (object, "address");
}

Xan Lopez's avatar
Xan Lopez committed
811 812 813 814 815 816 817 818
static void
uri_changed_cb (WebKitWebView *web_view,
                GParamSpec *spec,
                gpointer data)
{
  char *uri;
  const char *current_address;

819 820 821 822 823
  /* We already update the URI manually while loading, so only
   * update the URI when it changes after the page has been loaded
   * which is usually the result of navigation within the same page action.
   */
  if (webkit_web_view_is_loading (web_view))
824 825
    return;

Xan Lopez's avatar
Xan Lopez committed
826 827 828
  /* We need to check if we get URI notifications without going
     through the usual load process, as this can happen when changing
     location within a page */
829 830 831
  current_address = ephy_web_view_get_address (EPHY_WEB_VIEW (web_view));
  g_object_get (web_view, "uri", &uri, NULL);

Xan Lopez's avatar
Xan Lopez committed
832 833 834 835 836 837
  if (g_str_equal (uri, current_address) == FALSE)
    ephy_web_view_set_address (EPHY_WEB_VIEW (web_view), uri);

  g_free (uri);
}

838 839 840 841 842 843 844 845 846 847 848 849 850
static void
mouse_target_changed_cb (EphyWebView *web_view,
                         WebKitHitTestResult *hit_test_result,
                         guint modifiers,
                         gpointer data)
{
  const char *message = NULL;

  if (webkit_hit_test_result_context_is_link (hit_test_result))
    message = webkit_hit_test_result_get_link_uri (hit_test_result);

  ephy_web_view_set_link_message (web_view, message);
}
851 852

static void
853
process_crashed_cb (EphyWebView *web_view, gpointer user_data)
854
{
855 856
  if (ephy_embed_has_load_pending (EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (web_view)))
    return;
857

858 859
  ephy_web_view_load_error_page (web_view, ephy_web_view_get_address (web_view),
                                 EPHY_WEB_VIEW_ERROR_PROCESS_CRASH, NULL);
860 861
}

Xan Lopez's avatar
Xan Lopez committed
862 863 864
static void
ephy_web_view_constructed (GObject *object)
{
865 866 867
  if (G_OBJECT_CLASS (ephy_web_view_parent_class)->constructed)
    G_OBJECT_CLASS (ephy_web_view_parent_class)->constructed (object);

868 869 870 871 872
  /* Use full content zooming by default */
  /* FIXME: we could make this configurable through GSettings, or have
   * different keys for text and full content zooming. AFAIK you can
   * have both enabled at the same time in WebKit now (although our
   * API does not reflect this atm). See r67274 in WebKit. */
873
  g_signal_emit_by_name (ephy_embed_shell_get_default (), "web-view-created", object);
874 875 876

  g_signal_connect (object, "web-process-crashed",
                    G_CALLBACK (process_crashed_cb), object);
Xan Lopez's avatar
Xan Lopez committed
877 878
}

879 880 881
static void
impl_loading_homepage (EphyWebView *view)
{
882
  ephy_web_view_freeze_history (view);
883 884
}

885 886 887
static void
ephy_web_view_class_init (EphyWebViewClass *klass)
{
888
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
889
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
890 891 892 893 894

  gobject_class->dispose = ephy_web_view_dispose;
  gobject_class->finalize = ephy_web_view_finalize;
  gobject_class->get_property = ephy_web_view_get_property;
  gobject_class->set_property = ephy_web_view_set_property;
Xan Lopez's avatar
Xan Lopez committed
895
  gobject_class->constructed = ephy_web_view_constructed;
896

897
  widget_class->button_press_event = ephy_web_view_button_press_event;
898 899
  widget_class->key_press_event = ephy_web_view_key_press_event;

900 901
  klass->loading_homepage = impl_loading_homepage;

Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
902 903 904 905 906
/**
 * EphyWebView:address:
 *
 * View's current address.
 **/
907 908 909 910 911 912 913
  g_object_class_install_property (gobject_class,
                                   PROP_ADDRESS,
                                   g_param_spec_string ("address",
                                                        "Address",
                                                        "The view's address",
                                                        "",
                                                        G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
914 915 916 917 918 919

/**
 * EphyWebView:typed-address:
 *
 * User typed address for the current view.
 **/
920 921 922 923 924 925 926
  g_object_class_install_property (gobject_class,
                                   PROP_TYPED_ADDRESS,
                                   g_param_spec_string ("typed-address",
                                                        "Typed Address",
                                                        "The typed address",
                                                        "",
                                                        G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
927 928 929 930 931 932

/**
 * EphyWebView:embed-title:
 *
 * Title for this embed.
 **/
933 934 935 936 937 938 939 940
  g_object_class_install_property (gobject_class,
                                   PROP_EMBED_TITLE,
                                   g_param_spec_string ("embed-title",
                                                        "Title",
                                                        "The view's title",
                                                        EMPTY_PAGE,
                                                        G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));

Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
941 942 943 944 945
/**
 * EphyWebView:security-level:
 *
 * One of #EphyWebViewSecurityLevel, determining view's current security level.
 **/
946 947 948 949 950 951 952 953
  g_object_class_install_property (gobject_class,
                                   PROP_SECURITY,
                                   g_param_spec_enum ("security-level",
                                                      "Security Level",
                                                      "The view's security level",
                                                      EPHY_TYPE_WEB_VIEW_SECURITY_LEVEL,
                                                      EPHY_WEB_VIEW_STATE_IS_UNKNOWN,
                                                      G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
954 955 956 957 958 959

/**
 * EphyWebView:document-type:
 *
 * Document type determined for the view.
 **/
960 961 962 963
  g_object_class_install_property (gobject_class,
                                   PROP_DOCUMENT_TYPE,
                                   g_param_spec_enum ("document-type",
                                                      "Document Type",
Xan Lopez's avatar
Xan Lopez committed
964
                                                      "The view's document type",
965 966 967 968
                                                      EPHY_TYPE_WEB_VIEW_DOCUMENT_TYPE,
                                                      EPHY_WEB_VIEW_DOCUMENT_HTML,
                                                      G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));

Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
969 970 971 972 973
/**
 * EphyWebView:navigation:
 *
 * View's navigation flags as #EphyWebViewNavigationFlags.
 **/
974 975 976 977 978 979 980 981
  g_object_class_install_property (gobject_class,
                                   PROP_NAVIGATION,
                                   g_param_spec_flags ("navigation",
                                                       "Navigation flags",
                                                       "The view's navigation flags",
                                                       EPHY_TYPE_WEB_VIEW_NAVIGATION_FLAGS,
                                                       0,
                                                       G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
982 983 984 985 986 987

/**
 * EphyWebView:status-message:
 *
 * Statusbar message corresponding to this view.
 **/
988 989 990 991 992 993 994
  g_object_class_install_property (gobject_class,
                                   PROP_STATUS_MESSAGE,
                                   g_param_spec_string ("status-message",
                                                        "Status Message",
                                                        "The view's statusbar message",
                                                        NULL,
                                                        G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
995 996 997 998 999 1000

/**
 * EphyWebView:link-message:
 *
 * ???
 **/
1001 1002 1003 1004 1005 1006 1007
  g_object_class_install_property (gobject_class,
                                   PROP_LINK_MESSAGE,
                                   g_param_spec_string ("link-message",
                                                        "Link Message",
                                                        "The view's link message",
                                                        NULL,
                                                        G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
1008 1009 1010 1011 1012 1013

/**
 * EphyWebView:icon:
 *
 * View's favicon set by the loaded site.
 **/
1014 1015 1016 1017 1018 1019 1020 1021
  g_object_class_install_property (gobject_class,
                                   PROP_ICON,
                                   g_param_spec_object ("icon",
                                                        "Icon",
                                                        "The view icon's",
                                                        GDK_TYPE_PIXBUF,
                                                        G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));

Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
1022 1023 1024 1025 1026
/**
 * EphyWebView:hidden-popup-count:
 *
 * Number of hidden (blocked) popup windows.
 **/
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
  g_object_class_install_property (gobject_class,
                                   PROP_HIDDEN_POPUP_COUNT,
                                   g_param_spec_int ("hidden-popup-count",
                                                     "Number of Blocked Popups",
                                                     "The view's number of blocked popup windows",
                                                     0,
                                                     G_MAXINT,
                                                     0,
                                                     G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));

Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
1037 1038 1039 1040 1041
/**
 * EphyWebView:popups-allowed:
 *
 * If popup windows from this view are to be displayed.
 **/
1042 1043 1044 1045 1046 1047 1048 1049
  g_object_class_install_property (gobject_class,
                                   PROP_POPUPS_ALLOWED,
                                   g_param_spec_boolean ("popups-allowed",
                                                         "Popups Allowed",
                                                         "Whether popup windows are to be displayed",
                                                         FALSE,
                                                         G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));

1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
/**
 * EphyWebView:is-blank:
 *
 * Whether the view is showing the blank address.
 **/
  g_object_class_install_property (gobject_class,
                                   PROP_IS_BLANK,
                                   g_param_spec_boolean ("is-blank",
                                                         "Is blank",
                                                         "If the EphyWebView is blank",
                                                         FALSE,
                                                         G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));

1063
/**
1064
 * EphyWebView::new-window:
1065
 * @view: the #EphyWebView that received the signal
1066 1067
 * @new_view: the newly opened #EphyWebView
 *
1068
 * The ::new-window signal is emitted after a new window has been opened by
1069 1070
 * the view. For example, when a JavaScript popup window is opened.
 **/
1071
    g_signal_new ("new-window",
Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
1072 1073 1074 1075 1076 1077 1078 1079
            EPHY_TYPE_WEB_VIEW,
            G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
            G_STRUCT_OFFSET (EphyWebViewClass, new_window),
            NULL, NULL,
            g_cclosure_marshal_VOID__OBJECT,
            G_TYPE_NONE,
            1,
            GTK_TYPE_WIDGET);
1080 1081
/**
 * EphyWebView::ge-popup-blocked:
1082
 * @view: the #EphyWebView that received the signal
1083 1084 1085 1086 1087 1088 1089
 * @address: The requested URL
 * @target: The requested window name, e.g. "_blank"
 * @features: The requested features: for example, "height=400,width=200"
 *
 * The ::ge_popup_blocked signal is emitted when the viewed web page requests
 * a popup window (with javascript:open()) but popup windows are not allowed.
 **/
Xan Lopez's avatar
Xan Lopez committed
1090 1091 1092 1093 1094
    g_signal_new ("ge_popup_blocked",
            EPHY_TYPE_WEB_VIEW,
            G_SIGNAL_RUN_FIRST,
            G_STRUCT_OFFSET (EphyWebViewClass, popup_blocked),
            NULL, NULL,
1095
            g_cclosure_marshal_generic,
Xan Lopez's avatar
Xan Lopez committed
1096 1097 1098 1099 1100
            G_TYPE_NONE,
            3,
            G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
            G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
            G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
Xan Lopez's avatar
Xan Lopez committed
1101

1102 1103
/**
 * EphyWebView::ge-search-link:
1104
 * @view: the #EphyWebView that received the signal
1105 1106 1107 1108
 * @type: the mime-type of the search description
 * @title: the title of the news feed
 * @address: the URL to @embed's web site's search description
 *
1109 1110
 * The ::ge-search-link signal is emitted when @embed discovers that a
 * search description is available for the site it is visiting.
1111
 **/
Xan Lopez's avatar
Xan Lopez committed
1112 1113 1114 1115 1116
    g_signal_new ("ge_search_link",
            EPHY_TYPE_WEB_VIEW,
            G_SIGNAL_RUN_FIRST,
            G_STRUCT_OFFSET (EphyWebViewClass, search_link),
            NULL, NULL,
1117
            g_cclosure_marshal_generic,
Xan Lopez's avatar
Xan Lopez committed
1118 1119 1120 1121 1122
            G_TYPE_NONE,
            3,
            G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
            G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
            G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
1123 1124 1125

/**
 * EphyWebView::ge-feed-link:
1126
 * @view: the #EphyWebView that received the signal
1127 1128 1129 1130
 * @type: the mime-type of the news feed
 * @title: the title of the news feed
 * @address: the URL to @embed's web site's news feed
 *
1131 1132
 * The ::ge-feed-link signal is emitted when @embed discovers that a
 * news feed is available for the site it is visiting.
1133
 **/
Xan Lopez's avatar
Xan Lopez committed
1134 1135 1136 1137 1138
    g_signal_new ("ge_feed_link",
            EPHY_TYPE_WEB_VIEW,
            G_SIGNAL_RUN_FIRST,
            G_STRUCT_OFFSET (EphyWebViewClass, feed_link),
            NULL, NULL,
1139
            g_cclosure_marshal_generic,
Xan Lopez's avatar
Xan Lopez committed
1140 1141 1142 1143 1144
            G_TYPE_NONE,
            3,
            G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
            G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
            G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
1145 1146
/**
 * EphyWebView::ge-modal-alert:
1147
 * @view: the #EphyWebView that received the signal
1148 1149 1150 1151 1152 1153
 *
 * The ::ge-modal-alert signal is emitted when a DOM event will open a
 * modal alert.
 *
 * Return %TRUE to prevent the dialog from being opened.
 **/
Xan Lopez's avatar
Xan Lopez committed
1154 1155 1156 1157 1158
    g_signal_new ("ge_modal_alert",
            EPHY_TYPE_WEB_VIEW,
            G_SIGNAL_RUN_LAST,
            G_STRUCT_OFFSET (EphyWebViewClass, modal_alert),
            g_signal_accumulator_true_handled, NULL,
1159
            g_cclosure_marshal_generic,
Xan Lopez's avatar
Xan Lopez committed
1160 1161
            G_TYPE_BOOLEAN,
            0);
1162 1163
/**
 * EphyWebView::ge-modal-alert-closed:
1164
 * @view: the #EphyWebView that received the signal
1165 1166 1167 1168
 *
 * The ::ge-modal-alert-closed signal is emitted when a modal alert put up by a
 * DOM event was closed.
 **/
Xan Lopez's avatar
Xan Lopez committed
1169 1170 1171 1172 1173 1174 1175 1176
    g_signal_new ("ge_modal_alert_closed",
            EPHY_TYPE_WEB_VIEW,
            G_SIGNAL_RUN_LAST,
            G_STRUCT_OFFSET (EphyWebViewClass, modal_alert_closed),
            NULL, NULL,
            g_cclosure_marshal_VOID__VOID,
            G_TYPE_NONE,
            0);
1177 1178

/**
1179
 * EphyWebView::search-key-press:
1180
 * @view: the #EphyWebView that received the signal
1181 1182
 * @event: the #GdkEventKey which triggered this signal
 *
1183
 * The ::search-key-press signal is emitted for keypresses which
1184 1185
 * should be used for find implementations.
 **/
1186
    g_signal_new ("search-key-press",
Xan Lopez's avatar
Xan Lopez committed
1187 1188 1189 1190
            EPHY_TYPE_WEB_VIEW,
            G_SIGNAL_RUN_LAST,
            G_STRUCT_OFFSET (EphyWebViewClass, search_key_press),
            g_signal_accumulator_true_handled, NULL,
1191
            g_cclosure_marshal_generic,
Xan Lopez's avatar
Xan Lopez committed
1192 1193 1194
            G_TYPE_BOOLEAN,
            1,
            GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1195 1196 1197

/**
 * EphyWebView::content-blocked:
1198
 * @view: the #EphyWebView that received the signal
Xan Lopez's avatar
Xan Lopez committed
1199
 * @uri: blocked URI
1200 1201 1202
 *
 * The ::content-blocked signal is emitted when an url has been blocked.
 **/
Xan Lopez's avatar
Xan Lopez committed
1203 1204 1205 1206 1207 1208 1209 1210 1211
    g_signal_new ("content-blocked",
            EPHY_TYPE_WEB_VIEW,
            G_SIGNAL_RUN_LAST,
            G_STRUCT_OFFSET (EphyWebViewClass, content_blocked),
            NULL, NULL,
            g_cclosure_marshal_VOID__STRING,
            G_TYPE_NONE,
            1,
            G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
1212 1213
/**
 * EphyWebView::new-document-now:
1214
 * @view: the #EphyWebView that received the signal
1215 1216 1217 1218 1219 1220 1221
 * @uri: URI of the new content
 *
 * The ::new-document-now signal is emitted when a new page content
 * is being loaded into the browser. It's a good place to do view
 * related changes, for example to restore the zoom level of a page
 * or to set an user style sheet.
 **/
Diego Escalante Urrelo's avatar
Diego Escalante Urrelo committed
1222 1223 1224 1225 1226 1227 1228 1229 1230
    g_signal_new ("new-document-now",
            EPHY_TYPE_WEB_VIEW,
            G_SIGNAL_RUN_FIRST,
            G_STRUCT_OFFSET (EphyWebViewClass, new_document_now),
            NULL, NULL,
            g_cclosure_marshal_VOID__STRING,
            G_TYPE_NONE,
            1,
            G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
1231

1232
/**
1233
 * EphyWebView::loading-homepage:
1234 1235 1236 1237 1238 1239
 * @view: the #EphyWebView that received the signal
 *
 * The ::loading-homepage signal is emitted when the @view is about to
 * load the homepage set by the user.
 **/
    g_signal_new ("loading-homepage",
1240 1241 1242 1243 1244 1245 1246
                  EPHY_TYPE_WEB_VIEW,
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (EphyWebViewClass, loading_homepage),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE,
                  0);
1247

1248 1249 1250 1251
  g_type_class_add_private (gobject_class, sizeof (EphyWebViewPrivate));
}

static void
1252 1253 1254
new_window_cb (EphyWebView *view,
               EphyWebView *new_view,
               gpointer user_data)
1255 1256 1257 1258 1259 1260
{
  EphyEmbedContainer *container;

  g_return_if_fail (new_view != NULL);

  container = EPHY_EMBED_CONTAINER (gtk_widget_get_toplevel (GTK_WIDGET (new_view)));
1261
  g_return_if_fail (container != NULL || !gtk_widget_is_toplevel (GTK_WIDGET (container)));
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273

  popups_manager_add_window (view, container);
}

static void
ge_popup_blocked_cb (EphyWebView *view,
                     const char *url,
                     const char *name,
                     const char *features,
                     gpointer user_data)
{
  popups_manager_add (view, url, name, features);
1274 1275
}

1276 1277 1278 1279 1280 1281 1282 1283
static gboolean
decide_policy_cb (WebKitWebView *web_view,
                  WebKitPolicyDecision *decision,
                  WebKitPolicyDecisionType decision_type,
                  gpointer user_data)
{
  WebKitResponsePolicyDecision *response_decision;
  WebKitURIResponse *response;
1284
  WebKitURIRequest *request;
1285
  WebKitWebResource *main_resource;
1286
  EphyWebViewDocumentType type;