1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Copyright (c) 2009 The Chromium Authors. All rights reserved. 2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file. 4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/notifications/notification_object_proxy.h" 6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 7c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/message_loop.h" 8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/string16.h" 93345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#include "content/browser/browser_thread.h" 10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "content/browser/renderer_host/render_view_host.h" 113345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#include "content/common/desktop_notification_messages.h" 12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 1321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian MonsenNotificationObjectProxy::NotificationObjectProxy(int process_id, int route_id, 1472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen int notification_id, bool worker) 15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch : process_id_(process_id), 16dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen route_id_(route_id), 17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch notification_id_(notification_id), 18731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick worker_(worker) { 19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochvoid NotificationObjectProxy::Display() { 22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch Send(new DesktopNotificationMsg_PostDisplay(route_id_, notification_id_)); 2372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen} 2472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen 25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochvoid NotificationObjectProxy::Error() { 26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch Send(new DesktopNotificationMsg_PostError( 27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch route_id_, notification_id_, string16())); 28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochvoid NotificationObjectProxy::Close(bool by_user) { 31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch Send(new DesktopNotificationMsg_PostClose( 32731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick route_id_, notification_id_, by_user)); 33731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick} 34731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick 353345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickvoid NotificationObjectProxy::Click() { 36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch Send(new DesktopNotificationMsg_PostClick(route_id_, notification_id_)); 37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochstd::string NotificationObjectProxy::id() const { 40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch return StringPrintf("%d:%d:%d:%d", process_id_, route_id_, 41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch notification_id_, worker_); 42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochvoid NotificationObjectProxy::Send(IPC::Message* message) { 46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch if (worker_) { 473345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // TODO(johnnyg): http://crbug.com/23065 Worker support coming soon. 483345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick NOTREACHED(); 493345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick return; 503345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick } 513345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 523345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_); 533345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick if (host) { 543345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick host->Send(message); 55c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } else { 5621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen delete message; 573345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick } 583345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick} 593345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick