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

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

Issue 644643005: Implement a RenderFrame-less path for Web Notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add OWNERS file Created 6 years, 2 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
« no previous file with comments | « content/child/notifications/notification_manager.h ('k') | content/common/platform_notification_messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/notifications/notification_manager.cc
diff --git a/content/child/notifications/notification_manager.cc b/content/child/notifications/notification_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4c18798ac094ce53f8431ab98499592703faaea7
--- /dev/null
+++ b/content/child/notifications/notification_manager.cc
@@ -0,0 +1,135 @@
+// Copyright 2014 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 file.
+
+#include "content/child/notifications/notification_manager.h"
+
+#include "base/lazy_instance.h"
+#include "base/threading/thread_local.h"
+#include "content/child/notifications/notification_dispatcher.h"
+#include "content/child/thread_safe_sender.h"
+#include "content/child/worker_task_runner.h"
+#include "content/common/platform_notification_messages.h"
+#include "content/public/common/show_desktop_notification_params.h"
+#include "third_party/WebKit/public/platform/WebNotificationData.h"
+#include "third_party/WebKit/public/platform/WebNotificationDelegate.h"
+#include "third_party/WebKit/public/platform/WebSerializedOrigin.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+using blink::WebNotificationPermission;
+
+namespace content {
+namespace {
+
+int CurrentWorkerId() {
+ return WorkerTaskRunner::Instance()->CurrentWorkerId();
+}
+
+} // namespace
+
+static base::LazyInstance<base::ThreadLocalPointer<NotificationManager>>::Leaky
+ g_notification_manager_tls = LAZY_INSTANCE_INITIALIZER;
+
+NotificationManager::NotificationManager(
+ ThreadSafeSender* thread_safe_sender,
+ NotificationDispatcher* notification_dispatcher)
+ : thread_safe_sender_(thread_safe_sender),
+ notification_dispatcher_(notification_dispatcher) {
+ g_notification_manager_tls.Pointer()->Set(this);
+}
+
+NotificationManager::~NotificationManager() {
+ g_notification_manager_tls.Pointer()->Set(nullptr);
+}
+
+NotificationManager* NotificationManager::ThreadSpecificInstance(
+ ThreadSafeSender* thread_safe_sender,
+ NotificationDispatcher* notification_dispatcher) {
+ if (g_notification_manager_tls.Pointer()->Get())
+ return g_notification_manager_tls.Pointer()->Get();
+
+ NotificationManager* manager = new NotificationManager(
+ thread_safe_sender, notification_dispatcher);
+ if (WorkerTaskRunner::Instance()->CurrentWorkerId())
+ WorkerTaskRunner::Instance()->AddStopObserver(manager);
+ return manager;
+}
+
+void NotificationManager::OnWorkerRunLoopStopped() {
+ delete this;
+}
+
+void NotificationManager::show(
+ const blink::WebSerializedOrigin& origin,
+ const blink::WebNotificationData& notification_data,
+ blink::WebNotificationDelegate* delegate) {
+ int notification_id =
+ notification_dispatcher_->GenerateNotificationId(CurrentWorkerId());
+
+ active_notifications_[notification_id] = delegate;
+
+ ShowDesktopNotificationHostMsgParams params;
+ params.origin = GURL(origin.string());
+
+ // TODO(peter): Move the notification_icon_loader to //content/child/ and use
+ // it to download Notification icons here.
+ params.icon = SkBitmap();
+ params.title = notification_data.title;
+ params.body = notification_data.body;
+
+ // TODO(peter): Remove the usage of the Blink WebTextDirection enumeration for
+ // the text direction of notifications throughout Chrome.
+ params.direction = blink::WebTextDirectionLeftToRight;
+ params.replace_id = notification_data.tag;
+
+ thread_safe_sender_->Send(new PlatformNotificationHostMsg_Show(
+ notification_id, params));
+}
+
+void NotificationManager::close(blink::WebNotificationDelegate* delegate) {
+ auto iter = active_notifications_.begin();
+ for (; iter != active_notifications_.end(); ++iter) {
+ if (iter->second != delegate)
+ continue;
+
+ thread_safe_sender_->Send(
+ new PlatformNotificationHostMsg_Close(iter->first));
+ active_notifications_.erase(iter);
+
+ delegate->dispatchCloseEvent();
+ return;
+ }
+
+ // It should not be possible for Blink to call close() on a Notification which
+ // does not exist anymore in the manager.
+ NOTREACHED();
+}
+
+void NotificationManager::notifyDelegateDestroyed(
+ blink::WebNotificationDelegate* delegate) {
+ auto iter = active_notifications_.begin();
+ for (; iter != active_notifications_.end(); ++iter) {
+ if (iter->second != delegate)
+ continue;
+
+ active_notifications_.erase(iter);
+ return;
+ }
+}
+
+WebNotificationPermission NotificationManager::checkPermission(
+ const blink::WebSerializedOrigin& origin) {
+ WebNotificationPermission permission =
+ blink::WebNotificationPermissionAllowed;
+ thread_safe_sender_->Send(new PlatformNotificationHostMsg_CheckPermission(
+ GURL(origin.string()), &permission));
+
+ return permission;
+}
+
+bool NotificationManager::OnMessageReceived(const IPC::Message& message) {
+ // TODO(peter): Implement the message handlers for browser -> renderer events.
+ return false;
+}
+
+} // namespace content
« no previous file with comments | « content/child/notifications/notification_manager.h ('k') | content/common/platform_notification_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698