electron/brightray/browser/win/notification_presenter_win.cc

55 lines
1.6 KiB
C++
Raw Normal View History

// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2015 Felix Rieseberg <feriese@microsoft.com> and Jason Poon <jason.poon@microsoft.com>. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-CHROMIUM file.
#include "browser/win/notification_presenter_win.h"
2015-11-10 12:07:12 +00:00
#include "base/win/windows_version.h"
2015-11-10 12:07:12 +00:00
#include "browser/win/windows_toast_notification.h"
#include "common/application_info.h"
#include "content/public/browser/desktop_notification_delegate.h"
#include "content/public/common/platform_notification_data.h"
#include "third_party/skia/include/core/SkBitmap.h"
#pragma comment(lib, "runtimeobject.lib")
namespace brightray {
2015-11-10 12:23:08 +00:00
namespace {
void RemoveNotification(base::WeakPtr<WindowsToastNotification> notification) {
if (notification)
notification->DismissNotification();
}
} // namespace
// static
NotificationPresenter* NotificationPresenter::Create() {
return new NotificationPresenterWin;
}
NotificationPresenterWin::NotificationPresenterWin() {
}
NotificationPresenterWin::~NotificationPresenterWin() {
}
void NotificationPresenterWin::ShowNotification(
const content::PlatformNotificationData& data,
const SkBitmap& icon,
2015-11-10 11:50:38 +00:00
scoped_ptr<content::DesktopNotificationDelegate> delegate,
base::Closure* cancel_callback) {
2015-11-10 12:23:08 +00:00
// This class manages itself.
2015-11-20 05:28:37 +00:00
auto notification = new WindowsToastNotification(delegate.Pass());
2015-11-10 12:23:08 +00:00
notification->ShowNotification(data.title, data.body, data.icon.spec());
if (cancel_callback) {
*cancel_callback = base::Bind(
2015-11-10 12:23:08 +00:00
&RemoveNotification, notification->GetWeakPtr());
}
}
} // namespace brightray