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 : closing_all_popups_(false) { |
| 19 } |
| 20 |
| 21 PopupManager::~PopupManager() { |
| 22 DCHECK(child_popups_.empty()); |
| 23 } |
| 24 |
| 25 void PopupManager::ShowPopup(scoped_ptr<SinglePopupManager> manager) { |
| 26 child_popups_.push_back(new PopupState(manager->popup(), manager.Pass())); |
| 27 |
| 28 if (child_popups_.size() == 1) |
| 29 child_popups_.back()->manager->Show(); |
| 30 } |
| 31 |
| 32 bool PopupManager::IsPopupActiveInCurrentWebContents() const { |
| 33 return !child_popups_.empty(); |
| 34 } |
| 35 |
| 36 void PopupManager::FocusTopmostPopup() { |
| 37 DCHECK(!child_popups_.empty()); |
| 38 child_popups_.front()->manager->Focus(); |
| 39 } |
| 40 |
| 41 void PopupManager::WillClose(NativePopup popup) { |
| 42 PopupList::iterator dlg = FindPopupState(popup); |
| 43 |
| 44 // The Views tab contents modal dialog calls WillClose twice. Ignore the |
| 45 // second invocation. |
| 46 if (dlg == child_popups_.end()) |
| 47 return; |
| 48 |
| 49 bool removed_topmost_dialog = dlg == child_popups_.begin(); |
| 50 scoped_ptr<PopupState> deleter(*dlg); |
| 51 child_popups_.erase(dlg); |
| 52 if (!child_popups_.empty() && removed_topmost_dialog && |
| 53 !closing_all_popups_) { |
| 54 child_popups_.front()->manager->Show(); |
| 55 } |
| 56 } |
| 57 |
| 58 PopupManager::PopupState::PopupState( |
| 59 NativePopup popup, |
| 60 scoped_ptr<SinglePopupManager> mgr) |
| 61 : popup(popup), |
| 62 manager(mgr.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_popups_.begin(); i != child_popups_.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. |
| 90 while (!child_popups_.empty()) { |
| 91 child_popups_.front()->manager->Close(); |
| 92 } |
| 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. |
| 102 if (!net::registry_controlled_domains::SameDomainOrHost( |
| 103 details.previous_url, details.entry->GetURL(), |
| 104 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) |
| 105 CloseAllPopups(); |
| 106 } |
| 107 |
| 108 void PopupManager::DidGetIgnoredUIEvent(content::WebContents* web_contents) { |
| 109 if (!child_popups_.empty()) { |
| 110 child_popups_.front()->manager->Focus(); |
| 111 } |
| 112 } |
| 113 |
| 114 void PopupManager::WasShown(content::WebContents* web_contents) { |
| 115 if (!child_popups_.empty()) |
| 116 child_popups_.front()->manager->Show(); |
| 117 } |
| 118 |
| 119 void PopupManager::WasHidden(content::WebContents* web_contents) { |
| 120 if (!child_popups_.empty()) |
| 121 child_popups_.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 |
| 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_popups_); |
| 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 |