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

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

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years 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_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_SERVICE_H_
6 #define CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_ 6 #define CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_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 "content/public/browser/web_contents_observer.h"
12 #include "content/public/browser/web_contents_user_data.h" 12 #include "content/public/browser/web_contents_user_data.h"
13 13
14 class InfoBarDelegate; 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 InfoBarService : public content::WebContentsObserver,
19 public content::WebContentsUserData<InfoBarService> { 19 public content::WebContentsUserData<InfoBarService> {
20 public: 20 public:
21 // Changes whether infobars are enabled. The default is true. 21 // Changes whether infobars are enabled. The default is true.
22 void set_infobars_enabled(bool enabled) { infobars_enabled_ = enabled; } 22 void set_infobars_enabled(bool enabled) { infobars_enabled_ = enabled; }
23 23
24 // Adds an InfoBar for the specified |delegate|. 24 // Adds the specified |infobar|, which already owns a delegate.
25 // 25 //
26 // If infobars are disabled for this tab or the tab already has a delegate 26 // If infobars are disabled for this tab or the tab already has an infobar
27 // which returns true for InfoBarDelegate::EqualsDelegate(delegate), 27 // whose delegate returns true for
28 // |delegate| is closed immediately without being added. 28 // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted
29 // immediately without being added.
29 // 30 //
30 // Returns the delegate if it was successfully added. 31 // Returns the infobar if it was successfully added.
31 InfoBarDelegate* AddInfoBar(scoped_ptr<InfoBarDelegate> infobar); 32 virtual InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar);
32 33
33 // Removes the InfoBar for the specified |delegate|. 34 // Removes the specified |infobar|. This in turn may close immediately or
35 // animate closed; at the end the infobar will delete itself.
34 // 36 //
35 // If infobars are disabled for this tab, this will do nothing, on the 37 // If infobars are disabled for this tab, this will do nothing, on the
36 // assumption that the matching AddInfoBar() call will have already closed the 38 // assumption that the matching AddInfoBar() call will have already deleted
37 // delegate (see above). 39 // the infobar (see above).
38 void RemoveInfoBar(InfoBarDelegate* infobar); 40 void RemoveInfoBar(InfoBar* infobar);
39 41
40 // Replaces one infobar with another, without any animation in between. 42 // Replaces one infobar with another, without any animation in between. This
43 // will result in |old_infobar| being synchronously deleted.
41 // 44 //
42 // If infobars are disabled for this tab, |new_delegate| is closed immediately 45 // If infobars are disabled for this tab, |new_infobar| is deleted immediately
43 // without being added, and nothing else happens. 46 // without being added, and nothing else happens.
44 // 47 //
45 // Returns the new delegate if it was successfully added. 48 // Returns the new infobar if it was successfully added.
46 // 49 //
47 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). 50 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar().
48 InfoBarDelegate* ReplaceInfoBar(InfoBarDelegate* old_infobar, 51 InfoBar* ReplaceInfoBar(InfoBar* old_infobar,
49 scoped_ptr<InfoBarDelegate> new_infobar); 52 scoped_ptr<InfoBar> new_infobar);
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 InfoBarDelegate* 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 // Retrieve the WebContents for the tab this service is associated with.
61 content::WebContents* web_contents() { 64 content::WebContents* web_contents() {
62 return content::WebContentsObserver::web_contents(); 65 return content::WebContentsObserver::web_contents();
63 } 66 }
64 67
65 private: 68 private:
66 friend class content::WebContentsUserData<InfoBarService>; 69 friend class content::WebContentsUserData<InfoBarService>;
67 70
68 typedef std::vector<InfoBarDelegate*> InfoBars; 71 // InfoBars associated with this InfoBarService. We own these pointers.
72 // However, this is not a ScopedVector, because we don't delete the infobars
73 // directly once they've been added to this; instead, when we're done with an
74 // infobar, we instruct it to delete itself and then orphan it. See
75 // RemoveInfoBarInternal().
76 typedef std::vector<InfoBar*> InfoBars;
69 77
70 // Delegates for InfoBars associated with this InfoBarService. We do not own
71 // these pointers; they own themselves and are deleted in response to being
72 // closed.
73 // TODO(pkasting): These leak if closed while not visible.
74 explicit InfoBarService(content::WebContents* web_contents); 78 explicit InfoBarService(content::WebContents* web_contents);
75 virtual ~InfoBarService(); 79 virtual ~InfoBarService();
76 80
77 // content::WebContentsObserver: 81 // content::WebContentsObserver:
78 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; 82 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
79 virtual void NavigationEntryCommitted( 83 virtual void NavigationEntryCommitted(
80 const content::LoadCommittedDetails& load_details) OVERRIDE; 84 const content::LoadCommittedDetails& load_details) OVERRIDE;
81 virtual void WebContentsDestroyed( 85 virtual void WebContentsDestroyed(
82 content::WebContents* web_contents) OVERRIDE; 86 content::WebContents* web_contents) OVERRIDE;
83 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 87 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
84 88
85 void RemoveInfoBarInternal(InfoBarDelegate* infobar, bool animate); 89 void RemoveInfoBarInternal(InfoBar* infobar, bool animate);
86 void RemoveAllInfoBars(bool animate); 90 void RemoveAllInfoBars(bool animate);
87 91
88 // Message handlers. 92 // Message handlers.
89 void OnDidBlockDisplayingInsecureContent(); 93 void OnDidBlockDisplayingInsecureContent();
90 void OnDidBlockRunningInsecureContent(); 94 void OnDidBlockRunningInsecureContent();
91 95
92 InfoBars infobars_; 96 InfoBars infobars_;
93 bool infobars_enabled_; 97 bool infobars_enabled_;
94 98
95 DISALLOW_COPY_AND_ASSIGN(InfoBarService); 99 DISALLOW_COPY_AND_ASSIGN(InfoBarService);
96 }; 100 };
97 101
98 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_ 102 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/infobars/infobar_delegate.cc ('k') | chrome/browser/infobars/infobar_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698