#include "content/public/browser/navigation_entry.h"
#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;
void WebContentsModalDialogManager::SetDelegate(
WebContentsModalDialogManagerDelegate* d) {
delegate_ = d;
- // Delegate can be NULL on Views/Win32 during tab drag.
- native_manager_->HostChanged(d ? d->GetWebContentsModalDialogHost() : NULL);
+
+ for (WebContentsModalDialogList::iterator it = child_dialogs_.begin();
+ it != child_dialogs_.end(); it++) {
+ // Delegate can be NULL on Views/Win32 during tab drag.
+ (*it)->manager->HostChanged(d ? d->GetWebContentsModalDialogHost() : NULL);
+ }
}
-void WebContentsModalDialogManager::ShowDialog(
+void WebContentsModalDialogManager::ShowModalDialog(
NativeWebContentsModalDialog dialog) {
- child_dialogs_.push_back(DialogState(dialog));
+ scoped_ptr<SingleWebContentsDialogManager> mgr(
+ CreateNativeWebModalManager(dialog, this));
+ ShowDialogWithManager(dialog, mgr.Pass());
+}
- native_manager_->ManageDialog(dialog);
+// TODO(gbillock): Maybe "ShowBubbleWithManager"?
+void WebContentsModalDialogManager::ShowDialogWithManager(
+ NativeWebContentsModalDialog dialog,
+ scoped_ptr<SingleWebContentsDialogManager> manager) {
+ if (delegate_)
+ manager->HostChanged(delegate_->GetWebContentsModalDialogHost());
+ child_dialogs_.push_back(new DialogState(dialog, manager.Pass()));
if (child_dialogs_.size() == 1) {
- if (delegate_ && delegate_->IsWebContentsVisible(web_contents()))
- native_manager_->ShowDialog(dialog);
BlockWebContentsInteraction(true);
+ if (delegate_ && delegate_->IsWebContentsVisible(web_contents()))
+ child_dialogs_.back()->manager->Show();
}
}
return !child_dialogs_.empty();
}
-void WebContentsModalDialogManager::FocusTopmostDialog() {
+void WebContentsModalDialogManager::FocusTopmostDialog() const {
DCHECK(!child_dialogs_.empty());
- native_manager_->FocusDialog(child_dialogs_.front().dialog);
-}
-
-void WebContentsModalDialogManager::SetCloseOnInterstitialPage(
- NativeWebContentsModalDialog dialog,
- bool close) {
- WebContentsModalDialogList::iterator loc = FindDialogState(dialog);
- DCHECK(loc != child_dialogs_.end());
- loc->close_on_interstitial_webui = close;
+ child_dialogs_.front()->manager->Focus();
}
content::WebContents* WebContentsModalDialogManager::GetWebContents() const {
void WebContentsModalDialogManager::WillClose(
NativeWebContentsModalDialog dialog) {
- WebContentsModalDialogList::iterator i = FindDialogState(dialog);
+ WebContentsModalDialogList::iterator dlg = FindDialogState(dialog);
// The Views tab contents modal dialog calls WillClose twice. Ignore the
// second invocation.
- if (i == child_dialogs_.end())
+ if (dlg == child_dialogs_.end())
return;
- bool removed_topmost_dialog = i == child_dialogs_.begin();
- child_dialogs_.erase(i);
+ bool removed_topmost_dialog = dlg == child_dialogs_.begin();
+ scoped_ptr<DialogState> deleter(*dlg);
+ child_dialogs_.erase(dlg);
if (!child_dialogs_.empty() && removed_topmost_dialog &&
- !closing_all_dialogs_)
- native_manager_->ShowDialog(child_dialogs_.front().dialog);
+ !closing_all_dialogs_) {
+ child_dialogs_.front()->manager->Show();
+ }
BlockWebContentsInteraction(!child_dialogs_.empty());
}
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
delegate_(NULL),
- native_manager_(CreateNativeManager(this)),
closing_all_dialogs_(false) {
- DCHECK(native_manager_);
}
WebContentsModalDialogManager::DialogState::DialogState(
- NativeWebContentsModalDialog dialog)
+ NativeWebContentsModalDialog dialog,
+ scoped_ptr<SingleWebContentsDialogManager> mgr)
: dialog(dialog),
-#if defined(OS_WIN) || defined(USE_AURA)
- close_on_interstitial_webui(true)
-#else
- // TODO(wittman): Test that closing on interstitial webui works properly
- // on Mac and use the true default for all platforms.
- close_on_interstitial_webui(false)
-#endif
- {
+ manager(mgr.release()) {
}
+WebContentsModalDialogManager::DialogState::~DialogState() {}
+
WebContentsModalDialogManager::WebContentsModalDialogList::iterator
WebContentsModalDialogManager::FindDialogState(
NativeWebContentsModalDialog dialog) {
WebContentsModalDialogList::iterator i;
for (i = child_dialogs_.begin(); i != child_dialogs_.end(); ++i) {
- if (i->dialog == dialog)
+ if ((*i)->dialog == dialog)
break;
}
return i;
}
+// TODO(gbillock): Move this to Views impl within Show()? It would
+// call WebContents* contents = native_delegate_->GetWebContents(); and
+// then set the block state. Advantage: could restrict some of the
+// WCMDM delegate methods, then, and pass them behind the scenes.
void WebContentsModalDialogManager::BlockWebContentsInteraction(bool blocked) {
WebContents* contents = web_contents();
if (!contents) {
closing_all_dialogs_ = true;
// Clear out any dialogs since we are leaving this page entirely.
- while (!child_dialogs_.empty())
- native_manager_->CloseDialog(child_dialogs_.front().dialog);
+ while (!child_dialogs_.empty()) {
+ child_dialogs_.front()->manager->Close();
+ }
closing_all_dialogs_ = false;
}
// Close constrained windows if necessary.
if (!net::registry_controlled_domains::SameDomainOrHost(
details.previous_url, details.entry->GetURL(),
- net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES))
+ net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES))
CloseAllDialogs();
}
void WebContentsModalDialogManager::DidGetIgnoredUIEvent() {
- if (!child_dialogs_.empty())
- native_manager_->FocusDialog(child_dialogs_.front().dialog);
+ if (!child_dialogs_.empty()) {
+ child_dialogs_.front()->manager->Focus();
+ }
}
void WebContentsModalDialogManager::WasShown() {
if (!child_dialogs_.empty())
- native_manager_->ShowDialog(child_dialogs_.front().dialog);
+ child_dialogs_.front()->manager->Show();
}
void WebContentsModalDialogManager::WasHidden() {
if (!child_dialogs_.empty())
- native_manager_->HideDialog(child_dialogs_.front().dialog);
+ child_dialogs_.front()->manager->Hide();
}
-void WebContentsModalDialogManager::WebContentsDestroyed(WebContents* tab) {
+void WebContentsModalDialogManager::WebContentsDestroyed() {
// First cleanly close all child dialogs.
// TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
// some of these to close. CloseAllDialogs is async, so it might get called
}
void WebContentsModalDialogManager::DidAttachInterstitialPage() {
- // Copy the dialogs so we can close and remove them while iterating over the
- // list.
- WebContentsModalDialogList dialogs(child_dialogs_);
- for (WebContentsModalDialogList::iterator it = dialogs.begin();
- it != dialogs.end(); ++it) {
- if (it->close_on_interstitial_webui)
- native_manager_->CloseDialog(it->dialog);
- }
+ // TODO(wittman): Test closing on interstitial webui works properly on Mac.
+#if defined(USE_AURA)
+ CloseAllDialogs();
+#endif
}
} // namespace web_modal