/pidgin/main: acd0d7217593: Prevent crashing and stuff.

Elliott Sales de Andrade qulogic at pidgin.im
Tue Jul 24 04:03:42 EDT 2012


Changeset: acd0d7217593b2d7718d2b3b7461a414a3771f8a
Author:	 Elliott Sales de Andrade <qulogic at pidgin.im>
Date:	 2012-07-22 02:55 -0400
Branch:	 default
URL: http://hg.pidgin.im/pidgin/main/rev/acd0d7217593

Description:

Prevent crashing and stuff.

diffstat:

 pidgin/gtkwebview.c |  134 +++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 117 insertions(+), 17 deletions(-)

diffs (truncated from 410 to 300 lines):

diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -513,7 +513,11 @@
 gboolean
 gtk_webview_is_empty(GtkWebView *webview)
 {
-	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	GtkWebViewPriv *priv;
+
+	g_return_val_if_fail(webview != NULL, TRUE);
+
+	priv = GTK_WEBVIEW_GET_PRIVATE(webview);
 	return priv->empty;
 }
 
@@ -550,7 +554,11 @@
 void
 gtk_webview_safe_execute_script(GtkWebView *webview, const char *script)
 {
-	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	GtkWebViewPriv *priv;
+
+	g_return_if_fail(webview != NULL);
+
+	priv = GTK_WEBVIEW_GET_PRIVATE(webview);
 	g_queue_push_tail(priv->js_queue, g_strdup(script));
 	g_idle_add((GSourceFunc)process_js_script_queue, webview);
 }
@@ -558,6 +566,8 @@
 void
 gtk_webview_load_html_string(GtkWebView *webview, const char *html)
 {
+	g_return_if_fail(webview != NULL);
+
 	webkit_web_view_load_string(WEBKIT_WEB_VIEW(webview), html, NULL, NULL,
 	                            "file:///");
 }
