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

Side by Side Diff: chrome/browser/infobars/infobar_manager.h

Issue 240193003: Move Infobars core files to the Infobars component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nib name on mac Created 6 years, 8 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
« no previous file with comments | « chrome/browser/infobars/infobar_delegate.cc ('k') | chrome/browser/infobars/infobar_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_
6 #define CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_
7
8 #include <vector>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h"
12 #include "chrome/browser/infobars/infobar_delegate.h"
13
14 namespace content {
15 class WebContents;
16 }
17
18 class InfoBar;
19
20 // Provides access to creating, removing and enumerating info bars
21 // attached to a tab.
22 class InfoBarManager {
23 public:
24 // Observer class for infobar events.
25 class Observer {
26 public:
27 virtual void OnInfoBarAdded(InfoBar* infobar) = 0;
28 virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) = 0;
29 virtual void OnInfoBarReplaced(InfoBar* old_infobar,
30 InfoBar* new_infobar) = 0;
31 virtual void OnManagerShuttingDown(InfoBarManager* manager) = 0;
32 };
33
34 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();
41
42 // Adds the specified |infobar|, which already owns a delegate.
43 //
44 // If infobars are disabled for this tab or the tab already has an infobar
45 // whose delegate returns true for
46 // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted
47 // immediately without being added.
48 //
49 // Returns the infobar if it was successfully added.
50 InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar);
51
52 // Removes the specified |infobar|. This in turn may close immediately or
53 // animate closed; at the end the infobar will delete itself.
54 //
55 // If infobars are disabled for this tab, this will do nothing, on the
56 // assumption that the matching AddInfoBar() call will have already deleted
57 // the infobar (see above).
58 void RemoveInfoBar(InfoBar* infobar);
59
60 // Removes all the infobars.
61 void RemoveAllInfoBars(bool animate);
62
63 // Replaces one infobar with another, without any animation in between. This
64 // will result in |old_infobar| being synchronously deleted.
65 //
66 // If infobars are disabled for this tab, |new_infobar| is deleted immediately
67 // without being added, and nothing else happens.
68 //
69 // Returns the new infobar if it was successfully added.
70 //
71 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar().
72 InfoBar* ReplaceInfoBar(InfoBar* old_infobar,
73 scoped_ptr<InfoBar> new_infobar);
74
75 // Returns the number of infobars for this tab.
76 size_t infobar_count() const { return infobars_.size(); }
77
78 // Returns the infobar at the given |index|. The InfoBarManager retains
79 // ownership.
80 //
81 // Warning: Does not sanity check |index|.
82 InfoBar* infobar_at(size_t index) { return infobars_[index]; }
83
84 // Must be called when a navigation happens.
85 void OnNavigation(const InfoBarDelegate::NavigationDetails& details);
86
87 void AddObserver(Observer* obs);
88 void RemoveObserver(Observer* obs);
89
90 // Returns the active entry ID.
91 virtual int GetActiveEntryID() = 0;
92
93 protected:
94 // Notifies the observer in |observer_list_|.
95 // TODO(droger): Absorb these methods back into their callers once virtual
96 // overrides are removed (see http://crbug.com/354380).
97 virtual void NotifyInfoBarAdded(InfoBar* infobar);
98 virtual void NotifyInfoBarRemoved(InfoBar* infobar, bool animate);
99 virtual void NotifyInfoBarReplaced(InfoBar* old_infobar,
100 InfoBar* new_infobar);
101
102 private:
103 // InfoBars associated with this InfoBarManager. We own these pointers.
104 // However, this is not a ScopedVector, because we don't delete the infobars
105 // directly once they've been added to this; instead, when we're done with an
106 // infobar, we instruct it to delete itself and then orphan it. See
107 // RemoveInfoBarInternal().
108 typedef std::vector<InfoBar*> InfoBars;
109
110 void RemoveInfoBarInternal(InfoBar* infobar, bool animate);
111
112 InfoBars infobars_;
113 bool infobars_enabled_;
114
115 ObserverList<Observer, true> observer_list_;
116
117 DISALLOW_COPY_AND_ASSIGN(InfoBarManager);
118 };
119
120 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/infobars/infobar_delegate.cc ('k') | chrome/browser/infobars/infobar_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698