blob: 06e27f3a7eb9b9924ab3cd67f25fbcf8f3c4ba8c [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>
9
10#include "base/macros.h"
11#include "base/memory/weak_ptr.h"
12#include "chrome/browser/infobars/infobar_service.h"
13#include "chrome/browser/ui/browser_tab_strip_tracker.h"
14#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
15#include "components/infobars/core/confirm_infobar_delegate.h"
16
17namespace content {
18class WebContents;
19}
20
21// GlobalConfirmInfoBar is shown for every tab in every browser until it
22// is dismissed or the close method is called.
23// It listens to all tabs in all browsers and adds/removes confirm infobar
24// to each of the tabs.
25class GlobalConfirmInfoBar : public TabStripModelObserver,
26 public infobars::InfoBarManager::Observer {
27 public:
dchengb8eac3a2016-04-13 02:03:2328 static base::WeakPtr<GlobalConfirmInfoBar> Show(
29 std::unique_ptr<ConfirmInfoBarDelegate> delegate);
pfeldmand3a885c2015-10-22 23:28:2630 void Close();
31
johnchen4c5a6de62017-04-14 04:25:3432 // infobars::InfoBarManager::Observer:
33 void OnInfoBarRemoved(infobars::InfoBar* info_bar, bool animate) override;
34 void OnManagerShuttingDown(infobars::InfoBarManager* manager) override;
35
pfeldmand3a885c2015-10-22 23:28:2636 private:
dchengb8eac3a2016-04-13 02:03:2337 explicit GlobalConfirmInfoBar(
38 std::unique_ptr<ConfirmInfoBarDelegate> delegate);
pfeldmand3a885c2015-10-22 23:28:2639 ~GlobalConfirmInfoBar() override;
40 class DelegateProxy;
41
42 // TabStripModelObserver:
pmonette9119e492016-09-20 22:14:5543 void TabInsertedAt(TabStripModel* tab_strip_model,
44 content::WebContents* web_contents,
pfeldmand3a885c2015-10-22 23:28:2645 int index,
46 bool foreground) override;
47 void TabChangedAt(content::WebContents* web_contents,
48 int index,
49 TabChangeType change_type) override;
50
pmonette9119e492016-09-20 22:14:5551 // Adds the info bar to the tab if it is missing.
52 void MaybeAddInfoBar(content::WebContents* web_contents);
53
dchengb8eac3a2016-04-13 02:03:2354 std::unique_ptr<ConfirmInfoBarDelegate> delegate_;
pfeldmand3a885c2015-10-22 23:28:2655 std::map<infobars::InfoBarManager*, DelegateProxy*> proxies_;
56 BrowserTabStripTracker browser_tab_strip_tracker_;
57
58 base::WeakPtrFactory<GlobalConfirmInfoBar> weak_factory_;
59
60 DISALLOW_COPY_AND_ASSIGN(GlobalConfirmInfoBar);
61};
62
63#endif // CHROME_BROWSER_DEVTOOLS_GLOBAL_CONFIRM_INFO_BAR_H_