OLD | NEW |
| (Empty) |
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_INFOBARS_INFOBAR_TAB_HELPER_H_ | |
6 #define CHROME_BROWSER_INFOBARS_INFOBAR_TAB_HELPER_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "content/public/browser/notification_observer.h" | |
10 #include "content/public/browser/notification_registrar.h" | |
11 #include "content/public/browser/web_contents_observer.h" | |
12 | |
13 class InfoBarDelegate; | |
14 | |
15 // Per-tab info bar manager. | |
16 class InfoBarTabHelper : public content::WebContentsObserver, | |
17 public content::NotificationObserver { | |
18 public: | |
19 explicit InfoBarTabHelper(content::WebContents* web_contents); | |
20 virtual ~InfoBarTabHelper(); | |
21 | |
22 // Adds an InfoBar for the specified |delegate|. | |
23 // | |
24 // If infobars are disabled for this tab or the tab already has a delegate | |
25 // which returns true for InfoBarDelegate::EqualsDelegate(delegate), | |
26 // |delegate| is closed immediately without being added. | |
27 // | |
28 // Returns whether |delegate| was successfully added. | |
29 bool AddInfoBar(InfoBarDelegate* delegate); | |
30 | |
31 // Removes the InfoBar for the specified |delegate|. | |
32 // | |
33 // If infobars are disabled for this tab, this will do nothing, on the | |
34 // assumption that the matching AddInfoBar() call will have already closed the | |
35 // delegate (see above). | |
36 void RemoveInfoBar(InfoBarDelegate* delegate); | |
37 | |
38 // Replaces one infobar with another, without any animation in between. | |
39 // | |
40 // If infobars are disabled for this tab, |new_delegate| is closed immediately | |
41 // without being added, and nothing else happens. | |
42 // | |
43 // Returns whether |new_delegate| was successfully added. | |
44 // | |
45 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). | |
46 bool ReplaceInfoBar(InfoBarDelegate* old_delegate, | |
47 InfoBarDelegate* new_delegate); | |
48 | |
49 // Enumeration and access functions. | |
50 size_t infobar_count() const { return infobars_.size(); } | |
51 // WARNING: This does not sanity-check |index|! | |
52 InfoBarDelegate* GetInfoBarDelegateAt(size_t index); | |
53 void set_infobars_enabled(bool value) { infobars_enabled_ = value; } | |
54 | |
55 // content::WebContentsObserver overrides: | |
56 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | |
57 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
58 | |
59 // content::NotificationObserver overrides: | |
60 virtual void Observe(int type, | |
61 const content::NotificationSource& source, | |
62 const content::NotificationDetails& details) OVERRIDE; | |
63 | |
64 // Helper functions for infobars: | |
65 content::WebContents* web_contents() { | |
66 return content::WebContentsObserver::web_contents(); | |
67 } | |
68 | |
69 private: | |
70 typedef std::vector<InfoBarDelegate*> InfoBars; | |
71 | |
72 void RemoveInfoBarInternal(InfoBarDelegate* delegate, bool animate); | |
73 void RemoveAllInfoBars(bool animate); | |
74 | |
75 // Message handlers. | |
76 void OnDidBlockDisplayingInsecureContent(); | |
77 void OnDidBlockRunningInsecureContent(); | |
78 | |
79 // Delegates for InfoBars associated with this InfoBarTabHelper. | |
80 InfoBars infobars_; | |
81 bool infobars_enabled_; | |
82 | |
83 content::NotificationRegistrar registrar_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(InfoBarTabHelper); | |
86 }; | |
87 | |
88 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_TAB_HELPER_H_ | |
OLD | NEW |