[epiphany/mcatanzaro/web-view-signals: 14/15] web-view: rearrange



commit 7ce8f08e814a99d8b5948f24d84b096fcac197a8
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Tue Dec 17 15:55:44 2019 -0600

    web-view: rearrange
    
    Move the initialization and destruction stuff to the bottom of the file.
    This will avoid needless future code changes.

 embed/ephy-web-view.c | 1069 ++++++++++++++++++++++++-------------------------
 1 file changed, 534 insertions(+), 535 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index a74182e3d..ed18e76aa 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -658,67 +658,6 @@ allow_unsafe_browsing_cb (EphyEmbedShell *shell,
   ephy_web_view_load_url (view, ephy_web_view_get_address (view));
 }
 
-static void
-ephy_web_view_dispose (GObject *object)
-{
-  EphyWebView *view = EPHY_WEB_VIEW (object);
-  WebKitUserContentManager *ucm = webkit_web_view_get_user_content_manager (WEBKIT_WEB_VIEW (view));
-
-  ephy_embed_prefs_unregister_ucm (ucm);
-  ephy_embed_shell_unregister_ucm_handler (ephy_embed_shell_get_default (), ucm);
-
-  untrack_info_bar (&view->geolocation_info_bar);
-  untrack_info_bar (&view->notification_info_bar);
-  untrack_info_bar (&view->microphone_info_bar);
-  untrack_info_bar (&view->webcam_info_bar);
-  untrack_info_bar (&view->password_info_bar);
-  untrack_info_bar (&view->password_form_info_bar);
-
-  g_clear_object (&view->file_monitor);
-
-  g_clear_object (&view->icon);
-
-  if (view->cancellable) {
-    g_cancellable_cancel (view->cancellable);
-    g_clear_object (&view->cancellable);
-  }
-
-  if (view->snapshot_timeout_id) {
-    g_source_remove (view->snapshot_timeout_id);
-    view->snapshot_timeout_id = 0;
-  }
-
-  if (view->reader_js_timeout) {
-    g_source_remove (view->reader_js_timeout);
-    view->reader_js_timeout = 0;
-  }
-
-  g_clear_object (&view->certificate);
-
-  G_OBJECT_CLASS (ephy_web_view_parent_class)->dispose (object);
-}
-
-static void
-ephy_web_view_finalize (GObject *object)
-{
-  EphyWebView *view = EPHY_WEB_VIEW (object);
-
-  g_free (view->address);
-  g_free (view->display_address);
-  g_free (view->typed_address);
-  g_free (view->last_committed_address);
-  g_free (view->link_message);
-  g_free (view->loading_message);
-  g_free (view->tls_error_failing_uri);
-  g_free (view->pending_snapshot_uri);
-
-  g_free (view->reader_content);
-  g_free (view->reader_byline);
-  g_free (view->reader_url);
-
-  G_OBJECT_CLASS (ephy_web_view_parent_class)->finalize (object);
-}
-
 static void
 _ephy_web_view_set_is_blank (EphyWebView *view,
                              gboolean     is_blank)
@@ -916,356 +855,135 @@ style_updated_cb (EphyWebView *web_view,
   webkit_web_view_set_background_color (WEBKIT_WEB_VIEW (web_view), &color);
 }
 
