Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/browser/extensions/extension_infobar_delegate.h

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 ExtensionHost; 19 class ExtensionHost;
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::ExtensionHost* extension_host() { return extension_host_.get(); } 38 extensions::ExtensionHost* extension_host() { return extension_host_.get(); }
47 int height() { return height_; } 39 int height() { return height_; }
48 40
49 void set_observer(DelegateObserver* observer) { observer_ = observer; }
50
51 bool closing() const { return closing_; } 41 bool closing() const { return closing_; }
52 42
53 private: 43 private:
54 ExtensionInfoBarDelegate(Browser* browser, 44 ExtensionInfoBarDelegate(Browser* browser,
55 InfoBarService* infobar_service,
56 const extensions::Extension* extension, 45 const extensions::Extension* extension,
57 const GURL& url, 46 const GURL& url,
58 content::WebContents* web_contents, 47 content::WebContents* web_contents,
59 int height); 48 int height);
60 49
50 // Returns an extension infobar that owns |delegate|.
51 static scoped_ptr<InfoBar> CreateInfoBar(
52 scoped_ptr<ExtensionInfoBarDelegate> delegate);
53
61 // InfoBarDelegate: 54 // InfoBarDelegate:
62 virtual InfoBar* CreateInfoBar(InfoBarService* owner) OVERRIDE;
63 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE; 55 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE;
64 virtual void InfoBarDismissed() OVERRIDE; 56 virtual void InfoBarDismissed() OVERRIDE;
65 virtual Type GetInfoBarType() const OVERRIDE; 57 virtual Type GetInfoBarType() const OVERRIDE;
66 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE; 58 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE;
67 59
68 // content::NotificationObserver: 60 // content::NotificationObserver:
69 virtual void Observe(int type, 61 virtual void Observe(int type,
70 const content::NotificationSource& source, 62 const content::NotificationSource& source,
71 const content::NotificationDetails& details) OVERRIDE; 63 const content::NotificationDetails& details) OVERRIDE;
72 64
73 #if defined(TOOLKIT_VIEWS) 65 #if defined(TOOLKIT_VIEWS)
74 Browser* browser_; // We pass this to the ExtensionInfoBar. 66 Browser* browser_; // We pass this to the ExtensionInfoBar.
75 #endif 67 #endif
76 68
77 // The extension host we are showing the InfoBar for. The delegate needs to 69 // The extension host we are showing the InfoBar for.
78 // own this since the InfoBar gets deleted and recreated when you switch tabs 70 // TODO(pkasting): Should this live on the InfoBar instead?
79 // and come back (and we don't want the user's interaction with the InfoBar to
80 // get lost at that point).
81 scoped_ptr<extensions::ExtensionHost> extension_host_; 71 scoped_ptr<extensions::ExtensionHost> extension_host_;
82 72
83 // The observer monitoring when the delegate dies.
84 DelegateObserver* observer_;
85
86 const extensions::Extension* extension_; 73 const extensions::Extension* extension_;
87 content::NotificationRegistrar registrar_; 74 content::NotificationRegistrar registrar_;
88 75
89 // The requested height of the infobar (in pixels). 76 // The requested height of the infobar (in pixels).
90 int height_; 77 int height_;
91 78
92 // Whether we are currently animating to close. This is used to ignore 79 // Whether we are currently animating to close. This is used to ignore
93 // ExtensionView::PreferredSizeChanged notifications. 80 // ExtensionView::PreferredSizeChanged notifications.
94 bool closing_; 81 bool closing_;
95 82
96 DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate); 83 DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarDelegate);
97 }; 84 };
98 85
99 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_ 86 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698