OLD | NEW |
| (Empty) |
1 // Copyright (c) 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. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ | |
6 #define CHROME_BROWSER_UI_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ | |
7 | |
8 #include <deque> | |
9 | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "chrome/browser/ui/native_web_contents_modal_dialog_manager.h" | |
12 #include "content/public/browser/notification_observer.h" | |
13 #include "content/public/browser/notification_registrar.h" | |
14 #include "content/public/browser/web_contents_observer.h" | |
15 #include "content/public/browser/web_contents_user_data.h" | |
16 #include "ui/gfx/native_widget_types.h" | |
17 | |
18 class WebContentsModalDialogManagerDelegate; | |
19 | |
20 // Per-WebContents class to manage WebContents-modal dialogs. | |
21 class WebContentsModalDialogManager | |
22 : public NativeWebContentsModalDialogManagerDelegate, | |
23 public content::WebContentsObserver, | |
24 public content::WebContentsUserData<WebContentsModalDialogManager>, | |
25 public content::NotificationObserver { | |
26 public: | |
27 virtual ~WebContentsModalDialogManager(); | |
28 | |
29 WebContentsModalDialogManagerDelegate* delegate() const { return delegate_; } | |
30 void set_delegate(WebContentsModalDialogManagerDelegate* d) { delegate_ = d; } | |
31 | |
32 static NativeWebContentsModalDialogManager* CreateNativeManager( | |
33 NativeWebContentsModalDialogManagerDelegate* native_delegate); | |
34 | |
35 // Shows the dialog as a web contents modal dialog. The dialog will notify via | |
36 // WillClose() when it is being destroyed. | |
37 void ShowDialog(NativeWebContentsModalDialog dialog); | |
38 | |
39 // Returns true if a dialog is currently being shown. | |
40 bool IsShowingDialog() const; | |
41 | |
42 // Focus the topmost modal dialog. IsShowingDialog() must be true when | |
43 // calling this function. | |
44 void FocusTopmostDialog(); | |
45 | |
46 // Overriden from NativeWebContentsModalDialogManagerDelegate: | |
47 virtual content::WebContents* GetWebContents() const OVERRIDE; | |
48 // Called when a WebContentsModalDialogs we own is about to be closed. | |
49 virtual void WillClose(NativeWebContentsModalDialog dialog) OVERRIDE; | |
50 | |
51 // content::NotificationObserver overrides | |
52 virtual void Observe(int type, | |
53 const content::NotificationSource& source, | |
54 const content::NotificationDetails& details) OVERRIDE; | |
55 | |
56 // For testing. | |
57 class TestApi { | |
58 public: | |
59 explicit TestApi(WebContentsModalDialogManager* manager) | |
60 : manager_(manager) {} | |
61 | |
62 void CloseAllDialogs() { manager_->CloseAllDialogs(); } | |
63 void ResetNativeManager(NativeWebContentsModalDialogManager* delegate) { | |
64 manager_->native_manager_.reset(delegate); | |
65 } | |
66 | |
67 private: | |
68 WebContentsModalDialogManager* manager_; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(TestApi); | |
71 }; | |
72 | |
73 private: | |
74 explicit WebContentsModalDialogManager(content::WebContents* web_contents); | |
75 friend class content::WebContentsUserData<WebContentsModalDialogManager>; | |
76 | |
77 typedef std::deque<NativeWebContentsModalDialog> WebContentsModalDialogList; | |
78 | |
79 // Blocks/unblocks interaction with renderer process. | |
80 void BlockWebContentsInteraction(bool blocked); | |
81 | |
82 bool IsWebContentsVisible() const; | |
83 | |
84 // Closes all WebContentsModalDialogs. | |
85 void CloseAllDialogs(); | |
86 | |
87 // Overridden from content::WebContentsObserver: | |
88 virtual void DidNavigateMainFrame( | |
89 const content::LoadCommittedDetails& details, | |
90 const content::FrameNavigateParams& params) OVERRIDE; | |
91 virtual void DidGetIgnoredUIEvent() OVERRIDE; | |
92 virtual void WebContentsDestroyed(content::WebContents* tab) OVERRIDE; | |
93 | |
94 // Delegate for notifying our owner about stuff. Not owned by us. | |
95 WebContentsModalDialogManagerDelegate* delegate_; | |
96 | |
97 // Delegate for native UI-specific functions on the dialog. | |
98 scoped_ptr<NativeWebContentsModalDialogManager> native_manager_; | |
99 | |
100 // All active dialogs. | |
101 WebContentsModalDialogList child_dialogs_; | |
102 | |
103 // True while closing the dialogs on WebContents close. | |
104 bool closing_all_dialogs_; | |
105 | |
106 // A scoped container for notification registries. | |
107 content::NotificationRegistrar registrar_; | |
108 | |
109 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogManager); | |
110 }; | |
111 | |
112 #endif // CHROME_BROWSER_UI_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ | |
OLD | NEW |