summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-04 21:25:36 +0000
committerbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-04 21:25:36 +0000
commitf6e5d8c70005185a227f0a2fc4bdb6b6d4a63b81 (patch)
tree1326a32e06113cd4b890459e1030018e8dd1b978
parent16d90004f2f6c1f3d975cc8a56f9c3270139d01e (diff)
downloadchromium_src-f6e5d8c70005185a227f0a2fc4bdb6b6d4a63b81.zip
chromium_src-f6e5d8c70005185a227f0a2fc4bdb6b6d4a63b81.tar.gz
chromium_src-f6e5d8c70005185a227f0a2fc4bdb6b6d4a63b81.tar.bz2
Reland 116165:
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. Original review: http://codereview.chromium.org/9016039/ BUG=92795, 108327 TEST=TabModalConfirmDialogTest.* Review URL: http://codereview.chromium.org/9086004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116388 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/cocoa/constrained_window_mac.h4
-rw-r--r--chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.h4
-rw-r--r--chrome/browser/ui/tab_modal_confirm_dialog_browsertest.cc104
-rw-r--r--chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h54
-rw-r--r--chrome/browser/ui/tab_modal_confirm_dialog_browsertest_mac.mm22
-rw-r--r--chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc10
-rw-r--r--chrome/browser/ui/tab_modal_confirm_dialog_delegate.h11
-rw-r--r--chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc140
-rw-r--r--chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.h42
-rw-r--r--chrome/chrome_tests.gypi3
10 files changed, 294 insertions, 100 deletions
diff --git a/chrome/browser/ui/cocoa/constrained_window_mac.h b/chrome/browser/ui/cocoa/constrained_window_mac.h
index ca28fda..9e062d3 100644
--- a/chrome/browser/ui/cocoa/constrained_window_mac.h
+++ b/chrome/browser/ui/cocoa/constrained_window_mac.h
@@ -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.
@@ -68,6 +68,8 @@ class ConstrainedWindowMacDelegateSystemSheet
virtual NSArray* GetSheetParameters(id delegate, SEL didEndSelector);
private:
+ friend class TabModalConfirmDialogTest;
+
virtual void RunSheet(GTMWindowSheetController* sheetController,
NSView* view) OVERRIDE;
scoped_nsobject<id> systemSheet_;
diff --git a/chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.h b/chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.h
index 632d9a7..f8c4ed5 100644
--- a/chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.h
+++ b/chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.h
@@ -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.
@@ -32,6 +32,8 @@ class TabModalConfirmDialogGtk : public ConstrainedWindowGtkDelegate {
virtual void DeleteDelegate() OVERRIDE;
private:
+ friend class TabModalConfirmDialogTest;
+
virtual ~TabModalConfirmDialogGtk();
// Callbacks
diff --git a/chrome/browser/ui/tab_modal_confirm_dialog_browsertest.cc b/chrome/browser/ui/tab_modal_confirm_dialog_browsertest.cc
new file mode 100644
index 0000000..6d9366c
--- /dev/null
+++ b/chrome/browser/ui/tab_modal_confirm_dialog_browsertest.cc
@@ -0,0 +1,104 @@
+// 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.
+
+#include "chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h"
+
+#include "base/bind.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/ui/browser_dialogs.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/browser/tab_contents/test_tab_contents.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class MockTabModalConfirmDialogDelegate : public TabModalConfirmDialogDelegate {
+ public:
+ explicit MockTabModalConfirmDialogDelegate(content::WebContents* web_contents)
+ : TabModalConfirmDialogDelegate(web_contents) {}
+
+ virtual string16 GetTitle() OVERRIDE {
+ return ASCIIToUTF16("");
+ }
+ virtual string16 GetMessage() OVERRIDE {
+ return ASCIIToUTF16("");
+ }
+
+ MOCK_METHOD0(OnAccepted, void());
+ MOCK_METHOD0(OnCanceled, void());
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockTabModalConfirmDialogDelegate);
+};
+
+TabModalConfirmDialogTest::TabModalConfirmDialogTest()
+ : delegate_(NULL),
+ dialog_(NULL) {}
+
+void TabModalConfirmDialogTest::SetUpOnMainThread() {
+ delegate_ = new MockTabModalConfirmDialogDelegate(
+ browser()->GetSelectedWebContents());
+ dialog_ = CreateTestDialog(delegate_,
+ browser()->GetSelectedTabContentsWrapper());
+ ui_test_utils::RunAllPendingInMessageLoop();
+}
+
+void TabModalConfirmDialogTest::CleanUpOnMainThread() {
+ ui_test_utils::RunAllPendingInMessageLoop();
+ ::testing::Mock::VerifyAndClearExpectations(delegate_);
+}
+
+// On Mac OS, these methods need to be compiled as Objective-C++, so they're in
+// a separate file.
+#if !defined(OS_MACOSX)
+TabModalConfirmDialog* TabModalConfirmDialogTest::CreateTestDialog(
+ TabModalConfirmDialogDelegate* delegate, TabContentsWrapper* wrapper) {
+ return new TabModalConfirmDialog(delegate, wrapper);
+}
+
+void TabModalConfirmDialogTest::CloseDialog(bool accept) {
+#if defined(TOOLKIT_GTK)
+ if (accept)
+ dialog_->OnAccept(NULL);
+ else
+ dialog_->OnCancel(NULL);
+#elif defined(OS_CHROMEOS) || defined(USE_AURA)
+ // |dialog_| deletes itself in |OnDialogClosed()|, so we need to save its
+ // ConstrainedHTMLUIDelegate before that.
+ ConstrainedHtmlUIDelegate* constrained_html_ui_delegate =
+ dialog_->constrained_html_ui_delegate();
+ dialog_->OnDialogClosed(accept ? "true" : "false");
+ constrained_html_ui_delegate->OnDialogCloseFromWebUI();
+#elif defined(OS_WIN)
+ if (accept)
+ dialog_->GetDialogClientView()->AcceptWindow();
+ else
+ dialog_->GetDialogClientView()->CancelWindow();
+#endif
+}
+#endif // !defined(OS_MACOSX)
+
+IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, Accept) {
+ EXPECT_CALL(*delegate_, OnAccepted());
+ CloseDialog(true);
+}
+
+IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, Cancel) {
+ EXPECT_CALL(*delegate_, OnCanceled());
+ CloseDialog(false);
+}
+
+IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, CancelSelf) {
+ EXPECT_CALL(*delegate_, OnCanceled());
+ delegate_->Cancel();
+}
+
+IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, Quit) {
+ EXPECT_CALL(*delegate_, OnCanceled());
+ MessageLoopForUI::current()->PostTask(FROM_HERE,
+ base::Bind(&BrowserList::AttemptExit));
+ ui_test_utils::RunMessageLoop();
+}
diff --git a/chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h b/chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h
new file mode 100644
index 0000000..7bce236
--- /dev/null
+++ b/chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h
@@ -0,0 +1,54 @@
+// 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.
+
+#ifndef CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_BROWSERTEST_H_
+#define CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_BROWSERTEST_H_
+#pragma once
+
+#include "chrome/test/base/in_process_browser_test.h"
+#include "content/test/test_browser_thread.h"
+
+#if defined(OS_MACOSX)
+class TabModalConfirmDialogMac;
+typedef TabModalConfirmDialogMac TabModalConfirmDialog;
+#elif defined(TOOLKIT_GTK)
+#include "chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.h"
+typedef TabModalConfirmDialogGtk TabModalConfirmDialog;
+#elif defined(OS_CHROMEOS) || defined(USE_AURA)
+#include "chrome/browser/ui/webui/constrained_html_ui.h"
+#include "chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.h"
+typedef TabModalConfirmDialogWebUI TabModalConfirmDialog;
+#elif defined(OS_WIN)
+#include "chrome/browser/ui/views/tab_modal_confirm_dialog_views.h"
+typedef TabModalConfirmDialogViews TabModalConfirmDialog;
+#endif
+
+class MockTabModalConfirmDialogDelegate;
+class TabContentsWrapper;
+class TabModalConfirmDialogDelegate;
+
+class TabModalConfirmDialogTest : public InProcessBrowserTest {
+ public:
+ TabModalConfirmDialogTest();
+
+ virtual void SetUpOnMainThread() OVERRIDE;
+ virtual void CleanUpOnMainThread() OVERRIDE;
+
+ protected:
+ void CloseDialog(bool accept);
+
+ // Owned by |dialog_|.
+ MockTabModalConfirmDialogDelegate* delegate_;
+
+ private:
+ TabModalConfirmDialog* CreateTestDialog(
+ TabModalConfirmDialogDelegate* delegate, TabContentsWrapper* wrapper);
+
+ // Deletes itself.
+ TabModalConfirmDialog* dialog_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogTest);
+};
+
+#endif // CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_BROWSERTEST_H_
diff --git a/chrome/browser/ui/tab_modal_confirm_dialog_browsertest_mac.mm b/chrome/browser/ui/tab_modal_confirm_dialog_browsertest_mac.mm
new file mode 100644
index 0000000..20046a0
--- /dev/null
+++ b/chrome/browser/ui/tab_modal_confirm_dialog_browsertest_mac.mm
@@ -0,0 +1,22 @@
+// 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.
+
+#include "chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h"
+
+#include "chrome/browser/ui/cocoa/tab_modal_confirm_dialog_mac.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TabModalConfirmDialog* TabModalConfirmDialogTest::CreateTestDialog(
+ TabModalConfirmDialogDelegate* delegate, TabContentsWrapper* wrapper) {
+ return new TabModalConfirmDialogMac(delegate, wrapper);
+}
+
+void TabModalConfirmDialogTest::CloseDialog(bool accept) {
+ NSWindow* window = [(NSAlert*)dialog_->sheet() window];
+ ASSERT_TRUE(window);
+ ASSERT_TRUE(dialog_->is_sheet_open());
+ [NSApp endSheet:window
+ returnCode:accept ? NSAlertFirstButtonReturn :
+ NSAlertSecondButtonReturn];
+}
diff --git a/chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc b/chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc
index 1a81142..d4d6185 100644
--- a/chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc
+++ b/chrome/browser/ui/tab_modal_confirm_dialog_delegate.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.
@@ -36,6 +36,9 @@ TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() {
void TabModalConfirmDialogDelegate::Cancel() {
if (closing_)
return;
+ // Make sure we won't do anything when |Cancel()| or |Accept()| is called
+ // again.
+ closing_ = true;
OnCanceled();
CloseDialog();
}
@@ -43,6 +46,9 @@ void TabModalConfirmDialogDelegate::Cancel() {
void TabModalConfirmDialogDelegate::Accept() {
if (closing_)
return;
+ // Make sure we won't do anything when |Cancel()| or |Accept()| is called
+ // again.
+ closing_ = true;
OnAccepted();
CloseDialog();
}
@@ -89,8 +95,6 @@ void TabModalConfirmDialogDelegate::OnCanceled() {
}
void TabModalConfirmDialogDelegate::CloseDialog() {
- // Make sure we won't do anything when |Cancel()| is called again.
- closing_ = true;
if (window_)
window_->CloseConstrainedWindow();
}
diff --git a/chrome/browser/ui/tab_modal_confirm_dialog_delegate.h b/chrome/browser/ui/tab_modal_confirm_dialog_delegate.h
index 3e105dc..3b3e416 100644
--- a/chrome/browser/ui/tab_modal_confirm_dialog_delegate.h
+++ b/chrome/browser/ui/tab_modal_confirm_dialog_delegate.h
@@ -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.
@@ -31,7 +31,16 @@ class TabModalConfirmDialogDelegate : public content::NotificationObserver {
void set_window(ConstrainedWindow* window) { window_ = window; }
+ // Accepts the confirmation prompt and calls |OnAccepted|.
+ // This method is safe to call even from an |OnAccepted| or |OnCanceled|
+ // callback. It is guaranteed that exactly one of |OnAccepted| or |OnCanceled|
+ // is eventually called.
void Accept();
+
+ // Cancels the confirmation prompt and calls |OnCanceled|.
+ // This method is safe to call even from an |OnAccepted| or |OnCanceled|
+ // callback. It is guaranteed that exactly one of |OnAccepted| or |OnCanceled|
+ // is eventually called.
void Cancel();
// The title of the dialog. Note that the title is not shown on all platforms.
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;
}
diff --git a/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.h b/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.h
index edcb7b7..66ae8c9 100644
--- a/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.h
+++ b/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.h
@@ -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.
@@ -6,13 +6,15 @@
#define CHROME_BROWSER_UI_WEBUI_TAB_MODAL_CONFIRM_DIALOG_WEBUI_H_
#pragma once
-#if !(defined(USE_AURA) || defined(TOOLKIT_VIEWS))
+#if !(defined(USE_AURA) || defined(OS_CHROMEOS))
#error Tab-modal confirm dialog should be shown with native UI.
#endif
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/ui/webui/html_dialog_ui.h"
+class ConstrainedHtmlUIDelegate;
class TabContentsWrapper;
class TabModalConfirmDialogDelegate;
@@ -21,20 +23,38 @@ class TabModalConfirmDialogDelegate;
// To display the dialog, allocate this object on the heap. It will open the
// dialog from its constructor and then delete itself when the user dismisses
// the dialog.
-class TabModalConfirmDialogUI {
+class TabModalConfirmDialogWebUI : public HtmlDialogUIDelegate {
public:
- TabModalConfirmDialogUI(TabModalConfirmDialogDelegate* delegate,
- TabContentsWrapper* wrapper);
- ~TabModalConfirmDialogUI();
-
- // Invoked when the dialog is closed. Notifies the controller of the user's
- // response.
- void OnDialogClosed(bool accept);
+ TabModalConfirmDialogWebUI(
+ TabModalConfirmDialogDelegate* dialog_delegate,
+ TabContentsWrapper* wrapper);
+
+ // HtmlDialogUIDelegate implementation.
+ virtual bool IsDialogModal() const OVERRIDE;
+ virtual string16 GetDialogTitle() const OVERRIDE;
+ virtual GURL GetDialogContentURL() const OVERRIDE;
+ virtual void GetWebUIMessageHandlers(
+ std::vector<content::WebUIMessageHandler*>* handlers) const OVERRIDE;
+ virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
+ virtual std::string GetDialogArgs() const OVERRIDE;
+ virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE;
+ virtual void OnCloseContents(content::WebContents* source,
+ bool* out_close_dialog) OVERRIDE;
+ virtual bool ShouldShowDialogTitle() const OVERRIDE;
+
+ ConstrainedHtmlUIDelegate* constrained_html_ui_delegate() {
+ return constrained_html_ui_delegate_;
+ }
private:
+ virtual ~TabModalConfirmDialogWebUI();
+
scoped_ptr<TabModalConfirmDialogDelegate> delegate_;
- DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogUI);
+ // Deletes itself.
+ ConstrainedHtmlUIDelegate* constrained_html_ui_delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogWebUI);
};
#endif // CHROME_BROWSER_UI_WEBUI_TAB_MODAL_CONFIRM_DIALOG_WEBUI_H_
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 3796538..dc7656b 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -2674,6 +2674,9 @@
'browser/ui/panels/panel_app_browsertest.cc',
'browser/ui/panels/panel_browser_view_browsertest.cc',
'browser/ui/prefs/prefs_tab_helper_browsertest.cc',
+ 'browser/ui/tab_modal_confirm_dialog_browsertest_mac.mm',
+ 'browser/ui/tab_modal_confirm_dialog_browsertest.cc',
+ 'browser/ui/tab_modal_confirm_dialog_browsertest.h',
'browser/ui/views/browser_actions_container_browsertest.cc',
'browser/ui/views/dom_view_browsertest.cc',
'browser/ui/views/html_dialog_view_browsertest.cc',