Home | History | Annotate | Download | only in notifications
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OBJECT_PROXY_H_
      6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OBJECT_PROXY_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "chrome/browser/notifications/notification_delegate.h"
     12 
     13 class MessageLoop;
     14 namespace IPC {
     15 class Message;
     16 }
     17 
     18 // A NotificationObjectProxy stands in for the JavaScript Notification object
     19 // which corresponds to a notification toast on the desktop.  It can be signaled
     20 // when various events occur regarding the desktop notification, and the
     21 // attached JS listeners will be invoked in the renderer or worker process.
     22 class NotificationObjectProxy
     23     : public NotificationDelegate {
     24  public:
     25   // Creates a Proxy object with the necessary callback information.
     26   NotificationObjectProxy(int process_id, int route_id,
     27                           int notification_id, bool worker);
     28 
     29   // NotificationDelegate implementation.
     30   virtual void Display();
     31   virtual void Error();
     32   virtual void Close(bool by_user);
     33   virtual void Click();
     34   virtual std::string id() const;
     35 
     36  protected:
     37   friend class base::RefCountedThreadSafe<NotificationObjectProxy>;
     38 
     39   virtual ~NotificationObjectProxy() {}
     40 
     41  private:
     42   // Called on UI thread to send a message.
     43   void Send(IPC::Message* message);
     44 
     45   // Callback information to find the JS Notification object where it lives.
     46   int process_id_;
     47   int route_id_;
     48   int notification_id_;
     49   bool worker_;
     50 };
     51 
     52 #endif  // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OBJECT_PROXY_H_
     53