Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(866)

Unified Diff: content/child/notifications/notification_manager.cc

Issue 1620203004: Notification action icons prototype. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make it work on Android and clean up. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/child/notifications/notification_manager.cc
diff --git a/content/child/notifications/notification_manager.cc b/content/child/notifications/notification_manager.cc
index f7b839c18b1939036235bef14612270e1c006014..436c92e2fa1d0a878d55ccbf61e3d0cff8112429 100644
--- a/content/child/notifications/notification_manager.cc
+++ b/content/child/notifications/notification_manager.cc
@@ -17,11 +17,11 @@
#include "content/child/service_worker/web_service_worker_registration_impl.h"
#include "content/child/thread_safe_sender.h"
#include "content/common/notification_constants.h"
+#include "content/public/common/notification_resources.h"
#include "content/public/common/platform_notification_data.h"
#include "third_party/WebKit/public/platform/URLConversion.h"
#include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
#include "third_party/WebKit/public/platform/modules/notifications/WebNotificationDelegate.h"
-#include "third_party/skia/include/core/SkBitmap.h"
using blink::WebNotificationPermission;
@@ -32,6 +32,18 @@ int CurrentWorkerId() {
return WorkerThread::GetCurrentId();
}
+// Checks whether |notification_data| specifies any non-empty resources that
+// need to be fetched.
+bool hasResourcesToFetch(const blink::WebNotificationData& notification_data) {
+ if (!notification_data.icon.isEmpty())
+ return true;
+ for (const auto& action : notification_data.actions) {
+ if (!action.icon.isEmpty())
+ return true;
+ }
+ return false;
+}
+
} // namespace
static base::LazyInstance<base::ThreadLocalPointer<NotificationManager>>::Leaky
@@ -43,7 +55,7 @@ NotificationManager::NotificationManager(
NotificationDispatcher* notification_dispatcher)
: thread_safe_sender_(thread_safe_sender),
notification_dispatcher_(notification_dispatcher),
- pending_notifications_(main_thread_task_runner) {
+ notifications_tracker_(main_thread_task_runner) {
g_notification_manager_tls.Pointer()->Set(this);
}
@@ -73,15 +85,16 @@ void NotificationManager::show(
const blink::WebSecurityOrigin& origin,
const blink::WebNotificationData& notification_data,
blink::WebNotificationDelegate* delegate) {
- if (notification_data.icon.isEmpty()) {
- DisplayPageNotification(origin, notification_data, delegate, SkBitmap());
+ if (!hasResourcesToFetch(notification_data)) {
+ DisplayPageNotification(origin, notification_data, delegate,
+ NotificationResources());
return;
}
- pending_notifications_.FetchPageNotificationResources(
+ notifications_tracker_.FetchNotificationResources(
notification_data, delegate,
base::Bind(&NotificationManager::DisplayPageNotification,
- base::Unretained(this), // this owns |pending_notifications_|
+ base::Unretained(this), // this owns |notifications_tracker_|
origin, notification_data, delegate));
}
@@ -115,17 +128,22 @@ void NotificationManager::showPersistent(
return;
}
- if (notification_data.icon.isEmpty()) {
- DisplayPersistentNotification(origin, notification_data,
- service_worker_registration_id,
- std::move(owned_callbacks), SkBitmap());
+ if (!hasResourcesToFetch(notification_data)) {
+ NotificationResources notification_resources;
+ if (!notification_data.actions.isEmpty()) {
+ notification_resources.action_icons.resize(
+ notification_data.actions.size());
+ }
+ DisplayPersistentNotification(
+ origin, notification_data, service_worker_registration_id,
+ std::move(owned_callbacks), notification_resources);
return;
}
- pending_notifications_.FetchPersistentNotificationResources(
- notification_data,
+ notifications_tracker_.FetchNotificationResources(
+ notification_data, nullptr /* delegate */,
base::Bind(&NotificationManager::DisplayPersistentNotification,
- base::Unretained(this), // this owns |pending_notifications_|
+ base::Unretained(this), // this owns |notifications_tracker_|
origin, notification_data, service_worker_registration_id,
base::Passed(&owned_callbacks)));
}
@@ -158,7 +176,7 @@ void NotificationManager::getNotifications(
}
void NotificationManager::close(blink::WebNotificationDelegate* delegate) {
- if (pending_notifications_.CancelPageNotificationFetches(delegate))
+ if (notifications_tracker_.CancelResourceFetches(delegate))
return;
for (auto& iter : active_page_notifications_) {
@@ -188,7 +206,7 @@ void NotificationManager::closePersistent(
void NotificationManager::notifyDelegateDestroyed(
blink::WebNotificationDelegate* delegate) {
- if (pending_notifications_.CancelPageNotificationFetches(delegate))
+ if (notifications_tracker_.CancelResourceFetches(delegate))
return;
for (auto& iter : active_page_notifications_) {
@@ -304,7 +322,10 @@ void NotificationManager::DisplayPageNotification(
const blink::WebSecurityOrigin& origin,
const blink::WebNotificationData& notification_data,
blink::WebNotificationDelegate* delegate,
- const SkBitmap& icon) {
+ const NotificationResources& notification_resources) {
+ DCHECK_EQ(notification_data.actions.size(), 0u);
+ DCHECK_EQ(notification_resources.action_icons.size(), 0u);
+
int notification_id =
notification_dispatcher_->GenerateNotificationId(CurrentWorkerId());
@@ -313,8 +334,8 @@ void NotificationManager::DisplayPageNotification(
// origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See
// https://crbug.com/490074 for detail.
thread_safe_sender_->Send(new PlatformNotificationHostMsg_Show(
- notification_id, blink::WebStringToGURL(origin.toString()), icon,
- ToPlatformNotificationData(notification_data)));
+ notification_id, blink::WebStringToGURL(origin.toString()),
+ ToPlatformNotificationData(notification_data), notification_resources));
}
void NotificationManager::DisplayPersistentNotification(
@@ -322,7 +343,10 @@ void NotificationManager::DisplayPersistentNotification(
const blink::WebNotificationData& notification_data,
int64_t service_worker_registration_id,
scoped_ptr<blink::WebNotificationShowCallbacks> callbacks,
- const SkBitmap& icon) {
+ const NotificationResources& notification_resources) {
+ DCHECK_EQ(notification_data.actions.size(),
+ notification_resources.action_icons.size());
+
// TODO(peter): GenerateNotificationId is more of a request id. Consider
// renaming the method in the NotificationDispatcher if this makes sense.
int request_id =
@@ -336,8 +360,8 @@ void NotificationManager::DisplayPersistentNotification(
// https://crbug.com/490074 for detail.
thread_safe_sender_->Send(new PlatformNotificationHostMsg_ShowPersistent(
request_id, service_worker_registration_id,
- blink::WebStringToGURL(origin.toString()), icon,
- ToPlatformNotificationData(notification_data)));
+ blink::WebStringToGURL(origin.toString()),
+ ToPlatformNotificationData(notification_data), notification_resources));
}
} // namespace content
« no previous file with comments | « content/child/notifications/notification_manager.h ('k') | content/child/notifications/pending_notification.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698