OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/infobars/infobar_manager.h" | |
11 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
12 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
13 | 14 |
14 class InfoBar; | 15 namespace content { |
16 struct LoadCommittedDetails; | |
17 } | |
15 | 18 |
16 // Provides access to creating, removing and enumerating info bars | |
17 // attached to a tab. | |
18 class InfoBarService : public content::WebContentsObserver, | 19 class InfoBarService : public content::WebContentsObserver, |
droger
2014/03/18 15:59:53
InfoBarService no longer manages the list of infob
| |
19 public content::WebContentsUserData<InfoBarService> { | 20 public content::WebContentsUserData<InfoBarService>, |
Peter Kasting
2014/03/18 18:29:17
Nit: Leave the WebContentsUserData<> listed last
| |
21 public InfoBarManager::Observer { | |
droger
2014/03/18 15:59:53
InfoBarService is a InfoBarManager::Observer so th
| |
20 public: | 22 public: |
21 // Adds the specified |infobar|, which already owns a delegate. | 23 // Helper functions. |
droger
2014/03/18 15:59:53
The functions are just pass through to call the co
| |
22 // | 24 InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar); |
23 // If infobars are disabled for this tab or the tab already has an infobar | |
24 // whose delegate returns true for | |
25 // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted | |
26 // immediately without being added. | |
27 // | |
28 // Returns the infobar if it was successfully added. | |
29 virtual InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar); | |
30 | |
31 // Removes the specified |infobar|. This in turn may close immediately or | |
32 // animate closed; at the end the infobar will delete itself. | |
33 // | |
34 // If infobars are disabled for this tab, this will do nothing, on the | |
35 // assumption that the matching AddInfoBar() call will have already deleted | |
36 // the infobar (see above). | |
37 void RemoveInfoBar(InfoBar* infobar); | |
38 | |
39 // Replaces one infobar with another, without any animation in between. This | |
40 // will result in |old_infobar| being synchronously deleted. | |
41 // | |
42 // If infobars are disabled for this tab, |new_infobar| is deleted immediately | |
43 // without being added, and nothing else happens. | |
44 // | |
45 // Returns the new infobar if it was successfully added. | |
46 // | |
47 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). | |
48 InfoBar* ReplaceInfoBar(InfoBar* old_infobar, | 25 InfoBar* ReplaceInfoBar(InfoBar* old_infobar, |
49 scoped_ptr<InfoBar> new_infobar); | 26 scoped_ptr<InfoBar> new_infobar); |
50 | 27 |
51 // Returns the number of infobars for this tab. | 28 static InfoBarDelegate::NavigationDetails |
droger
2014/03/18 15:59:53
Converts content::LoadCommittedDetails to InfoBarD
Peter Kasting
2014/03/18 18:29:17
Nit: Do this and GetActiveEntryID() need to be pub
| |
52 size_t infobar_count() const { return infobars_.size(); } | 29 NavigationDetailsFromLoadCommittedDetails( |
53 | 30 const content::LoadCommittedDetails& details); |
54 // Returns the infobar at the given |index|. The InfoBarService retains | |
55 // ownership. | |
56 // | |
57 // Warning: Does not sanity check |index|. | |
58 InfoBar* infobar_at(size_t index) { return infobars_[index]; } | |
59 | 31 |
60 // Retrieve the WebContents for the tab this service is associated with. | 32 // Retrieve the WebContents for the tab this service is associated with. |
61 content::WebContents* web_contents() { | 33 content::WebContents* web_contents() { |
62 return content::WebContentsObserver::web_contents(); | 34 return content::WebContentsObserver::web_contents(); |
63 } | 35 } |
64 | 36 |
37 InfoBarManager& infobar_manager() { return infobar_manager_; } | |
38 | |
39 static int GetActiveEntryID(content::WebContents* web_contents); | |
droger
2014/03/18 15:59:53
InfoBarService computes the entry_id and explicitl
| |
40 | |
65 private: | 41 private: |
66 friend class content::WebContentsUserData<InfoBarService>; | 42 friend class content::WebContentsUserData<InfoBarService>; |
67 | 43 |
68 // InfoBars associated with this InfoBarService. We own these pointers. | |
69 // 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 | |
71 // infobar, we instruct it to delete itself and then orphan it. See | |
72 // RemoveInfoBarInternal(). | |
73 typedef std::vector<InfoBar*> InfoBars; | |
74 | |
75 explicit InfoBarService(content::WebContents* web_contents); | 44 explicit InfoBarService(content::WebContents* web_contents); |
76 virtual ~InfoBarService(); | 45 virtual ~InfoBarService(); |
77 | 46 |
78 // content::WebContentsObserver: | 47 // content::WebContentsObserver: |
79 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; | 48 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; |
80 virtual void NavigationEntryCommitted( | 49 virtual void NavigationEntryCommitted( |
81 const content::LoadCommittedDetails& load_details) OVERRIDE; | 50 const content::LoadCommittedDetails& load_details) OVERRIDE; |
82 virtual void WebContentsDestroyed( | 51 virtual void WebContentsDestroyed( |
83 content::WebContents* web_contents) OVERRIDE; | 52 content::WebContents* web_contents) OVERRIDE; |
84 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 53 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
85 | 54 |
86 void RemoveInfoBarInternal(InfoBar* infobar, bool animate); | |
87 void RemoveAllInfoBars(bool animate); | |
88 | |
89 // Message handlers. | 55 // Message handlers. |
90 void OnDidBlockDisplayingInsecureContent(); | 56 void OnDidBlockDisplayingInsecureContent(); |
91 void OnDidBlockRunningInsecureContent(); | 57 void OnDidBlockRunningInsecureContent(); |
92 | 58 |
93 InfoBars infobars_; | 59 // InfoBarManager::Observer: |
Peter Kasting
2014/03/18 18:29:17
Nit: Put this just below the WebContentsObserver o
| |
94 bool infobars_enabled_; | 60 virtual void OnInfoBarAdded(InfoBar* infobar) OVERRIDE; |
61 virtual void OnInfoBarReplaced(InfoBar* old_infobar, | |
62 InfoBar* new_infobar) OVERRIDE; | |
63 virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE; | |
64 | |
65 InfoBarManager infobar_manager_; | |
95 | 66 |
96 DISALLOW_COPY_AND_ASSIGN(InfoBarService); | 67 DISALLOW_COPY_AND_ASSIGN(InfoBarService); |
97 }; | 68 }; |
98 | 69 |
99 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_ | 70 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_ |
OLD | NEW |