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> |
Patrick Monette | 592bf1a | 2017-08-22 19:42:18 | [diff] [blame] | 9 | #include <memory> |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 10 | |
| 11 | #include "base/macros.h" |
| 12 | #include "base/memory/weak_ptr.h" |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser_tab_strip_tracker.h" |
| 14 | #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
Colin Blundell | e70a6d8 | 2021-05-04 12:03:19 | [diff] [blame^] | 15 | #include "components/infobars/content/content_infobar_manager.h" |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 16 | #include "components/infobars/core/confirm_infobar_delegate.h" |
| 17 | |
| 18 | namespace content { |
| 19 | class WebContents; |
| 20 | } |
| 21 | |
| 22 | // GlobalConfirmInfoBar is shown for every tab in every browser until it |
| 23 | // is dismissed or the close method is called. |
| 24 | // It listens to all tabs in all browsers and adds/removes confirm infobar |
| 25 | // to each of the tabs. |
Peter Kasting | 0cdd929e | 2020-05-08 04:26:32 | [diff] [blame] | 26 | // TODO(pkasting): This is a hack, driven by the original design of infobars |
| 27 | // being tab-scoped. Either this should be replaced by a different UI for |
| 28 | // whole-browser notifications, or the core infobar APIs should better |
| 29 | // accommodate these sorts of infobars (e.g. with a separate "global infobar |
| 30 | // manager" object or the like). |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 31 | class GlobalConfirmInfoBar : public TabStripModelObserver, |
| 32 | public infobars::InfoBarManager::Observer { |
| 33 | public: |
Peter Kasting | 0cdd929e | 2020-05-08 04:26:32 | [diff] [blame] | 34 | // Attempts to show a global infobar for |delegate|. If infobar addition |
| 35 | // fails (e.g. because infobars are disabled), the global infobar will not |
| 36 | // appear, and it (and |delegate|) will be deleted asynchronously. Otherwise, |
| 37 | // the delegate will be deleted synchronously when any of the tabs' infobars |
| 38 | // is closed via user action. Note that both of these aspects of lifetime |
| 39 | // management differ from how typical infobars work. |
Ghazale Hosseinabadi | 301cdb4 | 2020-10-02 20:16:57 | [diff] [blame] | 40 | static GlobalConfirmInfoBar* Show( |
| 41 | std::unique_ptr<ConfirmInfoBarDelegate> delegate); |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 42 | |
johnchen | 4c5a6de6 | 2017-04-14 04:25:34 | [diff] [blame] | 43 | // infobars::InfoBarManager::Observer: |
| 44 | void OnInfoBarRemoved(infobars::InfoBar* info_bar, bool animate) override; |
| 45 | void OnManagerShuttingDown(infobars::InfoBarManager* manager) override; |
| 46 | |
Ghazale Hosseinabadi | 301cdb4 | 2020-10-02 20:16:57 | [diff] [blame] | 47 | // Closes all the infobars. |
| 48 | void Close(); |
| 49 | |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 50 | private: |
Peter Kasting | 0cdd929e | 2020-05-08 04:26:32 | [diff] [blame] | 51 | class DelegateProxy; |
| 52 | |
dcheng | b8eac3a | 2016-04-13 02:03:23 | [diff] [blame] | 53 | explicit GlobalConfirmInfoBar( |
| 54 | std::unique_ptr<ConfirmInfoBarDelegate> delegate); |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 55 | ~GlobalConfirmInfoBar() override; |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 56 | |
| 57 | // TabStripModelObserver: |
sangwoo.ko | b4ce470b | 2018-08-09 07:47:02 | [diff] [blame] | 58 | void OnTabStripModelChanged( |
sangwoo.ko | a60a2e6 | 2018-08-14 05:39:47 | [diff] [blame] | 59 | TabStripModel* tab_strip_model, |
sangwoo.ko | b4ce470b | 2018-08-09 07:47:02 | [diff] [blame] | 60 | const TabStripModelChange& change, |
| 61 | const TabStripSelectionChange& selection) override; |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 62 | void TabChangedAt(content::WebContents* web_contents, |
| 63 | int index, |
| 64 | TabChangeType change_type) override; |
| 65 | |
pmonette | 9119e49 | 2016-09-20 22:14:55 | [diff] [blame] | 66 | // Adds the info bar to the tab if it is missing. |
| 67 | void MaybeAddInfoBar(content::WebContents* web_contents); |
| 68 | |
dcheng | b8eac3a | 2016-04-13 02:03:23 | [diff] [blame] | 69 | std::unique_ptr<ConfirmInfoBarDelegate> delegate_; |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 70 | std::map<infobars::InfoBarManager*, DelegateProxy*> proxies_; |
Francois Doray | c39105b | 2020-03-12 17:44:56 | [diff] [blame] | 71 | BrowserTabStripTracker browser_tab_strip_tracker_{this, nullptr}; |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 72 | |
Patrick Monette | 592bf1a | 2017-08-22 19:42:18 | [diff] [blame] | 73 | // Indicates if the global infobar is currently in the process of shutting |
| 74 | // down. |
Peter Kasting | 182d71d | 2020-01-07 05:28:18 | [diff] [blame] | 75 | bool is_closing_ = false; |
Patrick Monette | 592bf1a | 2017-08-22 19:42:18 | [diff] [blame] | 76 | |
Jeremy Roman | 495db68 | 2019-07-12 16:03:24 | [diff] [blame] | 77 | base::WeakPtrFactory<GlobalConfirmInfoBar> weak_factory_{this}; |
pfeldman | d3a885c | 2015-10-22 23:28:26 | [diff] [blame] | 78 | |
| 79 | DISALLOW_COPY_AND_ASSIGN(GlobalConfirmInfoBar); |
| 80 | }; |
| 81 | |
| 82 | #endif // CHROME_BROWSER_DEVTOOLS_GLOBAL_CONFIRM_INFO_BAR_H_ |