1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/notifications/notification_object_proxy.h" 6 7 #include "base/strings/stringprintf.h" 8 #include "content/public/browser/render_view_host.h" 9 10 using content::RenderViewHost; 11 12 NotificationObjectProxy::NotificationObjectProxy(int process_id, int route_id, 13 int notification_id, bool worker) 14 : process_id_(process_id), 15 route_id_(route_id), 16 notification_id_(notification_id), 17 worker_(worker), 18 displayed_(false) { 19 if (worker_) { 20 // TODO(johnnyg): http://crbug.com/23065 Worker support coming soon. 21 NOTREACHED(); 22 } 23 } 24 25 void NotificationObjectProxy::Display() { 26 // This method is called each time the notification is shown to the user 27 // but we only want to fire the event the first time. 28 if (displayed_) 29 return; 30 displayed_ = true; 31 32 RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_); 33 if (host) 34 host->DesktopNotificationPostDisplay(notification_id_); 35 } 36 37 void NotificationObjectProxy::Error() { 38 RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_); 39 if (host) 40 host->DesktopNotificationPostError(notification_id_, base::string16()); 41 } 42 43 void NotificationObjectProxy::Close(bool by_user) { 44 RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_); 45 if (host) 46 host->DesktopNotificationPostClose(notification_id_, by_user); 47 } 48 49 void NotificationObjectProxy::Click() { 50 RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_); 51 if (host) 52 host->DesktopNotificationPostClick(notification_id_); 53 } 54 55 std::string NotificationObjectProxy::id() const { 56 return base::StringPrintf("%d:%d:%d:%d", process_id_, route_id_, 57 notification_id_, worker_); 58 } 59 60 int NotificationObjectProxy::process_id() const { 61 return process_id_; 62 } 63 64 RenderViewHost* NotificationObjectProxy::GetRenderViewHost() const { 65 return RenderViewHost::FromID(process_id_, route_id_); 66 } 67