2015-03-09 02:37:13 +00:00
|
|
|
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE-CHROMIUM file.
|
|
|
|
|
2015-12-24 14:20:47 +00:00
|
|
|
#include "browser/platform_notification_service.h"
|
2015-03-09 02:37:13 +00:00
|
|
|
|
2015-12-24 14:20:47 +00:00
|
|
|
#include "browser/browser_client.h"
|
2015-12-25 02:16:07 +00:00
|
|
|
#include "browser/notification.h"
|
|
|
|
#include "browser/notification_delegate_adapter.h"
|
2015-03-09 02:37:13 +00:00
|
|
|
#include "browser/notification_presenter.h"
|
2015-12-25 02:16:07 +00:00
|
|
|
#include "content/public/common/platform_notification_data.h"
|
2016-04-27 02:52:26 +00:00
|
|
|
#include "content/public/common/notification_resources.h"
|
2016-01-23 13:32:30 +00:00
|
|
|
#include "third_party/skia/include/core/SkBitmap.h"
|
2015-03-09 02:37:13 +00:00
|
|
|
|
|
|
|
namespace brightray {
|
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void RemoveNotification(base::WeakPtr<Notification> notification) {
|
|
|
|
if (notification)
|
|
|
|
notification->Dismiss();
|
|
|
|
}
|
|
|
|
|
2016-01-23 13:32:30 +00:00
|
|
|
void OnWebNotificationAllowed(
|
|
|
|
brightray::BrowserClient* browser_client,
|
|
|
|
const SkBitmap& icon,
|
|
|
|
const content::PlatformNotificationData& data,
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<content::DesktopNotificationDelegate> delegate,
|
2016-01-23 13:32:30 +00:00
|
|
|
base::Closure* cancel_callback,
|
2016-07-02 07:53:48 +00:00
|
|
|
bool audio_muted,
|
2016-01-23 13:32:30 +00:00
|
|
|
bool allowed) {
|
|
|
|
if (!allowed)
|
|
|
|
return;
|
|
|
|
auto presenter = browser_client->GetNotificationPresenter();
|
|
|
|
if (!presenter)
|
|
|
|
return;
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<NotificationDelegateAdapter> adapter(
|
2016-03-08 11:59:29 +00:00
|
|
|
new NotificationDelegateAdapter(std::move(delegate)));
|
2016-01-23 13:32:30 +00:00
|
|
|
auto notification = presenter->CreateNotification(adapter.get());
|
|
|
|
if (notification) {
|
|
|
|
ignore_result(adapter.release()); // it will release itself automatically.
|
2016-07-02 07:53:48 +00:00
|
|
|
notification->Show(data.title, data.body, data.tag, data.icon, icon,
|
|
|
|
audio_muted ? true : data.silent);
|
2016-01-23 13:32:30 +00:00
|
|
|
*cancel_callback = base::Bind(&RemoveNotification, notification);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
} // namespace
|
|
|
|
|
2015-12-24 14:20:47 +00:00
|
|
|
PlatformNotificationService::PlatformNotificationService(
|
|
|
|
BrowserClient* browser_client)
|
2016-01-23 13:32:30 +00:00
|
|
|
: browser_client_(browser_client),
|
2016-01-27 15:18:42 +00:00
|
|
|
render_process_id_(-1) {
|
2015-03-09 02:37:13 +00:00
|
|
|
}
|
|
|
|
|
2015-12-24 14:20:47 +00:00
|
|
|
PlatformNotificationService::~PlatformNotificationService() {}
|
2015-03-09 02:37:13 +00:00
|
|
|
|
2015-12-24 14:20:47 +00:00
|
|
|
blink::WebNotificationPermission PlatformNotificationService::CheckPermissionOnUIThread(
|
2015-04-21 10:54:57 +00:00
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const GURL& origin,
|
|
|
|
int render_process_id) {
|
2016-01-23 13:32:30 +00:00
|
|
|
render_process_id_ = render_process_id;
|
2015-04-21 10:54:57 +00:00
|
|
|
return blink::WebNotificationPermissionAllowed;
|
|
|
|
}
|
|
|
|
|
2015-12-24 14:20:47 +00:00
|
|
|
blink::WebNotificationPermission PlatformNotificationService::CheckPermissionOnIOThread(
|
2015-03-09 02:37:13 +00:00
|
|
|
content::ResourceContext* resource_context,
|
|
|
|
const GURL& origin,
|
|
|
|
int render_process_id) {
|
|
|
|
return blink::WebNotificationPermissionAllowed;
|
|
|
|
}
|
|
|
|
|
2015-12-24 14:20:47 +00:00
|
|
|
void PlatformNotificationService::DisplayNotification(
|
2015-03-09 02:37:13 +00:00
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const GURL& origin,
|
2016-04-27 02:52:26 +00:00
|
|
|
const content::PlatformNotificationData& notification_data,
|
|
|
|
const content::NotificationResources& notification_resources,
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<content::DesktopNotificationDelegate> delegate,
|
2015-03-09 02:37:13 +00:00
|
|
|
base::Closure* cancel_callback) {
|
2016-01-23 13:32:30 +00:00
|
|
|
browser_client_->WebNotificationAllowed(
|
|
|
|
render_process_id_,
|
|
|
|
base::Bind(&OnWebNotificationAllowed,
|
2016-04-27 02:52:26 +00:00
|
|
|
browser_client_,
|
|
|
|
notification_resources.notification_icon,
|
|
|
|
notification_data,
|
2016-01-23 13:32:30 +00:00
|
|
|
base::Passed(&delegate),
|
|
|
|
cancel_callback));
|
2015-03-09 02:37:13 +00:00
|
|
|
}
|
|
|
|
|
2015-12-24 14:20:47 +00:00
|
|
|
void PlatformNotificationService::DisplayPersistentNotification(
|
2015-03-09 02:37:13 +00:00
|
|
|
content::BrowserContext* browser_context,
|
2016-04-27 02:52:26 +00:00
|
|
|
int64_t persistent_notification_id,
|
2015-03-09 02:37:13 +00:00
|
|
|
const GURL& origin,
|
2016-04-27 02:52:26 +00:00
|
|
|
const content::PlatformNotificationData& notification_data,
|
|
|
|
const content::NotificationResources& notification_resources) {
|
2015-03-09 02:37:13 +00:00
|
|
|
}
|
|
|
|
|
2015-12-24 14:20:47 +00:00
|
|
|
void PlatformNotificationService::ClosePersistentNotification(
|
2015-03-09 02:37:13 +00:00
|
|
|
content::BrowserContext* browser_context,
|
2015-07-23 06:53:42 +00:00
|
|
|
int64_t persistent_notification_id) {
|
|
|
|
}
|
|
|
|
|
2015-12-24 14:20:47 +00:00
|
|
|
bool PlatformNotificationService::GetDisplayedPersistentNotifications(
|
2015-07-23 06:53:42 +00:00
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
std::set<std::string>* displayed_notifications) {
|
|
|
|
return false;
|
2015-03-09 02:37:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace brightray
|