-static void
-ephy_web_view_constructed (GObject *object)
+static gboolean
+decide_policy_cb (WebKitWebView            *web_view,
+                  WebKitPolicyDecision     *decision,
+                  WebKitPolicyDecisionType  decision_type,
+                  gpointer                  user_data)
 {
-  EphyWebView *web_view = EPHY_WEB_VIEW (object);
+  WebKitResponsePolicyDecision *response_decision;
+  WebKitURIResponse *response;
+  WebKitURIRequest *request;
+  WebKitWebResource *main_resource;
+  EphyWebViewDocumentType type;
+  const char *mime_type;
+  const char *request_uri;
 
-  G_OBJECT_CLASS (ephy_web_view_parent_class)->constructed (object);
+  if (decision_type != WEBKIT_POLICY_DECISION_TYPE_RESPONSE)
+    return FALSE;
 
-  g_signal_emit_by_name (ephy_embed_shell_get_default (), "web-view-created", web_view);
+  response_decision = WEBKIT_RESPONSE_POLICY_DECISION (decision);
+  response = webkit_response_policy_decision_get_response (response_decision);
+  mime_type = webkit_uri_response_get_mime_type (response);
 
-  g_signal_connect (web_view, "web-process-terminated",
-                    G_CALLBACK (process_terminated_cb), NULL);
-  g_signal_connect_swapped (webkit_web_view_get_back_forward_list (WEBKIT_WEB_VIEW (web_view)),
-                            "changed", G_CALLBACK (update_navigation_flags), web_view);
+  /* If WebKit can't handle the mime type start the download
+   *  process */
+  if (webkit_response_policy_decision_is_mime_type_supported (response_decision))
+    return FALSE;
 
-  g_signal_connect (web_view, "style-updated",
-                    G_CALLBACK (style_updated_cb), NULL);
-  style_updated_cb (web_view, NULL);
+  /* If it's not the main resource we don't need to set the document type. */
+  request = webkit_response_policy_decision_get_request (response_decision);
+  request_uri = webkit_uri_request_get_uri (request);
+  main_resource = webkit_web_view_get_main_resource (web_view);
+  if (g_strcmp0 (webkit_web_resource_get_uri (main_resource), request_uri) != 0)
+    return FALSE;
+
+  type = EPHY_WEB_VIEW_DOCUMENT_OTHER;
+  if (!strcmp (mime_type, "text/html") || !strcmp (mime_type, "text/plain"))
+    type = EPHY_WEB_VIEW_DOCUMENT_HTML;
+  else if (!strcmp (mime_type, "application/xhtml+xml"))
+    type = EPHY_WEB_VIEW_DOCUMENT_XML;
+  else if (!strncmp (mime_type, "image/", 6))
+    type = EPHY_WEB_VIEW_DOCUMENT_IMAGE;
+
+  /* FIXME: maybe it makes more sense to have an API to query the mime
+   * type when the load of a page starts than doing this here.
+   */
+  if (EPHY_WEB_VIEW (web_view)->document_type != type) {
+    EPHY_WEB_VIEW (web_view)->document_type = type;
+
+    g_object_notify_by_pspec (G_OBJECT (web_view), obj_properties[PROP_DOCUMENT_TYPE]);
+  }
+
+  webkit_policy_decision_download (decision);
+
+  return TRUE;
+}
+
+typedef struct {
+  EphyWebView *web_view;
+  WebKitPermissionRequest *request;
+  char *origin;
+} PermissionRequestData;
+
+static PermissionRequestData *
+permission_request_data_new (EphyWebView             *web_view,
+                             WebKitPermissionRequest *request,
+                             const char              *origin)
+{
+  PermissionRequestData *data;
+  data = g_new (PermissionRequestData, 1);
+  data->web_view = web_view;
+  /* Ref the decision to keep it alive while we decide */
+  data->request = g_object_ref (request);
+  data->origin = g_strdup (origin);
+  return data;
 }
 
 static void
-ephy_web_view_class_init (EphyWebViewClass *klass)
+permission_request_data_free (PermissionRequestData *data)
 {
-  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-  WebKitWebViewClass *webkit_webview_class = WEBKIT_WEB_VIEW_CLASS (klass);
+  g_object_unref (data->request);
+  g_free (data->origin);
+  g_free (data);
+}
 
-  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;
-  gobject_class->constructed = ephy_web_view_constructed;
+static void
+permission_request_info_bar_destroyed_cb (PermissionRequestData *data,
+                                          GObject               *where_the_info_bar_was)
+{
+  webkit_permission_request_deny (data->request);
+  permission_request_data_free (data);
+}
 
-  widget_class->button_press_event = ephy_web_view_button_press_event;
-  widget_class->key_press_event = ephy_web_view_key_press_event;
+static void
+decide_on_permission_request (GtkWidget             *info_bar,
+                              int                    response,
+                              PermissionRequestData *data)
+{
+  const char *address;
+  EphyPermissionType permission_type;
 
-  webkit_webview_class->run_file_chooser = ephy_web_view_run_file_chooser;
+  switch (response) {
+    case GTK_RESPONSE_YES:
+      webkit_permission_request_allow (data->request);
+      break;
+    default:
+      webkit_permission_request_deny (data->request);
+      break;
+  }
 
-/**
- * EphyWebView:address:
- *
- * View's current address. This is a percent-encoded URI.
- **/
-  obj_properties[PROP_ADDRESS] =
-    g_param_spec_string ("address",
-                         "Address",
-                         "The view's address",
-                         "",
-                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+  if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST (data->request)) {
+    permission_type = EPHY_PERMISSION_TYPE_ACCESS_LOCATION;
+  } else if (WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST (data->request)) {
+    permission_type = EPHY_PERMISSION_TYPE_SHOW_NOTIFICATIONS;
+  } else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST (data->request)) {
+    if (webkit_user_media_permission_is_for_video_device (WEBKIT_USER_MEDIA_PERMISSION_REQUEST 
(data->request)))
+      permission_type = EPHY_PERMISSION_TYPE_ACCESS_WEBCAM;
+    else
+      permission_type = EPHY_PERMISSION_TYPE_ACCESS_MICROPHONE;
+  } else {
+    g_assert_not_reached ();
+  }
 