@@ -565,6 +575,8 @@
 void
 gtk_webview_load_html_string_with_selection(GtkWebView *webview, const char *html)
 {
+	g_return_if_fail(webview != NULL);
+
 	gtk_webview_load_html_string(webview, html);
 	gtk_webview_safe_execute_script(webview,
 		"var s = window.getSelection();"
@@ -582,9 +594,13 @@
 void
 gtk_webview_append_html(GtkWebView *webview, const char *html)
 {
-	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	GtkWebViewPriv *priv;
 	WebKitDOMDocument *doc;
 	WebKitDOMHTMLElement *body;
+
+	g_return_if_fail(webview != NULL);
+
+	priv = GTK_WEBVIEW_GET_PRIVATE(webview);
 	doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
 	body = webkit_dom_document_get_body(doc);
 	webkit_dom_html_element_insert_adjacent_html(body, "beforeend", html, NULL);
@@ -594,14 +610,22 @@
 void
 gtk_webview_set_vadjustment(GtkWebView *webview, GtkAdjustment *vadj)
 {
-	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	GtkWebViewPriv *priv;
+
+	g_return_if_fail(webview != NULL);
+
+	priv = GTK_WEBVIEW_GET_PRIVATE(webview);
 	priv->vadj = vadj;
 }
 
 void
 gtk_webview_scroll_to_end(GtkWebView *webview, gboolean smooth)
 {
-	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	GtkWebViewPriv *priv;
+
+	g_return_if_fail(webview != NULL);
+
+	priv = GTK_WEBVIEW_GET_PRIVATE(webview);
 	if (priv->scroll_time)
 		g_timer_destroy(priv->scroll_time);
 	if (priv->scroll_src)
@@ -618,10 +642,14 @@
 void
 gtk_webview_page_up(GtkWebView *webview)
 {
-	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
-	GtkAdjustment *vadj = priv->vadj;
+	GtkWebViewPriv *priv;
+	GtkAdjustment *vadj;
 	gdouble scroll_val;
 
+	g_return_if_fail(webview != NULL);
+
+	priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	vadj = priv->vadj;
 #if GTK_CHECK_VERSION(2,14,0)
 	scroll_val = gtk_adjustment_get_value(vadj) - gtk_adjustment_get_page_size(vadj);
 	scroll_val = MAX(scroll_val, gtk_adjustment_get_lower(vadj));
@@ -636,11 +664,15 @@
 void
 gtk_webview_page_down(GtkWebView *webview)
 {
-	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
-	GtkAdjustment *vadj = priv->vadj;
+	GtkWebViewPriv *priv;
+	GtkAdjustment *vadj;
 	gdouble scroll_val;
 	gdouble page_size;
 
+	g_return_if_fail(webview != NULL);
+
+	priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	vadj = priv->vadj;
 #if GTK_CHECK_VERSION(2,14,0)
 	page_size = gtk_adjustment_get_page_size(vadj);
 	scroll_val = gtk_adjustment_get_value(vadj) + page_size;
@@ -657,6 +689,8 @@
 void
 gtk_webview_set_editable(GtkWebView *webview, gboolean editable)
 {
+	g_return_if_fail(webview != NULL);
+
 	webkit_web_view_set_editable(WEBKIT_WEB_VIEW(webview), editable);
 
 	if (editable) {
@@ -674,6 +708,8 @@
 {
 	GtkWebViewButtons buttons;
 
+	g_return_if_fail(webview != NULL);
+
 	if (flags & PURPLE_CONNECTION_HTML) {
 		gboolean bold, italic, underline, strike;
 
@@ -750,6 +786,8 @@
 pidgin_webview_set_spellcheck(GtkWebView *webview, gboolean enable)
 {
 	WebKitWebSettings *settings;
+
+	g_return_if_fail(webview != NULL);
 	
 	settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview));
 	g_object_set(G_OBJECT(settings), "enable-spell-checking", enable, NULL);
@@ -759,15 +797,24 @@
 void
 gtk_webview_set_whole_buffer_formatting_only(GtkWebView *webview, gboolean wbfo)
 {
-	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	GtkWebViewPriv *priv;
+
+	g_return_if_fail(webview != NULL);
+
+	priv = GTK_WEBVIEW_GET_PRIVATE(webview);
 	priv->edit.wbfo = wbfo;
 }
 
 void
 gtk_webview_set_format_functions(GtkWebView *webview, GtkWebViewButtons buttons)
 {
-	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
-	GObject *object = g_object_ref(G_OBJECT(webview));
+	GtkWebViewPriv *priv;
+	GObject *object;
+
+	g_return_if_fail(webview != NULL);
+
+	priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	object = g_object_ref(G_OBJECT(webview));
 	priv->format_functions = buttons;
 	g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons);
 	g_object_unref(object);
@@ -780,6 +827,8 @@
 	WebKitDOMHTMLHeadElement *head;
 	gchar *html;
 
+	g_return_val_if_fail(webview != NULL, NULL);
+
 	doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
 	head = webkit_dom_document_get_head(doc);
 	html = webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(head));
@@ -794,6 +843,8 @@
 	WebKitDOMHTMLElement *body;
 	gchar *html;
 
+	g_return_val_if_fail(webview != NULL, NULL);
+
 	doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
 	body = webkit_dom_document_get_body(doc);
 	html = webkit_dom_html_element_get_inner_html(body);
@@ -808,6 +859,8 @@
 	WebKitDOMHTMLElement *body;
 	gchar *text;
 
+	g_return_val_if_fail(webview != NULL, NULL);
+
 	doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
 	body = webkit_dom_document_get_body(doc);
 	text = webkit_dom_html_element_get_inner_text(body);
@@ -823,6 +876,8 @@
 	WebKitDOMDOMSelection *sel;
 	WebKitDOMRange *range;
 
+	g_return_val_if_fail(webview != NULL, NULL);
+
 	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
 	win = webkit_dom_document_get_default_view(dom);
 	sel = webkit_dom_dom_window_get_selection(win);
@@ -834,7 +889,11 @@
 GtkWebViewButtons
 gtk_webview_get_format_functions(GtkWebView *webview)
 {
-	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	GtkWebViewPriv *priv;
+
+	g_return_val_if_fail(webview != NULL, 0);
+
+	priv = GTK_WEBVIEW_GET_PRIVATE(webview);
 	return priv->format_functions;
 }
 
@@ -844,6 +903,9 @@
                                gboolean *strike)
 {
 	WebKitDOMDocument *dom;
+
+	g_return_if_fail(webview != NULL);
+
 	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
 
 	if (bold)
@@ -860,6 +922,9 @@
 gtk_webview_get_current_fontface(GtkWebView *webview)
 {
 	WebKitDOMDocument *dom;
+
+	g_return_val_if_fail(webview != NULL, NULL);
+
 	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
 	return webkit_dom_document_query_command_value(dom, "fontName");
 }
@@ -868,6 +933,9 @@
 gtk_webview_get_current_forecolor(GtkWebView *webview)
 {
 	WebKitDOMDocument *dom;
+
+	g_return_val_if_fail(webview != NULL, NULL);
+
 	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
 	return webkit_dom_document_query_command_value(dom, "foreColor");
 }
@@ -876,6 +944,9 @@
 gtk_webview_get_current_backcolor(GtkWebView *webview)
 {
 	WebKitDOMDocument *dom;
+
+	g_return_val_if_fail(webview != NULL, NULL);
+
 	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
 	return webkit_dom_document_query_command_value(dom, "backColor");
 }
@@ -887,6 +958,8 @@
 	gchar *text;
 	gint size;
 
+	g_return_val_if_fail(webview != NULL, 0);
+
 	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
 	text = webkit_dom_document_query_command_value(dom, "fontSize");
 	size = atoi(text);
@@ -906,6 +979,8 @@
 {
 	GObject *object;
 
+	g_return_if_fail(webview != NULL);
+
 	object = g_object_ref(G_OBJECT(webview));
 	g_signal_emit(object, signals[CLEAR_FORMAT], 0);
 	g_object_unref(object);
@@ -914,30 +989,36 @@
 void
 gtk_webview_toggle_bold(GtkWebView *webview)
 {
+	g_return_if_fail(webview != NULL);
 	emit_format_signal(webview, GTK_WEBVIEW_BOLD);
 }
 
 void
 gtk_webview_toggle_italic(GtkWebView *webview)
 {
+	g_return_if_fail(webview != NULL);
 	emit_format_signal(webview, GTK_WEBVIEW_ITALIC);
 }
 
 void



More information about the Commits mailing list