OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 5 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
6 | 6 |
7 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 7 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
8 #include "content/public/browser/navigation_details.h" | 8 #include "content/public/browser/navigation_details.h" |
9 #include "content/public/browser/navigation_entry.h" | 9 #include "content/public/browser/navigation_entry.h" |
10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 bool WebContentsModalDialogManager::IsDialogActive() const { | 57 bool WebContentsModalDialogManager::IsDialogActive() const { |
58 return !child_dialogs_.empty(); | 58 return !child_dialogs_.empty(); |
59 } | 59 } |
60 | 60 |
61 void WebContentsModalDialogManager::FocusTopmostDialog() { | 61 void WebContentsModalDialogManager::FocusTopmostDialog() { |
62 DCHECK(!child_dialogs_.empty()); | 62 DCHECK(!child_dialogs_.empty()); |
63 child_dialogs_.front()->manager->Focus(); | 63 child_dialogs_.front()->manager->Focus(); |
64 } | 64 } |
65 | 65 |
66 void WebContentsModalDialogManager::SetCloseOnInterstitialPage( | |
67 NativeWebContentsModalDialog dialog, | |
68 bool close) { | |
69 WebContentsModalDialogList::iterator loc = FindDialogState(dialog); | |
70 DCHECK(loc != child_dialogs_.end()); | |
71 (*loc)->close_on_interstitial_webui = close; | |
72 } | |
73 | |
74 content::WebContents* WebContentsModalDialogManager::GetWebContents() const { | 66 content::WebContents* WebContentsModalDialogManager::GetWebContents() const { |
75 return web_contents(); | 67 return web_contents(); |
76 } | 68 } |
77 | 69 |
78 void WebContentsModalDialogManager::WillClose( | 70 void WebContentsModalDialogManager::WillClose( |
79 NativeWebContentsModalDialog dialog) { | 71 NativeWebContentsModalDialog dialog) { |
80 WebContentsModalDialogList::iterator dlg = FindDialogState(dialog); | 72 WebContentsModalDialogList::iterator dlg = FindDialogState(dialog); |
81 | 73 |
82 // The Views tab contents modal dialog calls WillClose twice. Ignore the | 74 // The Views tab contents modal dialog calls WillClose twice. Ignore the |
83 // second invocation. | 75 // second invocation. |
(...skipping 15 matching lines...) Expand all Loading... |
99 content::WebContents* web_contents) | 91 content::WebContents* web_contents) |
100 : content::WebContentsObserver(web_contents), | 92 : content::WebContentsObserver(web_contents), |
101 delegate_(NULL), | 93 delegate_(NULL), |
102 closing_all_dialogs_(false) { | 94 closing_all_dialogs_(false) { |
103 } | 95 } |
104 | 96 |
105 WebContentsModalDialogManager::DialogState::DialogState( | 97 WebContentsModalDialogManager::DialogState::DialogState( |
106 NativeWebContentsModalDialog dialog, | 98 NativeWebContentsModalDialog dialog, |
107 scoped_ptr<SingleWebContentsDialogManager> mgr) | 99 scoped_ptr<SingleWebContentsDialogManager> mgr) |
108 : dialog(dialog), | 100 : dialog(dialog), |
109 manager(mgr.release()), | 101 manager(mgr.release()) { |
110 #if defined(USE_AURA) | |
111 close_on_interstitial_webui(true) | |
112 #else | |
113 // TODO(wittman): Test that closing on interstitial webui works properly | |
114 // on Mac and use the true default for all platforms. | |
115 close_on_interstitial_webui(false) | |
116 #endif | |
117 { | |
118 } | 102 } |
119 | 103 |
120 WebContentsModalDialogManager::DialogState::~DialogState() {} | 104 WebContentsModalDialogManager::DialogState::~DialogState() {} |
121 | 105 |
122 WebContentsModalDialogManager::WebContentsModalDialogList::iterator | 106 WebContentsModalDialogManager::WebContentsModalDialogList::iterator |
123 WebContentsModalDialogManager::FindDialogState( | 107 WebContentsModalDialogManager::FindDialogState( |
124 NativeWebContentsModalDialog dialog) { | 108 NativeWebContentsModalDialog dialog) { |
125 WebContentsModalDialogList::iterator i; | 109 WebContentsModalDialogList::iterator i; |
126 for (i = child_dialogs_.begin(); i != child_dialogs_.end(); ++i) { | 110 for (i = child_dialogs_.begin(); i != child_dialogs_.end(); ++i) { |
127 if ((*i)->dialog == dialog) | 111 if ((*i)->dialog == dialog) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 173 |
190 void WebContentsModalDialogManager::WebContentsDestroyed() { | 174 void WebContentsModalDialogManager::WebContentsDestroyed() { |
191 // First cleanly close all child dialogs. | 175 // First cleanly close all child dialogs. |
192 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked | 176 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked |
193 // some of these to close. CloseAllDialogs is async, so it might get called | 177 // some of these to close. CloseAllDialogs is async, so it might get called |
194 // twice before it runs. | 178 // twice before it runs. |
195 CloseAllDialogs(); | 179 CloseAllDialogs(); |
196 } | 180 } |
197 | 181 |
198 void WebContentsModalDialogManager::DidAttachInterstitialPage() { | 182 void WebContentsModalDialogManager::DidAttachInterstitialPage() { |
199 // Copy the dialogs so we can close and remove them while iterating over the | 183 // TODO(wittman): Test closing on interstitial webui works properly on Mac. |
200 // list. | 184 #if defined(USE_AURA) |
201 WebContentsModalDialogList dialogs(child_dialogs_); | 185 CloseAllDialogs(); |
202 for (WebContentsModalDialogList::iterator it = dialogs.begin(); | 186 #endif |
203 it != dialogs.end(); ++it) { | |
204 if ((*it)->close_on_interstitial_webui) | |
205 (*it)->manager->Close(); | |
206 } | |
207 } | 187 } |
208 | 188 |
209 } // namespace web_modal | 189 } // namespace web_modal |
OLD | NEW |