[epiphany/mcatanzaro/web-view-signals: 1/2] web-view: rearrange
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/mcatanzaro/web-view-signals: 1/2] web-view: rearrange
- Date: Tue, 17 Dec 2019 23:09:08 +0000 (UTC)
commit 9dffceb4aa62267f2613297b229a7bb041e9f94b
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 | 1120 ++++++++++++++++++++++++-------------------------
1 file changed, 560 insertions(+), 560 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index f2e705ead..977a45eaf 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -896,69 +896,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->history_service_cancellable) {
- g_cancellable_cancel (view->history_service_cancellable);
- g_clear_object (&view->history_service_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);
-
- ephy_web_view_popups_manager_reset (view);
-
- 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)
@@ -1156,341 +1093,94 @@ style_updated_cb (EphyWebView *web_view,
}
static void
-ephy_web_view_constructed (GObject *object)
+new_window_cb (EphyWebView *view,
+ EphyWebView *new_view,
+ gpointer user_data)
{
- EphyWebView *web_view = EPHY_WEB_VIEW (object);
-
- G_OBJECT_CLASS (ephy_web_view_parent_class)->constructed (object);
+ EphyEmbedContainer *container;
- g_signal_emit_by_name (ephy_embed_shell_get_default (), "web-view-created", web_view);
+ g_assert (new_view != NULL);
- 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);
+ container = EPHY_EMBED_CONTAINER (gtk_widget_get_toplevel (GTK_WIDGET (new_view)));
+ g_assert (container != NULL || !gtk_widget_is_toplevel (GTK_WIDGET (container)));
- g_signal_connect (web_view, "style-updated",
- G_CALLBACK (style_updated_cb), NULL);
- style_updated_cb (web_view, NULL);
+ popups_manager_add_window (view, container);
}
-static void
-ephy_web_view_class_init (EphyWebViewClass *klass)
+static gboolean
+decide_policy_cb (WebKitWebView *web_view,
+ WebKitPolicyDecision *decision,
+ WebKitPolicyDecisionType decision_type,
+ gpointer user_data)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- WebKitWebViewClass *webkit_webview_class = WEBKIT_WEB_VIEW_CLASS (klass);
+ WebKitResponsePolicyDecision *response_decision;
+ WebKitURIResponse *response;
+ WebKitURIRequest *request;
+ WebKitWebResource *main_resource;
+ EphyWebViewDocumentType type;
+ const char *mime_type;
+ const char *request_uri;
- 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;
+ if (decision_type != WEBKIT_POLICY_DECISION_TYPE_RESPONSE)
+ return FALSE;
- widget_class->button_press_event = ephy_web_view_button_press_event;
- widget_class->key_press_event = ephy_web_view_key_press_event;
+ 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);
- webkit_webview_class->run_file_chooser = ephy_web_view_run_file_chooser;
+ /* 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;
-/**
- * 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 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;
-/**
- * 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);
+ 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;
-/**
- * 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);
+ /* 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;
-/**
- * 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);
+ g_object_notify_by_pspec (G_OBJECT (web_view), obj_properties[PROP_DOCUMENT_TYPE]);
+ }
-/**
- * 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);
+ webkit_policy_decision_download (decision);
-/**
- * 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);
+ return TRUE;
+}
-/**
- * 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);
+typedef struct {
+ EphyWebView *web_view;
+ WebKitPermissionRequest *request;
+ char *origin;
+} PermissionRequestData;
-/**
- * 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:hidden-popup-count:
- *
- * Number of hidden (blocked) popup windows.
- **/
- obj_properties[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_STRINGS);
-
-/**
- * EphyWebView:popups-allowed:
- *
- * If popup windows from this view are to be displayed.
- **/
- obj_properties[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_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 void
-new_window_cb (EphyWebView *view,
- EphyWebView *new_view,
- gpointer user_data)
-{
- EphyEmbedContainer *container;
-
- g_assert (new_view != NULL);
-
- container = EPHY_EMBED_CONTAINER (gtk_widget_get_toplevel (GTK_WIDGET (new_view)));
- g_assert (container != NULL || !gtk_widget_is_toplevel (GTK_WIDGET (container)));
-
- popups_manager_add_window (view, container);
-}
-
-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 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)
@@ -3067,195 +2757,53 @@ user_message_received_cb (WebKitWebView *web_view,
return FALSE;
}
-static void
-ephy_web_view_init (EphyWebView *web_view)
+/**
+ * ephy_web_view_load_request:
+ * @view: the #EphyWebView in which to load the request
+ * @request: the #WebKitNetworkRequest to be loaded
+ *
+ * Loads the given #WebKitNetworkRequest in the given #EphyWebView.
+ **/
+void
+ephy_web_view_load_request (EphyWebView *view,
+ WebKitURIRequest *request)
{
- EphyEmbedShell *shell;
+ const char *url;
+ char *effective_url;
- shell = ephy_embed_shell_get_default ();
+ g_assert (EPHY_IS_WEB_VIEW (view));
+ g_assert (WEBKIT_IS_URI_REQUEST (request));
- 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;
+ url = webkit_uri_request_get_uri (request);
+ effective_url = ephy_embed_utils_normalize_address (url);
- web_view->file_monitor = ephy_file_monitor_new (web_view);
+ webkit_uri_request_set_uri (request, effective_url);
+ g_free (effective_url);
- web_view->history_service = ephy_embed_shell_get_global_history_service (shell);
- web_view->history_service_cancellable = g_cancellable_new ();
+ webkit_web_view_load_request (WEBKIT_WEB_VIEW (view), request);
+}
- g_signal_connect_object (EPHY_SETTINGS_READER, "changed::" EPHY_PREFS_READER_FONT_STYLE,
- G_CALLBACK (reader_setting_changed_cb),
- web_view, 0);
+/**
+ * ephy_web_view_load_url:
+ * @view: an #EphyWebView
+ * @url: a URL
+ *
+ * Loads @url in @view.
+ **/
+void
+ephy_web_view_load_url (EphyWebView *view,
+ const char *url)
+{
+ char *effective_url;
- g_signal_connect_object (EPHY_SETTINGS_READER, "changed::" EPHY_PREFS_READER_COLOR_SCHEME,
- G_CALLBACK (reader_setting_changed_cb),
- web_view, 0);
+ g_assert (EPHY_IS_WEB_VIEW (view));
+ g_assert (url);
- g_signal_connect (web_view, "decide-policy",
- G_CALLBACK (decide_policy_cb),
- NULL);
+ view->reader_active = FALSE;
- 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, "new-window",
- G_CALLBACK (new_window_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
- * @request: the #WebKitNetworkRequest to be loaded
- *
- * Loads the given #WebKitNetworkRequest in the given #EphyWebView.
- **/
-void
-ephy_web_view_load_request (EphyWebView *view,
- WebKitURIRequest *request)
-{
- const char *url;
- char *effective_url;
-
- g_assert (EPHY_IS_WEB_VIEW (view));
- g_assert (WEBKIT_IS_URI_REQUEST (request));
-
- url = webkit_uri_request_get_uri (request);
- effective_url = ephy_embed_utils_normalize_address (url);
-
- webkit_uri_request_set_uri (request, effective_url);
- g_free (effective_url);
-
- webkit_web_view_load_request (WEBKIT_WEB_VIEW (view), request);
-}
-
-/**
- * ephy_web_view_load_url:
- * @view: an #EphyWebView
- * @url: a URL
- *
- * Loads @url in @view.
- **/
-void
-ephy_web_view_load_url (EphyWebView *view,
- const char *url)
-{
- char *effective_url;
-
- g_assert (EPHY_IS_WEB_VIEW (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;
+ effective_url = ephy_embed_utils_normalize_address (url);
+ if (g_str_has_prefix (effective_url, "javascript:")) {
+ char *decoded_url;
decoded_url = soup_uri_decode (effective_url);
webkit_web_view_run_javascript (WEBKIT_WEB_VIEW (view), decoded_url, NULL, NULL, NULL);
@@ -4142,3 +3690,455 @@ 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->history_service_cancellable) {
+ g_cancellable_cancel (view->history_service_cancellable);
+ g_clear_object (&view->history_service_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);
+
+ ephy_web_view_popups_manager_reset (view);
+
+ 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->history_service_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, "new-window",
+ G_CALLBACK (new_window_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:hidden-popup-count:
+ *
+ * Number of hidden (blocked) popup windows.
+ **/
+ obj_properties[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_STRINGS);
+
+/**
+ * EphyWebView:popups-allowed:
+ *
+ * If popup windows from this view are to be displayed.
+ **/
+ obj_properties[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_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]