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 |
27 virtual ~ExtensionInfoBarDelegate(); | 36 virtual ~ExtensionInfoBarDelegate(); |
28 | 37 |
29 // Creates an extension infobar and delegate and adds the infobar to | 38 // Creates an extension infobar delegate and adds it to |infobar_service|. |
30 // |infobar_service|. | |
31 static void Create(InfoBarService* infobar_service, | 39 static void Create(InfoBarService* infobar_service, |
32 Browser* browser, | 40 Browser* browser, |
33 const extensions::Extension* extension, | 41 const extensions::Extension* extension, |
34 const GURL& url, | 42 const GURL& url, |
35 int height); | 43 int height); |
36 | 44 |
37 const extensions::Extension* extension() { return extension_; } | 45 const extensions::Extension* extension() { return extension_; } |
38 extensions::ExtensionViewHost* extension_view_host() { | 46 extensions::ExtensionViewHost* extension_view_host() { |
39 return extension_view_host_.get(); | 47 return extension_view_host_.get(); |
40 } | 48 } |
41 int height() { return height_; } | 49 int height() { return height_; } |
42 | 50 |
| 51 void set_observer(DelegateObserver* observer) { observer_ = observer; } |
| 52 |
43 bool closing() const { return closing_; } | 53 bool closing() const { return closing_; } |
44 | 54 |
45 private: | 55 private: |
46 ExtensionInfoBarDelegate(Browser* browser, | 56 ExtensionInfoBarDelegate(Browser* browser, |
| 57 InfoBarService* infobar_service, |
47 const extensions::Extension* extension, | 58 const extensions::Extension* extension, |
48 const GURL& url, | 59 const GURL& url, |
49 content::WebContents* web_contents, | 60 content::WebContents* web_contents, |
50 int height); | 61 int height); |
51 | 62 |
52 // Returns an extension infobar that owns |delegate|. | |
53 static scoped_ptr<InfoBar> CreateInfoBar( | |
54 scoped_ptr<ExtensionInfoBarDelegate> delegate); | |
55 | |
56 // InfoBarDelegate: | 63 // InfoBarDelegate: |
| 64 virtual InfoBar* CreateInfoBar(InfoBarService* owner) OVERRIDE; |
57 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE; | 65 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE; |
58 virtual void InfoBarDismissed() OVERRIDE; | 66 virtual void InfoBarDismissed() OVERRIDE; |
59 virtual Type GetInfoBarType() const OVERRIDE; | 67 virtual Type GetInfoBarType() const OVERRIDE; |
60 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE; | 68 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE; |
61 | 69 |
62 // content::NotificationObserver: | 70 // content::NotificationObserver: |
63 virtual void Observe(int type, | 71 virtual void Observe(int type, |
64 const content::NotificationSource& source, | 72 const content::NotificationSource& source, |
65 const content::NotificationDetails& details) OVERRIDE; | 73 const content::NotificationDetails& details) OVERRIDE; |
66 | 74 |
67 #if defined(TOOLKIT_VIEWS) | 75 #if defined(TOOLKIT_VIEWS) |
68 Browser* browser_; // We pass this to the ExtensionInfoBar. | 76 Browser* browser_; // We pass this to the ExtensionInfoBar. |
69 #endif | 77 #endif |
70 | 78 |
71 // The extension host we are showing the InfoBar for. | 79 // The extension host we are showing the InfoBar for. The delegate needs to |
72 // TODO(pkasting): Should this live on the InfoBar instead? | 80 // own this since the InfoBar gets deleted and recreated when you switch tabs |
| 81 // and come back (and we don't want the user's interaction with the InfoBar to |
| 82 // get lost at that point). |
73 scoped_ptr<extensions::ExtensionViewHost> extension_view_host_; | 83 scoped_ptr<extensions::ExtensionViewHost> extension_view_host_; |
74 | 84 |
| 85 // The observer monitoring when the delegate dies. |
| 86 DelegateObserver* observer_; |
| 87 |
75 const extensions::Extension* extension_; | 88 const extensions::Extension* extension_; |
76 content::NotificationRegistrar registrar_; | 89 content::NotificationRegistrar registrar_; |
77 | 90 |
78 // The requested height of the infobar (in pixels). | 91 // The requested height of the infobar (in pixels). |
79 int height_; | 92 int height_; |
80 | 93 |
81 // Whether we are currently animating to close. This is used to ignore | 94 // Whether we are currently animating to close. This is used to ignore |
82 // ExtensionView::PreferredSizeChanged notifications. | 95 // ExtensionView::PreferredSizeChanged notifications. |
83 bool closing_; | 96 bool closing_; |
84 | 97 |
85 DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate); | 98 DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate); |
86 }; | 99 }; |
87 | 100 |
88 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_ | 101 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_ |
OLD | NEW |