blob: a91996d3493155a45803bce40a6ab3614af1e92c [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.
26class GlobalConfirmInfoBar : public TabStripModelObserver,
27 public infobars::InfoBarManager::Observer {
28 public:
dchengb8eac3a2016-04-13 02:03:2329 static base::WeakPtr<GlobalConfirmInfoBar> Show(
30 std::unique_ptr<ConfirmInfoBarDelegate> delegate);
Patrick Monette592bf1a2017-08-22 19:42:1831
32 // Closes all the infobars.
pfeldmand3a885c2015-10-22 23:28:2633 void Close();
34
johnchen4c5a6de62017-04-14 04:25:3435 // infobars::InfoBarManager::Observer:
36 void OnInfoBarRemoved(infobars::InfoBar* info_bar, bool animate) override;
37 void OnManagerShuttingDown(infobars::InfoBarManager* manager) override;
38
pfeldmand3a885c2015-10-22 23:28:2639 private:
dchengb8eac3a2016-04-13 02:03:2340 explicit GlobalConfirmInfoBar(
41 std::unique_ptr<ConfirmInfoBarDelegate> delegate);
pfeldmand3a885c2015-10-22 23:28:2642 ~GlobalConfirmInfoBar() override;
43 class DelegateProxy;
44
45 // TabStripModelObserver:
sangwoo.kob4ce470b2018-08-09 07:47:0246 void OnTabStripModelChanged(
47 const TabStripModelChange& change,
48 const TabStripSelectionChange& selection) override;
pfeldmand3a885c2015-10-22 23:28:2649 void TabChangedAt(content::WebContents* web_contents,
50 int index,
51 TabChangeType change_type) override;
52
pmonette9119e492016-09-20 22:14:5553 // Adds the info bar to the tab if it is missing.
54 void MaybeAddInfoBar(content::WebContents* web_contents);
55
dchengb8eac3a2016-04-13 02:03:2356 std::unique_ptr<ConfirmInfoBarDelegate> delegate_;
pfeldmand3a885c2015-10-22 23:28:2657 std::map<infobars::InfoBarManager*, DelegateProxy*> proxies_;
58 BrowserTabStripTracker browser_tab_strip_tracker_;
59
Patrick Monette592bf1a2017-08-22 19:42:1860 // Indicates if the global infobar is currently in the process of shutting
61 // down.
62 bool is_closing_;
63
pfeldmand3a885c2015-10-22 23:28:2664 base::WeakPtrFactory<GlobalConfirmInfoBar> weak_factory_;
65
66 DISALLOW_COPY_AND_ASSIGN(GlobalConfirmInfoBar);
67};
68
69#endif // CHROME_BROWSER_DEVTOOLS_GLOBAL_CONFIRM_INFO_BAR_H_