Don't crash on accesses to stale window-backed apps

The JS code could still be holding on to a reference to a window-backed app
after all windows have vanished. (For example, the dash queues an idle to
refetch apps and display them.) Avoid dying with an error message if we
attempt to activate or otherwise manipulate such a window.

https://bugzilla.gnome.org/show_bug.cgi?id=674799
This commit is contained in:
Owen W. Taylor 2015-10-07 22:56:11 -04:00
parent d57c146514
commit db297e7fdb

View File

@ -156,16 +156,20 @@ static MetaWindow *
window_backed_app_get_window (ShellApp *app)
{
g_assert (app->info == NULL);
g_assert (app->running_state);
g_assert (app->running_state->windows);
return app->running_state->windows->data;
if (app->running_state)
{
g_assert (app->running_state->windows);
return app->running_state->windows->data;
}
else
return NULL;
}
static ClutterActor *
window_backed_app_get_icon (ShellApp *app,
int size)
{
MetaWindow *window;
MetaWindow *window = NULL;
ClutterActor *actor;
gint scale;
ShellGlobal *global;
@ -181,14 +185,16 @@ window_backed_app_get_icon (ShellApp *app,
* window-backend apps, it's possible we get a request for the icon.
* Avoid asserting here and just return an empty image.
*/
if (app->running_state == NULL)
if (app->running_state != NULL)
window = window_backed_app_get_window (app);
if (window == NULL)
{
actor = clutter_texture_new ();
g_object_set (actor, "opacity", 0, "width", (float) size, "height", (float) size, NULL);
return actor;
}
window = window_backed_app_get_window (app);
actor = st_texture_cache_bind_cairo_surface_property (st_texture_cache_get_default (),
G_OBJECT (window),
"icon");
@ -232,9 +238,10 @@ shell_app_get_name (ShellApp *app)
else
{
MetaWindow *window = window_backed_app_get_window (app);
const char *name;
const char *name = NULL;
name = meta_window_get_wm_class (window);
if (window)
name = meta_window_get_wm_class (window);
if (!name)
name = C_("program", "Unknown");
return name;
@ -1154,7 +1161,13 @@ shell_app_launch (ShellApp *app,
if (app->info == NULL)
{
MetaWindow *window = window_backed_app_get_window (app);
meta_window_activate (window, timestamp);
/* We don't use an error return if there no longer any windows, because the
* user attempting to activate a stale window backed app isn't something
* we would expect the caller to meaningfully handle or display an error
* message to the user.
*/
if (window)
meta_window_activate (window, timestamp);
return TRUE;
}