| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_INFOBARS_CORE_INFOBAR_MANAGER_H_ | 5 #ifndef COMPONENTS_INFOBARS_CORE_INFOBAR_MANAGER_H_ |
| 6 #define COMPONENTS_INFOBARS_CORE_INFOBAR_MANAGER_H_ | 6 #define COMPONENTS_INFOBARS_CORE_INFOBAR_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "components/infobars/core/infobar_delegate.h" | 15 #include "components/infobars/core/infobar_delegate.h" |
| 16 | 16 |
| 17 class ConfirmInfoBarDelegate; | 17 class ConfirmInfoBarDelegate; |
| 18 class GURL; | 18 class GURL; |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 class WebContents; | 21 class WebContents; |
| 22 } | 22 } |
| 23 | 23 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 50 void ShutDown(); | 50 void ShutDown(); |
| 51 | 51 |
| 52 // Adds the specified |infobar|, which already owns a delegate. | 52 // Adds the specified |infobar|, which already owns a delegate. |
| 53 // | 53 // |
| 54 // If infobars are disabled for this tab or the tab already has an infobar | 54 // If infobars are disabled for this tab or the tab already has an infobar |
| 55 // whose delegate returns true for | 55 // whose delegate returns true for |
| 56 // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted | 56 // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted |
| 57 // immediately without being added. | 57 // immediately without being added. |
| 58 // | 58 // |
| 59 // Returns the infobar if it was successfully added. | 59 // Returns the infobar if it was successfully added. |
| 60 InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar); | 60 InfoBar* AddInfoBar(std::unique_ptr<InfoBar> infobar); |
| 61 | 61 |
| 62 // Removes the specified |infobar|. This in turn may close immediately or | 62 // Removes the specified |infobar|. This in turn may close immediately or |
| 63 // animate closed; at the end the infobar will delete itself. | 63 // animate closed; at the end the infobar will delete itself. |
| 64 // | 64 // |
| 65 // If infobars are disabled for this tab, this will do nothing, on the | 65 // If infobars are disabled for this tab, this will do nothing, on the |
| 66 // assumption that the matching AddInfoBar() call will have already deleted | 66 // assumption that the matching AddInfoBar() call will have already deleted |
| 67 // the infobar (see above). | 67 // the infobar (see above). |
| 68 void RemoveInfoBar(InfoBar* infobar); | 68 void RemoveInfoBar(InfoBar* infobar); |
| 69 | 69 |
| 70 // Removes all the infobars. | 70 // Removes all the infobars. |
| 71 void RemoveAllInfoBars(bool animate); | 71 void RemoveAllInfoBars(bool animate); |
| 72 | 72 |
| 73 // Replaces one infobar with another, without any animation in between. This | 73 // Replaces one infobar with another, without any animation in between. This |
| 74 // will result in |old_infobar| being synchronously deleted. | 74 // will result in |old_infobar| being synchronously deleted. |
| 75 // | 75 // |
| 76 // If infobars are disabled for this tab, |new_infobar| is deleted immediately | 76 // If infobars are disabled for this tab, |new_infobar| is deleted immediately |
| 77 // without being added, and nothing else happens. | 77 // without being added, and nothing else happens. |
| 78 // | 78 // |
| 79 // Returns the new infobar if it was successfully added. | 79 // Returns the new infobar if it was successfully added. |
| 80 // | 80 // |
| 81 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). | 81 // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). |
| 82 InfoBar* ReplaceInfoBar(InfoBar* old_infobar, | 82 InfoBar* ReplaceInfoBar(InfoBar* old_infobar, |
| 83 scoped_ptr<InfoBar> new_infobar); | 83 std::unique_ptr<InfoBar> new_infobar); |
| 84 | 84 |
| 85 // Returns the number of infobars for this tab. | 85 // Returns the number of infobars for this tab. |
| 86 size_t infobar_count() const { return infobars_.size(); } | 86 size_t infobar_count() const { return infobars_.size(); } |
| 87 | 87 |
| 88 // Returns the infobar at the given |index|. The InfoBarManager retains | 88 // Returns the infobar at the given |index|. The InfoBarManager retains |
| 89 // ownership. | 89 // ownership. |
| 90 // | 90 // |
| 91 // Warning: Does not sanity check |index|. | 91 // Warning: Does not sanity check |index|. |
| 92 InfoBar* infobar_at(size_t index) { return infobars_[index]; } | 92 InfoBar* infobar_at(size_t index) { return infobars_[index]; } |
| 93 | 93 |
| 94 // Must be called when a navigation happens. | 94 // Must be called when a navigation happens. |
| 95 void OnNavigation(const InfoBarDelegate::NavigationDetails& details); | 95 void OnNavigation(const InfoBarDelegate::NavigationDetails& details); |
| 96 | 96 |
| 97 void AddObserver(Observer* obs); | 97 void AddObserver(Observer* obs); |
| 98 void RemoveObserver(Observer* obs); | 98 void RemoveObserver(Observer* obs); |
| 99 | 99 |
| 100 // Returns the active entry ID. | 100 // Returns the active entry ID. |
| 101 virtual int GetActiveEntryID() = 0; | 101 virtual int GetActiveEntryID() = 0; |
| 102 | 102 |
| 103 // Returns a confirm infobar that owns |delegate|. | 103 // Returns a confirm infobar that owns |delegate|. |
| 104 virtual scoped_ptr<infobars::InfoBar> CreateConfirmInfoBar( | 104 virtual std::unique_ptr<infobars::InfoBar> CreateConfirmInfoBar( |
| 105 scoped_ptr<ConfirmInfoBarDelegate> delegate) = 0; | 105 std::unique_ptr<ConfirmInfoBarDelegate> delegate) = 0; |
| 106 | 106 |
| 107 // Opens a URL according to the specified |disposition|. | 107 // Opens a URL according to the specified |disposition|. |
| 108 virtual void OpenURL(const GURL& url, WindowOpenDisposition disposition) = 0; | 108 virtual void OpenURL(const GURL& url, WindowOpenDisposition disposition) = 0; |
| 109 | 109 |
| 110 protected: | 110 protected: |
| 111 // Notifies the observer in |observer_list_|. | 111 // Notifies the observer in |observer_list_|. |
| 112 // TODO(droger): Absorb these methods back into their callers once virtual | 112 // TODO(droger): Absorb these methods back into their callers once virtual |
| 113 // overrides are removed (see http://crbug.com/354380). | 113 // overrides are removed (see http://crbug.com/354380). |
| 114 virtual void NotifyInfoBarAdded(InfoBar* infobar); | 114 virtual void NotifyInfoBarAdded(InfoBar* infobar); |
| 115 virtual void NotifyInfoBarRemoved(InfoBar* infobar, bool animate); | 115 virtual void NotifyInfoBarRemoved(InfoBar* infobar, bool animate); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 128 bool infobars_enabled_; | 128 bool infobars_enabled_; |
| 129 | 129 |
| 130 base::ObserverList<Observer, true> observer_list_; | 130 base::ObserverList<Observer, true> observer_list_; |
| 131 | 131 |
| 132 DISALLOW_COPY_AND_ASSIGN(InfoBarManager); | 132 DISALLOW_COPY_AND_ASSIGN(InfoBarManager); |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 } // namespace infobars | 135 } // namespace infobars |
| 136 | 136 |
| 137 #endif // COMPONENTS_INFOBARS_CORE_INFOBAR_MANAGER_H_ | 137 #endif // COMPONENTS_INFOBARS_CORE_INFOBAR_MANAGER_H_ |
| OLD | NEW |