Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/browser/ui/web_contents_modal_dialog_manager.h

Issue 14969012: components: Create web_modal component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // Blocks/unblocks interaction with renderer process.
40 void BlockWebContentsInteraction(bool blocked);
41
42 // Returns true if a dialog is currently being shown.
43 bool IsShowingDialog() const;
44
45 // Focus the topmost modal dialog. IsShowingDialog() must be true when
46 // calling this function.
47 void FocusTopmostDialog();
48
49 // Overriden from NativeWebContentsModalDialogManagerDelegate:
50 virtual content::WebContents* GetWebContents() const OVERRIDE;
51 // Called when a WebContentsModalDialogs we own is about to be closed.
52 virtual void WillClose(NativeWebContentsModalDialog dialog) OVERRIDE;
53
54 // content::NotificationObserver overrides
55 virtual void Observe(int type,
56 const content::NotificationSource& source,
57 const content::NotificationDetails& details) OVERRIDE;
58
59 // For testing.
60 class TestApi {
61 public:
62 explicit TestApi(WebContentsModalDialogManager* manager)
63 : manager_(manager) {}
64
65 void CloseAllDialogs() { manager_->CloseAllDialogs(); }
66 void ResetNativeManager(NativeWebContentsModalDialogManager* delegate) {
67 manager_->native_manager_.reset(delegate);
68 }
69
70 private:
71 WebContentsModalDialogManager* manager_;
72
73 DISALLOW_COPY_AND_ASSIGN(TestApi);
74 };
75
76 private:
77 explicit WebContentsModalDialogManager(content::WebContents* web_contents);
78 friend class content::WebContentsUserData<WebContentsModalDialogManager>;
79
80 typedef std::deque<NativeWebContentsModalDialog> WebContentsModalDialogList;
81
82 // Returns the number of dialogs in this tab.
83 size_t dialog_count() const { return child_dialogs_.size(); }
84
85 // Return an iterator for the first dialog in this web contents.
86 WebContentsModalDialogList::iterator dialog_begin() {
87 return child_dialogs_.begin();
88 }
89
90 // Return an iterator for the last dialog in this web contents.
91 WebContentsModalDialogList::iterator dialog_end() {
92 return child_dialogs_.end();
93 }
94
95 // Closes all WebContentsModalDialogs.
96 void CloseAllDialogs();
97
98 // Overridden from content::WebContentsObserver:
99 virtual void DidNavigateMainFrame(
100 const content::LoadCommittedDetails& details,
101 const content::FrameNavigateParams& params) OVERRIDE;
102 virtual void DidGetIgnoredUIEvent() OVERRIDE;
103 virtual void WebContentsDestroyed(content::WebContents* tab) OVERRIDE;
104
105 // Delegate for notifying our owner about stuff. Not owned by us.
106 WebContentsModalDialogManagerDelegate* delegate_;
107
108 // Delegate for native UI-specific functions on the dialog.
109 scoped_ptr<NativeWebContentsModalDialogManager> native_manager_;
110
111 // All active dialogs.
112 WebContentsModalDialogList child_dialogs_;
113
114 // True while closing the dialogs on WebContents close.
115 bool closing_all_dialogs_;
116
117 // A scoped container for notification registries.
118 content::NotificationRegistrar registrar_;
119
120 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogManager);
121 };
122
123 #endif // CHROME_BROWSER_UI_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698