MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / chrome / browser / extensions / extension_infobar_delegate.h
blobfbc69d87aba9b73e6c046d41babbc04363223df2
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/scoped_observer.h"
10 #include "components/infobars/core/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"
15 class Browser;
16 class GURL;
18 namespace content {
19 class WebContents;
22 namespace extensions {
23 class Extension;
24 class ExtensionRegistry;
25 class ExtensionViewHost;
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 ~ExtensionInfoBarDelegate() override;
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);
44 const extensions::Extension* extension() { return extension_; }
45 extensions::ExtensionViewHost* extension_view_host() {
46 return extension_view_host_.get();
48 const extensions::ExtensionViewHost* extension_view_host() const {
49 return extension_view_host_.get();
52 int height() { return height_; }
54 bool closing() const { return closing_; }
56 // Returns the WebContents associated with the ExtensionInfoBarDelegate.
57 content::WebContents* GetWebContents();
59 private:
60 ExtensionInfoBarDelegate(Browser* browser,
61 const extensions::Extension* extension,
62 const GURL& url,
63 content::WebContents* web_contents,
64 int height);
66 // Returns an extension infobar that owns |delegate|.
67 static scoped_ptr<infobars::InfoBar> CreateInfoBar(
68 scoped_ptr<ExtensionInfoBarDelegate> delegate);
70 // InfoBarDelegate.
71 bool EqualsDelegate(infobars::InfoBarDelegate* delegate) const override;
72 void InfoBarDismissed() override;
73 Type GetInfoBarType() const override;
74 ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() override;
76 // content::NotificationObserver.
77 void Observe(int type,
78 const content::NotificationSource& source,
79 const content::NotificationDetails& details) override;
81 // extensions::ExtensionRegistryObserver.
82 void OnExtensionUnloaded(
83 content::BrowserContext* browser_context,
84 const extensions::Extension* extension,
85 extensions::UnloadedExtensionInfo::Reason reason) override;
87 #if defined(TOOLKIT_VIEWS)
88 Browser* browser_; // We pass this to the ExtensionInfoBar.
89 #endif
91 // The extension host we are showing the InfoBar for.
92 // TODO(pkasting): Should this live on the InfoBar instead?
93 scoped_ptr<extensions::ExtensionViewHost> extension_view_host_;
95 const extensions::Extension* extension_;
96 content::NotificationRegistrar registrar_;
98 ScopedObserver<extensions::ExtensionRegistry,
99 extensions::ExtensionRegistryObserver>
100 extension_registry_observer_;
102 // The requested height of the infobar (in pixels).
103 int height_;
105 // Whether we are currently animating to close. This is used to ignore
106 // ExtensionView::PreferredSizeChanged notifications.
107 bool closing_;
109 DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate);
112 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_