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 #include "components/web_modal/popup_manager.h" | |
6 | |
7 #include "content/public/browser/navigation_details.h" | |
8 #include "content/public/browser/navigation_entry.h" | |
9 #include "content/public/browser/render_view_host.h" | |
10 #include "content/public/browser/web_contents.h" | |
11 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | |
12 | |
13 using content::WebContents; | |
14 | |
15 namespace web_modal { | |
16 | |
17 PopupManager::~PopupManager() { | |
18 DCHECK(child_dialogs_.empty()); | |
19 } | |
20 | |
21 void PopupManager::ShowPopup(scoped_ptr<SinglePopupManager> manager) { | |
22 child_dialogs_.push_back(new PopupState(manager->popup(), manager.Pass())); | |
23 | |
24 if (child_dialogs_.size() == 1) | |
25 child_dialogs_.back()->manager->Show(); | |
26 } | |
27 | |
28 bool PopupManager::IsPopupActiveInCurrentWebContents() const { | |
29 return !child_dialogs_.empty(); | |
30 } | |
31 | |
32 void PopupManager::FocusTopmostPopup() { | |
Finnur
2014/05/16 12:38:14
Topmost isn't clear. How about FocusNextPopup?
| |
33 DCHECK(!child_dialogs_.empty()); | |
34 child_dialogs_.front()->manager->Focus(); | |
35 } | |
36 | |
37 void PopupManager::WillClose(NativePopup popup) { | |
38 PopupList::iterator dlg = FindPopupState(popup); | |
Finnur
2014/05/16 12:38:14
nit: Conflating dialogs and popups again. :)
| |
39 | |
40 // The Views tab contents modal dialog calls WillClose twice. Ignore the | |
41 // second invocation. | |
42 if (dlg == child_dialogs_.end()) | |
43 return; | |
Finnur
2014/05/16 12:38:14
This not the first time I've seen code trying to d
Mike Wittman
2014/05/16 20:35:40
This was my comment from investigating this for th
| |
44 | |
45 bool removed_topmost_dialog = dlg == child_dialogs_.begin(); | |
46 scoped_ptr<PopupState> deleter(*dlg); | |
47 child_dialogs_.erase(dlg); | |
Finnur
2014/05/16 12:38:14
You don't erase in CloseAllPopups. Is that intende
Mike Wittman
2014/05/16 20:35:40
Speaking based on the WCMDM implementation, yes. A
| |
48 if (!child_dialogs_.empty() && removed_topmost_dialog && | |
49 !closing_all_popups_) { | |
50 child_dialogs_.front()->manager->Show(); | |
51 } | |
52 } | |
53 | |
54 PopupManager::PopupManager() | |
55 : closing_all_popups_(false) { | |
56 } | |
57 | |
58 PopupManager::PopupState::PopupState( | |
59 NativePopup popup, | |
60 scoped_ptr<SinglePopupManager> mgr) | |
61 : popup(popup), | |
62 manager(mgr.release()), | |
Finnur
2014/05/16 12:38:14
Can this be .Pass() instead of .release()?
| |
63 #if defined(USE_AURA) | |
64 close_on_interstitial_webui(true) | |
65 #else | |
66 // TODO(wittman): Test that closing on interstitial webui works properly | |
67 // on Mac and use the true default for all platforms. | |
68 close_on_interstitial_webui(false) | |
69 #endif | |
70 { | |
71 } | |
72 | |
73 PopupManager::PopupState::~PopupState() {} | |
74 | |
75 PopupManager::PopupList::iterator PopupManager::FindPopupState( | |
76 NativePopup popup) { | |
77 PopupList::iterator i; | |
78 for (i = child_dialogs_.begin(); i != child_dialogs_.end(); ++i) { | |
79 if ((*i)->popup == popup) | |
80 break; | |
81 } | |
82 | |
83 return i; | |
84 } | |
85 | |
86 void PopupManager::CloseAllPopups() { | |
87 closing_all_popups_ = true; | |
88 | |
89 // Clear out any dialogs since we are leaving this page entirely. | |
Finnur
2014/05/16 12:38:14
Will this function only be called when leaving a p
Greg Billock
2014/05/16 15:49:56
I only really changed the header file to try to re
Mike Wittman
2014/05/16 20:35:40
I believe this function would be WCMD-specific.
| |
90 while (!child_dialogs_.empty()) { | |
91 child_dialogs_.front()->manager->Close(); | |
92 } | |
Finnur
2014/05/16 12:38:14
nit: No braces.
| |
93 | |
94 closing_all_popups_ = false; | |
95 } | |
96 | |
97 void PopupManager::DidNavigateMainFrame( | |
98 content::WebContents* web_contents, | |
99 const content::LoadCommittedDetails& details, | |
100 const content::FrameNavigateParams& params) { | |
101 // Close constrained windows if necessary. | |
Finnur
2014/05/16 12:38:14
I need to brush up on terminology. :) Are all popu
| |
102 if (!net::registry_controlled_domains::SameDomainOrHost( | |
103 details.previous_url, details.entry->GetURL(), | |
104 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) | |
105 CloseAllPopups(); | |
Finnur
2014/05/16 12:38:14
Don't you need to check here to see whether this i
Mike Wittman
2014/05/16 20:35:40
This is also WMCD-specific, and probably doesn't b
| |
106 } | |
107 | |
108 void PopupManager::DidGetIgnoredUIEvent(content::WebContents* web_contents) { | |
109 if (!child_dialogs_.empty()) { | |
110 child_dialogs_.front()->manager->Focus(); | |
111 } | |
Finnur
2014/05/16 12:38:14
nit: No braces.
| |
112 } | |
113 | |
114 void PopupManager::WasShown(content::WebContents* web_contents) { | |
115 if (!child_dialogs_.empty()) | |
116 child_dialogs_.front()->manager->Show(); | |
117 } | |
118 | |
119 void PopupManager::WasHidden(content::WebContents* web_contents) { | |
120 if (!child_dialogs_.empty()) | |
121 child_dialogs_.front()->manager->Hide(); | |
122 } | |
123 | |
124 void PopupManager::WebContentsDestroyed(content::WebContents* web_contents) { | |
125 // First cleanly close all child dialogs. | |
126 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked | |
127 // some of these to close. CloseAllDialogs is async, so it might get called | |
Finnur
2014/05/16 12:38:14
CloseAllDialogs?
| |
128 // twice before it runs. | |
129 CloseAllPopups(); | |
130 } | |
131 | |
132 void PopupManager::DidAttachInterstitialPage( | |
133 content::WebContents* web_contents) { | |
134 // Copy the dialogs so we can close and remove them while iterating over the | |
135 // list. | |
136 PopupList dialogs(child_dialogs_); | |
137 for (PopupList::iterator it = dialogs.begin(); | |
138 it != dialogs.end(); ++it) { | |
139 if ((*it)->close_on_interstitial_webui) | |
140 (*it)->manager->Close(); | |
141 } | |
142 } | |
143 | |
144 } // namespace web_modal | |
OLD | NEW |