| 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_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_INFOBARS_INFOBAR_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_INFOBARS_INFOBAR_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_INFOBARS_INFOBAR_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "chrome/browser/api/infobars/infobar_tab_service.h" |
| 9 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
| 10 #include "content/public/browser/notification_registrar.h" | 11 #include "content/public/browser/notification_registrar.h" |
| 11 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
| 12 | 13 |
| 13 class InfoBarDelegate; | 14 class InfoBarDelegate; |
| 14 | 15 |
| 15 // Per-tab info bar manager. | 16 // Per-tab info bar manager. |
| 16 class InfoBarTabHelper : public content::WebContentsObserver, | 17 class InfoBarTabHelper : public InfoBarTabService, |
| 18 public content::WebContentsObserver, |
| 17 public content::NotificationObserver { | 19 public content::NotificationObserver { |
| 18 public: | 20 public: |
| 19 explicit InfoBarTabHelper(content::WebContents* web_contents); | 21 explicit InfoBarTabHelper(content::WebContents* web_contents); |
| 20 virtual ~InfoBarTabHelper(); | 22 virtual ~InfoBarTabHelper(); |
| 21 | 23 |
| 22 // Adds an InfoBar for the specified |delegate|. | 24 // InfoBarTabService implementation. |
| 23 // | 25 virtual bool AddInfoBar(InfoBarDelegate* delegate) OVERRIDE; |
| 24 // If infobars are disabled for this tab or the tab already has a delegate | 26 virtual void RemoveInfoBar(InfoBarDelegate* delegate) OVERRIDE; |
| 25 // which returns true for InfoBarDelegate::EqualsDelegate(delegate), | 27 virtual bool ReplaceInfoBar(InfoBarDelegate* old_delegate, |
| 26 // |delegate| is closed immediately without being added. | 28 InfoBarDelegate* new_delegate) OVERRIDE; |
| 27 // | 29 virtual size_t GetInfoBarCount() const OVERRIDE; |
| 28 // Returns whether |delegate| was successfully added. | 30 virtual InfoBarDelegate* GetInfoBarDelegateAt(size_t index) OVERRIDE; |
| 29 bool AddInfoBar(InfoBarDelegate* delegate); | 31 virtual content::WebContents* GetWebContents() OVERRIDE; |
| 30 | 32 |
| 31 // Removes the InfoBar for the specified |delegate|. | 33 // Enables or disables infobars for the given tab. |
| 32 // | |
| 33 // If infobars are disabled for this tab, this will do nothing, on the | |
| 34 // assumption that the matching AddInfoBar() call will have already closed the | |
| 35 // delegate (see above). | |
| 36 void RemoveInfoBar(InfoBarDelegate* delegate); | |
| 37 | |
| 38 // Replaces one infobar with another, without any animation in between. | |
| 39 // | |
| 40 // If infobars are disabled for this tab, |new_delegate| is closed immediately | |
| 41 // without being added, and nothing else happens. | |
| 42 // | |
| 43 // Returns whether |new_delegate| was successfully added. | |
| 44 // | |
| 45 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). | |
| 46 bool ReplaceInfoBar(InfoBarDelegate* old_delegate, | |
| 47 InfoBarDelegate* new_delegate); | |
| 48 | |
| 49 // Enumeration and access functions. | |
| 50 size_t infobar_count() const { return infobars_.size(); } | |
| 51 // WARNING: This does not sanity-check |index|! | |
| 52 InfoBarDelegate* GetInfoBarDelegateAt(size_t index); | |
| 53 void set_infobars_enabled(bool value) { infobars_enabled_ = value; } | 34 void set_infobars_enabled(bool value) { infobars_enabled_ = value; } |
| 54 | 35 |
| 55 // content::WebContentsObserver overrides: | 36 // content::WebContentsObserver overrides: |
| 56 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | 37 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
| 57 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 38 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 58 | 39 |
| 59 // content::NotificationObserver overrides: | 40 // content::NotificationObserver overrides: |
| 60 virtual void Observe(int type, | 41 virtual void Observe(int type, |
| 61 const content::NotificationSource& source, | 42 const content::NotificationSource& source, |
| 62 const content::NotificationDetails& details) OVERRIDE; | 43 const content::NotificationDetails& details) OVERRIDE; |
| 63 | 44 |
| 64 // Helper functions for infobars: | |
| 65 content::WebContents* web_contents() { | |
| 66 return content::WebContentsObserver::web_contents(); | |
| 67 } | |
| 68 | |
| 69 private: | 45 private: |
| 70 typedef std::vector<InfoBarDelegate*> InfoBars; | 46 typedef std::vector<InfoBarDelegate*> InfoBars; |
| 71 | 47 |
| 72 void RemoveInfoBarInternal(InfoBarDelegate* delegate, bool animate); | 48 void RemoveInfoBarInternal(InfoBarDelegate* delegate, bool animate); |
| 73 void RemoveAllInfoBars(bool animate); | 49 void RemoveAllInfoBars(bool animate); |
| 74 | 50 |
| 75 // Message handlers. | 51 // Message handlers. |
| 76 void OnDidBlockDisplayingInsecureContent(); | 52 void OnDidBlockDisplayingInsecureContent(); |
| 77 void OnDidBlockRunningInsecureContent(); | 53 void OnDidBlockRunningInsecureContent(); |
| 78 | 54 |
| 79 // Delegates for InfoBars associated with this InfoBarTabHelper. | 55 // Delegates for InfoBars associated with this InfoBarTabHelper. |
| 80 InfoBars infobars_; | 56 InfoBars infobars_; |
| 81 bool infobars_enabled_; | 57 bool infobars_enabled_; |
| 82 | 58 |
| 83 content::NotificationRegistrar registrar_; | 59 content::NotificationRegistrar registrar_; |
| 84 | 60 |
| 85 DISALLOW_COPY_AND_ASSIGN(InfoBarTabHelper); | 61 DISALLOW_COPY_AND_ASSIGN(InfoBarTabHelper); |
| 86 }; | 62 }; |
| 87 | 63 |
| 88 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_TAB_HELPER_H_ | 64 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_TAB_HELPER_H_ |
| OLD | NEW |