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 
     16 namespace extensions {
     17 class Extension;
     18 class ExtensionViewHost;
     19 }
     20 
     21 // The InfobarDelegate for creating and managing state for the ExtensionInfobar
     22 // plus monitor when the extension goes away.
     23 class ExtensionInfoBarDelegate : public InfoBarDelegate,
     24                                  public content::NotificationObserver {
     25  public:
     26   virtual ~ExtensionInfoBarDelegate();
     27 
     28   // Creates an extension infobar and delegate and adds the infobar to the
     29   // infobar service for |web_contents|.
     30   static void Create(content::WebContents* web_contents,
     31                      Browser* browser,
     32                      const extensions::Extension* extension,
     33                      const GURL& url,
     34                      int height);
     35 
     36   const extensions::Extension* extension() { return extension_; }
     37   extensions::ExtensionViewHost* extension_view_host() {
     38     return extension_view_host_.get();
     39   }
     40   int height() { return height_; }
     41 
     42   bool closing() const { return closing_; }
     43 
     44  private:
     45   ExtensionInfoBarDelegate(Browser* browser,
     46                            const extensions::Extension* extension,
     47                            const GURL& url,
     48                            content::WebContents* web_contents,
     49                            int height);
     50 
     51   // Returns an extension infobar that owns |delegate|.
     52   static scoped_ptr<InfoBar> CreateInfoBar(
     53       scoped_ptr<ExtensionInfoBarDelegate> delegate);
     54 
     55   // InfoBarDelegate:
     56   virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE;
     57   virtual void InfoBarDismissed() OVERRIDE;
     58   virtual Type GetInfoBarType() const OVERRIDE;
     59   virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE;
     60 
     61   // content::NotificationObserver:
     62   virtual void Observe(int type,
     63                        const content::NotificationSource& source,
     64                        const content::NotificationDetails& details) OVERRIDE;
     65 
     66 #if defined(TOOLKIT_VIEWS)
     67   Browser* browser_;  // We pass this to the ExtensionInfoBar.
     68 #endif
     69 
     70   // The extension host we are showing the InfoBar for.
     71   // TODO(pkasting): Should this live on the InfoBar instead?
     72   scoped_ptr<extensions::ExtensionViewHost> extension_view_host_;
     73 
     74   const extensions::Extension* extension_;
     75   content::NotificationRegistrar registrar_;
     76 
     77   // The requested height of the infobar (in pixels).
     78   int height_;
     79 
     80   // Whether we are currently animating to close. This is used to ignore
     81   // ExtensionView::PreferredSizeChanged notifications.
     82   bool closing_;
     83 
     84   DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate);
     85 };
     86 
     87 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_
     88