OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ | 5 #ifndef COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ |
6 #define COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ | 6 #define COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "components/web_modal/native_web_contents_modal_dialog_manager.h" | 11 #include "components/web_modal/single_web_contents_dialog_manager.h" |
12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
13 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
14 #include "ui/gfx/native_widget_types.h" | 14 #include "ui/gfx/native_widget_types.h" |
15 | 15 |
16 namespace web_modal { | 16 namespace web_modal { |
17 | 17 |
18 class WebContentsModalDialogManagerDelegate; | 18 class WebContentsModalDialogManagerDelegate; |
19 | 19 |
20 // Per-WebContents class to manage WebContents-modal dialogs. | 20 // Per-WebContents class to manage WebContents-modal dialogs. |
21 class WebContentsModalDialogManager | 21 class WebContentsModalDialogManager |
22 : public NativeWebContentsModalDialogManagerDelegate, | 22 : public SingleWebContentsDialogManagerDelegate, |
23 public content::WebContentsObserver, | 23 public content::WebContentsObserver, |
24 public content::WebContentsUserData<WebContentsModalDialogManager> { | 24 public content::WebContentsUserData<WebContentsModalDialogManager> { |
25 public: | 25 public: |
26 virtual ~WebContentsModalDialogManager(); | 26 virtual ~WebContentsModalDialogManager(); |
27 | 27 |
28 WebContentsModalDialogManagerDelegate* delegate() const { return delegate_; } | 28 WebContentsModalDialogManagerDelegate* delegate() const { return delegate_; } |
29 void SetDelegate(WebContentsModalDialogManagerDelegate* d); | 29 void SetDelegate(WebContentsModalDialogManagerDelegate* d); |
30 | 30 |
31 // TODO(gbillock): Rename to CreateNativeWebModalManager(). | 31 static SingleWebContentsDialogManager* CreateNativeWebModalManager( |
32 static NativeWebContentsModalDialogManager* CreateNativeManager( | 32 SingleWebContentsDialogManagerDelegate* native_delegate); |
33 NativeWebContentsModalDialogManagerDelegate* native_delegate); | |
34 | 33 |
35 // Shows the dialog as a web contents modal dialog. The dialog will notify via | 34 // Shows the dialog as a web contents modal dialog. The dialog will notify via |
36 // WillClose() when it is being destroyed. | 35 // WillClose() when it is being destroyed. |
37 void ShowDialog(NativeWebContentsModalDialog dialog); | 36 void ShowModalDialog(NativeWebContentsModalDialog dialog); |
38 | 37 |
39 // Allow clients to supply their own native dialog manager. Suitable for | 38 // Allow clients to supply their own native dialog manager. Suitable for |
40 // bubble clients. | 39 // bubble clients. |
41 void ShowDialogWithManager( | 40 void ShowDialogWithManager( |
42 NativeWebContentsModalDialog dialog, | 41 NativeWebContentsModalDialog dialog, |
43 scoped_ptr<NativeWebContentsModalDialogManager> manager); | 42 scoped_ptr<SingleWebContentsDialogManager> manager); |
44 | 43 |
45 // Returns true if any dialogs are active and not closed. | 44 // Returns true if any dialogs are active and not closed. |
46 bool IsDialogActive() const; | 45 bool IsDialogActive() const; |
47 | 46 |
48 // Focus the topmost modal dialog. IsDialogActive() must be true when calling | 47 // Focus the topmost modal dialog. IsDialogActive() must be true when calling |
49 // this function. | 48 // this function. |
50 void FocusTopmostDialog(); | 49 void FocusTopmostDialog(); |
51 | 50 |
52 // Set to true to close the window when a page load starts on the WebContents. | 51 // Set to true to close the window when a page load starts on the WebContents. |
53 void SetCloseOnInterstitialPage(NativeWebContentsModalDialog dialog, | 52 void SetCloseOnInterstitialPage(NativeWebContentsModalDialog dialog, |
54 bool close); | 53 bool close); |
55 | 54 |
56 // Overriden from NativeWebContentsModalDialogManagerDelegate: | 55 // Overriden from SingleWebContentsDialogManagerDelegate: |
57 virtual content::WebContents* GetWebContents() const OVERRIDE; | 56 virtual content::WebContents* GetWebContents() const OVERRIDE; |
58 // Called when a WebContentsModalDialogs we own is about to be closed. | 57 // Called when a WebContentsModalDialogs we own is about to be closed. |
59 virtual void WillClose(NativeWebContentsModalDialog dialog) OVERRIDE; | 58 virtual void WillClose(NativeWebContentsModalDialog dialog) OVERRIDE; |
60 | 59 |
61 // For testing. | 60 // For testing. |
62 class TestApi { | 61 class TestApi { |
63 public: | 62 public: |
64 explicit TestApi(WebContentsModalDialogManager* manager) | 63 explicit TestApi(WebContentsModalDialogManager* manager) |
65 : manager_(manager) {} | 64 : manager_(manager) {} |
66 | 65 |
67 void CloseAllDialogs() { manager_->CloseAllDialogs(); } | 66 void CloseAllDialogs() { manager_->CloseAllDialogs(); } |
68 void DidAttachInterstitialPage() { manager_->DidAttachInterstitialPage(); } | 67 void DidAttachInterstitialPage() { manager_->DidAttachInterstitialPage(); } |
69 void WebContentsWasShown() { manager_->WasShown(); } | 68 void WebContentsWasShown() { manager_->WasShown(); } |
70 void WebContentsWasHidden() { manager_->WasHidden(); } | 69 void WebContentsWasHidden() { manager_->WasHidden(); } |
71 | 70 |
72 private: | 71 private: |
73 WebContentsModalDialogManager* manager_; | 72 WebContentsModalDialogManager* manager_; |
74 | 73 |
75 DISALLOW_COPY_AND_ASSIGN(TestApi); | 74 DISALLOW_COPY_AND_ASSIGN(TestApi); |
76 }; | 75 }; |
77 | 76 |
78 private: | 77 private: |
79 explicit WebContentsModalDialogManager(content::WebContents* web_contents); | 78 explicit WebContentsModalDialogManager(content::WebContents* web_contents); |
80 friend class content::WebContentsUserData<WebContentsModalDialogManager>; | 79 friend class content::WebContentsUserData<WebContentsModalDialogManager>; |
81 | 80 |
82 struct DialogState { | 81 struct DialogState { |
83 DialogState(NativeWebContentsModalDialog dialog, | 82 DialogState(NativeWebContentsModalDialog dialog, |
84 scoped_ptr<NativeWebContentsModalDialogManager> manager); | 83 scoped_ptr<SingleWebContentsDialogManager> manager); |
85 ~DialogState(); | 84 ~DialogState(); |
86 | 85 |
87 NativeWebContentsModalDialog dialog; | 86 NativeWebContentsModalDialog dialog; |
88 scoped_ptr<NativeWebContentsModalDialogManager> manager; | 87 scoped_ptr<SingleWebContentsDialogManager> manager; |
89 bool close_on_interstitial_webui; | 88 bool close_on_interstitial_webui; |
90 }; | 89 }; |
91 | 90 |
92 typedef std::deque<DialogState*> WebContentsModalDialogList; | 91 typedef std::deque<DialogState*> WebContentsModalDialogList; |
93 | 92 |
94 // Utility function to get the dialog state for a dialog. | 93 // Utility function to get the dialog state for a dialog. |
95 WebContentsModalDialogList::iterator FindDialogState( | 94 WebContentsModalDialogList::iterator FindDialogState( |
96 NativeWebContentsModalDialog dialog); | 95 NativeWebContentsModalDialog dialog); |
97 | 96 |
98 // Blocks/unblocks interaction with renderer process. | 97 // Blocks/unblocks interaction with renderer process. |
(...skipping 22 matching lines...) Expand all Loading... |
121 | 120 |
122 // True while closing the dialogs on WebContents close. | 121 // True while closing the dialogs on WebContents close. |
123 bool closing_all_dialogs_; | 122 bool closing_all_dialogs_; |
124 | 123 |
125 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogManager); | 124 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogManager); |
126 }; | 125 }; |
127 | 126 |
128 } // namespace web_modal | 127 } // namespace web_modal |
129 | 128 |
130 #endif // COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ | 129 #endif // COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ |
OLD | NEW |