blob: c1bfa57d48831871eba03da9d216fe1cd2161618 [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"
13#include "chrome/browser/infobars/infobar_service.h"
14#include "chrome/browser/ui/browser_tab_strip_tracker.h"
15#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
16#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.
40 static void Show(std::unique_ptr<ConfirmInfoBarDelegate> delegate);
pfeldmand3a885c2015-10-22 23:28:2641
johnchen4c5a6de62017-04-14 04:25:3442 // infobars::InfoBarManager::Observer:
43 void OnInfoBarRemoved(infobars::InfoBar* info_bar, bool animate) override;
44 void OnManagerShuttingDown(infobars::InfoBarManager* manager) override;
45
pfeldmand3a885c2015-10-22 23:28:2646 private:
Peter Kasting0cdd929e2020-05-08 04:26:3247 class DelegateProxy;
48
dchengb8eac3a2016-04-13 02:03:2349 explicit GlobalConfirmInfoBar(
50 std::unique_ptr<ConfirmInfoBarDelegate> delegate);
pfeldmand3a885c2015-10-22 23:28:2651 ~GlobalConfirmInfoBar() override;
pfeldmand3a885c2015-10-22 23:28:2652
53 // TabStripModelObserver:
sangwoo.kob4ce470b2018-08-09 07:47:0254 void OnTabStripModelChanged(
sangwoo.koa60a2e62018-08-14 05:39:4755 TabStripModel* tab_strip_model,
sangwoo.kob4ce470b2018-08-09 07:47:0256 const TabStripModelChange& change,
57 const TabStripSelectionChange& selection) override;
pfeldmand3a885c2015-10-22 23:28:2658 void TabChangedAt(content::WebContents* web_contents,
59 int index,
60 TabChangeType change_type) override;
61
pmonette9119e492016-09-20 22:14:5562 // Adds the info bar to the tab if it is missing.
63 void MaybeAddInfoBar(content::WebContents* web_contents);
64
Peter Kasting0cdd929e2020-05-08 04:26:3265 // Closes all the infobars.
66 void Close();
67
dchengb8eac3a2016-04-13 02:03:2368 std::unique_ptr<ConfirmInfoBarDelegate> delegate_;
pfeldmand3a885c2015-10-22 23:28:2669 std::map<infobars::InfoBarManager*, DelegateProxy*> proxies_;
Francois Dorayc39105b2020-03-12 17:44:5670 BrowserTabStripTracker browser_tab_strip_tracker_{this, nullptr};
pfeldmand3a885c2015-10-22 23:28:2671
Patrick Monette592bf1a2017-08-22 19:42:1872 // Indicates if the global infobar is currently in the process of shutting
73 // down.
Peter Kasting182d71d2020-01-07 05:28:1874 bool is_closing_ = false;
Patrick Monette592bf1a2017-08-22 19:42:1875
Jeremy Roman495db682019-07-12 16:03:2476 base::WeakPtrFactory<GlobalConfirmInfoBar> weak_factory_{this};
pfeldmand3a885c2015-10-22 23:28:2677
78 DISALLOW_COPY_AND_ASSIGN(GlobalConfirmInfoBar);
79};
80
81#endif // CHROME_BROWSER_DEVTOOLS_GLOBAL_CONFIRM_INFO_BAR_H_