Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / extension_infobar_delegate.h
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 "base/scoped_observer.h"
10 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "extensions/browser/extension_registry_observer.h"
14
15 class Browser;
16 class GURL;
17
18 namespace content {
19 class WebContents;
20 }
21
22 namespace extensions {
23 class Extension;
24 class ExtensionRegistry;
25 class ExtensionViewHost;
26 }
27
28 // The InfobarDelegate for creating and managing state for the ExtensionInfobar
29 // plus monitor when the extension goes away.
30 class ExtensionInfoBarDelegate : public infobars::InfoBarDelegate,
31                                  public content::NotificationObserver,
32                                  public extensions::ExtensionRegistryObserver {
33  public:
34   virtual ~ExtensionInfoBarDelegate();
35
36   // Creates an extension infobar and delegate and adds the infobar to the
37   // infobar service for |web_contents|.
38   static void Create(content::WebContents* web_contents,
39                      Browser* browser,
40                      const extensions::Extension* extension,
41                      const GURL& url,
42                      int height);
43
44   const extensions::Extension* extension() { return extension_; }
45   extensions::ExtensionViewHost* extension_view_host() {
46     return extension_view_host_.get();
47   }
48   int height() { return height_; }
49
50   bool closing() const { return closing_; }
51
52   // Returns the WebContents associated with the ExtensionInfoBarDelegate.
53   content::WebContents* GetWebContents();
54
55  private:
56   ExtensionInfoBarDelegate(Browser* browser,
57                            const extensions::Extension* extension,
58                            const GURL& url,
59                            content::WebContents* web_contents,
60                            int height);
61
62   // Returns an extension infobar that owns |delegate|.
63   static scoped_ptr<infobars::InfoBar> CreateInfoBar(
64       scoped_ptr<ExtensionInfoBarDelegate> delegate);
65
66   // InfoBarDelegate.
67   virtual bool EqualsDelegate(
68       infobars::InfoBarDelegate* delegate) const OVERRIDE;
69   virtual void InfoBarDismissed() OVERRIDE;
70   virtual Type GetInfoBarType() const OVERRIDE;
71   virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE;
72
73   // content::NotificationObserver.
74   virtual void Observe(int type,
75                        const content::NotificationSource& source,
76                        const content::NotificationDetails& details) OVERRIDE;
77
78   // extensions::ExtensionRegistryObserver.
79   virtual void OnExtensionUnloaded(
80       content::BrowserContext* browser_context,
81       const extensions::Extension* extension,
82       extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
83
84 #if defined(TOOLKIT_VIEWS)
85   Browser* browser_;  // We pass this to the ExtensionInfoBar.
86 #endif
87
88   // The extension host we are showing the InfoBar for.
89   // TODO(pkasting): Should this live on the InfoBar instead?
90   scoped_ptr<extensions::ExtensionViewHost> extension_view_host_;
91
92   const extensions::Extension* extension_;
93   content::NotificationRegistrar registrar_;
94
95   ScopedObserver<extensions::ExtensionRegistry,
96                  extensions::ExtensionRegistryObserver>
97       extension_registry_observer_;
98
99   // The requested height of the infobar (in pixels).
100   int height_;
101
102   // Whether we are currently animating to close. This is used to ignore
103   // ExtensionView::PreferredSizeChanged notifications.
104   bool closing_;
105
106   DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate);
107 };
108
109 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_