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

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

Issue 14241006: Eliminate InfoBarTabHelper. Make InfoBarService a concrete class. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 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_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>
9
8 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h"
9 15
10 namespace content { 16 namespace content {
11 class WebContents; 17 class WebContents;
12 } 18 }
13 19
14 class InfoBarDelegate; 20 class InfoBarDelegate;
15 21
16 // Provides access to creating, removing and enumerating info bars 22 // Provides access to creating, removing and enumerating info bars
17 // attached to a tab. 23 // attached to a tab.
18 class InfoBarService { 24 class InfoBarService : public content::WebContentsObserver,
25 public content::NotificationObserver,
26 public content::WebContentsUserData<InfoBarService> {
19 public: 27 public:
20 // Passthrough functions to the implementing subclass. The subclass .cc file
21 // should define these.
22 static void CreateForWebContents(content::WebContents* web_contents);
23 static InfoBarService* FromWebContents(content::WebContents* web_contents);
24 static const InfoBarService*
25 FromWebContents(const content::WebContents* web_contents);
26
27 virtual ~InfoBarService();
28
29 // Changes whether infobars are enabled. The default is true. 28 // Changes whether infobars are enabled. The default is true.
30 virtual void SetInfoBarsEnabled(bool enabled) = 0; 29 void set_infobars_enabled(bool enabled) { infobars_enabled_ = enabled; }
31 30
32 // Adds an InfoBar for the specified |delegate|. 31 // Adds an InfoBar for the specified |delegate|.
33 // 32 //
34 // If infobars are disabled for this tab or the tab already has a delegate 33 // If infobars are disabled for this tab or the tab already has a delegate
35 // which returns true for InfoBarDelegate::EqualsDelegate(delegate), 34 // which returns true for InfoBarDelegate::EqualsDelegate(delegate),
36 // |delegate| is closed immediately without being added. 35 // |delegate| is closed immediately without being added.
37 // 36 //
38 // Returns the delegate if it was successfully added. 37 // Returns the delegate if it was successfully added.
39 virtual InfoBarDelegate* AddInfoBar(scoped_ptr<InfoBarDelegate> delegate) = 0; 38 InfoBarDelegate* AddInfoBar(scoped_ptr<InfoBarDelegate> delegate);
40 39
41 // Removes the InfoBar for the specified |delegate|. 40 // Removes the InfoBar for the specified |delegate|.
42 // 41 //
43 // If infobars are disabled for this tab, this will do nothing, on the 42 // If infobars are disabled for this tab, this will do nothing, on the
44 // assumption that the matching AddInfoBar() call will have already closed the 43 // assumption that the matching AddInfoBar() call will have already closed the
45 // delegate (see above). 44 // delegate (see above).
46 virtual void RemoveInfoBar(InfoBarDelegate* delegate) = 0; 45 void RemoveInfoBar(InfoBarDelegate* delegate);
47 46
48 // Replaces one infobar with another, without any animation in between. 47 // Replaces one infobar with another, without any animation in between.
49 // 48 //
50 // If infobars are disabled for this tab, |new_delegate| is closed immediately 49 // If infobars are disabled for this tab, |new_delegate| is closed immediately
51 // without being added, and nothing else happens. 50 // without being added, and nothing else happens.
52 // 51 //
53 // Returns the new delegate if it was successfully added. 52 // Returns the new delegate if it was successfully added.
54 // 53 //
55 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). 54 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar().
56 virtual InfoBarDelegate* ReplaceInfoBar( 55 InfoBarDelegate* ReplaceInfoBar(InfoBarDelegate* old_delegate,
57 InfoBarDelegate* old_delegate, 56 scoped_ptr<InfoBarDelegate> new_delegate);
58 scoped_ptr<InfoBarDelegate> new_delegate) = 0;
59 57
60 // Returns the number of infobars for this tab. 58 // Returns the number of infobars for this tab.
61 virtual size_t GetInfoBarCount() const = 0; 59 size_t infobar_count() const { return infobars_.size(); }
62 60
63 // Returns the infobar delegate at the given |index|. The InfoBarService 61 // Returns the infobar delegate at the given |index|. The InfoBarService
64 // retains ownership. 62 // retains ownership.
65 // 63 //
66 // Warning: Does not sanity check |index|. 64 // Warning: Does not sanity check |index|.
67 virtual InfoBarDelegate* GetInfoBarDelegateAt(size_t index) = 0; 65 InfoBarDelegate* infobar_at(size_t index) { return infobars_[index]; }
68 66
69 // Retrieve the WebContents for the tab this service is associated with. 67 // Retrieve the WebContents for the tab this service is associated with.
70 virtual content::WebContents* GetWebContents() = 0; 68 content::WebContents* web_contents() {
69 return content::WebContentsObserver::web_contents();
70 }
71
72 private:
73 friend class content::WebContentsUserData<InfoBarService>;
74
75 typedef std::vector<InfoBarDelegate*> InfoBars;
76
77 explicit InfoBarService(content::WebContents* web_contents);
78 virtual ~InfoBarService();
79
80 // content::WebContentsObserver:
81 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
82 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
83
84 // content::NotificationObserver:
85 virtual void Observe(int type,
86 const content::NotificationSource& source,
87 const content::NotificationDetails& details) OVERRIDE;
88
89 void RemoveInfoBarInternal(InfoBarDelegate* delegate, bool animate);
90 void RemoveAllInfoBars(bool animate);
91
92 // Message handlers.
93 void OnDidBlockDisplayingInsecureContent();
94 void OnDidBlockRunningInsecureContent();
95
96 // Delegates for InfoBars associated with this InfoBarService.
97 InfoBars infobars_;
98 bool infobars_enabled_;
99
100 content::NotificationRegistrar registrar_;
101
102 DISALLOW_COPY_AND_ASSIGN(InfoBarService);
71 }; 103 };
72 104
73 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_ 105 #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