Revert 282130 "Adds API test for imageWriterPrivate.writeFromFile"
[chromium-blink-merge.git] / components / web_modal / web_contents_modal_dialog_manager.h
blob753130158cbab471866ba2e738b5a6abd0ee71f6
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_
8 #include <deque>
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"
16 namespace web_modal {
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> {
25 public:
26 virtual ~WebContentsModalDialogManager();
28 WebContentsModalDialogManagerDelegate* delegate() const { return delegate_; }
29 void SetDelegate(WebContentsModalDialogManagerDelegate* d);
31 static SingleWebContentsDialogManager* CreateNativeWebModalManager(
32 NativeWebContentsModalDialog 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(NativeWebContentsModalDialog dialog);
39 // Allow clients to supply their own native dialog manager. Suitable for
40 // bubble clients.
41 void ShowDialogWithManager(
42 NativeWebContentsModalDialog 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
49 // this function.
50 void FocusTopmostDialog();
52 // Overriden from SingleWebContentsDialogManagerDelegate:
53 virtual content::WebContents* GetWebContents() const OVERRIDE;
54 // Called when a WebContentsModalDialogs we own is about to be closed.
55 virtual void WillClose(NativeWebContentsModalDialog dialog) OVERRIDE;
57 // For testing.
58 class TestApi {
59 public:
60 explicit TestApi(WebContentsModalDialogManager* manager)
61 : manager_(manager) {}
63 void CloseAllDialogs() { manager_->CloseAllDialogs(); }
64 void DidAttachInterstitialPage() { manager_->DidAttachInterstitialPage(); }
65 void WebContentsWasShown() { manager_->WasShown(); }
66 void WebContentsWasHidden() { manager_->WasHidden(); }
68 private:
69 WebContentsModalDialogManager* manager_;
71 DISALLOW_COPY_AND_ASSIGN(TestApi);
74 private:
75 explicit WebContentsModalDialogManager(content::WebContents* web_contents);
76 friend class content::WebContentsUserData<WebContentsModalDialogManager>;
78 struct DialogState {
79 DialogState(NativeWebContentsModalDialog dialog,
80 scoped_ptr<SingleWebContentsDialogManager> manager);
81 ~DialogState();
83 NativeWebContentsModalDialog dialog;
84 scoped_ptr<SingleWebContentsDialogManager> manager;
87 typedef std::deque<DialogState*> WebContentsModalDialogList;
89 // Utility function to get the dialog state for a dialog.
90 WebContentsModalDialogList::iterator FindDialogState(
91 NativeWebContentsModalDialog dialog);
93 // Blocks/unblocks interaction with renderer process.
94 void BlockWebContentsInteraction(bool blocked);
96 bool IsWebContentsVisible() const;
98 // Closes all WebContentsModalDialogs.
99 void CloseAllDialogs();
101 // Overridden from content::WebContentsObserver:
102 virtual void DidNavigateMainFrame(
103 const content::LoadCommittedDetails& details,
104 const content::FrameNavigateParams& params) OVERRIDE;
105 virtual void DidGetIgnoredUIEvent() OVERRIDE;
106 virtual void WasShown() OVERRIDE;
107 virtual void WasHidden() OVERRIDE;
108 virtual void WebContentsDestroyed() OVERRIDE;
109 virtual void DidAttachInterstitialPage() OVERRIDE;
111 // Delegate for notifying our owner about stuff. Not owned by us.
112 WebContentsModalDialogManagerDelegate* delegate_;
114 // All active dialogs.
115 WebContentsModalDialogList child_dialogs_;
117 // True while closing the dialogs on WebContents close.
118 bool closing_all_dialogs_;
120 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogManager);
123 } // namespace web_modal
125 #endif // COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_