-/**
- * EphyWebView:typed-address:
- *
- * User typed address for the current view.
- **/
-  obj_properties[PROP_TYPED_ADDRESS] =
-    g_param_spec_string ("typed-address",
-                         "Typed Address",
-                         "The typed address",
-                         "",
-                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  address = ephy_web_view_get_address (data->web_view);
 
-/**
- * EphyWebView:security-level:
- *
- * One of #EphySecurityLevel, determining view's current security level.
- **/
-  obj_properties[PROP_SECURITY] =
-    g_param_spec_enum ("security-level",
-                       "Security Level",
-                       "The view's security level",
-                       EPHY_TYPE_SECURITY_LEVEL,
-                       EPHY_SECURITY_LEVEL_TO_BE_DETERMINED,
-                       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+  if (response != GTK_RESPONSE_NONE && ephy_embed_utils_address_has_web_scheme (address)) {
+    EphyEmbedShell *shell;
+    EphyPermissionsManager *permissions_manager;
 
-/**
- * EphyWebView:document-type:
- *
- * Document type determined for the view.
- **/
-  obj_properties[PROP_DOCUMENT_TYPE] =
-    g_param_spec_enum ("document-type",
-                       "Document Type",
-                       "The view's document type",
-                       EPHY_TYPE_WEB_VIEW_DOCUMENT_TYPE,
-                       EPHY_WEB_VIEW_DOCUMENT_HTML,
-                       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
-/**
- * EphyWebView:navigation:
- *
- * View's navigation flags as #EphyWebViewNavigationFlags.
- **/
-  obj_properties[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_STRINGS);
-
-/**
- * EphyWebView:status-message:
- *
- * Statusbar message corresponding to this view.
- **/
-  obj_properties[PROP_STATUS_MESSAGE] =
-    g_param_spec_string ("status-message",
-                         "Status Message",
-                         "The view's statusbar message",
-                         NULL,
-                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
-/**
- * EphyWebView:link-message:
- *
- * ???
- **/
-  obj_properties[PROP_LINK_MESSAGE] =
-    g_param_spec_string ("link-message",
-                         "Link Message",
-                         "The view's link message",
-                         NULL,
-                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
-/**
- * EphyWebView:icon:
- *
- * View's favicon set by the loaded site.
- **/
-  obj_properties[PROP_ICON] =
-    g_param_spec_object ("icon",
-                         "Icon",
-                         "The view icon's",
-                         GDK_TYPE_PIXBUF,
-                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
-/**
- * EphyWebView:is-blank:
- *
- * Whether the view is showing the blank address.
- **/
-  obj_properties[PROP_IS_BLANK] =
-    g_param_spec_boolean ("is-blank",
-                          "Is blank",
-                          "If the EphyWebView is blank",
-                          FALSE,
-                          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
-/**
- * EphyWebView:reader-mode:
- *
- * Whether the view is in reader mode.
- **/
-  obj_properties[PROP_READER_MODE] =
-    g_param_spec_boolean ("reader-mode",
-                          "Reader mode",
-                          "If the EphyWebView is in reader mode",
-                          FALSE,
-                          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
-/**
- * EphyWebView:display-address:
- *
- * View's current display address.
- **/
-  obj_properties[PROP_DISPLAY_ADDRESS] =
-    g_param_spec_string ("display-address",
-                         "Display address",
-                         "The view's display address",
-                         "",
-                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
-  g_object_class_install_properties (gobject_class, LAST_PROP, obj_properties);
-
-/**
- * EphyWebView::new-window:
- * @view: the #EphyWebView that received the signal
- * @new_view: the newly opened #EphyWebView
- *
- * The ::new-window signal is emitted after a new window has been opened by
- * the view. For example, when a JavaScript popup window is opened.
- **/
-  g_signal_new ("new-window",
-                EPHY_TYPE_WEB_VIEW,
-                G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
-                0, NULL, NULL, NULL,
-                G_TYPE_NONE,
-                1,
-                GTK_TYPE_WIDGET);
-
-/**
- * EphyWebView::search-key-press:
- * @view: the #EphyWebView that received the signal
- * @event: the #GdkEventKey which triggered this signal
- *
- * The ::search-key-press signal is emitted for keypresses which
- * should be used for find implementations.
- **/
-  g_signal_new ("search-key-press",
-                EPHY_TYPE_WEB_VIEW,
-                G_SIGNAL_RUN_LAST,
-                0, g_signal_accumulator_true_handled, NULL, NULL,
-                G_TYPE_BOOLEAN,
-                1,
-                GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
-
-/**
- * EphyWebView::download-only-load:
- * @view: the #EphyWebView that received the signal
- *
- * The ::download-only-load signal is emitted when the @view has its main load
- * replaced by a download, and that is the only reason why the @view has been created.
- **/
-  g_signal_new ("download-only-load",
-                EPHY_TYPE_WEB_VIEW,
-                G_SIGNAL_RUN_FIRST,
-                0, NULL, NULL, NULL,
-                G_TYPE_NONE,
-                0);
-}
-
-static gboolean
-decide_policy_cb (WebKitWebView            *web_view,
-                  WebKitPolicyDecision     *decision,
-                  WebKitPolicyDecisionType  decision_type,
-                  gpointer                  user_data)
-{
-  WebKitResponsePolicyDecision *response_decision;
-  WebKitURIResponse *response;
-  WebKitURIRequest *request;
-  WebKitWebResource *main_resource;
-  EphyWebViewDocumentType type;
-  const char *mime_type;
-  const char *request_uri;
-
-  if (decision_type != WEBKIT_POLICY_DECISION_TYPE_RESPONSE)
-    return FALSE;
-
-  response_decision = WEBKIT_RESPONSE_POLICY_DECISION (decision);
-  response = webkit_response_policy_decision_get_response (response_decision);
-  mime_type = webkit_uri_response_get_mime_type (response);
-
-  /* If WebKit can't handle the mime type start the download
-   *  process */
-  if (webkit_response_policy_decision_is_mime_type_supported (response_decision))
-    return FALSE;
-
-  /* If it's not the main resource we don't need to set the document type. */
-  request = webkit_response_policy_decision_get_request (response_decision);
-  request_uri = webkit_uri_request_get_uri (request);
-  main_resource = webkit_web_view_get_main_resource (web_view);
-  if (g_strcmp0 (webkit_web_resource_get_uri (main_resource), request_uri) != 0)
-    return FALSE;
-
-  type = EPHY_WEB_VIEW_DOCUMENT_OTHER;
-  if (!strcmp (mime_type, "text/html") || !strcmp (mime_type, "text/plain"))
-    type = EPHY_WEB_VIEW_DOCUMENT_HTML;
-  else if (!strcmp (mime_type, "application/xhtml+xml"))
-    type = EPHY_WEB_VIEW_DOCUMENT_XML;
-  else if (!strncmp (mime_type, "image/", 6))
-    type = EPHY_WEB_VIEW_DOCUMENT_IMAGE;
-
-  /* FIXME: maybe it makes more sense to have an API to query the mime
-   * type when the load of a page starts than doing this here.
-   */
-  if (EPHY_WEB_VIEW (web_view)->document_type != type) {
-    EPHY_WEB_VIEW (web_view)->document_type = type;
-
-    g_object_notify_by_pspec (G_OBJECT (web_view), obj_properties[PROP_DOCUMENT_TYPE]);
-  }
-
-  webkit_policy_decision_download (decision);
-
-  return TRUE;
-}
-
-typedef struct {
-  EphyWebView *web_view;
-  WebKitPermissionRequest *request;
-  char *origin;
-} PermissionRequestData;
-
-static PermissionRequestData *
-permission_request_data_new (EphyWebView             *web_view,
-                             WebKitPermissionRequest *request,
-                             const char              *origin)
-{
-  PermissionRequestData *data;
-  data = g_new (PermissionRequestData, 1);
-  data->web_view = web_view;
-  /* Ref the decision to keep it alive while we decide */
-  data->request = g_object_ref (request);
-  data->origin = g_strdup (origin);
-  return data;
-}
-
-static void
-permission_request_data_free (PermissionRequestData *data)
-{
-  g_object_unref (data->request);
-  g_free (data->origin);
-  g_free (data);
-}
-
-static void
-permission_request_info_bar_destroyed_cb (PermissionRequestData *data,
-                                          GObject               *where_the_info_bar_was)
-{
-  webkit_permission_request_deny (data->request);
-  permission_request_data_free (data);
-}
-
-static void
-decide_on_permission_request (GtkWidget             *info_bar,
-                              int                    response,
-                              PermissionRequestData *data)
-{
-  const char *address;
-  EphyPermissionType permission_type;
-
-  switch (response) {
-    case GTK_RESPONSE_YES:
-      webkit_permission_request_allow (data->request);
-      break;
-    default:
-      webkit_permission_request_deny (data->request);
-      break;
-  }
-
-  if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST (data->request)) {
-    permission_type = EPHY_PERMISSION_TYPE_ACCESS_LOCATION;
-  } else if (WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST (data->request)) {
-    permission_type = EPHY_PERMISSION_TYPE_SHOW_NOTIFICATIONS;
-  } else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST (data->request)) {
-    if (webkit_user_media_permission_is_for_video_device (WEBKIT_USER_MEDIA_PERMISSION_REQUEST 
(data->request)))
-      permission_type = EPHY_PERMISSION_TYPE_ACCESS_WEBCAM;
-    else
-      permission_type = EPHY_PERMISSION_TYPE_ACCESS_MICROPHONE;
-  } else {
-    g_assert_not_reached ();
-  }
-
-  address = ephy_web_view_get_address (data->web_view);
-
-  if (response != GTK_RESPONSE_NONE && ephy_embed_utils_address_has_web_scheme (address)) {
-    EphyEmbedShell *shell;
-    EphyPermissionsManager *permissions_manager;
-
-    shell = ephy_embed_shell_get_default ();
-    permissions_manager = ephy_embed_shell_get_permissions_manager (shell);
+    shell = ephy_embed_shell_get_default ();
+    permissions_manager = ephy_embed_shell_get_permissions_manager (shell);
 
     ephy_permissions_manager_set_permission (permissions_manager,
                                              permission_type,
@@ -2787,145 +2505,6 @@ user_message_received_cb (WebKitWebView     *web_view,
   return FALSE;
 }
 
-static void
-ephy_web_view_init (EphyWebView *web_view)
-{
-  EphyEmbedShell *shell;
-
-  shell = ephy_embed_shell_get_default ();
-
-  web_view->is_blank = TRUE;
-  web_view->ever_committed = FALSE;
-  web_view->document_type = EPHY_WEB_VIEW_DOCUMENT_HTML;
-  web_view->security_level = EPHY_SECURITY_LEVEL_TO_BE_DETERMINED;
-
-  web_view->file_monitor = ephy_file_monitor_new (web_view);
-
-  web_view->history_service = ephy_embed_shell_get_global_history_service (shell);
-
-  web_view->cancellable = g_cancellable_new ();
-
-  g_signal_connect_object (EPHY_SETTINGS_READER, "changed::" EPHY_PREFS_READER_FONT_STYLE,
-                           G_CALLBACK (reader_setting_changed_cb),
-                           web_view, 0);
-
-  g_signal_connect_object (EPHY_SETTINGS_READER, "changed::" EPHY_PREFS_READER_COLOR_SCHEME,
-                           G_CALLBACK (reader_setting_changed_cb),
-                           web_view, 0);
-
-  g_signal_connect (web_view, "decide-policy",
-                    G_CALLBACK (decide_policy_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "permission-request",
-                    G_CALLBACK (permission_request_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "load-changed",
-                    G_CALLBACK (load_changed_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "close",
-                    G_CALLBACK (close_web_view_cb),
-                    NULL);
-  g_signal_connect (web_view, "load-failed",
-                    G_CALLBACK (load_failed_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "load-failed-with-tls-errors",
-                    G_CALLBACK (load_failed_with_tls_error_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "insecure-content-detected",
-                    G_CALLBACK (mixed_content_detected_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "notify::zoom-level",
-                    G_CALLBACK (zoom_changed_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "notify::title",
-                    G_CALLBACK (title_changed_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "notify::uri",
-                    G_CALLBACK (uri_changed_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "mouse-target-changed",
-                    G_CALLBACK (mouse_target_changed_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "notify::favicon",
-                    G_CALLBACK (icon_changed_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "script-dialog",
-                    G_CALLBACK (script_dialog_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "authenticate",
-                    G_CALLBACK (authenticate_cb),
-                    NULL);
-
-  g_signal_connect (web_view, "user-message-received",
-                    G_CALLBACK (user_message_received_cb),
-                    NULL);
-
-  g_signal_connect_object (shell, "password-form-focused",
-                           G_CALLBACK (password_form_focused_cb),
-                           web_view, 0);
-
-  g_signal_connect_object (shell, "allow-tls-certificate",
-                           G_CALLBACK (allow_tls_certificate_cb),
-                           web_view, 0);
-
-  g_signal_connect_object (shell, "allow-unsafe-browsing",
-                           G_CALLBACK (allow_unsafe_browsing_cb),
-                           web_view, 0);
-}
-
-/**
- * ephy_web_view_new:
- *
- * Equivalent to g_object_new() but returns an #GtkWidget so you don't have
- * to cast it when dealing with most code.
- *
- * Return value: the newly created #EphyWebView widget
- **/
-GtkWidget *
-ephy_web_view_new (void)
-{
-  EphyEmbedShell *shell = ephy_embed_shell_get_default ();
-  WebKitUserContentManager *ucm = webkit_user_content_manager_new ();
-
-  ephy_embed_shell_register_ucm_handler (shell, ucm);
-  ephy_embed_prefs_register_ucm (ucm);
-
-  return g_object_new (EPHY_TYPE_WEB_VIEW,
-                       "web-context", ephy_embed_shell_get_web_context (shell),
-                       "user-content-manager", ucm,
-                       "settings", ephy_embed_prefs_get_settings (),
-                       "is-controlled-by-automation", ephy_embed_shell_get_mode (shell) == 
EPHY_EMBED_SHELL_MODE_AUTOMATION,
-                       NULL);
-}
-
-GtkWidget *
-ephy_web_view_new_with_related_view (WebKitWebView *related_view)
-{
-  EphyEmbedShell *shell = ephy_embed_shell_get_default ();
-  WebKitUserContentManager *ucm = webkit_user_content_manager_new ();
-
-  ephy_embed_shell_register_ucm_handler (shell, ucm);
-  ephy_embed_prefs_register_ucm (ucm);
-
-  return g_object_new (EPHY_TYPE_WEB_VIEW,
-                       "related-view", related_view,
-                       "user-content-manager", ucm,
-                       "settings", ephy_embed_prefs_get_settings (),
-                       NULL);
-}
-
 /**
  * ephy_web_view_load_request:
  * @view: the #EphyWebView in which to load the request
@@ -2969,7 +2548,6 @@ ephy_web_view_load_url (EphyWebView *view,
   g_assert (url);
 
   view->reader_active = FALSE;
-
   effective_url = ephy_embed_utils_normalize_address (url);
   if (g_str_has_prefix (effective_url, "javascript:")) {
     char *decoded_url;
@@ -3864,3 +3442,424 @@ ephy_web_view_is_in_auth_dialog (EphyWebView *view)
 {
   return view->in_auth_dialog;
 }
+
+static void
+ephy_web_view_dispose (GObject *object)
+{
+  EphyWebView *view = EPHY_WEB_VIEW (object);
+  WebKitUserContentManager *ucm = webkit_web_view_get_user_content_manager (WEBKIT_WEB_VIEW (view));
+
+  ephy_embed_prefs_unregister_ucm (ucm);
+  ephy_embed_shell_unregister_ucm_handler (ephy_embed_shell_get_default (), ucm);
+
+  untrack_info_bar (&view->geolocation_info_bar);
+  untrack_info_bar (&view->notification_info_bar);
+  untrack_info_bar (&view->microphone_info_bar);
+  untrack_info_bar (&view->webcam_info_bar);
+  untrack_info_bar (&view->password_info_bar);
+  untrack_info_bar (&view->password_form_info_bar);
+
+  g_clear_object (&view->file_monitor);
+
+  g_clear_object (&view->icon);
+
+  if (view->cancellable) {
+    g_cancellable_cancel (view->cancellable);
+    g_clear_object (&view->cancellable);
+  }
+
+  if (view->snapshot_timeout_id) {
+    g_source_remove (view->snapshot_timeout_id);
+    view->snapshot_timeout_id = 0;
+  }
+
+  if (view->reader_js_timeout) {
+    g_source_remove (view->reader_js_timeout);
+    view->reader_js_timeout = 0;
+  }
+
+  g_clear_object (&view->certificate);
+
+  G_OBJECT_CLASS (ephy_web_view_parent_class)->dispose (object);
+}
+
+static void
+ephy_web_view_finalize (GObject *object)
+{
+  EphyWebView *view = EPHY_WEB_VIEW (object);
+
+  g_free (view->address);
+  g_free (view->display_address);
+  g_free (view->typed_address);
+  g_free (view->last_committed_address);
+  g_free (view->link_message);
+  g_free (view->loading_message);
+  g_free (view->tls_error_failing_uri);
+  g_free (view->pending_snapshot_uri);
+
+  g_free (view->reader_content);
+  g_free (view->reader_byline);
+  g_free (view->reader_url);
+
+  G_OBJECT_CLASS (ephy_web_view_parent_class)->finalize (object);
+}
+
+static void
+ephy_web_view_constructed (GObject *object)
+{
+  EphyWebView *web_view = EPHY_WEB_VIEW (object);
+
+  G_OBJECT_CLASS (ephy_web_view_parent_class)->constructed (object);
+
+  g_signal_emit_by_name (ephy_embed_shell_get_default (), "web-view-created", web_view);
+
+  g_signal_connect (web_view, "web-process-terminated",
+                    G_CALLBACK (process_terminated_cb), NULL);
+  g_signal_connect_swapped (webkit_web_view_get_back_forward_list (WEBKIT_WEB_VIEW (web_view)),
+                            "changed", G_CALLBACK (update_navigation_flags), web_view);
+
+  g_signal_connect (web_view, "style-updated",
+                    G_CALLBACK (style_updated_cb), NULL);
+  style_updated_cb (web_view, NULL);
+}
+
+static void
+ephy_web_view_init (EphyWebView *web_view)
+{
+  EphyEmbedShell *shell;
+
+  shell = ephy_embed_shell_get_default ();
+
+  web_view->is_blank = TRUE;
+  web_view->ever_committed = FALSE;
+  web_view->document_type = EPHY_WEB_VIEW_DOCUMENT_HTML;
+  web_view->security_level = EPHY_SECURITY_LEVEL_TO_BE_DETERMINED;
+
+  web_view->file_monitor = ephy_file_monitor_new (web_view);
+
+  web_view->history_service = ephy_embed_shell_get_global_history_service (shell);
+
+  web_view->cancellable = g_cancellable_new ();
+
+  g_signal_connect_object (EPHY_SETTINGS_READER, "changed::" EPHY_PREFS_READER_FONT_STYLE,
+                           G_CALLBACK (reader_setting_changed_cb),
+                           web_view, 0);
+
+  g_signal_connect_object (EPHY_SETTINGS_READER, "changed::" EPHY_PREFS_READER_COLOR_SCHEME,
+                           G_CALLBACK (reader_setting_changed_cb),
+                           web_view, 0);
+
+  g_signal_connect (web_view, "decide-policy",
+                    G_CALLBACK (decide_policy_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "permission-request",
+                    G_CALLBACK (permission_request_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "load-changed",
+                    G_CALLBACK (load_changed_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "close",
+                    G_CALLBACK (close_web_view_cb),
+                    NULL);
+  g_signal_connect (web_view, "load-failed",
+                    G_CALLBACK (load_failed_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "load-failed-with-tls-errors",
+                    G_CALLBACK (load_failed_with_tls_error_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "insecure-content-detected",
+                    G_CALLBACK (mixed_content_detected_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "notify::zoom-level",
+                    G_CALLBACK (zoom_changed_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "notify::title",
+                    G_CALLBACK (title_changed_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "notify::uri",
+                    G_CALLBACK (uri_changed_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "mouse-target-changed",
+                    G_CALLBACK (mouse_target_changed_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "notify::favicon",
+                    G_CALLBACK (icon_changed_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "script-dialog",
+                    G_CALLBACK (script_dialog_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "authenticate",
+                    G_CALLBACK (authenticate_cb),
+                    NULL);
+
+  g_signal_connect (web_view, "user-message-received",
+                    G_CALLBACK (user_message_received_cb),
+                    NULL);
+
+  g_signal_connect_object (shell, "password-form-focused",
+                           G_CALLBACK (password_form_focused_cb),
+                           web_view, 0);
+
+  g_signal_connect_object (shell, "allow-tls-certificate",
+                           G_CALLBACK (allow_tls_certificate_cb),
+                           web_view, 0);
+
+  g_signal_connect_object (shell, "allow-unsafe-browsing",
+                           G_CALLBACK (allow_unsafe_browsing_cb),
+                           web_view, 0);
+}
+
+static void
+ephy_web_view_class_init (EphyWebViewClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  WebKitWebViewClass *webkit_webview_class = WEBKIT_WEB_VIEW_CLASS (klass);
+
+  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;
+  gobject_class->constructed = ephy_web_view_constructed;
+
+  widget_class->button_press_event = ephy_web_view_button_press_event;
+  widget_class->key_press_event = ephy_web_view_key_press_event;
+
+  webkit_webview_class->run_file_chooser = ephy_web_view_run_file_chooser;
+
+/**
+ * EphyWebView:address:
+ *
+ * View's current address. This is a percent-encoded URI.
+ **/
+  obj_properties[PROP_ADDRESS] =
+    g_param_spec_string ("address",
+                         "Address",
+                         "The view's address",
+                         "",
+                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+/**
+ * EphyWebView:typed-address:
+ *
+ * User typed address for the current view.
+ **/
+  obj_properties[PROP_TYPED_ADDRESS] =
+    g_param_spec_string ("typed-address",
+                         "Typed Address",
+                         "The typed address",
+                         "",
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+/**
+ * EphyWebView:security-level:
+ *
+ * One of #EphySecurityLevel, determining view's current security level.
+ **/
+  obj_properties[PROP_SECURITY] =
+    g_param_spec_enum ("security-level",
+                       "Security Level",
+                       "The view's security level",
+                       EPHY_TYPE_SECURITY_LEVEL,
+                       EPHY_SECURITY_LEVEL_TO_BE_DETERMINED,
+                       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+/**
+ * EphyWebView:document-type:
+ *
+ * Document type determined for the view.
+ **/
+  obj_properties[PROP_DOCUMENT_TYPE] =
+    g_param_spec_enum ("document-type",
+                       "Document Type",
+                       "The view's document type",
+                       EPHY_TYPE_WEB_VIEW_DOCUMENT_TYPE,
+                       EPHY_WEB_VIEW_DOCUMENT_HTML,
+                       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+/**
+ * EphyWebView:navigation:
+ *
+ * View's navigation flags as #EphyWebViewNavigationFlags.
+ **/
+  obj_properties[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_STRINGS);
+
+/**
+ * EphyWebView:status-message:
+ *
+ * Statusbar message corresponding to this view.
+ **/
+  obj_properties[PROP_STATUS_MESSAGE] =
+    g_param_spec_string ("status-message",
+                         "Status Message",
+                         "The view's statusbar message",
+                         NULL,
+                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+/**
+ * EphyWebView:link-message:
+ *
+ * ???
+ **/
+  obj_properties[PROP_LINK_MESSAGE] =
+    g_param_spec_string ("link-message",
+                         "Link Message",
+                         "The view's link message",
+                         NULL,
+                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+/**
+ * EphyWebView:icon:
+ *
+ * View's favicon set by the loaded site.
+ **/
+  obj_properties[PROP_ICON] =
+    g_param_spec_object ("icon",
+                         "Icon",
+                         "The view icon's",
+                         GDK_TYPE_PIXBUF,
+                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+/**
+ * EphyWebView:is-blank:
+ *
+ * Whether the view is showing the blank address.
+ **/
+  obj_properties[PROP_IS_BLANK] =
+    g_param_spec_boolean ("is-blank",
+                          "Is blank",
+                          "If the EphyWebView is blank",
+                          FALSE,
+                          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+/**
+ * EphyWebView:reader-mode:
+ *
+ * Whether the view is in reader mode.
+ **/
+  obj_properties[PROP_READER_MODE] =
+    g_param_spec_boolean ("reader-mode",
+                          "Reader mode",
+                          "If the EphyWebView is in reader mode",
+                          FALSE,
+                          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+/**
+ * EphyWebView:display-address:
+ *
+ * View's current display address.
+ **/
+  obj_properties[PROP_DISPLAY_ADDRESS] =
+    g_param_spec_string ("display-address",
+                         "Display address",
+                         "The view's display address",
+                         "",
+                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (gobject_class, LAST_PROP, obj_properties);
+
+/**
+ * EphyWebView::new-window:
+ * @view: the #EphyWebView that received the signal
+ * @new_view: the newly opened #EphyWebView
+ *
+ * The ::new-window signal is emitted after a new window has been opened by
+ * the view. For example, when a JavaScript popup window is opened.
+ **/
+  g_signal_new ("new-window",
+                EPHY_TYPE_WEB_VIEW,
+                G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
+                0, NULL, NULL, NULL,
+                G_TYPE_NONE,
+                1,
+                GTK_TYPE_WIDGET);
+
+/**
+ * EphyWebView::search-key-press:
+ * @view: the #EphyWebView that received the signal
+ * @event: the #GdkEventKey which triggered this signal
+ *
+ * The ::search-key-press signal is emitted for keypresses which
+ * should be used for find implementations.
+ **/
+  g_signal_new ("search-key-press",
+                EPHY_TYPE_WEB_VIEW,
+                G_SIGNAL_RUN_LAST,
+                0, g_signal_accumulator_true_handled, NULL, NULL,
+                G_TYPE_BOOLEAN,
+                1,
+                GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+
+/**
+ * EphyWebView::download-only-load:
+ * @view: the #EphyWebView that received the signal
+ *
+ * The ::download-only-load signal is emitted when the @view has its main load
+ * replaced by a download, and that is the only reason why the @view has been created.
+ **/
+  g_signal_new ("download-only-load",
+                EPHY_TYPE_WEB_VIEW,
+                G_SIGNAL_RUN_FIRST,
+                0, NULL, NULL, NULL,
+                G_TYPE_NONE,
+                0);
+}
+
+/**
+ * ephy_web_view_new:
+ *
+ * Equivalent to g_object_new() but returns an #GtkWidget so you don't have
+ * to cast it when dealing with most code.
+ *
+ * Return value: the newly created #EphyWebView widget
+ **/
+GtkWidget *
+ephy_web_view_new (void)
+{
+  EphyEmbedShell *shell = ephy_embed_shell_get_default ();
+  WebKitUserContentManager *ucm = webkit_user_content_manager_new ();
+
+  ephy_embed_shell_register_ucm_handler (shell, ucm);
+  ephy_embed_prefs_register_ucm (ucm);
+
+  return g_object_new (EPHY_TYPE_WEB_VIEW,
+                       "web-context", ephy_embed_shell_get_web_context (shell),
+                       "user-content-manager", ucm,
+                       "settings", ephy_embed_prefs_get_settings (),
+                       "is-controlled-by-automation", ephy_embed_shell_get_mode (shell) == 
EPHY_EMBED_SHELL_MODE_AUTOMATION,
+                       NULL);
+}
+
+GtkWidget *
+ephy_web_view_new_with_related_view (WebKitWebView *related_view)
+{
+  EphyEmbedShell *shell = ephy_embed_shell_get_default ();
+  WebKitUserContentManager *ucm = webkit_user_content_manager_new ();
+
+  ephy_embed_shell_register_ucm_handler (shell, ucm);
+  ephy_embed_prefs_register_ucm (ucm);
+
+  return g_object_new (EPHY_TYPE_WEB_VIEW,
+                       "related-view", related_view,
+                       "user-content-manager", ucm,
+                       "settings", ephy_embed_prefs_get_settings (),
+                       NULL);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]