File: tab_dialog_manager.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (117 lines) | stat: -rw-r--r-- 4,729 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_TABS_PUBLIC_TAB_DIALOG_MANAGER_H_
#define CHROME_BROWSER_UI_TABS_PUBLIC_TAB_DIALOG_MANAGER_H_

#include <memory>
#include <optional>

#include "base/callback_list.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "components/tabs/public/tab_interface.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"

namespace views {
class Widget;
class WidgetObserver;
class DialogDelegate;
}  // namespace views

namespace tabs {

class TabDialogWidgetObserver;
class BrowserWindowWidgetObserver;

// Class provides a mechanism to show a tab-scoped dialog on desktop platforms.
// Please file a bug if you encounter any issues.
class TabDialogManager : public content::WebContentsObserver {
 public:
  explicit TabDialogManager(TabInterface* tab_interface);
  TabDialogManager(const TabDialogManager&) = delete;
  TabDialogManager& operator=(const TabDialogManager&) = delete;
  ~TabDialogManager() override;

  // Parameters that are used to configure the behavior of the tab dialog.
  struct Params {
    // If the tab's main frame performs a different-site navigation, close the
    // dialog.
    bool close_on_navigate = true;

    // If the tab is detached, close the dialog.
    bool close_on_detach = true;

    // Disable input on the underlying WebContents.
    bool disable_input = true;
  };

  // Create a dialog widget from the given DialogDelegate suitable for showing
  // as scoped to a tab.
  std::unique_ptr<views::Widget> CreateTabScopedDialog(
      views::DialogDelegate* delegate);
  // Shows a widget scoped to the associated `tab_interface_`. Only one
  // tab-scoped dialog widget may be shown at a time. Interrogate
  // TabInterface::CanShowModalUI() to determine whether it is safe to call this
  // function. The dialog is centered above the hosting view as obtained via
  // TabInterface::GetBrowserWindowInterface() and will be shown/hidden along
  // with the tab. Currently, the returned widget's ownership model is still
  // dependent on ownership within the DialogDelegate. If the call-site
  // ownership hasn't been migrated to CLIENT_OWNS_WIDGET or
  // WIDGET_OWNS_NATIVE_WIDGET, do not hold on to the Widget as a unique_ptr.
  // TODO(kylixrd):
  //   (1) Call-sites expect to own the Widget using CLIENT_OWNS_WIDGET and be
  //       updated accordingly.
  void ShowDialog(views::Widget* dialog, std::unique_ptr<Params> params);
  // Combines the above two functions into a single invocation. This is the most
  // commonly used version. Only use the other APIs if the caller must do
  // something special with the widget.
  std::unique_ptr<views::Widget> CreateAndShowDialog(
      views::DialogDelegate* delegate,
      std::unique_ptr<Params> params);

  void CloseDialog();

  // Resets all state associated with `widget_`.
  // Called in two different circumstances:
  //  * From an internal WidgetObserver when the Widget is in the process of
  //    being destroyed by external code.
  //  * From CloseDialog(), right before calling Close() on the widget.
  void WidgetDestroyed(views::Widget* widget);

  // Returns the widget associated with the browser window. This widget is used
  // as the parent for tab-scoped widgets.
  views::Widget* GetHostWidget() const;

 private:
  // Overridden from content::WebContentObserver:
  void DidFinishNavigation(
      content::NavigationHandle* navigation_handle) override;

  void TabDidEnterForeground(TabInterface* tab_interface);
  void TabWillEnterBackground(TabInterface* tab_interface);
  void TabWillDetach(TabInterface* tab_interface,
                     TabInterface::DetachReason reason);

  raw_ptr<TabInterface> tab_interface_ = nullptr;
  base::CallbackListSubscription tab_did_enter_foreground_subscription_;
  base::CallbackListSubscription tab_will_enter_background_subscription_;
  base::CallbackListSubscription tab_will_detach_subscription_;

  // Active dialog and associated state. These members should be set and cleared
  // simultaneously.
  raw_ptr<views::Widget> widget_;
  std::optional<content::WebContents::ScopedIgnoreInputEvents>
      scoped_ignore_input_events_;
  std::unique_ptr<TabDialogWidgetObserver> tab_dialog_widget_observer_;
  std::unique_ptr<BrowserWindowWidgetObserver> browser_window_widget_observer_;
  std::unique_ptr<ScopedTabModalUI> showing_modal_ui_;
  std::unique_ptr<Params> params_;
};

}  // namespace tabs

#endif  // CHROME_BROWSER_UI_TABS_PUBLIC_TAB_DIALOG_MANAGER_H_