summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/desktop_notifications/active_notification_tracker.cc69
-rw-r--r--chrome/common/desktop_notifications/active_notification_tracker.h50
-rw-r--r--chrome/common/render_messages_internal.h41
3 files changed, 160 insertions, 0 deletions
diff --git a/chrome/common/desktop_notifications/active_notification_tracker.cc b/chrome/common/desktop_notifications/active_notification_tracker.cc
new file mode 100644
index 0000000..230d76a
--- /dev/null
+++ b/chrome/common/desktop_notifications/active_notification_tracker.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2009 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 "chrome/common/desktop_notifications/active_notification_tracker.h"
+
+#include "base/message_loop.h"
+#include "webkit/api/public/WebNotification.h"
+#include "webkit/api/public/WebNotificationPermissionCallback.h"
+
+using WebKit::WebNotification;
+using WebKit::WebNotificationPermissionCallback;
+
+bool ActiveNotificationTracker::GetId(
+ const WebNotification& notification, int& id) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ ReverseTable::iterator iter = reverse_notification_table_.find(notification);
+ if (iter == reverse_notification_table_.end())
+ return false;
+ id = iter->second;
+ return true;
+}
+
+bool ActiveNotificationTracker::GetNotification(
+ int id, WebNotification* notification) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ WebNotification* lookup = notification_table_.Lookup(id);
+ if (!lookup)
+ return false;
+
+ *notification = *lookup;
+ return true;
+}
+
+int ActiveNotificationTracker::RegisterNotification(
+ const WebKit::WebNotification& proxy) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ WebNotification* notification = new WebNotification(proxy);
+ int id = notification_table_.Add(notification);
+ reverse_notification_table_[proxy] = id;
+ return id;
+}
+
+void ActiveNotificationTracker::UnregisterNotification(int id) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ // We want to free the notification after removing it from the table.
+ scoped_ptr<WebNotification> notification(notification_table_.Lookup(id));
+ notification_table_.Remove(id);
+ DCHECK(notification.get());
+ if (notification.get())
+ reverse_notification_table_.erase(*notification);
+}
+
+WebNotificationPermissionCallback* ActiveNotificationTracker::GetCallback(
+ int id) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ return callback_table_.Lookup(id);
+}
+
+int ActiveNotificationTracker::RegisterPermissionRequest(
+ WebNotificationPermissionCallback* callback) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ return callback_table_.Add(callback);
+}
+
+void ActiveNotificationTracker::OnPermissionRequestComplete(int id) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ callback_table_.Remove(id);
+}
diff --git a/chrome/common/desktop_notifications/active_notification_tracker.h b/chrome/common/desktop_notifications/active_notification_tracker.h
new file mode 100644
index 0000000..4bdd5d9
--- /dev/null
+++ b/chrome/common/desktop_notifications/active_notification_tracker.h
@@ -0,0 +1,50 @@
+// Copyright (c) 2009 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 CHROME_COMMON_DESKTOP_NOTIFICATIONS_ACTIVE_NOTIFICATION_TRACKER_H_
+#define CHROME_COMMON_DESKTOP_NOTIFICATIONS_ACTIVE_NOTIFICATION_TRACKER_H_
+
+#include <map>
+
+#include "base/basictypes.h"
+#include "base/id_map.h"
+#include "base/hash_tables.h"
+#include "webkit/api/public/WebNotification.h"
+
+namespace WebKit {
+class WebNotificationPermissionCallback;
+}
+
+// This class manages the set of active Notification objects in either
+// a render or worker process. This class should be accessed only on
+// the main thread.
+class ActiveNotificationTracker {
+ public:
+ ActiveNotificationTracker() {}
+
+ // Methods for tracking active notification objects.
+ int RegisterNotification(const WebKit::WebNotification& notification);
+ void UnregisterNotification(int id);
+ bool GetId(const WebKit::WebNotification& notification, int& id);
+ bool GetNotification(int id, WebKit::WebNotification* notification);
+
+ // Methods for tracking active permission requests.
+ int RegisterPermissionRequest(
+ WebKit::WebNotificationPermissionCallback* callback);
+ void OnPermissionRequestComplete(int id);
+ WebKit::WebNotificationPermissionCallback* GetCallback(int id);
+
+ private:
+ typedef std::map<WebKit::WebNotification, int> ReverseTable;
+
+ // Tracking maps for active notifications and permission requests.
+ IDMap<WebKit::WebNotification> notification_table_;
+ ReverseTable reverse_notification_table_;
+ IDMap<WebKit::WebNotificationPermissionCallback> callback_table_;
+
+ DISALLOW_COPY_AND_ASSIGN(ActiveNotificationTracker);
+};
+
+#endif // CHROME_COMMON_DESKTOP_NOTIFICATIONS_ACTIVE_NOTIFICATION_TRACKER_H_
+
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 804e624..62451cc 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -689,6 +689,26 @@ IPC_BEGIN_MESSAGES(View)
// width.
IPC_MESSAGE_ROUTED0(ViewMsg_EnableIntrinsicWidthChangedMode)
+ // Used to inform the renderer that the browser has displayed its
+ // requested notification.
+ IPC_MESSAGE_ROUTED1(ViewMsg_PostDisplayToNotificationObject,
+ int /* notification_id */)
+
+ // Used to inform the renderer that the browser has encountered an error
+ // trying to display a notification.
+ IPC_MESSAGE_ROUTED2(ViewMsg_PostErrorToNotificationObject,
+ int /* notification_id */,
+ string16 /* message */)
+
+ // Informs the renderer that the one if its notifications has closed.
+ IPC_MESSAGE_ROUTED2(ViewMsg_PostCloseToNotificationObject,
+ int /* notification_id */,
+ bool /* by_user */)
+
+ // Informs the renderer that the one if its notifications has closed.
+ IPC_MESSAGE_ROUTED1(ViewMsg_PermissionRequestDone,
+ int /* request_id */)
+
// Activate/deactivate the RenderView (i.e., set its controls' tint
// accordingly, etc.).
IPC_MESSAGE_ROUTED1(ViewMsg_SetActive,
@@ -1622,6 +1642,27 @@ IPC_BEGIN_MESSAGES(ViewHost)
int /* render_view_route_id */,
int /* route_id */)
+ // A message sent to the browser on behalf of a renderer which wants to show
+ // a desktop notification.
+ IPC_MESSAGE_ROUTED3(ViewHostMsg_ShowDesktopNotification,
+ GURL /* origin */,
+ GURL /* contents_url */,
+ int /* notification_id */)
+ IPC_MESSAGE_ROUTED5(ViewHostMsg_ShowDesktopNotificationText,
+ GURL /* origin */,
+ GURL /* icon_url */,
+ string16 /* title */,
+ string16 /* text */,
+ int /* notification_id */)
+ IPC_MESSAGE_ROUTED1(ViewHostMsg_CancelDesktopNotification,
+ int /* notification_id */ )
+ IPC_MESSAGE_ROUTED2(ViewHostMsg_RequestNotificationPermission,
+ string16 /* origin */,
+ int /* callback_context */)
+ IPC_SYNC_MESSAGE_ROUTED1_1(ViewHostMsg_CheckNotificationPermission,
+ string16 /* origin */,
+ int /* permission_result */)
+
// Sent if the worker object has sent a ViewHostMsg_CreateDedicatedWorker
// message and not received a ViewMsg_DedicatedWorkerCreated reply, but in the
// mean time it's destroyed. This tells the browser to not create the queued