1// Copyright (c) 2011 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/confirm_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,
31                           TabContents* contents,
32                           const Extension* extension,
33                           const GURL& url);
34
35  const Extension* extension() { return extension_; }
36  ExtensionHost* extension_host() { return extension_host_.get(); }
37
38  void set_observer(DelegateObserver* observer) { observer_ = observer; }
39
40  bool closing() const { return closing_; }
41
42 private:
43  virtual ~ExtensionInfoBarDelegate();
44
45  // InfoBarDelegate:
46  virtual InfoBar* CreateInfoBar();
47  virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
48  virtual void InfoBarDismissed();
49  virtual void InfoBarClosed();
50  virtual Type GetInfoBarType() const;
51  virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate();
52
53  // NotificationObserver:
54  virtual void Observe(NotificationType type,
55                       const NotificationSource& source,
56                       const NotificationDetails& details);
57
58  // The extension host we are showing the InfoBar for. The delegate needs to
59  // own this since the InfoBar gets deleted and recreated when you switch tabs
60  // and come back (and we don't want the user's interaction with the InfoBar to
61  // get lost at that point).
62  scoped_ptr<ExtensionHost> extension_host_;
63
64  // The observer monitoring when the delegate dies.
65  DelegateObserver* observer_;
66
67  const Extension* extension_;
68  TabContents* tab_contents_;
69  NotificationRegistrar registrar_;
70
71  // Whether we are currently animating to close. This is used to ignore
72  // ExtensionView::PreferredSizeChanged notifications.
73  bool closing_;
74
75  DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate);
76};
77
78#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_
79