blob: d243f9468fc44179131057892fb1cada3571cc64 [file] [log] [blame]
pfeldmand3a885c2015-10-22 23:28:261// 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 Monette592bf1a2017-08-22 19:42:189#include <memory>
pfeldmand3a885c2015-10-22 23:28:2610
11#include "base/macros.h"
12#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
johnchen4c5a6de62017-04-14 04:25:3443 // infobars::InfoBarManager::Observer:
44 void OnInfoBarRemoved(infobars::InfoBar* info_bar, bool animate) override;
45 void OnManagerShuttingDown(infobars::InfoBarManager* manager) override;
46
Ghazale Hosseinabadi301cdb42020-10-02 20:16:5747 // Closes all the infobars.
48 void Close();
49
pfeldmand3a885c2015-10-22 23:28:2650 private:
Peter Kasting0cdd929e2020-05-08 04:26:3251 class DelegateProxy;
52
dchengb8eac3a2016-04-13 02:03:2353 explicit GlobalConfirmInfoBar(
54 std::unique_ptr<ConfirmInfoBarDelegate> delegate);
pfeldmand3a885c2015-10-22 23:28:2655 ~GlobalConfirmInfoBar() override;
pfeldmand3a885c2015-10-22 23:28:2656
57 // TabStripModelObserver:
sangwoo.kob4ce470b2018-08-09 07:47:0258 void OnTabStripModelChanged(
sangwoo.koa60a2e62018-08-14 05:39:4759 TabStripModel* tab_strip_model,
sangwoo.kob4ce470b2018-08-09 07:47:0260 const TabStripModelChange& change,
61 const TabStripSelectionChange& selection) override;
pfeldmand3a885c2015-10-22 23:28:2662 void TabChangedAt(content::WebContents* web_contents,
63 int index,
64 TabChangeType change_type) override;
65
pmonette9119e492016-09-20 22:14:5566 // Adds the info bar to the tab if it is missing.
67 void MaybeAddInfoBar(content::WebContents* web_contents);
68
dchengb8eac3a2016-04-13 02:03:2369 std::unique_ptr<ConfirmInfoBarDelegate> delegate_;
pfeldmand3a885c2015-10-22 23:28:2670 std::map<infobars::InfoBarManager*, DelegateProxy*> proxies_;
Francois Dorayc39105b2020-03-12 17:44:5671 BrowserTabStripTracker browser_tab_strip_tracker_{this, nullptr};
pfeldmand3a885c2015-10-22 23:28:2672
Patrick Monette592bf1a2017-08-22 19:42:1873 // Indicates if the global infobar is currently in the process of shutting
74 // down.
Peter Kasting182d71d2020-01-07 05:28:1875 bool is_closing_ = false;
Patrick Monette592bf1a2017-08-22 19:42:1876
Jeremy Roman495db682019-07-12 16:03:2477 base::WeakPtrFactory<GlobalConfirmInfoBar> weak_factory_{this};
pfeldmand3a885c2015-10-22 23:28:2678
79 DISALLOW_COPY_AND_ASSIGN(GlobalConfirmInfoBar);
80};
81
82#endif // CHROME_BROWSER_DEVTOOLS_GLOBAL_CONFIRM_INFO_BAR_H_