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

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

Issue 190063006: Infobar Componentization Proof of Concept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixes Created 6 years, 9 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
OLDNEW
1 // Copyright (c) 2012 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_SERVICE_H_ 5 #ifndef CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_
6 #define CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_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"
11 #include "content/public/browser/web_contents_observer.h" 11 #include "base/observer_list.h"
12 #include "content/public/browser/web_contents_user_data.h" 12 #include "chrome/browser/infobars/infobar_delegate.h"
13 13
14 class InfoBar; 14 class InfoBar;
15 15
16 // Provides access to creating, removing and enumerating info bars 16 // Provides access to creating, removing and enumerating info bars
17 // attached to a tab. 17 // attached to a tab.
18 class InfoBarService : public content::WebContentsObserver, 18 class InfoBarManager {
droger 2014/03/18 15:59:53 InfoBarManager has the core logic. It will move in
19 public content::WebContentsUserData<InfoBarService> {
20 public: 19 public:
20 InfoBarManager();
21 ~InfoBarManager();
22
21 // Adds the specified |infobar|, which already owns a delegate. 23 // Adds the specified |infobar|, which already owns a delegate.
22 // 24 //
23 // If infobars are disabled for this tab or the tab already has an infobar 25 // If infobars are disabled for this tab or the tab already has an infobar
24 // whose delegate returns true for 26 // whose delegate returns true for
25 // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted 27 // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted
26 // immediately without being added. 28 // immediately without being added.
27 // 29 //
28 // Returns the infobar if it was successfully added. 30 // Returns the infobar if it was successfully added.
29 virtual InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar); 31 virtual InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar, int entry_id);
30 32
31 // Removes the specified |infobar|. This in turn may close immediately or 33 // Removes the specified |infobar|. This in turn may close immediately or
32 // animate closed; at the end the infobar will delete itself. 34 // animate closed; at the end the infobar will delete itself.
33 // 35 //
34 // If infobars are disabled for this tab, this will do nothing, on the 36 // If infobars are disabled for this tab, this will do nothing, on the
35 // assumption that the matching AddInfoBar() call will have already deleted 37 // assumption that the matching AddInfoBar() call will have already deleted
36 // the infobar (see above). 38 // the infobar (see above).
37 void RemoveInfoBar(InfoBar* infobar); 39 void RemoveInfoBar(InfoBar* infobar);
38 40
39 // Replaces one infobar with another, without any animation in between. This 41 // Replaces one infobar with another, without any animation in between. This
40 // will result in |old_infobar| being synchronously deleted. 42 // will result in |old_infobar| being synchronously deleted.
41 // 43 //
42 // If infobars are disabled for this tab, |new_infobar| is deleted immediately 44 // If infobars are disabled for this tab, |new_infobar| is deleted immediately
43 // without being added, and nothing else happens. 45 // without being added, and nothing else happens.
44 // 46 //
45 // Returns the new infobar if it was successfully added. 47 // Returns the new infobar if it was successfully added.
46 // 48 //
47 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). 49 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar().
48 InfoBar* ReplaceInfoBar(InfoBar* old_infobar, 50 InfoBar* ReplaceInfoBar(InfoBar* old_infobar,
49 scoped_ptr<InfoBar> new_infobar); 51 scoped_ptr<InfoBar> new_infobar,
52 int entry_id);
50 53
51 // Returns the number of infobars for this tab. 54 // Returns the number of infobars for this tab.
52 size_t infobar_count() const { return infobars_.size(); } 55 size_t infobar_count() const { return infobars_.size(); }
53 56
54 // Returns the infobar at the given |index|. The InfoBarService retains 57 // Returns the infobar at the given |index|. The InfoBarService retains
55 // ownership. 58 // ownership.
56 // 59 //
57 // Warning: Does not sanity check |index|. 60 // Warning: Does not sanity check |index|.
58 InfoBar* infobar_at(size_t index) { return infobars_[index]; } 61 InfoBar* infobar_at(size_t index) { return infobars_[index]; }
59 62
60 // Retrieve the WebContents for the tab this service is associated with. 63 void RemoveAllInfoBars(bool animate);
61 content::WebContents* web_contents() { 64
62 return content::WebContentsObserver::web_contents(); 65 void OnNavigation(const InfoBarDelegate::NavigationDetails& details);
63 } 66
67 void CleanUp();
Peter Kasting 2014/03/18 18:29:17 Nit: Again, add comments here (and, frankly, above
68
69 class Observer {
droger 2014/03/18 15:59:53 Observer class, to replace the notifications.
Peter Kasting 2014/03/18 18:29:17 Nit: Classes should be declared at the top of the
70 public:
71 virtual void OnInfoBarAdded(InfoBar* infobar) = 0;
72 virtual void OnInfoBarReplaced(InfoBar* old_infobar,
73 InfoBar* new_infobar) = 0;
74 virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) = 0;
75 };
76
77 void AddObserver(Observer* obs) { observer_list_.AddObserver(obs); }
Peter Kasting 2014/03/18 18:29:17 Nit: Don't inline non-unix_hacker()-style function
78
79 void RemoveObserver(Observer* obs) { observer_list_.RemoveObserver(obs); }
64 80
65 private: 81 private:
66 friend class content::WebContentsUserData<InfoBarService>;
67
68 // InfoBars associated with this InfoBarService. We own these pointers. 82 // InfoBars associated with this InfoBarService. We own these pointers.
69 // However, this is not a ScopedVector, because we don't delete the infobars 83 // However, this is not a ScopedVector, because we don't delete the infobars
70 // directly once they've been added to this; instead, when we're done with an 84 // directly once they've been added to this; instead, when we're done with an
71 // infobar, we instruct it to delete itself and then orphan it. See 85 // infobar, we instruct it to delete itself and then orphan it. See
72 // RemoveInfoBarInternal(). 86 // RemoveInfoBarInternal().
73 typedef std::vector<InfoBar*> InfoBars; 87 typedef std::vector<InfoBar*> InfoBars;
74 88
75 explicit InfoBarService(content::WebContents* web_contents);
76 virtual ~InfoBarService();
77
78 // content::WebContentsObserver:
79 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
80 virtual void NavigationEntryCommitted(
81 const content::LoadCommittedDetails& load_details) OVERRIDE;
82 virtual void WebContentsDestroyed(
83 content::WebContents* web_contents) OVERRIDE;
84 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
85
86 void RemoveInfoBarInternal(InfoBar* infobar, bool animate); 89 void RemoveInfoBarInternal(InfoBar* infobar, bool animate);
87 void RemoveAllInfoBars(bool animate);
88
89 // Message handlers.
90 void OnDidBlockDisplayingInsecureContent();
91 void OnDidBlockRunningInsecureContent();
92 90
93 InfoBars infobars_; 91 InfoBars infobars_;
94 bool infobars_enabled_; 92 bool infobars_enabled_;
93 ObserverList<Observer> observer_list_;
95 94
96 DISALLOW_COPY_AND_ASSIGN(InfoBarService); 95 DISALLOW_COPY_AND_ASSIGN(InfoBarManager);
97 }; 96 };
98 97
99 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_ 98 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698