summaryrefslogtreecommitdiff
path: root/chromium/content/browser/notifications
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/content/browser/notifications')
-rw-r--r--chromium/content/browser/notifications/OWNERS1
-rw-r--r--chromium/content/browser/notifications/notification_message_filter.cc89
-rw-r--r--chromium/content/browser/notifications/notification_message_filter.h58
-rw-r--r--chromium/content/browser/notifications/page_notification_delegate.cc48
-rw-r--r--chromium/content/browser/notifications/page_notification_delegate.h32
5 files changed, 228 insertions, 0 deletions
diff --git a/chromium/content/browser/notifications/OWNERS b/chromium/content/browser/notifications/OWNERS
new file mode 100644
index 00000000000..2fca67fdfda
--- /dev/null
+++ b/chromium/content/browser/notifications/OWNERS
@@ -0,0 +1 @@
+peter@chromium.org \ No newline at end of file
diff --git a/chromium/content/browser/notifications/notification_message_filter.cc b/chromium/content/browser/notifications/notification_message_filter.cc
new file mode 100644
index 00000000000..fecd0730b77
--- /dev/null
+++ b/chromium/content/browser/notifications/notification_message_filter.cc
@@ -0,0 +1,89 @@
+// 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/browser/notifications/notification_message_filter.h"
+
+#include "base/callback.h"
+#include "content/browser/notifications/page_notification_delegate.h"
+#include "content/common/platform_notification_messages.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/desktop_notification_delegate.h"
+#include "content/public/common/content_client.h"
+
+namespace content {
+
+NotificationMessageFilter::NotificationMessageFilter(
+ int process_id,
+ ResourceContext* resource_context,
+ BrowserContext* browser_context)
+ : BrowserMessageFilter(PlatformNotificationMsgStart),
+ process_id_(process_id),
+ resource_context_(resource_context),
+ browser_context_(browser_context) {}
+
+NotificationMessageFilter::~NotificationMessageFilter() {}
+
+void NotificationMessageFilter::DidCloseNotification(int notification_id) {
+ close_closures_.erase(notification_id);
+}
+
+bool NotificationMessageFilter::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(NotificationMessageFilter, message)
+ IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_CheckPermission,
+ OnCheckNotificationPermission)
+ IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_Show,
+ OnShowPlatformNotification)
+ IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_Close,
+ OnClosePlatformNotification)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ return handled;
+}
+
+void NotificationMessageFilter::OverrideThreadForMessage(
+ const IPC::Message& message, content::BrowserThread::ID* thread) {
+ if (message.type() == PlatformNotificationHostMsg_Show::ID ||
+ message.type() == PlatformNotificationHostMsg_Close::ID)
+ *thread = BrowserThread::UI;
+}
+
+void NotificationMessageFilter::OnCheckNotificationPermission(
+ const GURL& origin, blink::WebNotificationPermission* permission) {
+ *permission =
+ GetContentClient()->browser()->CheckDesktopNotificationPermission(
+ origin,
+ resource_context_,
+ process_id_);
+}
+
+void NotificationMessageFilter::OnShowPlatformNotification(
+ int notification_id, const ShowDesktopNotificationHostMsgParams& params) {
+ scoped_ptr<DesktopNotificationDelegate> delegate(
+ new PageNotificationDelegate(process_id_, notification_id));
+
+ base::Closure close_closure;
+ GetContentClient()->browser()->ShowDesktopNotification(params,
+ browser_context_,
+ process_id_,
+ delegate.Pass(),
+ &close_closure);
+
+ if (!close_closure.is_null())
+ close_closures_[notification_id] = close_closure;
+}
+
+void NotificationMessageFilter::OnClosePlatformNotification(
+ int notification_id) {
+ if (!close_closures_.count(notification_id))
+ return;
+
+ close_closures_[notification_id].Run();
+ close_closures_.erase(notification_id);
+}
+
+} // namespace content
diff --git a/chromium/content/browser/notifications/notification_message_filter.h b/chromium/content/browser/notifications/notification_message_filter.h
new file mode 100644
index 00000000000..0b5159b18b7
--- /dev/null
+++ b/chromium/content/browser/notifications/notification_message_filter.h
@@ -0,0 +1,58 @@
+// 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.
+
+#ifndef CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_MESSAGE_FILTER_H_
+#define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_MESSAGE_FILTER_H_
+
+#include <map>
+
+#include "base/callback_forward.h"
+#include "content/public/browser/browser_message_filter.h"
+#include "third_party/WebKit/public/platform/WebNotificationPermission.h"
+
+class GURL;
+
+namespace content {
+
+class BrowserContext;
+class ResourceContext;
+struct ShowDesktopNotificationHostMsgParams;
+
+class NotificationMessageFilter : public BrowserMessageFilter {
+ public:
+ NotificationMessageFilter(
+ int process_id,
+ ResourceContext* resource_context,
+ BrowserContext* browser_context);
+
+ // To be called by the notification's delegate when it has closed, so that
+ // the close closure associated with that notification can be removed.
+ void DidCloseNotification(int notification_id);
+
+ // BrowserMessageFilter implementation. Called on the UI thread.
+ bool OnMessageReceived(const IPC::Message& message) override;
+ void OverrideThreadForMessage(
+ const IPC::Message& message, content::BrowserThread::ID* thread) override;
+
+ protected:
+ ~NotificationMessageFilter() override;
+
+ private:
+ void OnCheckNotificationPermission(
+ const GURL& origin, blink::WebNotificationPermission* permission);
+ void OnShowPlatformNotification(
+ int notification_id, const ShowDesktopNotificationHostMsgParams& params);
+ void OnClosePlatformNotification(int notification_id);
+
+ int process_id_;
+ ResourceContext* resource_context_;
+ BrowserContext* browser_context_;
+
+ // Map mapping notification ids to their associated close closures.
+ std::map<int, base::Closure> close_closures_;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_MESSAGE_FILTER_H_
diff --git a/chromium/content/browser/notifications/page_notification_delegate.cc b/chromium/content/browser/notifications/page_notification_delegate.cc
new file mode 100644
index 00000000000..dacfffbfd22
--- /dev/null
+++ b/chromium/content/browser/notifications/page_notification_delegate.cc
@@ -0,0 +1,48 @@
+// 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/browser/notifications/page_notification_delegate.h"
+
+#include "content/browser/notifications/notification_message_filter.h"
+#include "content/browser/renderer_host/render_process_host_impl.h"
+#include "content/common/platform_notification_messages.h"
+#include "content/public/browser/render_process_host.h"
+
+namespace content {
+
+PageNotificationDelegate::PageNotificationDelegate(int render_process_id,
+ int notification_id)
+ : render_process_id_(render_process_id),
+ notification_id_(notification_id) {}
+
+PageNotificationDelegate::~PageNotificationDelegate() {}
+
+void PageNotificationDelegate::NotificationDisplayed() {
+ RenderProcessHost* sender = RenderProcessHost::FromID(render_process_id_);
+ if (!sender)
+ return;
+
+ sender->Send(new PlatformNotificationMsg_DidShow(notification_id_));
+}
+
+// TODO(peter): Remove |by_user| since we're not using that anywhere.
+void PageNotificationDelegate::NotificationClosed(bool by_user) {
+ RenderProcessHost* sender = RenderProcessHost::FromID(render_process_id_);
+ if (!sender)
+ return;
+
+ sender->Send(new PlatformNotificationMsg_DidClose(notification_id_));
+ static_cast<RenderProcessHostImpl*>(sender)
+ ->notification_message_filter()->DidCloseNotification(notification_id_);
+}
+
+void PageNotificationDelegate::NotificationClick() {
+ RenderProcessHost* sender = RenderProcessHost::FromID(render_process_id_);
+ if (!sender)
+ return;
+
+ sender->Send(new PlatformNotificationMsg_DidClick(notification_id_));
+}
+
+} // namespace content
diff --git a/chromium/content/browser/notifications/page_notification_delegate.h b/chromium/content/browser/notifications/page_notification_delegate.h
new file mode 100644
index 00000000000..dd3422f2c4e
--- /dev/null
+++ b/chromium/content/browser/notifications/page_notification_delegate.h
@@ -0,0 +1,32 @@
+// 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.
+
+#ifndef CONTENT_BROWSER_NOTIFICATIONS_PAGE_NOTIFICATION_DELEGATE_H_
+#define CONTENT_BROWSER_NOTIFICATIONS_PAGE_NOTIFICATION_DELEGATE_H_
+
+#include "content/public/browser/desktop_notification_delegate.h"
+
+namespace content {
+
+// A delegate used by the notification service to report the results of platform
+// notification interactions to Web Notifications whose lifetime is tied to
+// that of the page displaying them.
+class PageNotificationDelegate : public DesktopNotificationDelegate {
+ public:
+ PageNotificationDelegate(int render_process_id, int notification_id);
+ ~PageNotificationDelegate() override;
+
+ // DesktopNotificationDelegate implementation.
+ void NotificationDisplayed() override;
+ void NotificationClosed(bool by_user) override;
+ void NotificationClick() override;
+
+ private:
+ int render_process_id_;
+ int notification_id_;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_NOTIFICATIONS_PAGE_NOTIFICATION_DELEGATE_H_