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

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

Issue 211273007: Split InfoBarService core code into InfoBarManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android compilation 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 | Annotate | Revision Log
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 "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "content/public/browser/web_contents_observer.h" 12
13 #include "content/public/browser/web_contents_user_data.h" 13 namespace content {
14 struct LoadCommittedDetails;
15 class WebContents;
16 }
14 17
15 class InfoBar; 18 class InfoBar;
16 19
17 // Provides access to creating, removing and enumerating info bars 20 // Provides access to creating, removing and enumerating info bars
18 // attached to a tab. 21 // attached to a tab.
19 class InfoBarService : public content::WebContentsObserver, 22 class InfoBarManager {
20 public content::WebContentsUserData<InfoBarService> {
21 public: 23 public:
22
23 // Observer class for infobar events. 24 // Observer class for infobar events.
24 class Observer { 25 class Observer {
25 public: 26 public:
26 virtual void OnInfoBarAdded(InfoBar* infobar) = 0; 27 virtual void OnInfoBarAdded(InfoBar* infobar) = 0;
27 virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) = 0; 28 virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) = 0;
28 virtual void OnInfoBarReplaced(InfoBar* old_infobar, 29 virtual void OnInfoBarReplaced(InfoBar* old_infobar,
29 InfoBar* new_infobar) = 0; 30 InfoBar* new_infobar) = 0;
30 virtual void OnServiceShuttingDown(InfoBarService* service) = 0; 31 virtual void OnManagerShuttingDown(InfoBarManager* manager) = 0;
31 }; 32 };
32 33
34 explicit InfoBarManager(content::WebContents* web_contents);
35 ~InfoBarManager();
36
33 // Adds the specified |infobar|, which already owns a delegate. 37 // Adds the specified |infobar|, which already owns a delegate.
34 // 38 //
35 // If infobars are disabled for this tab or the tab already has an infobar 39 // If infobars are disabled for this tab or the tab already has an infobar
36 // whose delegate returns true for 40 // whose delegate returns true for
37 // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted 41 // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted
38 // immediately without being added. 42 // immediately without being added.
39 // 43 //
40 // Returns the infobar if it was successfully added. 44 // Returns the infobar if it was successfully added.
41 virtual InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar); 45 virtual InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar);
42 46
(...skipping 13 matching lines...) Expand all
56 // 60 //
57 // Returns the new infobar if it was successfully added. 61 // Returns the new infobar if it was successfully added.
58 // 62 //
59 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). 63 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar().
60 InfoBar* ReplaceInfoBar(InfoBar* old_infobar, 64 InfoBar* ReplaceInfoBar(InfoBar* old_infobar,
61 scoped_ptr<InfoBar> new_infobar); 65 scoped_ptr<InfoBar> new_infobar);
62 66
63 // Returns the number of infobars for this tab. 67 // Returns the number of infobars for this tab.
64 size_t infobar_count() const { return infobars_.size(); } 68 size_t infobar_count() const { return infobars_.size(); }
65 69
66 // Returns the infobar at the given |index|. The InfoBarService retains 70 // Returns the infobar at the given |index|. The InfoBarManager retains
67 // ownership. 71 // ownership.
68 // 72 //
69 // Warning: Does not sanity check |index|. 73 // Warning: Does not sanity check |index|.
70 InfoBar* infobar_at(size_t index) { return infobars_[index]; } 74 InfoBar* infobar_at(size_t index) { return infobars_[index]; }
71 75
76 // Removes all the infobars.
Peter Kasting 2014/03/26 23:51:30 Nit: This should be up be RemoveInfoBar().
77 void RemoveAllInfoBars(bool animate);
78
72 // Retrieve the WebContents for the tab this service is associated with. 79 // Retrieve the WebContents for the tab this service is associated with.
73 content::WebContents* web_contents() { 80 // Do not add new call sites for this.
74 return content::WebContentsObserver::web_contents(); 81 // TODO(droger): remove this method. See http://crbug.com/
blundell 2014/03/27 09:40:30 bug number?
75 } 82 content::WebContents* web_contents() { return web_contents_; }
83
84 // Must be called when a navigation happens.
85 void OnNavigation(const content::LoadCommittedDetails& load_details);
86
87 // Called when the associated WebContents is being destroyed.
88 void CleanUp();
Peter Kasting 2014/03/26 23:51:30 Nit: Why is the name of this so vague? Why isn't
blundell 2014/03/27 09:40:30 This method is going to stay in InfoBarManager aft
Peter Kasting 2014/03/27 17:51:33 What's it going to do at that point? (Side note:
76 89
77 void AddObserver(Observer* obs); 90 void AddObserver(Observer* obs);
78 void RemoveObserver(Observer* obs); 91 void RemoveObserver(Observer* obs);
79 92
80 private: 93 private:
81 friend class content::WebContentsUserData<InfoBarService>; 94 // InfoBars associated with this InfoBarManager. We own these pointers.
82
83 // InfoBars associated with this InfoBarService. We own these pointers.
84 // However, this is not a ScopedVector, because we don't delete the infobars 95 // However, this is not a ScopedVector, because we don't delete the infobars
85 // directly once they've been added to this; instead, when we're done with an 96 // directly once they've been added to this; instead, when we're done with an
86 // infobar, we instruct it to delete itself and then orphan it. See 97 // infobar, we instruct it to delete itself and then orphan it. See
87 // RemoveInfoBarInternal(). 98 // RemoveInfoBarInternal().
88 typedef std::vector<InfoBar*> InfoBars; 99 typedef std::vector<InfoBar*> InfoBars;
89 100
90 explicit InfoBarService(content::WebContents* web_contents);
91 virtual ~InfoBarService();
92
93 // content::WebContentsObserver:
94 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
95 virtual void NavigationEntryCommitted(
96 const content::LoadCommittedDetails& load_details) OVERRIDE;
97 virtual void WebContentsDestroyed(
98 content::WebContents* web_contents) OVERRIDE;
99 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
100
101 void RemoveInfoBarInternal(InfoBar* infobar, bool animate); 101 void RemoveInfoBarInternal(InfoBar* infobar, bool animate);
102 void RemoveAllInfoBars(bool animate);
103
104 // Message handlers.
105 void OnDidBlockDisplayingInsecureContent();
106 void OnDidBlockRunningInsecureContent();
107 102
108 InfoBars infobars_; 103 InfoBars infobars_;
109 bool infobars_enabled_; 104 bool infobars_enabled_;
105 content::WebContents* web_contents_;
blundell 2014/03/27 09:40:30 Put a TODO and bug reference here as well.
110 ObserverList<Observer, true> observer_list_; 106 ObserverList<Observer, true> observer_list_;
111 107
112 DISALLOW_COPY_AND_ASSIGN(InfoBarService); 108 DISALLOW_COPY_AND_ASSIGN(InfoBarManager);
113 }; 109 };
114 110
115 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_ 111 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698