Merge pull request #130 from atom/linux-notification

Guard against outside input in Linux notifications
This commit is contained in:
Cheng Zhao 2015-08-04 16:46:53 +08:00
commit 545c62994f

View file

@ -13,6 +13,7 @@
#include "content/public/common/platform_notification_data.h" #include "content/public/common/platform_notification_data.h"
#include "common/application_info.h" #include "common/application_info.h"
#include "dbus/dbus.h" #include "dbus/dbus.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace brightray { namespace brightray {
@ -111,11 +112,12 @@ void NotificationPresenterLinux::ShowNotification(
notification, "default", "View", OnNotificationViewThunk, this, nullptr); notification, "default", "View", OnNotificationViewThunk, this, nullptr);
} }
GdkPixbuf* pixbuf = libgtk2ui::GdkPixbufFromSkBitmap(icon); if (!icon.drawsNothing()) {
GdkPixbuf* pixbuf = libgtk2ui::GdkPixbufFromSkBitmap(icon);
notify_notification_set_image_from_pixbuf(notification, pixbuf); notify_notification_set_image_from_pixbuf(notification, pixbuf);
notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT); notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT);
g_object_unref(pixbuf); g_object_unref(pixbuf);
}
GError* error = nullptr; GError* error = nullptr;
notify_notification_show(notification, &error); notify_notification_show(notification, &error);
@ -151,12 +153,16 @@ void NotificationPresenterLinux::DeleteNotification(NotifyNotification* notifica
} }
void NotificationPresenterLinux::OnNotificationClosed(NotifyNotification* notification) { void NotificationPresenterLinux::OnNotificationClosed(NotifyNotification* notification) {
if (!notification)
return;
GetDelegateFromNotification(notification)->NotificationClosed(); GetDelegateFromNotification(notification)->NotificationClosed();
DeleteNotification(notification); DeleteNotification(notification);
} }
void NotificationPresenterLinux::OnNotificationView( void NotificationPresenterLinux::OnNotificationView(
NotifyNotification* notification, char* action) { NotifyNotification* notification, char* action) {
if (!notification)
return;
GetDelegateFromNotification(notification)->NotificationClick(); GetDelegateFromNotification(notification)->NotificationClick();
DeleteNotification(notification); DeleteNotification(notification);
} }