OLD | NEW |
---|---|
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 "chrome/browser/infobars/infobar_manager.h" | 11 #include "chrome/browser/infobars/infobar_manager.h" |
12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
13 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 struct LoadCommittedDetails; | 16 struct LoadCommittedDetails; |
17 class WebContents; | 17 class WebContents; |
18 } | 18 } |
19 | 19 |
20 class InfoBar; | 20 class InfoBar; |
21 | 21 |
22 // Associates a Tab to a InfoBarManager and manages its lifetime. | 22 // Associates a Tab to a InfoBarManager and manages its lifetime. |
23 // It manages the infobar notifications and responds to navigation events. | 23 // It manages the infobar notifications and responds to navigation events. |
24 class InfoBarService : public content::WebContentsObserver, | 24 class InfoBarService : public InfoBarManager, |
25 public content::WebContentsUserData<InfoBarService>, | 25 public content::WebContentsObserver, |
26 public InfoBarManager::Observer { | 26 public content::WebContentsUserData<InfoBarService> { |
27 public: | 27 public: |
28 // Helper function to get the InfoBarManager attached to |web_contents|. | 28 // Helper function to get the InfoBarManager attached to |web_contents|. |
29 static InfoBarManager* InfoBarManagerFromWebContents( | 29 static InfoBarManager* InfoBarManagerFromWebContents( |
30 content::WebContents* web_contents); | 30 content::WebContents* web_contents); |
31 | 31 |
32 static InfoBarDelegate::NavigationDetails | 32 static InfoBarDelegate::NavigationDetails |
33 NavigationDetailsFromLoadCommittedDetails( | 33 NavigationDetailsFromLoadCommittedDetails( |
34 const content::LoadCommittedDetails& details); | 34 const content::LoadCommittedDetails& details); |
35 | 35 |
36 // These methods are simple pass-throughs to InfoBarManager, and are here to | |
37 // prepare for the componentization of Infobars, see http://crbug.com/354379. | |
38 InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar); | |
39 InfoBar* ReplaceInfoBar(InfoBar* old_infobar, | |
40 scoped_ptr<InfoBar> new_infobar); | |
41 | |
42 // Retrieve the WebContents for the tab this service is associated with. | 36 // Retrieve the WebContents for the tab this service is associated with. |
43 content::WebContents* web_contents() { | 37 content::WebContents* web_contents() { |
44 return content::WebContentsObserver::web_contents(); | 38 return content::WebContentsObserver::web_contents(); |
45 } | 39 } |
46 | 40 |
47 InfoBarManager* infobar_manager() { return &infobar_manager_; } | 41 InfoBarManager* infobar_manager() { return this; } |
droger
2014/04/08 12:11:00
This method needs to be removed. I'll do this once
| |
48 | 42 |
49 private: | 43 private: |
50 friend class content::WebContentsUserData<InfoBarService>; | 44 friend class content::WebContentsUserData<InfoBarService>; |
51 | 45 |
52 explicit InfoBarService(content::WebContents* web_contents); | 46 explicit InfoBarService(content::WebContents* web_contents); |
53 virtual ~InfoBarService(); | 47 virtual ~InfoBarService(); |
54 | 48 |
49 // InfoBarManager: | |
50 // TODO(droger): Remove these functions once infobar notifications are | |
51 // removed. See http://crbug.com/354380 | |
52 virtual void NotifyInfoBarAdded(InfoBar* infobar) OVERRIDE; | |
53 virtual void NotifyInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE; | |
54 virtual void NotifyInfoBarReplaced(InfoBar* old_infobar, | |
55 InfoBar* new_infobar) OVERRIDE; | |
56 | |
55 // content::WebContentsObserver: | 57 // content::WebContentsObserver: |
56 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; | 58 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; |
57 virtual void NavigationEntryCommitted( | 59 virtual void NavigationEntryCommitted( |
58 const content::LoadCommittedDetails& load_details) OVERRIDE; | 60 const content::LoadCommittedDetails& load_details) OVERRIDE; |
59 virtual void WebContentsDestroyed( | 61 virtual void WebContentsDestroyed( |
60 content::WebContents* web_contents) OVERRIDE; | 62 content::WebContents* web_contents) OVERRIDE; |
61 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 63 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
62 | 64 |
63 // InfoBarManager::Observer: | |
64 virtual void OnInfoBarAdded(InfoBar* infobar) OVERRIDE; | |
65 virtual void OnInfoBarReplaced(InfoBar* old_infobar, | |
66 InfoBar* new_infobar) OVERRIDE; | |
67 virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE; | |
68 virtual void OnManagerShuttingDown(InfoBarManager* manager) OVERRIDE; | |
69 | |
70 // Message handlers. | 65 // Message handlers. |
71 void OnDidBlockDisplayingInsecureContent(); | 66 void OnDidBlockDisplayingInsecureContent(); |
72 void OnDidBlockRunningInsecureContent(); | 67 void OnDidBlockRunningInsecureContent(); |
73 | 68 |
74 InfoBarManager infobar_manager_; | |
75 | 69 |
76 DISALLOW_COPY_AND_ASSIGN(InfoBarService); | 70 DISALLOW_COPY_AND_ASSIGN(InfoBarService); |
77 }; | 71 }; |
78 | 72 |
79 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_ | 73 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_ |
OLD | NEW |