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

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

Issue 1094553002: Revert "Speculative revert by sheriff" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 96963df004cd40ad0f91db3c73f58006809e871b..b442bafb2eaa8b2ee3aedb14a587c05cbce6247c 100644
--- a/content/child/notifications/notification_manager.cc
+++ b/content/child/notifications/notification_manager.cc
@@ -4,7 +4,10 @@
#include "content/child/notifications/notification_manager.h"
+#include <cmath>
+
#include "base/lazy_instance.h"
+#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/thread_task_runner_handle.h"
@@ -95,6 +98,24 @@ void NotificationManager::showPersistent(
service_worker_registration)->registration_id();
scoped_ptr<blink::WebNotificationShowCallbacks> owned_callbacks(callbacks);
+
+ // Verify that the author-provided payload size does not exceed our limit.
+ // This is an implementation-defined limit to prevent abuse of notification
+ // data as a storage mechanism. A UMA histogram records the requested sizes,
+ // which enables us to track how much data authors are attempting to store.
+ //
+ // If the size exceeds this limit, reject the showNotification() promise. This
+ // is outside of the boundaries set by the specification, but it gives authors
+ // an indication that something has gone wrong.
+ size_t author_data_size = notification_data.data.size();
+ UMA_HISTOGRAM_MEMORY_KB("Notifications.AuthorDataSizeKB",
+ static_cast<int>(ceil(author_data_size / 1024.0)));
+
+ if (author_data_size > PlatformNotificationData::kMaximumDeveloperDataSize) {
+ owned_callbacks->onError();
+ return;
+ }
+
if (notification_data.icon.isEmpty()) {
DisplayPersistentNotification(origin,
notification_data,
« no previous file with comments | « content/child/notifications/notification_data_conversions_unittest.cc ('k') | content/common/platform_notification_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698