OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 9 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
10 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
11 #include "content/public/browser/notification_registrar.h" | 11 #include "content/public/browser/notification_registrar.h" |
12 | 12 |
13 class Browser; | 13 class Browser; |
14 class GURL; | 14 class GURL; |
15 class InfoBarService; | 15 class InfoBarService; |
16 | 16 |
17 namespace extensions { | 17 namespace extensions { |
18 class Extension; | 18 class Extension; |
19 class ExtensionViewHost; | 19 class ExtensionViewHost; |
20 } | 20 } |
21 | 21 |
22 // The InfobarDelegate for creating and managing state for the ExtensionInfobar | 22 // The InfobarDelegate for creating and managing state for the ExtensionInfobar |
23 // plus monitor when the extension goes away. | 23 // plus monitor when the extension goes away. |
24 class ExtensionInfoBarDelegate : public InfoBarDelegate, | 24 class ExtensionInfoBarDelegate : public InfoBarDelegate, |
25 public content::NotificationObserver { | 25 public content::NotificationObserver { |
26 public: | 26 public: |
27 // The observer for when the delegate dies. | |
28 class DelegateObserver { | |
29 public: | |
30 virtual void OnDelegateDeleted() = 0; | |
31 | |
32 protected: | |
33 virtual ~DelegateObserver() {} | |
34 }; | |
35 | |
36 virtual ~ExtensionInfoBarDelegate(); | 27 virtual ~ExtensionInfoBarDelegate(); |
37 | 28 |
38 // Creates an extension infobar delegate and adds it to |infobar_service|. | 29 // Creates an extension infobar and delegate and adds the infobar to |
| 30 // |infobar_service|. |
39 static void Create(InfoBarService* infobar_service, | 31 static void Create(InfoBarService* infobar_service, |
40 Browser* browser, | 32 Browser* browser, |
41 const extensions::Extension* extension, | 33 const extensions::Extension* extension, |
42 const GURL& url, | 34 const GURL& url, |
43 int height); | 35 int height); |
44 | 36 |
45 const extensions::Extension* extension() { return extension_; } | 37 const extensions::Extension* extension() { return extension_; } |
46 extensions::ExtensionViewHost* extension_view_host() { | 38 extensions::ExtensionViewHost* extension_view_host() { |
47 return extension_view_host_.get(); | 39 return extension_view_host_.get(); |
48 } | 40 } |
49 int height() { return height_; } | 41 int height() { return height_; } |
50 | 42 |
51 void set_observer(DelegateObserver* observer) { observer_ = observer; } | |
52 | |
53 bool closing() const { return closing_; } | 43 bool closing() const { return closing_; } |
54 | 44 |
55 private: | 45 private: |
56 ExtensionInfoBarDelegate(Browser* browser, | 46 ExtensionInfoBarDelegate(Browser* browser, |
57 InfoBarService* infobar_service, | |
58 const extensions::Extension* extension, | 47 const extensions::Extension* extension, |
59 const GURL& url, | 48 const GURL& url, |
60 content::WebContents* web_contents, | 49 content::WebContents* web_contents, |
61 int height); | 50 int height); |
62 | 51 |
| 52 // Returns an extension infobar that owns |delegate|. |
| 53 static scoped_ptr<InfoBar> CreateInfoBar( |
| 54 scoped_ptr<ExtensionInfoBarDelegate> delegate); |
| 55 |
63 // InfoBarDelegate: | 56 // InfoBarDelegate: |
64 virtual InfoBar* CreateInfoBar(InfoBarService* owner) OVERRIDE; | |
65 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE; | 57 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE; |
66 virtual void InfoBarDismissed() OVERRIDE; | 58 virtual void InfoBarDismissed() OVERRIDE; |
67 virtual Type GetInfoBarType() const OVERRIDE; | 59 virtual Type GetInfoBarType() const OVERRIDE; |
68 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE; | 60 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE; |
69 | 61 |
70 // content::NotificationObserver: | 62 // content::NotificationObserver: |
71 virtual void Observe(int type, | 63 virtual void Observe(int type, |
72 const content::NotificationSource& source, | 64 const content::NotificationSource& source, |
73 const content::NotificationDetails& details) OVERRIDE; | 65 const content::NotificationDetails& details) OVERRIDE; |
74 | 66 |
75 #if defined(TOOLKIT_VIEWS) | 67 #if defined(TOOLKIT_VIEWS) |
76 Browser* browser_; // We pass this to the ExtensionInfoBar. | 68 Browser* browser_; // We pass this to the ExtensionInfoBar. |
77 #endif | 69 #endif |
78 | 70 |
79 // The extension host we are showing the InfoBar for. The delegate needs to | 71 // The extension host we are showing the InfoBar for. |
80 // own this since the InfoBar gets deleted and recreated when you switch tabs | 72 // TODO(pkasting): Should this live on the InfoBar instead? |
81 // and come back (and we don't want the user's interaction with the InfoBar to | |
82 // get lost at that point). | |
83 scoped_ptr<extensions::ExtensionViewHost> extension_view_host_; | 73 scoped_ptr<extensions::ExtensionViewHost> extension_view_host_; |
84 | 74 |
85 // The observer monitoring when the delegate dies. | |
86 DelegateObserver* observer_; | |
87 | |
88 const extensions::Extension* extension_; | 75 const extensions::Extension* extension_; |
89 content::NotificationRegistrar registrar_; | 76 content::NotificationRegistrar registrar_; |
90 | 77 |
91 // The requested height of the infobar (in pixels). | 78 // The requested height of the infobar (in pixels). |
92 int height_; | 79 int height_; |
93 | 80 |
94 // Whether we are currently animating to close. This is used to ignore | 81 // Whether we are currently animating to close. This is used to ignore |
95 // ExtensionView::PreferredSizeChanged notifications. | 82 // ExtensionView::PreferredSizeChanged notifications. |
96 bool closing_; | 83 bool closing_; |
97 | 84 |
98 DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate); | 85 DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate); |
99 }; | 86 }; |
100 | 87 |
101 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_ | 88 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_ |
OLD | NEW |