summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-02 21:46:59 +0000
committerjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-02 21:46:59 +0000
commit1f2b2fcea5361d4d1c1dca69bf1651bb93efcb08 (patch)
treee56f368b97549742870e1e8dceb14eaf348428b5
parent719c79fc5b526f35a6ea9be6f67f294fbe9c6001 (diff)
downloadchromium_src-1f2b2fcea5361d4d1c1dca69bf1651bb93efcb08.zip
chromium_src-1f2b2fcea5361d4d1c1dca69bf1651bb93efcb08.tar.gz
chromium_src-1f2b2fcea5361d4d1c1dca69bf1651bb93efcb08.tar.bz2
Add CanCloseDialog to WebDialogDelegate to allow blocking closing of dialog if needed.
There are some use cases that we don't allow user to close the web dialog until they have finish the UI flow and confirmed some important information. Currently, WebDialogDelegate can't control the closing of the dialog if user presses the "x" button on dialog title bar or presses Esc shortcut key. I am adding a CanClose() method to allow the subclass to block the dialog close if it needs to do so. BUG=322614 Review URL: https://codereview.chromium.org/82913007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238193 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/views/controls/webview/web_dialog_view.cc5
-rw-r--r--ui/web_dialogs/web_dialog_delegate.cc4
-rw-r--r--ui/web_dialogs/web_dialog_delegate.h6
3 files changed, 15 insertions, 0 deletions
diff --git a/ui/views/controls/webview/web_dialog_view.cc b/ui/views/controls/webview/web_dialog_view.cc
index 079200c..7f88f02 100644
--- a/ui/views/controls/webview/web_dialog_view.cc
+++ b/ui/views/controls/webview/web_dialog_view.cc
@@ -100,6 +100,11 @@ void WebDialogView::ViewHierarchyChanged(
}
bool WebDialogView::CanClose() {
+ // Don't close UI if |delegate_| does not allow users to close it by
+ // clicking on "x" button or pressing Esc shortcut key on hosting dialog.
+ if (!delegate_->CanCloseDialog() && !close_contents_called_)
+ return false;
+
// If CloseContents() is called before CanClose(), which is called by
// RenderViewHostImpl::ClosePageIgnoringUnloadEvents, it indicates
// beforeunload event should not be fired during closing.
diff --git a/ui/web_dialogs/web_dialog_delegate.cc b/ui/web_dialogs/web_dialog_delegate.cc
index ed41410..d3688e0 100644
--- a/ui/web_dialogs/web_dialog_delegate.cc
+++ b/ui/web_dialogs/web_dialog_delegate.cc
@@ -14,6 +14,10 @@ void WebDialogDelegate::GetMinimumDialogSize(gfx::Size* size) const {
GetDialogSize(size);
}
+bool WebDialogDelegate::CanCloseDialog() const {
+ return true;
+}
+
void WebDialogDelegate::OnDialogCloseFromWebUI(
const std::string& json_retval) {
OnDialogClosed(json_retval);
diff --git a/ui/web_dialogs/web_dialog_delegate.h b/ui/web_dialogs/web_dialog_delegate.h
index 8416c1f..2bd772f 100644
--- a/ui/web_dialogs/web_dialog_delegate.h
+++ b/ui/web_dialogs/web_dialog_delegate.h
@@ -63,6 +63,12 @@ class WEB_DIALOGS_EXPORT WebDialogDelegate {
// Gets the JSON string input to use when showing the dialog.
virtual std::string GetDialogArgs() const = 0;
+ // Returns true to signal that the dialog can be closed. Specialized
+ // WebDialogDelegate subclasses can override this default behavior to allow
+ // the close to be blocked until the user corrects mistakes, accepts an
+ // agreement, etc.
+ virtual bool CanCloseDialog() const;
+
// A callback to notify the delegate that |source|'s loading state has
// changed.
virtual void OnLoadingStateChanged(content::WebContents* source) {}