1 // Copyright 2012 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.
5 #ifndef COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_
6 #define COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "components/web_modal/single_web_contents_dialog_manager.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h"
14 #include "ui/gfx/native_widget_types.h"
18 class WebContentsModalDialogManagerDelegate
;
20 // Per-WebContents class to manage WebContents-modal dialogs.
21 class WebContentsModalDialogManager
22 : public SingleWebContentsDialogManagerDelegate
,
23 public content::WebContentsObserver
,
24 public content::WebContentsUserData
<WebContentsModalDialogManager
> {
26 ~WebContentsModalDialogManager() override
;
28 WebContentsModalDialogManagerDelegate
* delegate() const { return delegate_
; }
29 void SetDelegate(WebContentsModalDialogManagerDelegate
* d
);
31 static SingleWebContentsDialogManager
* CreateNativeWebModalManager(
32 gfx::NativeWindow dialog
,
33 SingleWebContentsDialogManagerDelegate
* native_delegate
);
35 // Shows the dialog as a web contents modal dialog. The dialog will notify via
36 // WillClose() when it is being destroyed.
37 void ShowModalDialog(gfx::NativeWindow dialog
);
39 // Allow clients to supply their own native dialog manager. Suitable for
41 void ShowDialogWithManager(
42 gfx::NativeWindow dialog
,
43 scoped_ptr
<SingleWebContentsDialogManager
> manager
);
45 // Returns true if any dialogs are active and not closed.
46 bool IsDialogActive() const;
48 // Focus the topmost modal dialog. IsDialogActive() must be true when calling
50 void FocusTopmostDialog() const;
52 // SingleWebContentsDialogManagerDelegate:
53 content::WebContents
* GetWebContents() const override
;
54 void WillClose(gfx::NativeWindow dialog
) override
;
59 explicit TestApi(WebContentsModalDialogManager
* manager
)
60 : manager_(manager
) {}
62 void CloseAllDialogs() { manager_
->CloseAllDialogs(); }
63 void DidAttachInterstitialPage() { manager_
->DidAttachInterstitialPage(); }
64 void WebContentsWasShown() { manager_
->WasShown(); }
65 void WebContentsWasHidden() { manager_
->WasHidden(); }
68 WebContentsModalDialogManager
* manager_
;
70 DISALLOW_COPY_AND_ASSIGN(TestApi
);
74 explicit WebContentsModalDialogManager(content::WebContents
* web_contents
);
75 friend class content::WebContentsUserData
<WebContentsModalDialogManager
>;
78 DialogState(gfx::NativeWindow dialog
,
79 scoped_ptr
<SingleWebContentsDialogManager
> manager
);
82 gfx::NativeWindow dialog
;
83 scoped_ptr
<SingleWebContentsDialogManager
> manager
;
86 typedef std::deque
<DialogState
*> WebContentsModalDialogList
;
88 // Utility function to get the dialog state for a dialog.
89 WebContentsModalDialogList::iterator
FindDialogState(
90 gfx::NativeWindow dialog
);
92 // Blocks/unblocks interaction with renderer process.
93 void BlockWebContentsInteraction(bool blocked
);
95 bool IsWebContentsVisible() const;
97 // Closes all WebContentsModalDialogs.
98 void CloseAllDialogs();
100 // Overridden from content::WebContentsObserver:
101 void DidNavigateMainFrame(
102 const content::LoadCommittedDetails
& details
,
103 const content::FrameNavigateParams
& params
) override
;
104 void DidGetIgnoredUIEvent() override
;
105 void WasShown() override
;
106 void WasHidden() override
;
107 void WebContentsDestroyed() override
;
108 void DidAttachInterstitialPage() override
;
110 // Delegate for notifying our owner about stuff. Not owned by us.
111 WebContentsModalDialogManagerDelegate
* delegate_
;
113 // All active dialogs.
114 WebContentsModalDialogList child_dialogs_
;
116 // True while closing the dialogs on WebContents close.
117 bool closing_all_dialogs_
;
119 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogManager
);
122 } // namespace web_modal
124 #endif // COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_