shell/screenshot: Check preconditions of public API

It's good practice to guard public API against programmer errors,
so add the usual g_return*_if_fail() calls.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1123
This commit is contained in:
Florian Müllner 2020-03-24 08:45:12 +01:00 committed by Carlos Garnacho
parent eb51942a05
commit b4162afa65

View File

@ -479,10 +479,15 @@ shell_screenshot_screenshot (ShellScreenshot *screenshot,
gpointer user_data) gpointer user_data)
{ {
ClutterActor *stage; ClutterActor *stage;
ShellScreenshotPrivate *priv = screenshot->priv; ShellScreenshotPrivate *priv;
gboolean use_paint_signal = FALSE; gboolean use_paint_signal = FALSE;
GTask *result; GTask *result;
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
priv = screenshot->priv;
if (priv->stream != NULL) { if (priv->stream != NULL) {
if (callback) if (callback)
g_task_report_new_error (screenshot, g_task_report_new_error (screenshot,
@ -549,6 +554,8 @@ shell_screenshot_screenshot_finish (ShellScreenshot *screenshot,
cairo_rectangle_int_t **area, cairo_rectangle_int_t **area,
GError **error) GError **error)
{ {
g_return_val_if_fail (SHELL_IS_SCREENSHOT (screenshot), FALSE);
g_return_val_if_fail (G_IS_TASK (result), FALSE);
g_return_val_if_fail (g_async_result_is_tagged (result, g_return_val_if_fail (g_async_result_is_tagged (result,
shell_screenshot_screenshot), shell_screenshot_screenshot),
FALSE); FALSE);
@ -582,9 +589,14 @@ shell_screenshot_screenshot_area (ShellScreenshot *screenshot,
gpointer user_data) gpointer user_data)
{ {
ClutterActor *stage; ClutterActor *stage;
ShellScreenshotPrivate *priv = screenshot->priv; ShellScreenshotPrivate *priv;
GTask *result; GTask *result;
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
priv = screenshot->priv;
if (priv->stream != NULL) { if (priv->stream != NULL) {
if (callback) if (callback)
g_task_report_new_error (screenshot, g_task_report_new_error (screenshot,
@ -635,6 +647,8 @@ shell_screenshot_screenshot_area_finish (ShellScreenshot *screenshot,
cairo_rectangle_int_t **area, cairo_rectangle_int_t **area,
GError **error) GError **error)
{ {
g_return_val_if_fail (SHELL_IS_SCREENSHOT (screenshot), FALSE);
g_return_val_if_fail (G_IS_TASK (result), FALSE);
g_return_val_if_fail (g_async_result_is_tagged (result, g_return_val_if_fail (g_async_result_is_tagged (result,
shell_screenshot_screenshot_area), shell_screenshot_screenshot_area),
FALSE); FALSE);
@ -663,12 +677,19 @@ shell_screenshot_screenshot_window (ShellScreenshot *screenshot,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
ShellScreenshotPrivate *priv = screenshot->priv; ShellScreenshotPrivate *priv;
MetaDisplay *display = shell_global_get_display (priv->global); MetaDisplay *display;
ClutterActor *stage; ClutterActor *stage;
MetaWindow *window = meta_display_get_focus_window (display); MetaWindow *window;
GTask *result; GTask *result;
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
priv = screenshot->priv;
display = shell_global_get_display (priv->global);
window = meta_display_get_focus_window (display);
if (priv->stream != NULL || !window) { if (priv->stream != NULL || !window) {
if (callback) if (callback)
g_task_report_new_error (screenshot, g_task_report_new_error (screenshot,
@ -718,6 +739,8 @@ shell_screenshot_screenshot_window_finish (ShellScreenshot *screenshot,
cairo_rectangle_int_t **area, cairo_rectangle_int_t **area,
GError **error) GError **error)
{ {
g_return_val_if_fail (SHELL_IS_SCREENSHOT (screenshot), FALSE);
g_return_val_if_fail (G_IS_TASK (result), FALSE);
g_return_val_if_fail (g_async_result_is_tagged (result, g_return_val_if_fail (g_async_result_is_tagged (result,
shell_screenshot_screenshot_window), shell_screenshot_screenshot_window),
FALSE); FALSE);
@ -742,19 +765,24 @@ shell_screenshot_pick_color (ShellScreenshot *screenshot,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
ShellScreenshotPrivate *priv = screenshot->priv; ShellScreenshotPrivate *priv;
MetaDisplay *display = shell_global_get_display (priv->global); MetaDisplay *display;
ClutterActor *stage; ClutterActor *stage;
GTask *result; GTask *result;
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
result = g_task_new (screenshot, NULL, callback, user_data); result = g_task_new (screenshot, NULL, callback, user_data);
g_task_set_source_tag (result, shell_screenshot_pick_color); g_task_set_source_tag (result, shell_screenshot_pick_color);
priv = screenshot->priv;
priv->screenshot_area.x = x; priv->screenshot_area.x = x;
priv->screenshot_area.y = y; priv->screenshot_area.y = y;
priv->screenshot_area.width = 1; priv->screenshot_area.width = 1;
priv->screenshot_area.height = 1; priv->screenshot_area.height = 1;
display = shell_global_get_display (priv->global);
stage = CLUTTER_ACTOR (shell_global_get_stage (priv->global)); stage = CLUTTER_ACTOR (shell_global_get_stage (priv->global));
meta_disable_unredirect_for_display (display); meta_disable_unredirect_for_display (display);
@ -795,8 +823,11 @@ shell_screenshot_pick_color_finish (ShellScreenshot *screenshot,
ClutterColor *color, ClutterColor *color,
GError **error) GError **error)
{ {
ShellScreenshotPrivate *priv = screenshot->priv; ShellScreenshotPrivate *priv;
g_return_val_if_fail (SHELL_IS_SCREENSHOT (screenshot), FALSE);
g_return_val_if_fail (G_IS_TASK (result), FALSE);
g_return_val_if_fail (color != NULL, FALSE);
g_return_val_if_fail (g_async_result_is_tagged (result, g_return_val_if_fail (g_async_result_is_tagged (result,
shell_screenshot_pick_color), shell_screenshot_pick_color),
FALSE); FALSE);
@ -804,6 +835,8 @@ shell_screenshot_pick_color_finish (ShellScreenshot *screenshot,
if (!g_task_propagate_boolean (G_TASK (result), error)) if (!g_task_propagate_boolean (G_TASK (result), error))
return FALSE; return FALSE;
priv = screenshot->priv;
/* protect against mutter changing the format used for stage captures */ /* protect against mutter changing the format used for stage captures */
g_assert (cairo_image_surface_get_format (priv->image) == CAIRO_FORMAT_ARGB32); g_assert (cairo_image_surface_get_format (priv->image) == CAIRO_FORMAT_ARGB32);