Index: trunk/src/components/web_modal/web_contents_modal_dialog_manager.cc |
=================================================================== |
--- trunk/src/components/web_modal/web_contents_modal_dialog_manager.cc (revision 214772) |
+++ trunk/src/components/web_modal/web_contents_modal_dialog_manager.cc (working copy) |
@@ -13,6 +13,7 @@ |
#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; |
@@ -26,7 +27,7 @@ |
void WebContentsModalDialogManager::ShowDialog( |
NativeWebContentsModalDialog dialog) { |
- child_dialogs_.push_back(DialogState(dialog)); |
+ child_dialogs_.push_back(dialog); |
native_manager_->ManageDialog(dialog); |
@@ -43,24 +44,17 @@ |
void WebContentsModalDialogManager::FocusTopmostDialog() { |
DCHECK(!child_dialogs_.empty()); |
- native_manager_->FocusDialog(child_dialogs_.front().dialog); |
+ native_manager_->FocusDialog(child_dialogs_.front()); |
} |
-void WebContentsModalDialogManager::SetPreventCloseOnLoadStart( |
- NativeWebContentsModalDialog dialog, |
- bool prevent) { |
- WebContentsModalDialogList::iterator loc = FindDialogState(dialog); |
- DCHECK(loc != child_dialogs_.end()); |
- loc->prevent_close_on_load_start = true; |
-} |
- |
content::WebContents* WebContentsModalDialogManager::GetWebContents() const { |
return web_contents(); |
} |
void WebContentsModalDialogManager::WillClose( |
NativeWebContentsModalDialog dialog) { |
- WebContentsModalDialogList::iterator i = FindDialogState(dialog); |
+ WebContentsModalDialogList::iterator i( |
+ std::find(child_dialogs_.begin(), child_dialogs_.end(), dialog)); |
// The Views tab contents modal dialog calls WillClose twice. Ignore the |
// second invocation. |
@@ -71,7 +65,7 @@ |
child_dialogs_.erase(i); |
if (!child_dialogs_.empty() && removed_topmost_dialog && |
!closing_all_dialogs_) |
- native_manager_->ShowDialog(child_dialogs_.front().dialog); |
+ native_manager_->ShowDialog(child_dialogs_.front()); |
BlockWebContentsInteraction(!child_dialogs_.empty()); |
} |
@@ -80,20 +74,16 @@ |
int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
- if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { |
- if (child_dialogs_.empty()) |
- return; |
+ DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED); |
- 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().prevent_close_on_load_start) |
- native_manager_->CloseDialog(child_dialogs_.front().dialog); |
- } |
+ 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()); |
} |
WebContentsModalDialogManager::WebContentsModalDialogManager( |
@@ -103,34 +93,11 @@ |
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), |
- prevent_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) { |
- if (i->dialog == dialog) |
- break; |
- } |
- |
- return i; |
-} |
- |
void WebContentsModalDialogManager::BlockWebContentsInteraction(bool blocked) { |
WebContents* contents = web_contents(); |
if (!contents) { |
@@ -151,14 +118,24 @@ |
// Clear out any dialogs since we are leaving this page entirely. |
while (!child_dialogs_.empty()) |
- native_manager_->CloseDialog(child_dialogs_.front().dialog); |
+ native_manager_->CloseDialog(child_dialogs_.front()); |
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().dialog); |
+ native_manager_->FocusDialog(child_dialogs_.front()); |
} |
void WebContentsModalDialogManager::WebContentsDestroyed(WebContents* tab) { |