Decouple notification code from content module

This commit is contained in:
Cheng Zhao 2015-12-25 10:16:07 +08:00
parent 6f81d1e29f
commit 5b7c7be804
15 changed files with 316 additions and 139 deletions

View file

@ -5,11 +5,22 @@
#include "browser/platform_notification_service.h"
#include "browser/browser_client.h"
#include "browser/notification.h"
#include "browser/notification_delegate_adapter.h"
#include "browser/notification_presenter.h"
#include "content/public/browser/desktop_notification_delegate.h"
#include "content/public/common/platform_notification_data.h"
namespace brightray {
namespace {
void RemoveNotification(base::WeakPtr<Notification> notification) {
if (notification)
notification->Dismiss();
}
} // namespace
PlatformNotificationService::PlatformNotificationService(
BrowserClient* browser_client)
: browser_client_(browser_client) {
@ -35,12 +46,20 @@ void PlatformNotificationService::DisplayNotification(
content::BrowserContext* browser_context,
const GURL& origin,
const SkBitmap& icon,
const content::PlatformNotificationData& notification_data,
const content::PlatformNotificationData& data,
scoped_ptr<content::DesktopNotificationDelegate> delegate,
base::Closure* cancel_callback) {
auto presenter = browser_client_->GetNotificationPresenter();
if (presenter)
presenter->ShowNotification(notification_data, icon, delegate.Pass(), cancel_callback);
if (!presenter)
return;
scoped_ptr<NotificationDelegateAdapter> adapter(
new NotificationDelegateAdapter(delegate.Pass()));
auto notification = presenter->CreateNotification(adapter.get());
if (notification) {
ignore_result(adapter.release()); // it will release itself automatically.
notification->Show(data.title, data.body, icon);
*cancel_callback = base::Bind(&RemoveNotification, notification);
}
}
void PlatformNotificationService::DisplayPersistentNotification(