summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r--chrome/browser/ui/browser.cc5
-rw-r--r--chrome/browser/ui/browser_dialogs.h6
-rw-r--r--chrome/browser/ui/browser_window.h3
-rw-r--r--chrome/browser/ui/cocoa/browser_window_cocoa.h1
-rw-r--r--chrome/browser/ui/cocoa/browser_window_cocoa.mm6
-rw-r--r--chrome/browser/ui/cocoa/repost_form_warning_mac.h43
-rw-r--r--chrome/browser/ui/cocoa/repost_form_warning_mac.mm88
-rw-r--r--chrome/browser/ui/cocoa/tab_modal_confirm_dialog_mac.h40
-rw-r--r--chrome/browser/ui/cocoa/tab_modal_confirm_dialog_mac.mm96
-rw-r--r--chrome/browser/ui/gtk/browser_window_gtk.cc5
-rw-r--r--chrome/browser/ui/gtk/browser_window_gtk.h1
-rw-r--r--chrome/browser/ui/gtk/repost_form_warning_gtk.cc85
-rw-r--r--chrome/browser/ui/gtk/repost_form_warning_gtk.h49
-rw-r--r--chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.cc109
-rw-r--r--chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.h51
-rw-r--r--chrome/browser/ui/panels/panel.cc4
-rw-r--r--chrome/browser/ui/panels/panel.h1
-rw-r--r--chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc93
-rw-r--r--chrome/browser/ui/tab_modal_confirm_dialog_delegate.h79
-rw-r--r--chrome/browser/ui/views/browser_dialogs.h5
-rw-r--r--chrome/browser/ui/views/dialog_stubs_gtk.cc6
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc4
-rw-r--r--chrome/browser/ui/views/frame/browser_view.h1
-rw-r--r--chrome/browser/ui/views/tab_modal_confirm_dialog_views.cc (renamed from chrome/browser/ui/views/repost_form_warning_view.cc)70
-rw-r--r--chrome/browser/ui/views/tab_modal_confirm_dialog_views.h (renamed from chrome/browser/ui/views/repost_form_warning_view.h)28
-rw-r--r--chrome/browser/ui/webui/chrome_url_data_manager_backend.cc2
-rw-r--r--chrome/browser/ui/webui/chrome_web_ui_factory.cc2
-rw-r--r--chrome/browser/ui/webui/repost_form_warning_ui.cc166
-rw-r--r--chrome/browser/ui/webui/repost_form_warning_ui.h47
-rw-r--r--chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc143
-rw-r--r--chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.h40
31 files changed, 713 insertions, 566 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index d862822..ab62271 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -77,6 +77,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
+#include "chrome/browser/repost_form_warning_controller.h"
#include "chrome/browser/sessions/restore_tab_helper.h"
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sessions/session_service_factory.h"
@@ -3795,7 +3796,9 @@ void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
}
void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) {
- window()->ShowRepostFormWarningDialog(tab_contents);
+ browser::ShowTabModalConfirmDialog(
+ new RepostFormWarningController(tab_contents),
+ window()->GetNativeHandle(), tab_contents);
}
void Browser::ShowContentSettingsPage(ContentSettingsType content_type) {
diff --git a/chrome/browser/ui/browser_dialogs.h b/chrome/browser/ui/browser_dialogs.h
index ca42868..3a715be 100644
--- a/chrome/browser/ui/browser_dialogs.h
+++ b/chrome/browser/ui/browser_dialogs.h
@@ -16,6 +16,7 @@ class HtmlDialogUIDelegate;
class Profile;
class SkBitmap;
class TabContents;
+class TabModalConfirmDialogDelegate;
class TemplateURL;
namespace browser {
@@ -62,6 +63,11 @@ void HideNativeHungRendererDialog(TabContents* contents);
void ConfirmAddSearchProvider(const TemplateURL* template_url,
Profile* profile);
+// Shows a tab-modal dialog box.
+void ShowTabModalConfirmDialog(TabModalConfirmDialogDelegate* delegate,
+ gfx::NativeWindow parent_window,
+ TabContents* tab_contents);
+
} // namespace browser
#endif // CHROME_BROWSER_UI_BROWSER_DIALOGS_H_
diff --git a/chrome/browser/ui/browser_window.h b/chrome/browser/ui/browser_window.h
index 41b321d..598b9ff 100644
--- a/chrome/browser/ui/browser_window.h
+++ b/chrome/browser/ui/browser_window.h
@@ -239,9 +239,6 @@ class BrowserWindow {
// Returns the DownloadShelf.
virtual DownloadShelf* GetDownloadShelf() = 0;
- // Shows the repost form confirmation dialog box.
- virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) = 0;
-
// Shows the collected cookies dialog box.
virtual void ShowCollectedCookiesDialog(TabContentsWrapper* tab_contents) = 0;
diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.h b/chrome/browser/ui/cocoa/browser_window_cocoa.h
index 425e55e..fdf714f 100644
--- a/chrome/browser/ui/cocoa/browser_window_cocoa.h
+++ b/chrome/browser/ui/cocoa/browser_window_cocoa.h
@@ -91,7 +91,6 @@ class BrowserWindowCocoa : public BrowserWindow,
bool already_bookmarked) OVERRIDE;
virtual bool IsDownloadShelfVisible() const OVERRIDE;
virtual DownloadShelf* GetDownloadShelf() OVERRIDE;
- virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) OVERRIDE;
virtual void ShowCollectedCookiesDialog(TabContentsWrapper* wrapper) OVERRIDE;
virtual void ConfirmBrowserCloseWithPendingDownloads() OVERRIDE;
virtual void UserChangedTheme() OVERRIDE;
diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
index 46b289d..9db4de1 100644
--- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
@@ -31,7 +31,6 @@
#import "chrome/browser/ui/cocoa/info_bubble_view.h"
#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
-#include "chrome/browser/ui/cocoa/repost_form_warning_mac.h"
#include "chrome/browser/ui/cocoa/restart_browser.h"
#include "chrome/browser/ui/cocoa/status_bubble_mac.h"
#include "chrome/browser/ui/cocoa/task_manager_mac.h"
@@ -433,11 +432,6 @@ DownloadShelf* BrowserWindowCocoa::GetDownloadShelf() {
return [shelfController bridge];
}
-void BrowserWindowCocoa::ShowRepostFormWarningDialog(
- TabContents* tab_contents) {
- RepostFormWarningMac::Create(GetNativeHandle(), tab_contents);
-}
-
void BrowserWindowCocoa::ShowCollectedCookiesDialog(
TabContentsWrapper* wrapper) {
// Deletes itself on close.
diff --git a/chrome/browser/ui/cocoa/repost_form_warning_mac.h b/chrome/browser/ui/cocoa/repost_form_warning_mac.h
deleted file mode 100644
index 700cfd9..0000000
--- a/chrome/browser/ui/cocoa/repost_form_warning_mac.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) 2011 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_COCOA_REPOST_FORM_WARNING_MAC_H_
-#define CHROME_BROWSER_UI_COCOA_REPOST_FORM_WARNING_MAC_H_
-#pragma once
-
-#import <Cocoa/Cocoa.h>
-
-#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/ui/cocoa/constrained_window_mac.h"
-
-class RepostFormWarningController;
-class TabContents;
-
-// Displays a dialog that warns the user that they are about to resubmit
-// a form. To show the dialog, call the |Create| method. It will open the
-// dialog and then delete itself when the user dismisses the dialog.
-class RepostFormWarningMac : public ConstrainedWindowMacDelegateSystemSheet {
- public:
- // Convenience method that creates a new |RepostFormWarningController| and
- // then a new |RepostFormWarningMac| from that.
- static RepostFormWarningMac* Create(NSWindow* parent,
- TabContents* tab_contents);
-
- RepostFormWarningMac(NSWindow* parent,
- RepostFormWarningController* controller,
- TabContents* tab_contents);
-
- // ConstrainedWindowDelegateMacSystemSheet methods:
- virtual void DeleteDelegate() OVERRIDE;
-
- private:
- virtual ~RepostFormWarningMac();
-
- scoped_ptr<RepostFormWarningController> controller_;
- TabContents* tab_contents_;
-
- DISALLOW_COPY_AND_ASSIGN(RepostFormWarningMac);
-};
-
-#endif // CHROME_BROWSER_UI_COCOA_REPOST_FORM_WARNING_MAC_H_
diff --git a/chrome/browser/ui/cocoa/repost_form_warning_mac.mm b/chrome/browser/ui/cocoa/repost_form_warning_mac.mm
deleted file mode 100644
index 4300ac1..0000000
--- a/chrome/browser/ui/cocoa/repost_form_warning_mac.mm
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright (c) 2011 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/cocoa/repost_form_warning_mac.h"
-
-#include "base/memory/scoped_nsobject.h"
-#include "chrome/browser/repost_form_warning_controller.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
-#include "grit/generated_resources.h"
-#include "ui/base/l10n/l10n_util_mac.h"
-
-// The delegate of the NSAlert used to display the dialog. Forwards the alert's
-// completion event to the C++ class |RepostFormWarningController|.
-@interface RepostDelegate : NSObject {
- RepostFormWarningController* warning_; // weak
-}
-- (id)initWithWarning:(RepostFormWarningController*)warning;
-- (void)alertDidEnd:(NSAlert*)alert
- returnCode:(int)returnCode
- contextInfo:(void*)contextInfo;
-@end
-
-@implementation RepostDelegate
-- (id)initWithWarning:(RepostFormWarningController*)warning {
- if ((self = [super init])) {
- warning_ = warning;
- }
- return self;
-}
-
-- (void)alertDidEnd:(NSAlert*)alert
- returnCode:(int)returnCode
- contextInfo:(void*)contextInfo {
- if (returnCode == NSAlertFirstButtonReturn) {
- warning_->Continue();
- } else {
- warning_->Cancel();
- }
-}
-@end
-
-RepostFormWarningMac* RepostFormWarningMac::Create(NSWindow* parent,
- TabContents* tab_contents) {
- return new RepostFormWarningMac(
- parent,
- new RepostFormWarningController(tab_contents),
- tab_contents);
-}
-
-RepostFormWarningMac::RepostFormWarningMac(
- NSWindow* parent,
- RepostFormWarningController* controller,
- TabContents* tab_contents)
- : ConstrainedWindowMacDelegateSystemSheet(
- [[[RepostDelegate alloc] initWithWarning:controller]
- autorelease],
- @selector(alertDidEnd:returnCode:contextInfo:)),
- controller_(controller),
- tab_contents_(tab_contents) {
- scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]);
- [alert setMessageText:
- l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING_TITLE)];
- [alert setInformativeText:
- l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING)];
- [alert addButtonWithTitle:
- l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING_RESEND)];
- [alert addButtonWithTitle:
- l10n_util::GetNSStringWithFixup(IDS_CANCEL)];
-
- set_sheet(alert);
-
- TabContentsWrapper* wrapper =
- TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
- controller->set_window(new ConstrainedWindowMac(wrapper, this));
-}
-
-RepostFormWarningMac::~RepostFormWarningMac() {
- NSWindow* window = [(NSAlert*)sheet() window];
- if (window && is_sheet_open()) {
- [NSApp endSheet:window
- returnCode:NSAlertSecondButtonReturn];
- }
-}
-
-void RepostFormWarningMac::DeleteDelegate() {
- delete this;
-}
diff --git a/chrome/browser/ui/cocoa/tab_modal_confirm_dialog_mac.h b/chrome/browser/ui/cocoa/tab_modal_confirm_dialog_mac.h
new file mode 100644
index 0000000..26398e4
--- /dev/null
+++ b/chrome/browser/ui/cocoa/tab_modal_confirm_dialog_mac.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2011 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_COCOA_TAB_MODAL_CONFIRM_DIALOG_MAC_H_
+#define CHROME_BROWSER_UI_COCOA_TAB_MODAL_CONFIRM_DIALOG_MAC_H_
+#pragma once
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/ui/cocoa/constrained_window_mac.h"
+
+class TabModalConfirmDialogDelegate;
+class TabContents;
+
+// Displays a tab-modal dialog, i.e. a dialog that will block the current page
+// but still allow the user to switch to a different page.
+// 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 TabModalConfirmDialogMac
+ : public ConstrainedWindowMacDelegateSystemSheet {
+ public:
+ TabModalConfirmDialogMac(NSWindow* parent,
+ TabModalConfirmDialogDelegate* delegate,
+ TabContents* tab_contents);
+
+ // ConstrainedWindowDelegateMacSystemSheet methods:
+ virtual void DeleteDelegate() OVERRIDE;
+
+ private:
+ virtual ~TabModalConfirmDialogMac();
+
+ scoped_ptr<TabModalConfirmDialogDelegate> delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogMac);
+};
+
+#endif // CHROME_BROWSER_UI_COCOA_TAB_MODAL_CONFIRM_DIALOG_MAC_H_
diff --git a/chrome/browser/ui/cocoa/tab_modal_confirm_dialog_mac.mm b/chrome/browser/ui/cocoa/tab_modal_confirm_dialog_mac.mm
new file mode 100644
index 0000000..564b5dc
--- /dev/null
+++ b/chrome/browser/ui/cocoa/tab_modal_confirm_dialog_mac.mm
@@ -0,0 +1,96 @@
+// Copyright (c) 2011 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/cocoa/tab_modal_confirm_dialog_mac.h"
+
+#include "base/memory/scoped_nsobject.h"
+#include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "ui/base/l10n/l10n_util_mac.h"
+#include "ui/gfx/image/image.h"
+
+// The delegate of the NSAlert used to display the dialog. Forwards the alert's
+// completion event to the C++ class |TabModalConfirmDialogDelegate|.
+@interface TabModalConfirmDialogMacBridge : NSObject {
+ TabModalConfirmDialogDelegate* delegate_; // weak
+}
+- (id)initWithDelegate:(TabModalConfirmDialogDelegate*)delegate;
+- (void)alertDidEnd:(NSAlert*)alert
+ returnCode:(int)returnCode
+ contextInfo:(void*)contextInfo;
+@end
+
+@implementation TabModalConfirmDialogMacBridge
+- (id)initWithDelegate:(TabModalConfirmDialogDelegate*)delegate {
+ if ((self = [super init])) {
+ delegate_ = delegate;
+ }
+ return self;
+}
+
+- (void)alertDidEnd:(NSAlert*)alert
+ returnCode:(int)returnCode
+ contextInfo:(void*)contextInfo {
+ if (returnCode == NSAlertFirstButtonReturn) {
+ delegate_->Accept();
+ } else {
+ delegate_->Cancel();
+ }
+}
+@end
+
+namespace browser {
+
+// Declared in browser_dialogs.h so others don't have to depend on our header.
+void ShowTabModalConfirmDialog(TabModalConfirmDialogDelegate* delegate,
+ gfx::NativeWindow parent_window,
+ TabContents* tab_contents) {
+ // Deletes itself when closed.
+ new TabModalConfirmDialogMac(parent_window, delegate, tab_contents);
+}
+
+}
+
+TabModalConfirmDialogMac::TabModalConfirmDialogMac(
+ NSWindow* parent,
+ TabModalConfirmDialogDelegate* delegate,
+ TabContents* tab_contents)
+ : ConstrainedWindowMacDelegateSystemSheet(
+ [[[TabModalConfirmDialogMacBridge alloc] initWithDelegate:delegate]
+ autorelease],
+ @selector(alertDidEnd:returnCode:contextInfo:)),
+ delegate_(delegate) {
+ scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]);
+ [alert setMessageText:
+ l10n_util::FixUpWindowsStyleLabel(delegate->GetTitle())];
+ [alert setInformativeText:
+ l10n_util::FixUpWindowsStyleLabel(delegate->GetMessage())];
+ [alert addButtonWithTitle:
+ l10n_util::FixUpWindowsStyleLabel(delegate->GetAcceptButtonTitle())];
+ [alert addButtonWithTitle:
+ l10n_util::FixUpWindowsStyleLabel(delegate->GetCancelButtonTitle())];
+ gfx::Image* icon = delegate->GetIcon();
+ if (icon)
+ [alert setIcon:icon->ToNSImage()];
+
+ set_sheet(alert);
+
+ TabContentsWrapper* wrapper =
+ TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
+ delegate->set_window(new ConstrainedWindowMac(wrapper, this));
+}
+
+TabModalConfirmDialogMac::~TabModalConfirmDialogMac() {
+ NSWindow* window = [(NSAlert*)sheet() window];
+ if (window && is_sheet_open()) {
+ [NSApp endSheet:window
+ returnCode:NSAlertSecondButtonReturn];
+ }
+}
+
+// "DeleteDelegate" refers to this class being a ConstrainedWindow delegate
+// and deleting itself, not to deleting the member variable |delegate_|.
+void TabModalConfirmDialogMac::DeleteDelegate() {
+ delete this;
+}
diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc
index 9e37e02..879b2f0 100644
--- a/chrome/browser/ui/gtk/browser_window_gtk.cc
+++ b/chrome/browser/ui/gtk/browser_window_gtk.cc
@@ -62,7 +62,6 @@
#include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
#include "chrome/browser/ui/gtk/nine_box.h"
#include "chrome/browser/ui/gtk/reload_button_gtk.h"
-#include "chrome/browser/ui/gtk/repost_form_warning_gtk.h"
#include "chrome/browser/ui/gtk/status_bubble_gtk.h"
#include "chrome/browser/ui/gtk/tab_contents_container_gtk.h"
#include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h"
@@ -1046,10 +1045,6 @@ DownloadShelf* BrowserWindowGtk::GetDownloadShelf() {
return download_shelf_.get();
}
-void BrowserWindowGtk::ShowRepostFormWarningDialog(TabContents* tab_contents) {
- new RepostFormWarningGtk(GetNativeHandle(), tab_contents);
-}
-
void BrowserWindowGtk::ShowCollectedCookiesDialog(TabContentsWrapper* wrapper) {
// Deletes itself on close.
new CollectedCookiesGtk(GetNativeHandle(), wrapper);
diff --git a/chrome/browser/ui/gtk/browser_window_gtk.h b/chrome/browser/ui/gtk/browser_window_gtk.h
index 201aba2..4e95d87 100644
--- a/chrome/browser/ui/gtk/browser_window_gtk.h
+++ b/chrome/browser/ui/gtk/browser_window_gtk.h
@@ -128,7 +128,6 @@ class BrowserWindowGtk : public BrowserWindow,
bool already_bookmarked) OVERRIDE;
virtual bool IsDownloadShelfVisible() const OVERRIDE;
virtual DownloadShelf* GetDownloadShelf() OVERRIDE;
- virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) OVERRIDE;
virtual void ShowCollectedCookiesDialog(
TabContentsWrapper* tab_contents) OVERRIDE;
virtual void ConfirmBrowserCloseWithPendingDownloads() OVERRIDE;
diff --git a/chrome/browser/ui/gtk/repost_form_warning_gtk.cc b/chrome/browser/ui/gtk/repost_form_warning_gtk.cc
deleted file mode 100644
index db4e838..0000000
--- a/chrome/browser/ui/gtk/repost_form_warning_gtk.cc
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright (c) 2011 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/gtk/repost_form_warning_gtk.h"
-
-#include "base/message_loop.h"
-#include "chrome/browser/repost_form_warning_controller.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
-#include "content/browser/tab_contents/navigation_controller.h"
-#include "content/browser/tab_contents/tab_contents.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/notification_types.h"
-#include "grit/generated_resources.h"
-#include "ui/base/gtk/gtk_hig_constants.h"
-#include "ui/base/l10n/l10n_util.h"
-
-RepostFormWarningGtk::RepostFormWarningGtk(GtkWindow* parent,
- TabContents* tab_contents)
- : controller_(new RepostFormWarningController(tab_contents)) {
- dialog_ = gtk_vbox_new(FALSE, ui::kContentAreaBorder);
- gtk_box_set_spacing(GTK_BOX(dialog_), ui::kContentAreaSpacing);
- GtkWidget* label = gtk_label_new(
- l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING).c_str());
- GtkWidget* image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION,
- GTK_ICON_SIZE_DIALOG);
- gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0);
-
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
- gtk_label_set_selectable(GTK_LABEL(label), TRUE);
-
- GtkWidget *hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
-
- gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
-
- gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
-
- gtk_box_pack_start(GTK_BOX(dialog_), hbox, FALSE, FALSE, 0);
-
- GtkWidget* buttonBox = gtk_hbutton_box_new();
- gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END);
- gtk_box_set_spacing(GTK_BOX(buttonBox), ui::kControlSpacing);
- gtk_box_pack_end(GTK_BOX(dialog_), buttonBox, FALSE, TRUE, 0);
-
- cancel_ = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
- gtk_button_set_label(GTK_BUTTON(cancel_),
- l10n_util::GetStringUTF8(IDS_CANCEL).c_str());
- g_signal_connect(cancel_, "clicked", G_CALLBACK(OnCancelThunk), this);
- gtk_box_pack_end(GTK_BOX(buttonBox), cancel_, FALSE, TRUE, 0);
-
- ok_ = gtk_button_new_from_stock(GTK_STOCK_REFRESH);
- gtk_button_set_label(
- GTK_BUTTON(ok_),
- l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING_RESEND).c_str());
- g_signal_connect(ok_, "clicked", G_CALLBACK(OnRefreshThunk), this);
- gtk_box_pack_end(GTK_BOX(buttonBox), ok_, FALSE, TRUE, 0);
-
- TabContentsWrapper* wrapper =
- TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
- controller_->set_window(new ConstrainedWindowGtk(wrapper, this));
-}
-
-GtkWidget* RepostFormWarningGtk::GetWidgetRoot() {
- return dialog_;
-}
-
-GtkWidget* RepostFormWarningGtk::GetFocusWidget() {
- return cancel_;
-}
-
-void RepostFormWarningGtk::DeleteDelegate() {
- delete this;
-}
-
-RepostFormWarningGtk::~RepostFormWarningGtk() {
- gtk_widget_destroy(dialog_);
-}
-
-void RepostFormWarningGtk::OnRefresh(GtkWidget* widget) {
- controller_->Continue();
-}
-
-void RepostFormWarningGtk::OnCancel(GtkWidget* widget) {
- controller_->Cancel();
-}
diff --git a/chrome/browser/ui/gtk/repost_form_warning_gtk.h b/chrome/browser/ui/gtk/repost_form_warning_gtk.h
deleted file mode 100644
index f14d335..0000000
--- a/chrome/browser/ui/gtk/repost_form_warning_gtk.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (c) 2011 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_GTK_REPOST_FORM_WARNING_GTK_H_
-#define CHROME_BROWSER_UI_GTK_REPOST_FORM_WARNING_GTK_H_
-#pragma once
-
-#include <gtk/gtk.h>
-
-#include "base/compiler_specific.h"
-#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/ui/gtk/constrained_window_gtk.h"
-#include "ui/base/gtk/gtk_signal.h"
-
-class RepostFormWarningController;
-class TabContents;
-
-// Displays a dialog that warns the user that they are about to resubmit
-// a form.
-// 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 RepostFormWarningGtk : public ConstrainedWindowGtkDelegate {
- public:
- RepostFormWarningGtk(GtkWindow* parent, TabContents* tab_contents);
-
- // ConstrainedWindowGtkDelegate methods
- virtual GtkWidget* GetWidgetRoot() OVERRIDE;
- virtual GtkWidget* GetFocusWidget() OVERRIDE;
- virtual void DeleteDelegate() OVERRIDE;
-
- private:
- virtual ~RepostFormWarningGtk();
-
- // Callbacks
- CHROMEGTK_CALLBACK_0(RepostFormWarningGtk, void, OnRefresh);
- CHROMEGTK_CALLBACK_0(RepostFormWarningGtk, void, OnCancel);
-
- scoped_ptr<RepostFormWarningController> controller_;
-
- GtkWidget* dialog_;
- GtkWidget* ok_;
- GtkWidget* cancel_;
-
- DISALLOW_COPY_AND_ASSIGN(RepostFormWarningGtk);
-};
-
-#endif // CHROME_BROWSER_UI_GTK_REPOST_FORM_WARNING_GTK_H_
diff --git a/chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.cc b/chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.cc
new file mode 100644
index 0000000..8cdafdb
--- /dev/null
+++ b/chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.cc
@@ -0,0 +1,109 @@
+// Copyright (c) 2011 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/gtk/tab_modal_confirm_dialog_gtk.h"
+
+#include "base/message_loop.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
+#include "content/browser/tab_contents/navigation_controller.h"
+#include "content/browser/tab_contents/tab_contents.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_types.h"
+#include "grit/generated_resources.h"
+#include "ui/base/gtk/gtk_hig_constants.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/gfx/image/image.h"
+
+namespace browser {
+
+// Declared in browser_dialogs.h so others don't have to depend on our header.
+void ShowTabModalConfirmDialog(TabModalConfirmDialogDelegate* delegate,
+ gfx::NativeWindow parent_window,
+ TabContents* tab_contents) {
+ new TabModalConfirmDialogGtk(parent_window, delegate, tab_contents);
+}
+
+}
+
+TabModalConfirmDialogGtk::TabModalConfirmDialogGtk(
+ GtkWindow* parent,
+ TabModalConfirmDialogDelegate* delegate,
+ TabContents* tab_contents)
+ : delegate_(delegate) {
+ dialog_ = gtk_vbox_new(FALSE, ui::kContentAreaBorder);
+ gtk_box_set_spacing(GTK_BOX(dialog_), ui::kContentAreaSpacing);
+ GtkWidget* label = gtk_label_new(
+ UTF16ToUTF8(delegate->GetMessage()).c_str());
+ gfx::Image* icon = delegate->GetIcon();
+ GtkWidget* image = icon ? gtk_image_new_from_pixbuf(icon->ToGdkPixbuf())
+ : gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION,
+ GTK_ICON_SIZE_DIALOG);
+ gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0);
+
+ gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
+ gtk_label_set_selectable(GTK_LABEL(label), TRUE);
+
+ GtkWidget *hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
+
+ gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
+
+ gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
+
+ gtk_box_pack_start(GTK_BOX(dialog_), hbox, FALSE, FALSE, 0);
+
+ GtkWidget* buttonBox = gtk_hbutton_box_new();
+ gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END);
+ gtk_box_set_spacing(GTK_BOX(buttonBox), ui::kControlSpacing);
+ gtk_box_pack_end(GTK_BOX(dialog_), buttonBox, FALSE, TRUE, 0);
+
+ cancel_ = gtk_button_new_with_label(
+ UTF16ToUTF8(delegate->GetCancelButtonTitle()).c_str());
+ const char* cancel_button_icon_id = delegate->GetCancelButtonIcon();
+ if (cancel_button_icon_id) {
+ gtk_button_set_image(GTK_BUTTON(cancel_), gtk_image_new_from_stock(
+ cancel_button_icon_id, GTK_ICON_SIZE_BUTTON));
+ }
+ g_signal_connect(cancel_, "clicked", G_CALLBACK(OnCancelThunk), this);
+ gtk_box_pack_end(GTK_BOX(buttonBox), cancel_, FALSE, TRUE, 0);
+
+ ok_ = gtk_button_new_with_label(
+ UTF16ToUTF8(delegate->GetAcceptButtonTitle()).c_str());
+ const char* accept_button_icon_id = delegate->GetAcceptButtonIcon();
+ if (accept_button_icon_id) {
+ gtk_button_set_image(GTK_BUTTON(ok_), gtk_image_new_from_stock(
+ accept_button_icon_id, GTK_ICON_SIZE_BUTTON));
+ }
+ g_signal_connect(ok_, "clicked", G_CALLBACK(OnRefreshThunk), this);
+ gtk_box_pack_end(GTK_BOX(buttonBox), ok_, FALSE, TRUE, 0);
+
+ TabContentsWrapper* wrapper =
+ TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
+ delegate->set_window(new ConstrainedWindowGtk(wrapper, this));
+}
+
+GtkWidget* TabModalConfirmDialogGtk::GetWidgetRoot() {
+ return dialog_;
+}
+
+GtkWidget* TabModalConfirmDialogGtk::GetFocusWidget() {
+ return cancel_;
+}
+
+void TabModalConfirmDialogGtk::DeleteDelegate() {
+ delete this;
+}
+
+TabModalConfirmDialogGtk::~TabModalConfirmDialogGtk() {
+ gtk_widget_destroy(dialog_);
+}
+
+void TabModalConfirmDialogGtk::OnRefresh(GtkWidget* widget) {
+ delegate_->Accept();
+}
+
+void TabModalConfirmDialogGtk::OnCancel(GtkWidget* widget) {
+ delegate_->Cancel();
+}
diff --git a/chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.h b/chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.h
new file mode 100644
index 0000000..3cfbfed
--- /dev/null
+++ b/chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.h
@@ -0,0 +1,51 @@
+// Copyright (c) 2011 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_GTK_TAB_MODAL_CONFIRM_DIALOG_GTK_H_
+#define CHROME_BROWSER_UI_GTK_TAB_MODAL_CONFIRM_DIALOG_GTK_H_
+#pragma once
+
+#include <gtk/gtk.h>
+
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/ui/gtk/constrained_window_gtk.h"
+#include "ui/base/gtk/gtk_signal.h"
+
+class TabContents;
+class TabModalConfirmDialogDelegate;
+
+// Displays a tab-modal dialog, i.e. a dialog that will block the current page
+// but still allow the user to switch to a different page.
+// 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 TabModalConfirmDialogGtk : public ConstrainedWindowGtkDelegate {
+ public:
+ TabModalConfirmDialogGtk(GtkWindow* parent,
+ TabModalConfirmDialogDelegate* delegate,
+ TabContents* tab_contents);
+
+ // ConstrainedWindowGtkDelegate methods
+ virtual GtkWidget* GetWidgetRoot() OVERRIDE;
+ virtual GtkWidget* GetFocusWidget() OVERRIDE;
+ virtual void DeleteDelegate() OVERRIDE;
+
+ private:
+ virtual ~TabModalConfirmDialogGtk();
+
+ // Callbacks
+ CHROMEGTK_CALLBACK_0(TabModalConfirmDialogGtk, void, OnRefresh);
+ CHROMEGTK_CALLBACK_0(TabModalConfirmDialogGtk, void, OnCancel);
+
+ scoped_ptr<TabModalConfirmDialogDelegate> delegate_;
+
+ GtkWidget* dialog_;
+ GtkWidget* ok_;
+ GtkWidget* cancel_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogGtk);
+};
+
+#endif // CHROME_BROWSER_UI_GTK_TAB_MODAL_CONFIRM_DIALOG_GTK_H_
diff --git a/chrome/browser/ui/panels/panel.cc b/chrome/browser/ui/panels/panel.cc
index d09e373..1e4d991 100644
--- a/chrome/browser/ui/panels/panel.cc
+++ b/chrome/browser/ui/panels/panel.cc
@@ -427,10 +427,6 @@ DownloadShelf* Panel::GetDownloadShelf() {
return tabbed_browser->window()->GetDownloadShelf();
}
-void Panel::ShowRepostFormWarningDialog(TabContents* tab_contents) {
- NOTIMPLEMENTED();
-}
-
void Panel::ShowCollectedCookiesDialog(TabContentsWrapper* wrapper) {
NOTIMPLEMENTED();
}
diff --git a/chrome/browser/ui/panels/panel.h b/chrome/browser/ui/panels/panel.h
index d3e6b49..547ccff 100644
--- a/chrome/browser/ui/panels/panel.h
+++ b/chrome/browser/ui/panels/panel.h
@@ -140,7 +140,6 @@ class Panel : public BrowserWindow,
const GURL& url, bool already_bookmarked) OVERRIDE;
virtual bool IsDownloadShelfVisible() const OVERRIDE;
virtual DownloadShelf* GetDownloadShelf() OVERRIDE;
- virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) OVERRIDE;
virtual void ShowCollectedCookiesDialog(TabContentsWrapper* wrapper) OVERRIDE;
virtual void ConfirmBrowserCloseWithPendingDownloads() OVERRIDE;
virtual void UserChangedTheme() OVERRIDE;
diff --git a/chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc b/chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc
new file mode 100644
index 0000000..f2b3590
--- /dev/null
+++ b/chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc
@@ -0,0 +1,93 @@
+// Copyright (c) 2011 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_delegate.h"
+
+#include "chrome/browser/ui/constrained_window.h"
+#include "content/browser/tab_contents/tab_contents.h"
+#include "content/public/browser/notification_source.h"
+#include "content/public/browser/notification_types.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+
+TabModalConfirmDialogDelegate::TabModalConfirmDialogDelegate(
+ TabContents* tab_contents)
+ : window_(NULL),
+ closing_(false) {
+ NavigationController* controller = &tab_contents->controller();
+ registrar_.Add(this, content::NOTIFICATION_LOAD_START,
+ content::Source<NavigationController>(controller));
+ registrar_.Add(this, content::NOTIFICATION_TAB_CLOSING,
+ content::Source<NavigationController>(controller));
+}
+
+TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() {
+ // If we end up here, the constrained window has been closed, so make sure we
+ // don't close it again.
+ window_ = NULL;
+ // Make sure everything is cleaned up.
+ Cancel();
+}
+
+void TabModalConfirmDialogDelegate::Cancel() {
+ if (closing_)
+ return;
+ OnCanceled();
+ CloseDialog();
+}
+
+void TabModalConfirmDialogDelegate::Accept() {
+ if (closing_)
+ return;
+ OnAccepted();
+ CloseDialog();
+}
+
+
+void TabModalConfirmDialogDelegate::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ // Close the dialog if we load a page (because the action might not apply to
+ // the same page anymore) or if the tab is closed.
+ if (type == content::NOTIFICATION_LOAD_START ||
+ type == content::NOTIFICATION_TAB_CLOSING) {
+ Cancel();
+ } else {
+ NOTREACHED();
+ }
+}
+
+gfx::Image* TabModalConfirmDialogDelegate::GetIcon() {
+ return NULL;
+}
+
+string16 TabModalConfirmDialogDelegate::GetAcceptButtonTitle() {
+ return l10n_util::GetStringUTF16(IDS_OK);
+}
+
+string16 TabModalConfirmDialogDelegate::GetCancelButtonTitle() {
+ return l10n_util::GetStringUTF16(IDS_CANCEL);
+}
+
+const char* TabModalConfirmDialogDelegate::GetAcceptButtonIcon() {
+ return NULL;
+}
+
+const char* TabModalConfirmDialogDelegate::GetCancelButtonIcon() {
+ return NULL;
+}
+
+void TabModalConfirmDialogDelegate::OnAccepted() {
+}
+
+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
new file mode 100644
index 0000000..7055a6f
--- /dev/null
+++ b/chrome/browser/ui/tab_modal_confirm_dialog_delegate.h
@@ -0,0 +1,79 @@
+// Copyright (c) 2011 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_DELEGATE_H_
+#define CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_
+#pragma once
+
+#include "base/callback.h"
+#include "base/compiler_specific.h"
+#include "base/string16.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+
+namespace gfx {
+class Image;
+}
+class ConstrainedWindow;
+class TabContents;
+
+// This class acts as the delegate for a simple tab-modal dialog confirming
+// whether the user wants to execute a certain action.
+class TabModalConfirmDialogDelegate : public content::NotificationObserver {
+ public:
+ explicit TabModalConfirmDialogDelegate(TabContents* tab_contents);
+ virtual ~TabModalConfirmDialogDelegate();
+
+ void set_window(ConstrainedWindow* window) { window_ = window; }
+
+ void Accept();
+ void Cancel();
+
+ // The title of the dialog. Note that the title is not shown on all platforms.
+ virtual string16 GetTitle() = 0;
+ virtual string16 GetMessage() = 0;
+
+ // Icon to show for the dialog. If this method is not overridden, a default
+ // icon (like the application icon) is shown.
+ virtual gfx::Image* GetIcon();
+
+ // Title for the accept and the cancel buttons.
+ // The default implementation uses IDS_OK and IDS_CANCEL.
+ virtual string16 GetAcceptButtonTitle();
+ virtual string16 GetCancelButtonTitle();
+
+ // GTK stock icon names for the accept and cancel buttons, respectively.
+ // The icons are only used on GTK. If these methods are not overriden,
+ // the buttons have no stock icons.
+ virtual const char* GetAcceptButtonIcon();
+ virtual const char* GetCancelButtonIcon();
+
+ protected:
+ ConstrainedWindow* window() { return window_; }
+
+ // content::NotificationObserver implementation.
+ // Watch for a new load or a closed tab and dismiss the dialog if they occur.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ content::NotificationRegistrar registrar_;
+
+ private:
+ // Called when the user accepts or cancels the dialog, respectively.
+ virtual void OnAccepted();
+ virtual void OnCanceled();
+
+ // Close the dialog.
+ void CloseDialog();
+
+ ConstrainedWindow* window_;
+ // True iff we are in the process of closing, to avoid running callbacks
+ // multiple times.
+ bool closing_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogDelegate);
+};
+
+#endif // CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_
diff --git a/chrome/browser/ui/views/browser_dialogs.h b/chrome/browser/ui/views/browser_dialogs.h
index af21b2c..4afb960 100644
--- a/chrome/browser/ui/views/browser_dialogs.h
+++ b/chrome/browser/ui/views/browser_dialogs.h
@@ -82,15 +82,10 @@ void EditSearchEngine(gfx::NativeWindow parent,
EditSearchEngineControllerDelegate* delegate,
Profile* profile);
-// Shows the repost form confirmation dialog box.
-void ShowRepostFormWarningDialog(gfx::NativeWindow parent_window,
- TabContents* tab_contents);
-
// Shows the collected cookies dialog box.
void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window,
TabContentsWrapper* tab_contents);
-
// Shows the create web app shortcut dialog box.
void ShowCreateWebAppShortcutsDialog(gfx::NativeWindow parent_window,
TabContentsWrapper* tab_contents);
diff --git a/chrome/browser/ui/views/dialog_stubs_gtk.cc b/chrome/browser/ui/views/dialog_stubs_gtk.cc
index 5306594..e255bd5 100644
--- a/chrome/browser/ui/views/dialog_stubs_gtk.cc
+++ b/chrome/browser/ui/views/dialog_stubs_gtk.cc
@@ -10,18 +10,12 @@
#include "base/logging.h"
#include "chrome/browser/ui/gtk/edit_search_engine_dialog.h"
#include "chrome/browser/ui/views/browser_dialogs.h"
-#include "chrome/browser/ui/webui/collected_cookies_ui_delegate.h"
#include "ui/gfx/native_widget_types.h"
#if !defined(WEBUI_TASK_MANAGER)
#include "chrome/browser/ui/gtk/task_manager_gtk.h"
#endif
-#if !defined(OS_CHROMEOS)
-#include "chrome/browser/ui/gtk/collected_cookies_gtk.h"
-#include "chrome/browser/ui/gtk/repost_form_warning_gtk.h"
-#endif
-
namespace browser {
#if !defined(WEBUI_TASK_MANAGER)
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index d6b30c7..f8f7b6e 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -1146,10 +1146,6 @@ DownloadShelf* BrowserView::GetDownloadShelf() {
#endif
}
-void BrowserView::ShowRepostFormWarningDialog(TabContents* tab_contents) {
- browser::ShowRepostFormWarningDialog(GetNativeHandle(), tab_contents);
-}
-
void BrowserView::ShowCollectedCookiesDialog(TabContentsWrapper* wrapper) {
browser::ShowCollectedCookiesDialog(GetNativeHandle(), wrapper);
}
diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h
index 24c010e..ba32747 100644
--- a/chrome/browser/ui/views/frame/browser_view.h
+++ b/chrome/browser/ui/views/frame/browser_view.h
@@ -307,7 +307,6 @@ class BrowserView : public BrowserWindow,
void SetDownloadShelfVisible(bool visible);
virtual bool IsDownloadShelfVisible() const OVERRIDE;
virtual DownloadShelf* GetDownloadShelf() OVERRIDE;
- virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) OVERRIDE;
virtual void ShowCollectedCookiesDialog(TabContentsWrapper* wrapper) OVERRIDE;
virtual void ConfirmBrowserCloseWithPendingDownloads() OVERRIDE;
virtual void UserChangedTheme() OVERRIDE;
diff --git a/chrome/browser/ui/views/repost_form_warning_view.cc b/chrome/browser/ui/views/tab_modal_confirm_dialog_views.cc
index 36d9290..761a7a1 100644
--- a/chrome/browser/ui/views/repost_form_warning_view.cc
+++ b/chrome/browser/ui/views/tab_modal_confirm_dialog_views.cc
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/views/repost_form_warning_view.h"
+#include "chrome/browser/ui/views/tab_modal_confirm_dialog_views.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/repost_form_warning_controller.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
#include "chrome/browser/ui/views/constrained_window_views.h"
#include "content/browser/tab_contents/navigation_controller.h"
#include "content/browser/tab_contents/tab_contents.h"
@@ -19,74 +19,76 @@
namespace browser {
// Declared in browser_dialogs.h so others don't have to depend on our header.
-void ShowRepostFormWarningDialog(gfx::NativeWindow parent_window,
- TabContents* tab_contents) {
- new RepostFormWarningView(parent_window, tab_contents);
+void ShowTabModalConfirmDialog(TabModalConfirmDialogDelegate* delegate,
+ gfx::NativeWindow parent_window,
+ TabContents* tab_contents) {
+ new TabModalConfirmDialogViews(delegate, parent_window, tab_contents);
}
} // namespace browser
//////////////////////////////////////////////////////////////////////////////
-// RepostFormWarningView, constructor & destructor:
+// TabModalConfirmDialogViews, constructor & destructor:
-RepostFormWarningView::RepostFormWarningView(
+TabModalConfirmDialogViews::TabModalConfirmDialogViews(
+ TabModalConfirmDialogDelegate* delegate,
gfx::NativeWindow parent_window,
TabContents* tab_contents)
- : controller_(new RepostFormWarningController(tab_contents)),
- message_box_view_(NULL) {
+ : delegate_(delegate),
+ message_box_view_(NULL) {
message_box_view_ = new views::MessageBoxView(
views::MessageBoxView::NO_OPTIONS,
- l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING),
+ delegate->GetMessage(),
string16());
TabContentsWrapper* wrapper =
TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
- controller_->set_window(new ConstrainedWindowViews(wrapper, this));
+ delegate_->set_window(new ConstrainedWindowViews(wrapper, this));
}
-RepostFormWarningView::~RepostFormWarningView() {
+TabModalConfirmDialogViews::~TabModalConfirmDialogViews() {
}
//////////////////////////////////////////////////////////////////////////////
-// RepostFormWarningView, views::DialogDelegate implementation:
+// TabModalConfirmDialogViews, views::DialogDelegate implementation:
-string16 RepostFormWarningView::GetWindowTitle() const {
- return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE);
+string16 TabModalConfirmDialogViews::GetWindowTitle() const {
+ return delegate_->GetTitle();
}
-string16 RepostFormWarningView::GetDialogButtonLabel(
+string16 TabModalConfirmDialogViews::GetDialogButtonLabel(
ui::DialogButton button) const {
if (button == ui::DIALOG_BUTTON_OK)
- return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_RESEND);
+ return delegate_->GetAcceptButtonTitle();
if (button == ui::DIALOG_BUTTON_CANCEL)
- return l10n_util::GetStringUTF16(IDS_CANCEL);
+ return delegate_->GetCancelButtonTitle();
return string16();
}
-views::View* RepostFormWarningView::GetContentsView() {
- return message_box_view_;
+bool TabModalConfirmDialogViews::Cancel() {
+ delegate_->Cancel();
+ return true;
}
-views::Widget* RepostFormWarningView::GetWidget() {
- return message_box_view_->GetWidget();
+bool TabModalConfirmDialogViews::Accept() {
+ delegate_->Accept();
+ return true;
}
-const views::Widget* RepostFormWarningView::GetWidget() const {
- return message_box_view_->GetWidget();
-}
+///////////////////////////////////////////////////////////////////////////////
+// TabModalConfirmDialogViews, views::WidgetDelegate implementation:
-bool RepostFormWarningView::Cancel() {
- controller_->Cancel();
- return true;
+views::View* TabModalConfirmDialogViews::GetContentsView() {
+ return message_box_view_;
}
-bool RepostFormWarningView::Accept() {
- controller_->Continue();
- return true;
+views::Widget* TabModalConfirmDialogViews::GetWidget() {
+ return message_box_view_->GetWidget();
}
-///////////////////////////////////////////////////////////////////////////////
-// RepostFormWarningView, RepostFormWarning implementation:
+const views::Widget* TabModalConfirmDialogViews::GetWidget() const {
+ return message_box_view_->GetWidget();
+}
-void RepostFormWarningView::DeleteDelegate() {
+void TabModalConfirmDialogViews::DeleteDelegate() {
delete this;
}
diff --git a/chrome/browser/ui/views/repost_form_warning_view.h b/chrome/browser/ui/views/tab_modal_confirm_dialog_views.h
index d12301f..86c106c 100644
--- a/chrome/browser/ui/views/repost_form_warning_view.h
+++ b/chrome/browser/ui/views/tab_modal_confirm_dialog_views.h
@@ -2,35 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_UI_VIEWS_REPOST_FORM_WARNING_VIEW_H_
-#define CHROME_BROWSER_UI_VIEWS_REPOST_FORM_WARNING_VIEW_H_
+#ifndef CHROME_BROWSER_UI_VIEWS_TAB_MODAL_CONFIRM_DIALOG_VIEWS_H_
+#define CHROME_BROWSER_UI_VIEWS_TAB_MODAL_CONFIRM_DIALOG_VIEWS_H_
#pragma once
#include "ui/gfx/native_widget_types.h"
#include "ui/views/window/dialog_delegate.h"
-class RepostFormWarningController;
+class TabModalConfirmDialogDelegate;
class TabContents;
namespace views {
class MessageBoxView;
}
-// Displays a dialog that warns the user that they are about to resubmit
-// a form.
+// Displays a tab-modal dialog, i.e. a dialog that will block the current page
+// but still allow the user to switch to a different page.
// 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 RepostFormWarningView : public views::DialogDelegate {
+class TabModalConfirmDialogViews : public views::DialogDelegate {
public:
- // Use BrowserWindow::ShowRepostFormWarningDialog to use.
- RepostFormWarningView(gfx::NativeWindow parent_window,
- TabContents* tab_contents);
+ TabModalConfirmDialogViews(TabModalConfirmDialogDelegate* delegate,
+ gfx::NativeWindow parent_window,
+ TabContents* tab_contents);
// views::DialogDelegate:
virtual string16 GetWindowTitle() const OVERRIDE;
virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE;
- virtual void DeleteDelegate() OVERRIDE;
virtual bool Cancel() OVERRIDE;
virtual bool Accept() OVERRIDE;
@@ -38,16 +37,17 @@ class RepostFormWarningView : public views::DialogDelegate {
virtual views::View* GetContentsView() OVERRIDE;
virtual views::Widget* GetWidget() OVERRIDE;
virtual const views::Widget* GetWidget() const OVERRIDE;
+ virtual void DeleteDelegate() OVERRIDE;
private:
- virtual ~RepostFormWarningView();
+ virtual ~TabModalConfirmDialogViews();
- scoped_ptr<RepostFormWarningController> controller_;
+ scoped_ptr<TabModalConfirmDialogDelegate> delegate_;
// The message box view whose commands we handle.
views::MessageBoxView* message_box_view_;
- DISALLOW_COPY_AND_ASSIGN(RepostFormWarningView);
+ DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogViews);
};
-#endif // CHROME_BROWSER_UI_VIEWS_REPOST_FORM_WARNING_VIEW_H_
+#endif // CHROME_BROWSER_UI_VIEWS_TAB_MODAL_CONFIRM_DIALOG_VIEWS_H_
diff --git a/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc b/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc
index 5c3295a..c3bc631 100644
--- a/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc
+++ b/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc
@@ -78,7 +78,7 @@ class ChromeURLContentSecurityPolicyExceptionSet
#if defined(OS_CHROMEOS) || defined(USE_AURA)
insert(chrome::kChromeUICollectedCookiesHost);
insert(chrome::kChromeUIHttpAuthHost);
- insert(chrome::kChromeUIRepostFormWarningHost);
+ insert(chrome::kChromeUITabModalConfirmDialogHost);
#endif
#if defined(USE_AURA)
insert(chrome::kChromeUIAppListHost);
diff --git a/chrome/browser/ui/webui/chrome_web_ui_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_factory.cc
index fab6328..39f88e5 100644
--- a/chrome/browser/ui/webui/chrome_web_ui_factory.cc
+++ b/chrome/browser/ui/webui/chrome_web_ui_factory.cc
@@ -261,7 +261,7 @@ WebUIFactoryFunction GetWebUIFactoryFunction(TabContents* tab_contents,
#if (defined(OS_LINUX) && defined(TOOLKIT_VIEWS)) || defined(USE_AURA)
if (url.host() == chrome::kChromeUICollectedCookiesHost ||
url.host() == chrome::kChromeUIHttpAuthHost ||
- url.host() == chrome::kChromeUIRepostFormWarningHost) {
+ url.host() == chrome::kChromeUITabModalConfirmDialogHost) {
return &NewWebUI<ConstrainedHtmlUI>;
}
#endif
diff --git a/chrome/browser/ui/webui/repost_form_warning_ui.cc b/chrome/browser/ui/webui/repost_form_warning_ui.cc
deleted file mode 100644
index 652fdcb..0000000
--- a/chrome/browser/ui/webui/repost_form_warning_ui.cc
+++ /dev/null
@@ -1,166 +0,0 @@
-// Copyright (c) 2011 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/webui/repost_form_warning_ui.h"
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/json/json_reader.h"
-#include "base/message_loop.h"
-#include "base/string_piece.h"
-#include "base/utf_string_conversions.h"
-#include "base/values.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/repost_form_warning_controller.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
-#include "chrome/browser/ui/webui/chrome_url_data_manager.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"
-#include "grit/browser_resources.h"
-#include "grit/generated_resources.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/size.h"
-
-using std::string;
-
-namespace browser {
-
-// Declared in browser_dialogs.h so others don't have to depend on our header.
-void ShowRepostFormWarningDialog(gfx::NativeWindow parent_window,
- TabContents* tab_contents) {
- new RepostFormWarningUI(parent_window, tab_contents);
-}
-
-} // namespace browser
-
-class RepostFormWarningSource : public ChromeURLDataManager::DataSource {
- public:
- RepostFormWarningSource()
- : DataSource(chrome::kChromeUIRepostFormWarningHost,
- MessageLoop::current()) {
- }
-
- virtual void StartDataRequest(const std::string& path,
- bool is_off_the_record,
- int request_id) OVERRIDE {
- DictionaryValue dict;
- dict.SetString("explanation",
- l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING));
- dict.SetString("resend",
- l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_RESEND));
- dict.SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL));
-
- SetFontAndTextDirection(&dict);
- base::StringPiece html =
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_REPOST_FORM_WARNING_HTML);
- string response = jstemplate_builder::GetI18nTemplateHtml(html, &dict);
- SendResponse(request_id, base::RefCountedString::TakeString(&response));
- }
-
- virtual string GetMimeType(const std::string& path) const OVERRIDE {
- return "text/html";
- }
-
- static void RegisterDataSource(Profile* profile) {
- ChromeURLDataManager* url_manager = profile->GetChromeURLDataManager();
- url_manager->AddDataSource(new RepostFormWarningSource());
- }
-
- private:
- virtual ~RepostFormWarningSource() {}
-
- DISALLOW_COPY_AND_ASSIGN(RepostFormWarningSource);
-};
-
-class RepostFormWarningHtmlDelegate : public HtmlDialogUIDelegate {
- public:
- explicit RepostFormWarningHtmlDelegate(RepostFormWarningUI* ui) : ui_(ui) {}
-
- virtual ~RepostFormWarningHtmlDelegate() {}
-
- // HtmlDialogUIDelegate implementation.
- virtual bool IsDialogModal() const OVERRIDE {
- return true;
- }
-
- virtual string16 GetDialogTitle() const OVERRIDE {
- return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE);
- }
-
- virtual GURL GetDialogContentURL() const OVERRIDE {
- return GURL(chrome::kChromeUIRepostFormWarningURL);
- }
-
- 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 {
- return string();
- }
-
- virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE {
- bool repost = false;
- if (!json_retval.empty()) {
- base::JSONReader reader;
- scoped_ptr<Value> value(reader.JsonToValue(json_retval, false, false));
- if (!value.get() || !value->GetAsBoolean(&repost))
- NOTREACHED() << "Missing or unreadable response from dialog";
- }
-
- ui_->OnDialogClosed(repost);
- ui_ = NULL;
- delete this;
- }
-
- virtual void OnCloseContents(TabContents* source,
- bool* out_close_dialog) OVERRIDE {}
-
- virtual bool ShouldShowDialogTitle() const OVERRIDE {
- return true;
- }
-
- private:
- static const int kDialogWidth = 400;
- static const int kDialogHeight = 108;
-
- RepostFormWarningUI* ui_; // not owned
-
- DISALLOW_COPY_AND_ASSIGN(RepostFormWarningHtmlDelegate);
-};
-
-RepostFormWarningUI::RepostFormWarningUI(gfx::NativeWindow parent_window,
- TabContents* tab_contents)
- : controller_(new RepostFormWarningController(tab_contents)) {
- TabContentsWrapper* wrapper =
- TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
- Profile* profile = wrapper->profile();
- RepostFormWarningSource::RegisterDataSource(profile);
- RepostFormWarningHtmlDelegate* html_delegate =
- new RepostFormWarningHtmlDelegate(this);
- ConstrainedHtmlUIDelegate* dialog_delegate =
- ConstrainedHtmlUI::CreateConstrainedHtmlDialog(
- profile, html_delegate, wrapper);
- controller_->set_window(dialog_delegate->window());
-}
-
-RepostFormWarningUI::~RepostFormWarningUI() {}
-
-void RepostFormWarningUI::OnDialogClosed(bool repost) {
- controller_->set_window(NULL);
- if (repost)
- controller_->Continue();
- else
- controller_->Cancel();
- delete this;
-}
diff --git a/chrome/browser/ui/webui/repost_form_warning_ui.h b/chrome/browser/ui/webui/repost_form_warning_ui.h
deleted file mode 100644
index a8a3e72..0000000
--- a/chrome/browser/ui/webui/repost_form_warning_ui.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (c) 2011 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_WEBUI_REPOST_FORM_WARNING_UI_H_
-#define CHROME_BROWSER_UI_WEBUI_REPOST_FORM_WARNING_UI_H_
-#pragma once
-
-#include "base/memory/scoped_ptr.h"
-#include "ui/gfx/native_widget_types.h"
-
-class BrowserWindow;
-class RepostFormWarningController;
-class TabContents;
-
-namespace browser {
-void ShowRepostFormWarningDialog(gfx::NativeWindow parent_window,
- TabContents* tab_contents);
-}
-
-// Displays a dialog that warns the user that they are about to resubmit
-// a form.
-// 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 RepostFormWarningUI {
- public:
- // Invoked when the dialog is closed. Notifies the controller of the user's
- // response and deletes this object.
- void OnDialogClosed(bool repost);
-
- private:
- friend void browser::ShowRepostFormWarningDialog(
- gfx::NativeWindow parent_window, TabContents* tab_contents);
-
- // Call BrowserWindow::ShowRepostFormWarningDialog() to use.
- RepostFormWarningUI(gfx::NativeWindow parent_window,
- TabContents* tab_contents);
-
- virtual ~RepostFormWarningUI();
-
- scoped_ptr<RepostFormWarningController> controller_;
-
- DISALLOW_COPY_AND_ASSIGN(RepostFormWarningUI);
-};
-
-#endif // CHROME_BROWSER_UI_WEBUI_REPOST_FORM_WARNING_UI_H_
diff --git a/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc b/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc
new file mode 100644
index 0000000..ece1b11
--- /dev/null
+++ b/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc
@@ -0,0 +1,143 @@
+// Copyright (c) 2011 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/webui/tab_modal_confirm_dialog_webui.h"
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/json/json_reader.h"
+#include "base/json/json_writer.h"
+#include "base/string_piece.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/constrained_window.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#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"
+#include "grit/browser_resources.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/size.h"
+
+using std::string;
+
+namespace browser {
+
+// Declared in browser_dialogs.h so others don't have to depend on our header.
+void ShowTabModalConfirmDialog(TabModalConfirmDialogDelegate* delegate,
+ TabContents* tab_contents) {
+ new TabModalConfirmDialogUI(delegate, tab_contents);
+}
+
+} // namespace browser
+
+class TabModalConfirmDialogHtmlDelegate : public HtmlDialogUIDelegate {
+ public:
+ TabModalConfirmDialogHtmlDelegate(
+ TabModalConfirmDialogUI* ui,
+ TabModalConfirmDialogDelegate* dialog_delegate)
+ : ui_(ui),
+ dialog_delegate_(dialog_delegate) {}
+
+ 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(TabContents* 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(
+ TabModalConfirmDialogDelegate* delegate,
+ TabContents* tab_contents)
+ : delegate_(delegate) {
+ TabContentsWrapper* wrapper =
+ TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
+ Profile* profile = wrapper->profile();
+ ChromeWebUIDataSource* data_source =
+ new ChromeWebUIDataSource(chrome::kChromeUITabModalConfirmDialogHost);
+ 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());
+}
+
+TabModalConfirmDialogUI::~TabModalConfirmDialogUI() {}
+
+void TabModalConfirmDialogUI::OnDialogClosed(bool accepted) {
+ delegate_->set_window(NULL);
+ if (accepted)
+ delegate_->Accept();
+ else
+ delegate_->Cancel();
+}
diff --git a/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.h b/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.h
new file mode 100644
index 0000000..93dc7a6
--- /dev/null
+++ b/chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2011 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_WEBUI_TAB_MODAL_CONFIRM_DIALOG_WEBUI_H_
+#define CHROME_BROWSER_UI_WEBUI_TAB_MODAL_CONFIRM_DIALOG_WEBUI_H_
+#pragma once
+
+#if !(defined(USE_AURA) || defined(TOOLKIT_VIEWS))
+#error Tab-modal confirm dialog should be shown with native UI.
+#endif
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+
+class TabContents;
+class TabModalConfirmDialogDelegate;
+
+// Displays a tab-modal dialog, i.e. a dialog that will block the current page
+// but still allow the user to switch to a different page.
+// 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 {
+ public:
+ TabModalConfirmDialogUI(TabModalConfirmDialogDelegate* delegate,
+ TabContents* tab_contents);
+ ~TabModalConfirmDialogUI();
+
+ // Invoked when the dialog is closed. Notifies the controller of the user's
+ // response.
+ void OnDialogClosed(bool accept);
+
+ private:
+ scoped_ptr<TabModalConfirmDialogDelegate> delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogUI);
+};
+
+#endif // CHROME_BROWSER_UI_WEBUI_TAB_MODAL_CONFIRM_DIALOG_WEBUI_H_