extension_infobar_delegate.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
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
8#include "chrome/browser/tab_contents/infobar_delegate.h"
9
10class Browser;
11class Extension;
12class ExtensionHost;
13class TabContents;
14
15// The InfobarDelegate for creating and managing state for the ExtensionInfobar
16// plus monitor when the extension goes away.
17class ExtensionInfoBarDelegate : public InfoBarDelegate,
18                                 public NotificationObserver {
19 public:
20  // The observer for when the delegate dies.
21  class DelegateObserver {
22   public:
23    virtual void OnDelegateDeleted() = 0;
24  };
25
26  ExtensionInfoBarDelegate(Browser* browser, TabContents* contents,
27                           Extension* extension, const GURL& url);
28  ~ExtensionInfoBarDelegate();
29
30  Extension* extension() { return extension_; }
31  ExtensionHost* extension_host() { return extension_host_.get(); }
32
33  void set_observer(DelegateObserver* observer) { observer_ = observer; }
34
35  // Overridden from InfoBarDelegate:
36  virtual void InfoBarDismissed() { closing_ = true; }
37  virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
38  virtual void InfoBarClosed();
39  virtual InfoBar* CreateInfoBar();
40  virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() {
41    return this;
42  }
43  virtual Type GetInfoBarType() {
44    return PAGE_ACTION_TYPE;
45  }
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  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