Chromium Code Reviews| Index: components/web_modal/web_contents_modal_dialog_manager.cc |
| diff --git a/components/web_modal/web_contents_modal_dialog_manager.cc b/components/web_modal/web_contents_modal_dialog_manager.cc |
| index 0e07f8dd1d96cee1aba119f641a82522aa48018c..7a885fbdc4e4131012355cd34c5f0ee07cd0a1b2 100644 |
| --- a/components/web_modal/web_contents_modal_dialog_manager.cc |
| +++ b/components/web_modal/web_contents_modal_dialog_manager.cc |
| @@ -13,7 +13,6 @@ |
| #include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_contents_view.h" |
| -#include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| using content::WebContents; |
| @@ -27,7 +26,7 @@ WebContentsModalDialogManager::~WebContentsModalDialogManager() { |
| void WebContentsModalDialogManager::ShowDialog( |
| NativeWebContentsModalDialog dialog) { |
| - child_dialogs_.push_back(dialog); |
| + child_dialogs_.push_back(DialogState(dialog)); |
| native_manager_->ManageDialog(dialog); |
| @@ -44,7 +43,15 @@ bool WebContentsModalDialogManager::IsShowingDialog() const { |
| void WebContentsModalDialogManager::FocusTopmostDialog() { |
| DCHECK(!child_dialogs_.empty()); |
| - native_manager_->FocusDialog(child_dialogs_.front()); |
| + native_manager_->FocusDialog(child_dialogs_.front().dialog); |
| +} |
| + |
| +void WebContentsModalDialogManager::SetInhibitCloseOnLoadStart( |
| + NativeWebContentsModalDialog dialog, |
| + bool inhibit) { |
| + WebContentsModalDialogList::iterator loc = FindDialogState(dialog); |
| + DCHECK(loc != child_dialogs_.end()); |
| + loc->inhibit_close_on_load_start = true; |
| } |
| content::WebContents* WebContentsModalDialogManager::GetWebContents() const { |
| @@ -53,8 +60,7 @@ content::WebContents* WebContentsModalDialogManager::GetWebContents() const { |
| void WebContentsModalDialogManager::WillClose( |
| NativeWebContentsModalDialog dialog) { |
| - WebContentsModalDialogList::iterator i( |
| - std::find(child_dialogs_.begin(), child_dialogs_.end(), dialog)); |
| + WebContentsModalDialogList::iterator i = FindDialogState(dialog); |
| // The Views tab contents modal dialog calls WillClose twice. Ignore the |
| // second invocation. |
| @@ -65,7 +71,7 @@ void WebContentsModalDialogManager::WillClose( |
| child_dialogs_.erase(i); |
| if (!child_dialogs_.empty() && removed_topmost_dialog && |
| !closing_all_dialogs_) |
| - native_manager_->ShowDialog(child_dialogs_.front()); |
| + native_manager_->ShowDialog(child_dialogs_.front().dialog); |
| BlockWebContentsInteraction(!child_dialogs_.empty()); |
| } |
| @@ -74,16 +80,20 @@ void WebContentsModalDialogManager::Observe( |
| int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| - DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED); |
| - |
| - if (child_dialogs_.empty()) |
| - return; |
| - |
| - bool visible = *content::Details<bool>(details).ptr(); |
| - if (visible) |
| - native_manager_->ShowDialog(child_dialogs_.front()); |
| - else |
| - native_manager_->HideDialog(child_dialogs_.front()); |
| + if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { |
| + if (child_dialogs_.empty()) |
| + return; |
| + |
| + bool visible = *content::Details<bool>(details).ptr(); |
| + if (visible) |
| + native_manager_->ShowDialog(child_dialogs_.front().dialog); |
| + else |
| + native_manager_->HideDialog(child_dialogs_.front().dialog); |
| + } else if (type == content::NOTIFICATION_LOAD_START) { |
| + if (!child_dialogs_.empty() && |
| + !child_dialogs_.front().inhibit_close_on_load_start) |
| + native_manager_->CloseDialog(child_dialogs_.front().dialog); |
| + } |
| } |
| WebContentsModalDialogManager::WebContentsModalDialogManager( |
| @@ -93,11 +103,34 @@ WebContentsModalDialogManager::WebContentsModalDialogManager( |
| native_manager_(CreateNativeManager(this)), |
| closing_all_dialogs_(false) { |
| DCHECK(native_manager_); |
| + content::NavigationController* controller = |
| + &GetWebContents()->GetController(); |
| + registrar_.Add(this, |
| + content::NOTIFICATION_LOAD_START, |
| + content::Source<content::NavigationController>(controller)); |
| registrar_.Add(this, |
| content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
| content::Source<content::WebContents>(web_contents)); |
| } |
| +WebContentsModalDialogManager::DialogState::DialogState( |
| + NativeWebContentsModalDialog dialog) |
| + : dialog(dialog), |
| + inhibit_close_on_load_start(false) { |
| +} |
| + |
| +WebContentsModalDialogManager::WebContentsModalDialogList::iterator |
| + WebContentsModalDialogManager::FindDialogState( |
| + NativeWebContentsModalDialog dialog) { |
| + WebContentsModalDialogList::iterator i; |
| + for (i = child_dialogs_.begin(); i != child_dialogs_.end(); i++) { |
|
Ilya Sherman
2013/07/12 23:58:28
nit: ++i
Mike Wittman
2013/07/13 00:16:34
Done.
|
| + if (i->dialog == dialog) |
| + break; |
| + } |
| + |
| + return i; |
| +} |
| + |
| void WebContentsModalDialogManager::BlockWebContentsInteraction(bool blocked) { |
| WebContents* contents = web_contents(); |
| if (!contents) { |
| @@ -118,24 +151,14 @@ void WebContentsModalDialogManager::CloseAllDialogs() { |
| // Clear out any dialogs since we are leaving this page entirely. |
| while (!child_dialogs_.empty()) |
| - native_manager_->CloseDialog(child_dialogs_.front()); |
| + native_manager_->CloseDialog(child_dialogs_.front().dialog); |
| closing_all_dialogs_ = false; |
| } |
| -void WebContentsModalDialogManager::DidNavigateMainFrame( |
| - const content::LoadCommittedDetails& details, |
| - const content::FrameNavigateParams& params) { |
| - // Close constrained windows if necessary. |
| - if (!net::registry_controlled_domains::SameDomainOrHost( |
| - details.previous_url, details.entry->GetURL(), |
| - net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)) |
| - CloseAllDialogs(); |
| -} |
| - |
| void WebContentsModalDialogManager::DidGetIgnoredUIEvent() { |
| if (!child_dialogs_.empty()) |
| - native_manager_->FocusDialog(child_dialogs_.front()); |
| + native_manager_->FocusDialog(child_dialogs_.front().dialog); |
| } |
| void WebContentsModalDialogManager::WebContentsDestroyed(WebContents* tab) { |