pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_DEVTOOLS_GLOBAL_CONFIRM_INFO_BAR_H_ |
| 6 | #define CHROME_BROWSER_DEVTOOLS_GLOBAL_CONFIRM_INFO_BAR_H_ |
| 7 | |
| 8 | #include <map> |
| 9 | |
| 10 | #include "base/macros.h" |
| 11 | #include "base/memory/weak_ptr.h" |
| 12 | #include "chrome/browser/infobars/infobar_service.h" |
| 13 | #include "chrome/browser/ui/browser_tab_strip_tracker.h" |
| 14 | #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 15 | #include "components/infobars/core/confirm_infobar_delegate.h" |
| 16 | |
| 17 | namespace content { |
| 18 | class WebContents; |
| 19 | } |
| 20 | |
| 21 | // GlobalConfirmInfoBar is shown for every tab in every browser until it |
| 22 | // is dismissed or the close method is called. |
| 23 | // It listens to all tabs in all browsers and adds/removes confirm infobar |
| 24 | // to each of the tabs. |
| 25 | class GlobalConfirmInfoBar : public TabStripModelObserver, |
| 26 | public infobars::InfoBarManager::Observer { |
| 27 | public: |
dcheng | b8eac3a | 2016-04-13 02:03:23 | [diff] [blame] | 28 | static base::WeakPtr<GlobalConfirmInfoBar> Show( |
| 29 | std::unique_ptr<ConfirmInfoBarDelegate> delegate); |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 30 | void Close(); |
| 31 | |
johnchen | 4c5a6de6 | 2017-04-14 04:25:34 | [diff] [blame^] | 32 | // infobars::InfoBarManager::Observer: |
| 33 | void OnInfoBarRemoved(infobars::InfoBar* info_bar, bool animate) override; |
| 34 | void OnManagerShuttingDown(infobars::InfoBarManager* manager) override; |
| 35 | |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 36 | private: |
dcheng | b8eac3a | 2016-04-13 02:03:23 | [diff] [blame] | 37 | explicit GlobalConfirmInfoBar( |
| 38 | std::unique_ptr<ConfirmInfoBarDelegate> delegate); |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 39 | ~GlobalConfirmInfoBar() override; |
| 40 | class DelegateProxy; |
| 41 | |
| 42 | // TabStripModelObserver: |
pmonette | 9119e49 | 2016-09-20 22:14:55 | [diff] [blame] | 43 | void TabInsertedAt(TabStripModel* tab_strip_model, |
| 44 | content::WebContents* web_contents, |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 45 | int index, |
| 46 | bool foreground) override; |
| 47 | void TabChangedAt(content::WebContents* web_contents, |
| 48 | int index, |
| 49 | TabChangeType change_type) override; |
| 50 | |
pmonette | 9119e49 | 2016-09-20 22:14:55 | [diff] [blame] | 51 | // Adds the info bar to the tab if it is missing. |
| 52 | void MaybeAddInfoBar(content::WebContents* web_contents); |
| 53 | |
dcheng | b8eac3a | 2016-04-13 02:03:23 | [diff] [blame] | 54 | std::unique_ptr<ConfirmInfoBarDelegate> delegate_; |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 55 | std::map<infobars::InfoBarManager*, DelegateProxy*> proxies_; |
| 56 | BrowserTabStripTracker browser_tab_strip_tracker_; |
| 57 | |
| 58 | base::WeakPtrFactory<GlobalConfirmInfoBar> weak_factory_; |
| 59 | |
| 60 | DISALLOW_COPY_AND_ASSIGN(GlobalConfirmInfoBar); |
| 61 | }; |
| 62 | |
| 63 | #endif // CHROME_BROWSER_DEVTOOLS_GLOBAL_CONFIRM_INFO_BAR_H_ |