| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/notifications/notification_object_proxy.h" | 5 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/string16.h" | |
| 9 #include "content/browser/browser_thread.h" | |
| 10 #include "content/browser/renderer_host/render_view_host.h" | 8 #include "content/browser/renderer_host/render_view_host.h" |
| 11 #include "content/common/desktop_notification_messages.h" | |
| 12 | 9 |
| 13 NotificationObjectProxy::NotificationObjectProxy(int process_id, int route_id, | 10 NotificationObjectProxy::NotificationObjectProxy(int process_id, int route_id, |
| 14 int notification_id, bool worker) | 11 int notification_id, bool worker) |
| 15 : process_id_(process_id), | 12 : process_id_(process_id), |
| 16 route_id_(route_id), | 13 route_id_(route_id), |
| 17 notification_id_(notification_id), | 14 notification_id_(notification_id), |
| 18 worker_(worker) { | 15 worker_(worker) { |
| 16 if (worker_) { |
| 17 // TODO(johnnyg): http://crbug.com/23065 Worker support coming soon. |
| 18 NOTREACHED(); |
| 19 } |
| 19 } | 20 } |
| 20 | 21 |
| 21 void NotificationObjectProxy::Display() { | 22 void NotificationObjectProxy::Display() { |
| 22 Send(new DesktopNotificationMsg_PostDisplay(route_id_, notification_id_)); | 23 RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_); |
| 24 if (host) |
| 25 host->DesktopNotificationPostDisplay(notification_id_); |
| 23 } | 26 } |
| 24 | 27 |
| 25 void NotificationObjectProxy::Error() { | 28 void NotificationObjectProxy::Error() { |
| 26 Send(new DesktopNotificationMsg_PostError( | 29 RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_); |
| 27 route_id_, notification_id_, string16())); | 30 if (host) |
| 31 host->DesktopNotificationPostError(notification_id_, string16()); |
| 28 } | 32 } |
| 29 | 33 |
| 30 void NotificationObjectProxy::Close(bool by_user) { | 34 void NotificationObjectProxy::Close(bool by_user) { |
| 31 Send(new DesktopNotificationMsg_PostClose( | 35 RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_); |
| 32 route_id_, notification_id_, by_user)); | 36 if (host) |
| 37 host->DesktopNotificationPostClose(notification_id_, by_user); |
| 33 } | 38 } |
| 34 | 39 |
| 35 void NotificationObjectProxy::Click() { | 40 void NotificationObjectProxy::Click() { |
| 36 Send(new DesktopNotificationMsg_PostClick(route_id_, notification_id_)); | 41 RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_); |
| 42 if (host) |
| 43 host->DesktopNotificationPostClick(notification_id_); |
| 37 } | 44 } |
| 38 | 45 |
| 39 std::string NotificationObjectProxy::id() const { | 46 std::string NotificationObjectProxy::id() const { |
| 40 return StringPrintf("%d:%d:%d:%d", process_id_, route_id_, | 47 return StringPrintf("%d:%d:%d:%d", process_id_, route_id_, |
| 41 notification_id_, worker_); | 48 notification_id_, worker_); |
| 42 } | 49 } |
| 43 | |
| 44 | |
| 45 void NotificationObjectProxy::Send(IPC::Message* message) { | |
| 46 if (worker_) { | |
| 47 // TODO(johnnyg): http://crbug.com/23065 Worker support coming soon. | |
| 48 NOTREACHED(); | |
| 49 return; | |
| 50 } | |
| 51 | |
| 52 RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_); | |
| 53 if (host) { | |
| 54 host->Send(message); | |
| 55 } else { | |
| 56 delete message; | |
| 57 } | |
| 58 } | |
| OLD | NEW |