blob: a335c0b1b669f211e5070192e44a5c4130ce7afd [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2014 The Chromium Authors
pfeldmand3a885c2015-10-22 23:28:262// 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 Monette592bf1a2017-08-22 19:42:189#include <memory>
pfeldmand3a885c2015-10-22 23:28:2610
Ali Hijazi60a72b0a2024-09-30 17:58:5311#include "base/memory/raw_ptr.h"
pfeldmand3a885c2015-10-22 23:28:2612#include "base/memory/weak_ptr.h"
pfeldmand3a885c2015-10-22 23:28:2613#include "chrome/browser/ui/browser_tab_strip_tracker.h"
14#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
Colin Blundelle70a6d82021-05-04 12:03:1915#include "components/infobars/content/content_infobar_manager.h"
pfeldmand3a885c2015-10-22 23:28:2616#include "components/infobars/core/confirm_infobar_delegate.h"
17
18namespace content {
19class 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 Kasting0cdd929e2020-05-08 04:26:3226// 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).
pfeldmand3a885c2015-10-22 23:28:2631class GlobalConfirmInfoBar : public TabStripModelObserver,
32 public infobars::InfoBarManager::Observer {
33 public:
Peter Kasting0cdd929e2020-05-08 04:26:3234 // 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 Hosseinabadi301cdb42020-10-02 20:16:5740 static GlobalConfirmInfoBar* Show(
41 std::unique_ptr<ConfirmInfoBarDelegate> delegate);
pfeldmand3a885c2015-10-22 23:28:2642
Peter Boströmfadb1752021-09-30 19:17:0143 GlobalConfirmInfoBar(const GlobalConfirmInfoBar&) = delete;
44 GlobalConfirmInfoBar& operator=(const GlobalConfirmInfoBar&) = delete;
45
johnchen4c5a6de62017-04-14 04:25:3446 // infobars::InfoBarManager::Observer:
47 void OnInfoBarRemoved(infobars::InfoBar* info_bar, bool animate) override;
48 void OnManagerShuttingDown(infobars::InfoBarManager* manager) override;
49
Ghazale Hosseinabadi301cdb42020-10-02 20:16:5750 // Closes all the infobars.
51 void Close();
52
pfeldmand3a885c2015-10-22 23:28:2653 private:
Peter Kasting0cdd929e2020-05-08 04:26:3254 class DelegateProxy;
55
dchengb8eac3a2016-04-13 02:03:2356 explicit GlobalConfirmInfoBar(
57 std::unique_ptr<ConfirmInfoBarDelegate> delegate);
pfeldmand3a885c2015-10-22 23:28:2658 ~GlobalConfirmInfoBar() override;
pfeldmand3a885c2015-10-22 23:28:2659
60 // TabStripModelObserver:
sangwoo.kob4ce470b2018-08-09 07:47:0261 void OnTabStripModelChanged(
sangwoo.koa60a2e62018-08-14 05:39:4762 TabStripModel* tab_strip_model,
sangwoo.kob4ce470b2018-08-09 07:47:0263 const TabStripModelChange& change,
64 const TabStripSelectionChange& selection) override;
pfeldmand3a885c2015-10-22 23:28:2665 void TabChangedAt(content::WebContents* web_contents,
66 int index,
67 TabChangeType change_type) override;
68
pmonette9119e492016-09-20 22:14:5569 // Adds the info bar to the tab if it is missing.
70 void MaybeAddInfoBar(content::WebContents* web_contents);
71
dchengb8eac3a2016-04-13 02:03:2372 std::unique_ptr<ConfirmInfoBarDelegate> delegate_;
Ali Hijazi60a72b0a2024-09-30 17:58:5373 std::map<infobars::InfoBarManager*, raw_ptr<DelegateProxy, CtnExperimental>>
74 proxies_;
Francois Dorayc39105b2020-03-12 17:44:5675 BrowserTabStripTracker browser_tab_strip_tracker_{this, nullptr};
pfeldmand3a885c2015-10-22 23:28:2676
Patrick Monette592bf1a2017-08-22 19:42:1877 // Indicates if the global infobar is currently in the process of shutting
78 // down.
Peter Kasting182d71d2020-01-07 05:28:1879 bool is_closing_ = false;
Patrick Monette592bf1a2017-08-22 19:42:1880
Jeremy Roman495db682019-07-12 16:03:2481 base::WeakPtrFactory<GlobalConfirmInfoBar> weak_factory_{this};
pfeldmand3a885c2015-10-22 23:28:2682};
83
84#endif // CHROME_BROWSER_DEVTOOLS_GLOBAL_CONFIRM_INFO_BAR_H_