diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-03 19:24:03 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-03 19:24:03 +0000 |
commit | 6739bc6e6b9d7b66e011b3f6a26c9394aec2e268 (patch) | |
tree | 78c0dc0114d0b108f0cfc8902e6cb592cbe9f234 /chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc | |
parent | 3e70c72cf356df8969b2b97794ac19eb1767af02 (diff) | |
download | chromium_src-6739bc6e6b9d7b66e011b3f6a26c9394aec2e268.zip chromium_src-6739bc6e6b9d7b66e011b3f6a26c9394aec2e268.tar.gz chromium_src-6739bc6e6b9d7b66e011b3f6a26c9394aec2e268.tar.bz2 |
Avoid calling OnCanceled when accepting a Re-POST form warning dialog, and add a browser test.
TabModalConfirmDialogHtmlDelegate needs to be visible to test code, so we move it into the header file, and merge it with TabModalConfirmDialogUI, as they have the same lifetime.
BUG=92795,108327
TEST=TabModalConfirmDialogTest.*
Review URL: http://codereview.chromium.org/9016039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116165 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc')
-rw-r--r-- | chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc | 140 |
1 files changed, 57 insertions, 83 deletions
diff --git a/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc b/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc index 38deeb9..f748f1a 100644 --- a/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc +++ b/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -19,7 +19,6 @@ #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" #include "chrome/browser/ui/webui/constrained_html_ui.h" -#include "chrome/browser/ui/webui/html_dialog_ui.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/url_constants.h" #include "content/browser/tab_contents/tab_contents.h" @@ -37,84 +36,15 @@ namespace browser { // Declared in browser_dialogs.h so others don't have to depend on our header. void ShowTabModalConfirmDialog(TabModalConfirmDialogDelegate* delegate, TabContentsWrapper* wrapper) { - new TabModalConfirmDialogUI(delegate, wrapper); + new TabModalConfirmDialogWebUI(delegate, wrapper); } } // namespace browser -class TabModalConfirmDialogHtmlDelegate : public HtmlDialogUIDelegate { - public: - TabModalConfirmDialogHtmlDelegate( - TabModalConfirmDialogUI* ui, - TabModalConfirmDialogDelegate* dialog_delegate) - : ui_(ui), - dialog_delegate_(dialog_delegate) {} +const int kDialogWidth = 400; +const int kDialogHeight = 120; - virtual ~TabModalConfirmDialogHtmlDelegate() {} - - // HtmlDialogUIDelegate implementation. - virtual bool IsDialogModal() const OVERRIDE { - return true; - } - - virtual string16 GetDialogTitle() const OVERRIDE { - return dialog_delegate_->GetTitle(); - } - - virtual GURL GetDialogContentURL() const OVERRIDE { - return GURL(chrome::kChromeUITabModalConfirmDialogURL); - } - - virtual void GetWebUIMessageHandlers( - std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE {} - - virtual void GetDialogSize(gfx::Size* size) const OVERRIDE { - size->SetSize(kDialogWidth, kDialogHeight); - } - - virtual std::string GetDialogArgs() const OVERRIDE { - DictionaryValue dict; - dict.SetString("message", dialog_delegate_->GetMessage()); - dict.SetString("accept", dialog_delegate_->GetAcceptButtonTitle()); - dict.SetString("cancel", dialog_delegate_->GetCancelButtonTitle()); - ChromeWebUIDataSource::SetFontAndTextDirection(&dict); - std::string json; - base::JSONWriter::Write(&dict, false, &json); - return json; - } - - virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { - bool accepted = false; - if (!json_retval.empty()) { - base::JSONReader reader; - scoped_ptr<Value> value(reader.JsonToValue(json_retval, false, false)); - DCHECK(value.get() && value->GetAsBoolean(&accepted)) - << "Missing or unreadable response from dialog"; - } - - ui_->OnDialogClosed(accepted); - delete this; - } - - virtual void OnCloseContents(WebContents* source, - bool* out_close_dialog) OVERRIDE {} - - virtual bool ShouldShowDialogTitle() const OVERRIDE { - return true; - } - - private: - static const int kDialogWidth = 400; - static const int kDialogHeight = 120; - - scoped_ptr<TabModalConfirmDialogUI> ui_; - // Owned by TabModalConfirmDialogUI, which we own. - TabModalConfirmDialogDelegate* dialog_delegate_; - - DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogHtmlDelegate); -}; - -TabModalConfirmDialogUI::TabModalConfirmDialogUI( +TabModalConfirmDialogWebUI::TabModalConfirmDialogWebUI( TabModalConfirmDialogDelegate* delegate, TabContentsWrapper* wrapper) : delegate_(delegate) { @@ -124,20 +54,64 @@ TabModalConfirmDialogUI::TabModalConfirmDialogUI( data_source->set_default_resource(IDR_TAB_MODAL_CONFIRM_DIALOG_HTML); profile->GetChromeURLDataManager()->AddDataSource(data_source); - TabModalConfirmDialogHtmlDelegate* html_delegate = - new TabModalConfirmDialogHtmlDelegate(this, delegate); - ConstrainedHtmlUIDelegate* dialog_delegate = - ConstrainedHtmlUI::CreateConstrainedHtmlDialog(profile, html_delegate, - wrapper); - delegate_->set_window(dialog_delegate->window()); + constrained_html_ui_delegate_ = + ConstrainedHtmlUI::CreateConstrainedHtmlDialog(profile, this, wrapper); + delegate_->set_window(constrained_html_ui_delegate_->window()); +} + +TabModalConfirmDialogWebUI::~TabModalConfirmDialogWebUI() {} + +bool TabModalConfirmDialogWebUI::IsDialogModal() const { + return true; +} + +string16 TabModalConfirmDialogWebUI::GetDialogTitle() const { + return delegate_->GetTitle(); +} + +GURL TabModalConfirmDialogWebUI::GetDialogContentURL() const { + return GURL(chrome::kChromeUITabModalConfirmDialogURL); } -TabModalConfirmDialogUI::~TabModalConfirmDialogUI() {} +void TabModalConfirmDialogWebUI::GetWebUIMessageHandlers( + std::vector<WebUIMessageHandler*>* handlers) const {} + +void TabModalConfirmDialogWebUI::GetDialogSize(gfx::Size* size) const { + size->SetSize(kDialogWidth, kDialogHeight); +} + +std::string TabModalConfirmDialogWebUI::GetDialogArgs() const { + DictionaryValue dict; + dict.SetString("message", delegate_->GetMessage()); + dict.SetString("accept", delegate_->GetAcceptButtonTitle()); + dict.SetString("cancel", delegate_->GetCancelButtonTitle()); + ChromeWebUIDataSource::SetFontAndTextDirection(&dict); + std::string json; + base::JSONWriter::Write(&dict, false, &json); + return json; +} + +void TabModalConfirmDialogWebUI::OnDialogClosed( + const std::string& json_retval) { + bool accepted = false; + if (!json_retval.empty()) { + base::JSONReader reader; + scoped_ptr<Value> value(reader.JsonToValue(json_retval, false, false)); + DCHECK(value.get() && value->GetAsBoolean(&accepted)) + << "Missing or unreadable response from dialog"; + } -void TabModalConfirmDialogUI::OnDialogClosed(bool accepted) { delegate_->set_window(NULL); if (accepted) delegate_->Accept(); else delegate_->Cancel(); + delete this; +} + +void TabModalConfirmDialogWebUI::OnCloseContents(WebContents* source, + bool* out_close_dialog) {} + +bool TabModalConfirmDialogWebUI::ShouldShowDialogTitle() const { + return true; } |