Commit 85d7edfc authored by Tomas Popela's avatar Tomas Popela

Fix various leaks of WebKit DOM objects

Specifically WebKitDOMDOMWindow, WebKitDOMDOMSelection, WebKitDOMRange and
WebKitDOMCSSStyleDeclaration objects
parent 8a0a6940
......@@ -538,25 +538,32 @@ action_cut_cb (GtkAction *action,
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
dom_window = webkit_dom_document_get_default_view (document);
dom_selection = webkit_dom_dom_window_get_selection (dom_window);
g_object_unref (dom_window);
if (!webkit_dom_dom_selection_get_range_count (dom_selection))
if (!webkit_dom_dom_selection_get_range_count (dom_selection)) {
g_object_unref (dom_selection);
return;
}
selection = e_html_editor_view_get_selection (view);
ev = g_new0 (EHTMLEditorViewHistoryEvent, 1);
ev->type = HISTORY_DELETE;
range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
e_html_editor_selection_get_selection_coordinates (
selection, &ev->before.start.x, &ev->before.start.y, &ev->before.end.x, &ev->before.end.y);
range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
if (webkit_dom_range_get_collapsed (range, NULL))
if (webkit_dom_range_get_collapsed (range, NULL)) {
g_object_unref (range);
g_object_unref (dom_selection);
return;
}
/* Save the fragment. */
fragment = webkit_dom_range_clone_contents (range, NULL);
g_object_unref (range);
g_object_unref (dom_selection);
ev->data.fragment = g_object_ref (fragment);
webkit_web_view_cut_clipboard (WEBKIT_WEB_VIEW (view));
......
......@@ -106,7 +106,7 @@ html_editor_link_dialog_ok (EHTMLEditorLinkDialog *dialog)
EHTMLEditorView *view;
EHTMLEditorSelection *selection;
WebKitDOMDocument *document;
WebKitDOMDOMWindow *window;
WebKitDOMDOMWindow *dom_window;
WebKitDOMDOMSelection *dom_selection;
WebKitDOMRange *range;
WebKitDOMElement *link;
......@@ -116,12 +116,14 @@ html_editor_link_dialog_ok (EHTMLEditorLinkDialog *dialog)
selection = e_html_editor_view_get_selection (view);
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
window = webkit_dom_document_get_default_view (document);
dom_selection = webkit_dom_dom_window_get_selection (window);
dom_window = webkit_dom_document_get_default_view (document);
dom_selection = webkit_dom_dom_window_get_selection (dom_window);
g_object_unref (dom_window);
if (!dom_selection ||
(webkit_dom_dom_selection_get_range_count (dom_selection) == 0)) {
gtk_widget_hide (GTK_WIDGET (dialog));
g_object_unref (dom_selection);
return;
}
......@@ -198,6 +200,8 @@ html_editor_link_dialog_ok (EHTMLEditorLinkDialog *dialog)
g_free (text);
}
g_object_unref (range);
g_object_unref (dom_selection);
gtk_widget_hide (GTK_WIDGET (dialog));
}
......@@ -222,7 +226,7 @@ html_editor_link_dialog_show (GtkWidget *widget)
EHTMLEditorView *view;
EHTMLEditorLinkDialog *dialog;
WebKitDOMDocument *document;
WebKitDOMDOMWindow *window;
WebKitDOMDOMWindow *dom_window;
WebKitDOMDOMSelection *dom_selection;
WebKitDOMRange *range;
WebKitDOMElement *link;
......@@ -232,8 +236,9 @@ html_editor_link_dialog_show (GtkWidget *widget)
view = e_html_editor_get_view (editor);
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
window = webkit_dom_document_get_default_view (document);
dom_selection = webkit_dom_dom_window_get_selection (window);
dom_window = webkit_dom_document_get_default_view (document);
dom_selection = webkit_dom_dom_window_get_selection (dom_window);
g_object_unref (dom_window);
/* Reset to default values */
gtk_entry_set_text (GTK_ENTRY (dialog->priv->url_edit), "http://");
......@@ -305,7 +310,9 @@ html_editor_link_dialog_show (GtkWidget *widget)
g_free (text);
}
g_object_unref (range);
chainup:
g_object_unref (dom_selection);
/* Chain up to parent implementation */
GTK_WIDGET_CLASS (e_html_editor_link_dialog_parent_class)->show (widget);
}
......
This diff is collapsed.
......@@ -180,6 +180,7 @@ html_editor_spell_check_dialog_next (EHTMLEditorSpellCheckDialog *dialog)
range = webkit_dom_dom_selection_get_range_at (
dialog->priv->selection, 0, NULL);
word = webkit_dom_range_get_text (range);
g_object_unref (range);
checker = WEBKIT_SPELL_CHECKER (webkit_get_text_checker ());
webkit_spell_checker_check_spelling_of_string (
......@@ -277,6 +278,7 @@ html_editor_spell_check_dialog_prev (EHTMLEditorSpellCheckDialog *dialog)
range = webkit_dom_dom_selection_get_range_at (
dialog->priv->selection, 0, NULL);
word = webkit_dom_range_get_text (range);
g_object_unref (range);
checker = WEBKIT_SPELL_CHECKER (webkit_get_text_checker ());
webkit_spell_checker_check_spelling_of_string (
......@@ -419,7 +421,7 @@ html_editor_spell_check_dialog_show (GtkWidget *widget)
EHTMLEditorView *view;
EHTMLEditorSpellCheckDialog *dialog;
WebKitDOMDocument *document;
WebKitDOMDOMWindow *window;
WebKitDOMDOMWindow *dom_window;
dialog = E_HTML_EDITOR_SPELL_CHECK_DIALOG (widget);
......@@ -430,8 +432,9 @@ html_editor_spell_check_dialog_show (GtkWidget *widget)
view = e_html_editor_get_view (editor);
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
window = webkit_dom_document_get_default_view (document);
dialog->priv->selection = webkit_dom_dom_window_get_selection (window);
dom_window = webkit_dom_document_get_default_view (document);
dialog->priv->selection = webkit_dom_dom_window_get_selection (dom_window);
g_object_unref (dom_window);
/* Select the first word or quit */
if (html_editor_spell_check_dialog_next (dialog)) {
......@@ -447,6 +450,7 @@ html_editor_spell_check_dialog_finalize (GObject *object)
priv = E_HTML_EDITOR_SPELL_CHECK_DIALOG_GET_PRIVATE (object);
g_clear_object (&priv->selection);
g_free (priv->word);
/* Chain up to parent's finalize() method. */
......
......@@ -632,23 +632,25 @@ html_editor_table_dialog_show (GtkWidget *widget)
EHTMLEditor *editor;
EHTMLEditorView *view;
WebKitDOMDocument *document;
WebKitDOMDOMWindow *window;
WebKitDOMDOMSelection *selection;
WebKitDOMDOMWindow *dom_window;
WebKitDOMDOMSelection *dom_selection;
dialog = E_HTML_EDITOR_TABLE_DIALOG (widget);
editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
view = e_html_editor_get_view (editor);
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
window = webkit_dom_document_get_default_view (document);
selection = webkit_dom_dom_window_get_selection (window);
if (selection && (webkit_dom_dom_selection_get_range_count (selection) > 0)) {
dom_window = webkit_dom_document_get_default_view (document);
dom_selection = webkit_dom_dom_window_get_selection (dom_window);
g_object_unref (dom_window);
if (dom_selection && (webkit_dom_dom_selection_get_range_count (dom_selection) > 0)) {
WebKitDOMElement *table;
WebKitDOMRange *range;
range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
table = e_html_editor_dom_node_find_parent_element (
webkit_dom_range_get_start_container (range, NULL), "TABLE");
g_object_unref (range);
if (!table) {
dialog->priv->table_element = WEBKIT_DOM_HTML_TABLE_ELEMENT (
......@@ -677,6 +679,8 @@ html_editor_table_dialog_show (GtkWidget *widget)
}
}
g_object_unref (dom_selection);
/* Chain up to parent implementation */
GTK_WIDGET_CLASS (e_html_editor_table_dialog_parent_class)->show (widget);
}
......
This diff is collapsed.
......@@ -2483,21 +2483,22 @@ static gchar *
web_view_get_frame_selection_html (WebKitDOMElement *iframe)
{
WebKitDOMDocument *document;
WebKitDOMDOMWindow *window;
WebKitDOMDOMSelection *selection;
WebKitDOMDOMWindow *dom_window;
WebKitDOMDOMSelection *dom_selection;
WebKitDOMNodeList *frames;
gulong ii, length;
document = webkit_dom_html_iframe_element_get_content_document (
WEBKIT_DOM_HTML_IFRAME_ELEMENT (iframe));
window = webkit_dom_document_get_default_view (document);
selection = webkit_dom_dom_window_get_selection (window);
if (selection && (webkit_dom_dom_selection_get_range_count (selection) > 0)) {
dom_window = webkit_dom_document_get_default_view (document);
dom_selection = webkit_dom_dom_window_get_selection (dom_window);
g_object_unref (dom_window);
if (dom_selection && (webkit_dom_dom_selection_get_range_count (dom_selection) > 0)) {
WebKitDOMRange *range;
WebKitDOMElement *element;
WebKitDOMDocumentFragment *fragment;
range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
if (range != NULL) {
gchar *inner_html;
WebKitDOMNode *node;
......@@ -2520,10 +2521,14 @@ web_view_get_frame_selection_html (WebKitDOMElement *iframe)
g_free (tmp);
}
g_object_unref (range);
g_object_unref (dom_selection);
return inner_html;
}
}
g_object_unref (dom_selection);
frames = webkit_dom_document_get_elements_by_tag_name (
document, "IFRAME");
length = webkit_dom_node_list_get_length (frames);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment