15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OBJECT_PROXY_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OBJECT_PROXY_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/notifications/notification_delegate.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochnamespace content {
140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass DesktopNotificationDelegate;
150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass RenderFrameHost;
160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A NotificationObjectProxy stands in for the JavaScript Notification object
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// which corresponds to a notification toast on the desktop.  It can be signaled
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// when various events occur regarding the desktop notification, and the
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// attached JS listeners will be invoked in the renderer or worker process.
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NotificationObjectProxy
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : public NotificationDelegate {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Creates a Proxy object with the necessary callback information. The Proxy
265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // will take ownership of |delegate|.
275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  NotificationObjectProxy(
285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      content::RenderFrameHost* render_frame_host,
295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      scoped_ptr<content::DesktopNotificationDelegate> delegate);
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NotificationDelegate implementation.
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Display() OVERRIDE;
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Error() OVERRIDE;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Close(bool by_user) OVERRIDE;
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Click() OVERRIDE;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual std::string id() const OVERRIDE;
370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  virtual content::WebContents* GetWebContents() const OVERRIDE;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class base::RefCountedThreadSafe<NotificationObjectProxy>;
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual ~NotificationObjectProxy();
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Callback information to find the JS Notification object where it lives.
460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  int render_process_id_;
470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  int render_frame_id_;
485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  scoped_ptr<content::DesktopNotificationDelegate> delegate_;
49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool displayed_;
500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  std::string id_;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OBJECT_PROXY_H_
54