OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_INFOBARS_INFOBAR_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_ |
6 #define CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_ | 6 #define CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 // Observer class for infobar events. | 24 // Observer class for infobar events. |
25 class Observer { | 25 class Observer { |
26 public: | 26 public: |
27 virtual void OnInfoBarAdded(InfoBar* infobar) = 0; | 27 virtual void OnInfoBarAdded(InfoBar* infobar) = 0; |
28 virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) = 0; | 28 virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) = 0; |
29 virtual void OnInfoBarReplaced(InfoBar* old_infobar, | 29 virtual void OnInfoBarReplaced(InfoBar* old_infobar, |
30 InfoBar* new_infobar) = 0; | 30 InfoBar* new_infobar) = 0; |
31 virtual void OnManagerShuttingDown(InfoBarManager* manager) = 0; | 31 virtual void OnManagerShuttingDown(InfoBarManager* manager) = 0; |
32 }; | 32 }; |
33 | 33 |
34 explicit InfoBarManager(content::WebContents* web_contents); | 34 InfoBarManager(); |
35 ~InfoBarManager(); | 35 virtual ~InfoBarManager(); |
36 | |
37 // Must be called before destruction. | |
38 // TODO(droger): Merge this method with the destructor once the virtual calls | |
39 // for notifications are removed (see http://crbug.com/354380). | |
40 void ShutDown(); | |
36 | 41 |
37 // Adds the specified |infobar|, which already owns a delegate. | 42 // Adds the specified |infobar|, which already owns a delegate. |
38 // | 43 // |
39 // If infobars are disabled for this tab or the tab already has an infobar | 44 // If infobars are disabled for this tab or the tab already has an infobar |
40 // whose delegate returns true for | 45 // whose delegate returns true for |
41 // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted | 46 // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted |
42 // immediately without being added. | 47 // immediately without being added. |
43 // | 48 // |
44 // Returns the infobar if it was successfully added. | 49 // Returns the infobar if it was successfully added. |
45 virtual InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar); | 50 InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar); |
46 | 51 |
47 // Removes the specified |infobar|. This in turn may close immediately or | 52 // Removes the specified |infobar|. This in turn may close immediately or |
48 // animate closed; at the end the infobar will delete itself. | 53 // animate closed; at the end the infobar will delete itself. |
49 // | 54 // |
50 // If infobars are disabled for this tab, this will do nothing, on the | 55 // If infobars are disabled for this tab, this will do nothing, on the |
51 // assumption that the matching AddInfoBar() call will have already deleted | 56 // assumption that the matching AddInfoBar() call will have already deleted |
52 // the infobar (see above). | 57 // the infobar (see above). |
53 void RemoveInfoBar(InfoBar* infobar); | 58 void RemoveInfoBar(InfoBar* infobar); |
54 | 59 |
55 // Removes all the infobars. | 60 // Removes all the infobars. |
(...skipping 13 matching lines...) Expand all Loading... | |
69 | 74 |
70 // Returns the number of infobars for this tab. | 75 // Returns the number of infobars for this tab. |
71 size_t infobar_count() const { return infobars_.size(); } | 76 size_t infobar_count() const { return infobars_.size(); } |
72 | 77 |
73 // Returns the infobar at the given |index|. The InfoBarManager retains | 78 // Returns the infobar at the given |index|. The InfoBarManager retains |
74 // ownership. | 79 // ownership. |
75 // | 80 // |
76 // Warning: Does not sanity check |index|. | 81 // Warning: Does not sanity check |index|. |
77 InfoBar* infobar_at(size_t index) { return infobars_[index]; } | 82 InfoBar* infobar_at(size_t index) { return infobars_[index]; } |
78 | 83 |
79 // Retrieve the WebContents for the tab this service is associated with. | |
80 // Do not add new call sites for this. | |
81 // TODO(droger): remove this method. See http://crbug.com/354379. | |
82 content::WebContents* web_contents() { return web_contents_; } | |
83 | |
84 // Must be called when a navigation happens. | 84 // Must be called when a navigation happens. |
85 void OnNavigation(const InfoBarDelegate::NavigationDetails& details); | 85 void OnNavigation(const InfoBarDelegate::NavigationDetails& details); |
86 | 86 |
87 // Called when the associated WebContents is being destroyed. | |
88 void OnWebContentsDestroyed(); | |
89 | |
90 void AddObserver(Observer* obs); | 87 void AddObserver(Observer* obs); |
91 void RemoveObserver(Observer* obs); | 88 void RemoveObserver(Observer* obs); |
92 | 89 |
90 protected: | |
91 // Notifies the observer in |observer_list_|. | |
92 // TODO(droger): make these methods non-virtual once overrides for | |
93 // notifications are removed (see http://crbug.com/354380). | |
Peter Kasting
2014/04/10 00:08:59
Nit: I might say something more like "Absorb these
| |
94 virtual void NotifyInfoBarAdded(InfoBar* infobar); | |
95 virtual void NotifyInfoBarRemoved(InfoBar* infobar, bool animate); | |
96 virtual void NotifyInfoBarReplaced(InfoBar* old_infobar, | |
97 InfoBar* new_infobar); | |
98 void NotifyManagerShuttingDown(); | |
99 | |
93 private: | 100 private: |
94 // InfoBars associated with this InfoBarManager. We own these pointers. | 101 // InfoBars associated with this InfoBarManager. We own these pointers. |
95 // However, this is not a ScopedVector, because we don't delete the infobars | 102 // However, this is not a ScopedVector, because we don't delete the infobars |
96 // directly once they've been added to this; instead, when we're done with an | 103 // directly once they've been added to this; instead, when we're done with an |
97 // infobar, we instruct it to delete itself and then orphan it. See | 104 // infobar, we instruct it to delete itself and then orphan it. See |
98 // RemoveInfoBarInternal(). | 105 // RemoveInfoBarInternal(). |
99 typedef std::vector<InfoBar*> InfoBars; | 106 typedef std::vector<InfoBar*> InfoBars; |
100 | 107 |
101 void RemoveInfoBarInternal(InfoBar* infobar, bool animate); | 108 void RemoveInfoBarInternal(InfoBar* infobar, bool animate); |
102 | 109 |
103 InfoBars infobars_; | 110 InfoBars infobars_; |
104 bool infobars_enabled_; | 111 bool infobars_enabled_; |
105 | 112 |
106 // TODO(droger): remove this field. See http://crbug.com/354379. | |
107 content::WebContents* web_contents_; | |
108 | |
109 ObserverList<Observer, true> observer_list_; | 113 ObserverList<Observer, true> observer_list_; |
110 | 114 |
111 DISALLOW_COPY_AND_ASSIGN(InfoBarManager); | 115 DISALLOW_COPY_AND_ASSIGN(InfoBarManager); |
112 }; | 116 }; |
113 | 117 |
114 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_ | 118 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_ |
OLD | NEW |