Home | History | Annotate | Download | only in extensions
      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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_
      6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
     10 #include "content/public/browser/notification_observer.h"
     11 #include "content/public/browser/notification_registrar.h"
     12 
     13 class Browser;
     14 class GURL;
     15 class InfoBarService;
     16 
     17 namespace extensions {
     18 class Extension;
     19 class ExtensionHost;
     20 }
     21 
     22 // The InfobarDelegate for creating and managing state for the ExtensionInfobar
     23 // plus monitor when the extension goes away.
     24 class ExtensionInfoBarDelegate : public InfoBarDelegate,
     25                                  public content::NotificationObserver {
     26  public:
     27   // The observer for when the delegate dies.
     28   class DelegateObserver {
     29    public:
     30     virtual void OnDelegateDeleted() = 0;
     31 
     32    protected:
     33     virtual ~DelegateObserver() {}
     34   };
     35 
     36   virtual ~ExtensionInfoBarDelegate();
     37 
     38   // Creates an extension infobar delegate and adds it to |infobar_service|.
     39   static void Create(InfoBarService* infobar_service,
     40                      Browser* browser,
     41                      const extensions::Extension* extension,
     42                      const GURL& url,
     43                      int height);
     44 
     45   const extensions::Extension* extension() { return extension_; }
     46   extensions::ExtensionHost* extension_host() { return extension_host_.get(); }
     47   int height() { return height_; }
     48 
     49   void set_observer(DelegateObserver* observer) { observer_ = observer; }
     50 
     51   bool closing() const { return closing_; }
     52 
     53  private:
     54   ExtensionInfoBarDelegate(Browser* browser,
     55                            InfoBarService* infobar_service,
     56                            const extensions::Extension* extension,
     57                            const GURL& url,
     58                            content::WebContents* web_contents,
     59                            int height);
     60 
     61   // InfoBarDelegate:
     62   virtual InfoBar* CreateInfoBar(InfoBarService* owner) OVERRIDE;
     63   virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE;
     64   virtual void InfoBarDismissed() OVERRIDE;
     65   virtual Type GetInfoBarType() const OVERRIDE;
     66   virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE;
     67 
     68   // content::NotificationObserver:
     69   virtual void Observe(int type,
     70                        const content::NotificationSource& source,
     71                        const content::NotificationDetails& details) OVERRIDE;
     72 
     73 #if defined(TOOLKIT_VIEWS)
     74   Browser* browser_;  // We pass this to the ExtensionInfoBar.
     75 #endif
     76 
     77   // The extension host we are showing the InfoBar for. The delegate needs to
     78   // own this since the InfoBar gets deleted and recreated when you switch tabs
     79   // and come back (and we don't want the user's interaction with the InfoBar to
     80   // get lost at that point).
     81   scoped_ptr<extensions::ExtensionHost> extension_host_;
     82 
     83   // The observer monitoring when the delegate dies.
     84   DelegateObserver* observer_;
     85 
     86   const extensions::Extension* extension_;
     87   content::NotificationRegistrar registrar_;
     88 
     89   // The requested height of the infobar (in pixels).
     90   int height_;
     91 
     92   // Whether we are currently animating to close. This is used to ignore
     93   // ExtensionView::PreferredSizeChanged notifications.
     94   bool closing_;
     95 
     96   DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate);
     97 };
     98 
     99 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_
    100