| 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|. | |
| 29 static InfoBarManager* InfoBarManagerFromWebContents( | |
| 30 content::WebContents* web_contents); | |
| 31 | |
| 32 static InfoBarDelegate::NavigationDetails | 28 static InfoBarDelegate::NavigationDetails |
| 33 NavigationDetailsFromLoadCommittedDetails( | 29 NavigationDetailsFromLoadCommittedDetails( |
| 34 const content::LoadCommittedDetails& details); | 30 const content::LoadCommittedDetails& details); |
| 35 | 31 |
| 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. | 32 // Retrieve the WebContents for the tab this service is associated with. |
| 43 content::WebContents* web_contents() { | 33 content::WebContents* web_contents() { |
| 44 return content::WebContentsObserver::web_contents(); | 34 return content::WebContentsObserver::web_contents(); |
| 45 } | 35 } |
| 46 | 36 |
| 47 InfoBarManager* infobar_manager() { return &infobar_manager_; } | |
| 48 | |
| 49 private: | 37 private: |
| 50 friend class content::WebContentsUserData<InfoBarService>; | 38 friend class content::WebContentsUserData<InfoBarService>; |
| 51 | 39 |
| 52 explicit InfoBarService(content::WebContents* web_contents); | 40 explicit InfoBarService(content::WebContents* web_contents); |
| 53 virtual ~InfoBarService(); | 41 virtual ~InfoBarService(); |
| 54 | 42 |
| 43 // InfoBarManager: |
| 44 // TODO(droger): Remove these functions once infobar notifications are |
| 45 // removed. See http://crbug.com/354380 |
| 46 virtual void NotifyInfoBarAdded(InfoBar* infobar) OVERRIDE; |
| 47 virtual void NotifyInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE; |
| 48 virtual void NotifyInfoBarReplaced(InfoBar* old_infobar, |
| 49 InfoBar* new_infobar) OVERRIDE; |
| 50 |
| 55 // content::WebContentsObserver: | 51 // content::WebContentsObserver: |
| 56 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; | 52 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; |
| 57 virtual void NavigationEntryCommitted( | 53 virtual void NavigationEntryCommitted( |
| 58 const content::LoadCommittedDetails& load_details) OVERRIDE; | 54 const content::LoadCommittedDetails& load_details) OVERRIDE; |
| 59 virtual void WebContentsDestroyed( | 55 virtual void WebContentsDestroyed( |
| 60 content::WebContents* web_contents) OVERRIDE; | 56 content::WebContents* web_contents) OVERRIDE; |
| 61 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 57 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 62 | 58 |
| 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. | 59 // Message handlers. |
| 71 void OnDidBlockDisplayingInsecureContent(); | 60 void OnDidBlockDisplayingInsecureContent(); |
| 72 void OnDidBlockRunningInsecureContent(); | 61 void OnDidBlockRunningInsecureContent(); |
| 73 | 62 |
| 74 InfoBarManager infobar_manager_; | |
| 75 | 63 |
| 76 DISALLOW_COPY_AND_ASSIGN(InfoBarService); | 64 DISALLOW_COPY_AND_ASSIGN(InfoBarService); |
| 77 }; | 65 }; |
| 78 | 66 |
| 79 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_ | 67 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_SERVICE_H_ |
| OLD | NEW |