extension_infobar_delegate.h revision 513209b27ff55e2841eac0e4120199c23acce758
1// Copyright (c) 2010 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#pragma once
8
9#include "chrome/browser/tab_contents/infobar_delegate.h"
10
11class Browser;
12class Extension;
13class ExtensionHost;
14class TabContents;
15
16// The InfobarDelegate for creating and managing state for the ExtensionInfobar
17// plus monitor when the extension goes away.
18class ExtensionInfoBarDelegate : public InfoBarDelegate,
19                                 public NotificationObserver {
20 public:
21  // The observer for when the delegate dies.
22  class DelegateObserver {
23   public:
24    virtual void OnDelegateDeleted() = 0;
25
26   protected:
27    virtual ~DelegateObserver() {}
28  };
29
30  ExtensionInfoBarDelegate(Browser* browser, TabContents* contents,
31                           const Extension* extension, const GURL& url);
32  ~ExtensionInfoBarDelegate();
33
34  const Extension* extension() { return extension_; }
35  ExtensionHost* extension_host() { return extension_host_.get(); }
36
37  void set_observer(DelegateObserver* observer) { observer_ = observer; }
38
39  // Overridden from InfoBarDelegate:
40  virtual void InfoBarDismissed() { closing_ = true; }
41  virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
42  virtual void InfoBarClosed();
43  virtual InfoBar* CreateInfoBar();
44  virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate();
45  virtual Type GetInfoBarType();
46
47  // Overridden from NotificationObserver:
48  virtual void Observe(NotificationType type,
49                       const NotificationSource& source,
50                       const NotificationDetails& details);
51
52  bool closing() { return closing_; }
53 private:
54  // The extension host we are showing the InfoBar for. The delegate needs to
55  // own this since the InfoBar gets deleted and recreated when you switch tabs
56  // and come back (and we don't want the user's interaction with the InfoBar to
57  // get lost at that point.
58  scoped_ptr<ExtensionHost> extension_host_;
59
60  // The observer monitoring when the delegate dies.
61  DelegateObserver* observer_;
62
63  const Extension* extension_;
64
65  TabContents* tab_contents_;
66
67  NotificationRegistrar registrar_;
68
69  // Whether we are currently animating to close. This is used to ignore
70  // ExtensionView::PreferredSizeChanged notifications.
71  bool closing_;
72
73  DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate);
74};
75
76#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_
77