diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-31 20:53:53 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-31 20:53:53 +0000 |
commit | 14f3408a98e69385382ab026a98a7421d6cf0a2f (patch) | |
tree | 833aad9b3012fe8c122cd4cca8be881895fa61b8 /chrome/browser | |
parent | 2163916abe6e98e336012144a689c30537f33725 (diff) | |
download | chromium_src-14f3408a98e69385382ab026a98a7421d6cf0a2f.zip chromium_src-14f3408a98e69385382ab026a98a7421d6cf0a2f.tar.gz chromium_src-14f3408a98e69385382ab026a98a7421d6cf0a2f.tar.bz2 |
Gtk confirm form resubmission dialog.
Refactor so that the dialog is shown by calling BrowserWindow::ShowRepostFormWarningDialog
BUG=19761
TEST=see bug
Review URL: http://codereview.chromium.org/174294
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24930 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser.cc | 4 | ||||
-rw-r--r-- | chrome/browser/browser.h | 1 | ||||
-rw-r--r-- | chrome/browser/browser_window.h | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_cocoa.h | 1 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_cocoa.mm | 5 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.h | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/repost_form_warning_gtk.cc | 86 | ||||
-rw-r--r-- | chrome/browser/gtk/repost_form_warning_gtk.h | 46 | ||||
-rw-r--r-- | chrome/browser/tab_contents/navigation_controller.cc | 9 | ||||
-rw-r--r-- | chrome/browser/tab_contents/repost_form_warning.h | 17 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_delegate.h | 3 | ||||
-rw-r--r-- | chrome/browser/views/browser_dialogs.h | 4 | ||||
-rw-r--r-- | chrome/browser/views/dialog_stubs_gtk.cc | 5 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.h | 1 | ||||
-rw-r--r-- | chrome/browser/views/repost_form_warning_view.cc | 36 | ||||
-rw-r--r-- | chrome/browser/views/repost_form_warning_view.h | 6 |
18 files changed, 195 insertions, 43 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index fe6474e..dfec448 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -2070,6 +2070,10 @@ void Browser::ShowPageInfo(Profile* profile, window()->ShowPageInfo(profile, url, ssl, show_history); } +void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { + window()->ShowRepostFormWarningDialog(tab_contents); +} + /////////////////////////////////////////////////////////////////////////////// // Browser, SelectFileDialog::Listener implementation: diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 72e58a2..fd2982f 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -532,6 +532,7 @@ class Browser : public TabStripModelDelegate, const GURL& url, const NavigationEntry::SSLStatus& ssl, bool show_history); + virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); // Overridden from SelectFileDialog::Listener: virtual void FileSelected(const FilePath& path, int index, void* params); diff --git a/chrome/browser/browser_window.h b/chrome/browser/browser_window.h index 4a5c5ac..5268318 100644 --- a/chrome/browser/browser_window.h +++ b/chrome/browser/browser_window.h @@ -193,6 +193,9 @@ class BrowserWindow { // Shows the New Profile dialog box. virtual void ShowNewProfileDialog() = 0; + // Shows the repost form confirmation dialog box. + virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) = 0; + // Shows the confirmation dialog box warning that the browser is closing with // in-progress downloads. // This method should call Browser::InProgressDownloadResponse once the user diff --git a/chrome/browser/cocoa/browser_window_cocoa.h b/chrome/browser/cocoa/browser_window_cocoa.h index 8d1c60d..7258d43 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.h +++ b/chrome/browser/cocoa/browser_window_cocoa.h @@ -73,6 +73,7 @@ class BrowserWindowCocoa : public BrowserWindow, virtual void ShowPasswordManager(); virtual void ShowSelectProfileDialog(); virtual void ShowNewProfileDialog(); + virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); virtual void ConfirmBrowserCloseWithPendingDownloads(); virtual void ShowHTMLDialog(HtmlDialogUIDelegate* delegate, gfx::NativeWindow parent_window); diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index 18900fb..3f58e8c 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -254,6 +254,11 @@ void BrowserWindowCocoa::ShowNewProfileDialog() { NOTIMPLEMENTED(); } +void BrowserWindowCocoa::ShowRepostFormWarningDialog( + TabContents* tab_contents) { + NOTIMPLEMENTED(); +} + // We allow closing the window here since the real quit decision on Mac is made // in [AppController quit:]. void BrowserWindowCocoa::ConfirmBrowserCloseWithPendingDownloads() { diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 1d593f9..a91d07b 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -52,6 +52,7 @@ #include "chrome/browser/gtk/infobar_container_gtk.h" #include "chrome/browser/gtk/keyword_editor_view.h" #include "chrome/browser/gtk/nine_box.h" +#include "chrome/browser/gtk/repost_form_warning_gtk.h" #include "chrome/browser/gtk/status_bubble_gtk.h" #include "chrome/browser/gtk/tab_contents_container_gtk.h" #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" @@ -1032,6 +1033,11 @@ void BrowserWindowGtk::ShowNewProfileDialog() { NOTIMPLEMENTED(); } +void BrowserWindowGtk::ShowRepostFormWarningDialog( + TabContents* tab_contents) { + new RepostFormWarningGtk(GetNativeHandle(), &tab_contents->controller()); +} + void BrowserWindowGtk::ShowHTMLDialog(HtmlDialogUIDelegate* delegate, gfx::NativeWindow parent_window) { NOTIMPLEMENTED(); diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index 32d3228..5125c1a 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -104,6 +104,7 @@ class BrowserWindowGtk : public BrowserWindow, virtual void ShowPasswordManager(); virtual void ShowSelectProfileDialog(); virtual void ShowNewProfileDialog(); + virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); virtual void ConfirmBrowserCloseWithPendingDownloads(); virtual void ShowHTMLDialog(HtmlDialogUIDelegate* delegate, gfx::NativeWindow parent_window); diff --git a/chrome/browser/gtk/repost_form_warning_gtk.cc b/chrome/browser/gtk/repost_form_warning_gtk.cc new file mode 100644 index 0000000..fab88e6 --- /dev/null +++ b/chrome/browser/gtk/repost_form_warning_gtk.cc @@ -0,0 +1,86 @@ +// Copyright (c) 2009 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/gtk/repost_form_warning_gtk.h" + +#include "app/l10n_util.h" +#include "base/message_loop.h" +#include "chrome/browser/tab_contents/navigation_controller.h" +#include "chrome/common/gtk_util.h" +#include "chrome/common/notification_service.h" +#include "grit/generated_resources.h" + +RepostFormWarningGtk::RepostFormWarningGtk( + GtkWindow* parent, + NavigationController* navigation_controller) + : navigation_controller_(navigation_controller) { + dialog_ = gtk_message_dialog_new( + parent, + GTK_DIALOG_MODAL, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + "%s", + l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING).c_str()); + gtk_window_set_title(GTK_WINDOW(dialog_), + l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING_TITLE).c_str()); + gtk_util::AddButtonToDialog(dialog_, + l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING_CANCEL).c_str(), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_util::AddButtonToDialog(dialog_, + l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING_RESEND).c_str(), + GTK_STOCK_REFRESH, GTK_RESPONSE_OK); + gtk_util::SetWindowIcon(GTK_WINDOW(dialog_)); + + g_signal_connect(dialog_, "response", G_CALLBACK(OnResponse), this); + g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroy), this); + + gtk_widget_show_all(dialog_); + + registrar_.Add(this, NotificationType::LOAD_START, + Source<NavigationController>(navigation_controller_)); + registrar_.Add(this, NotificationType::TAB_CLOSING, + Source<NavigationController>(navigation_controller_)); +} + +RepostFormWarningGtk::~RepostFormWarningGtk() { +} + +void RepostFormWarningGtk::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + // Close the dialog if we load a page (because reloading might not apply to + // the same page anymore) or if the tab is closed, because then we won't have + // a navigation controller anymore. + if (dialog_ && navigation_controller_ && + (type == NotificationType::LOAD_START || + type == NotificationType::TAB_CLOSING)) { + DCHECK_EQ(Source<NavigationController>(source).ptr(), + navigation_controller_); + navigation_controller_ = NULL; + Destroy(); + } +} + +void RepostFormWarningGtk::Destroy() { + if (dialog_) { + gtk_widget_destroy(dialog_); + dialog_ = NULL; + } +} + +// static +void RepostFormWarningGtk::OnResponse(GtkWidget* widget, int response, + RepostFormWarningGtk* dialog) { + dialog->Destroy(); + if (response == GTK_RESPONSE_OK) { + if (dialog->navigation_controller_) + dialog->navigation_controller_->Reload(false); + } +} + +// static +void RepostFormWarningGtk::OnWindowDestroy(GtkWidget* widget, + RepostFormWarningGtk* dialog) { + MessageLoop::current()->DeleteSoon(FROM_HERE, dialog); +} diff --git a/chrome/browser/gtk/repost_form_warning_gtk.h b/chrome/browser/gtk/repost_form_warning_gtk.h new file mode 100644 index 0000000..8b6f168 --- /dev/null +++ b/chrome/browser/gtk/repost_form_warning_gtk.h @@ -0,0 +1,46 @@ +// Copyright (c) 2009 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_GTK_REPOST_FORM_WARNING_GTK_H_ +#define CHROME_BROWSER_GTK_REPOST_FORM_WARNING_GTK_H_ + +#include <gtk/gtk.h> + +#include "chrome/common/notification_registrar.h" + +class NavigationController; + +class RepostFormWarningGtk : public NotificationObserver { + public: + RepostFormWarningGtk(GtkWindow* parent, + NavigationController* navigation_controller); + virtual ~RepostFormWarningGtk(); + + private: + // NotificationObserver implementation. + // Watch for a new load or a closed tab and dismiss the dialog if they occur. + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // Tell Gtk to destroy the dialog window. This will only be done once, even + // if Destroy is called multiple times (eg, from both OnResponse and Observe.) + void Destroy(); + + static void OnResponse(GtkWidget* widget, + int response, + RepostFormWarningGtk* dialog); + static void OnWindowDestroy(GtkWidget* widget, RepostFormWarningGtk* dialog); + + NotificationRegistrar registrar_; + + // Navigation controller, used to continue the reload. + NavigationController* navigation_controller_; + + GtkWidget* dialog_; + + DISALLOW_COPY_AND_ASSIGN(RepostFormWarningGtk); +}; + +#endif // CHROME_BROWSER_GTK_REPOST_FORM_WARNING_GTK_H_ diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/chrome/browser/tab_contents/navigation_controller.cc index 3704169..7f5fa99 100644 --- a/chrome/browser/tab_contents/navigation_controller.cc +++ b/chrome/browser/tab_contents/navigation_controller.cc @@ -16,8 +16,8 @@ #include "chrome/browser/renderer_host/site_instance.h" #include "chrome/browser/sessions/session_types.h" #include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/browser/tab_contents/repost_form_warning.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/common/navigation_types.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" @@ -29,11 +29,6 @@ #include "net/base/net_util.h" #include "webkit/glue/webkit_glue.h" -#if defined(OS_WIN) -#include "chrome/browser/tab_contents/repost_form_warning.h" -#include "chrome/browser/tab_contents/tab_contents_delegate.h" -#endif - namespace { // Invoked when entries have been pruned, or removed. For example, if the @@ -173,7 +168,7 @@ void NavigationController::Reload(bool check_for_repost) { // they really want to do this. If they do, the dialog will call us back // with check_for_repost = false. tab_contents_->Activate(); - RunRepostFormWarningDialog(this); + tab_contents_->delegate()->ShowRepostFormWarningDialog(tab_contents_); } else { // Base the navigation on where we are now... int current_index = GetCurrentEntryIndex(); diff --git a/chrome/browser/tab_contents/repost_form_warning.h b/chrome/browser/tab_contents/repost_form_warning.h deleted file mode 100644 index 9bbbbaa..0000000 --- a/chrome/browser/tab_contents/repost_form_warning.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2009 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_TAB_CONTENTS_REPOST_FORM_WARNING_H_ -#define CHROME_BROWSER_TAB_CONTENTS_REPOST_FORM_WARNING_H_ - -class NavigationController; - -// Runs the form repost warning dialog. If the user accepts the action, then -// it will call Reload on the navigation controller back with check_for_repost -// set to false. -// -// This function is implemented by the platform-specific frontend. -void RunRepostFormWarningDialog(NavigationController* nav_controller); - -#endif // CHROME_BROWSER_TAB_CONTENTS_REPOST_FORM_WARNING_H_ diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h index 3799569..156bb18 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.h +++ b/chrome/browser/tab_contents/tab_contents_delegate.h @@ -221,6 +221,9 @@ class TabContentsDelegate { return false; } + // Shows the repost form confirmation dialog box. + virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) {} + protected: ~TabContentsDelegate() {} diff --git a/chrome/browser/views/browser_dialogs.h b/chrome/browser/views/browser_dialogs.h index c2b13f3..805f565 100644 --- a/chrome/browser/views/browser_dialogs.h +++ b/chrome/browser/views/browser_dialogs.h @@ -97,6 +97,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); + } // namespace browser #endif // CHROME_BROWSER_VIEWS_BROWSER_DIALOGS_H_ diff --git a/chrome/browser/views/dialog_stubs_gtk.cc b/chrome/browser/views/dialog_stubs_gtk.cc index f57446d..0fe25e5 100644 --- a/chrome/browser/views/dialog_stubs_gtk.cc +++ b/chrome/browser/views/dialog_stubs_gtk.cc @@ -74,6 +74,11 @@ void EditSearchEngine(gfx::NativeWindow parent, NOTIMPLEMENTED(); } +void ShowRepostFormWarningDialog(gfx::NativeWindow parent_window, + TabContents* tab_contents) { + NOTIMPLEMENTED(); +} + } // namespace browser void ShowOptionsWindow(OptionsPage page, diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index ae02466..b7e7f28 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -937,6 +937,10 @@ void BrowserView::ShowNewProfileDialog() { browser::ShowNewProfileDialog(); } +void BrowserView::ShowRepostFormWarningDialog(TabContents* tab_contents) { + browser::ShowRepostFormWarningDialog(GetNativeHandle(), tab_contents); +} + void BrowserView::ConfirmBrowserCloseWithPendingDownloads() { DownloadInProgressConfirmDialogDelegate* delegate = new DownloadInProgressConfirmDialogDelegate(browser_.get()); diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index 2fd3d4a..bbdfd6f 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -245,6 +245,7 @@ class BrowserView : public BrowserWindow, virtual void ShowPasswordManager(); virtual void ShowSelectProfileDialog(); virtual void ShowNewProfileDialog(); + virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); virtual void ConfirmBrowserCloseWithPendingDownloads(); virtual void ShowHTMLDialog(HtmlDialogUIDelegate* delegate, gfx::NativeWindow parent_window); diff --git a/chrome/browser/views/repost_form_warning_view.cc b/chrome/browser/views/repost_form_warning_view.cc index c9ef167..2a6f810 100644 --- a/chrome/browser/views/repost_form_warning_view.cc +++ b/chrome/browser/views/repost_form_warning_view.cc @@ -9,19 +9,27 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/tab_contents/navigation_controller.h" +#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/notification_service.h" #include "grit/generated_resources.h" #include "views/controls/message_box_view.h" #include "views/window/window.h" -// Implementation of function declared in -// browser/tab_contents/repost_form_warning.h -void RunRepostFormWarningDialog(NavigationController* navigation_controller) { - RepostFormWarningView* dialog = - new RepostFormWarningView(navigation_controller); +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->controller()); } +} // namespace browser + +////////////////////////////////////////////////////////////////////////////// +// RepostFormWarningView, constructor & destructor: + RepostFormWarningView::RepostFormWarningView( + gfx::NativeWindow parent_window, NavigationController* navigation_controller) : navigation_controller_(navigation_controller), message_box_view_(NULL) { @@ -29,19 +37,12 @@ RepostFormWarningView::RepostFormWarningView( MessageBoxFlags::kIsConfirmMessageBox, l10n_util::GetString(IDS_HTTP_POST_WARNING), L""); - // TODO(beng): fix this - this dialog box should be shown by a method on the - // Browser. - HWND root_hwnd = NULL; - if (BrowserList::GetLastActive()) { - root_hwnd = reinterpret_cast<HWND>(BrowserList::GetLastActive()-> - window()->GetNativeHandle()); - } - views::Window::CreateChromeWindow(root_hwnd, gfx::Rect(), this)->Show(); + views::Window::CreateChromeWindow(parent_window, gfx::Rect(), this)->Show(); registrar_.Add(this, NotificationType::LOAD_START, - NotificationService::AllSources()); + Source<NavigationController>(navigation_controller_)); registrar_.Add(this, NotificationType::TAB_CLOSING, - NotificationService::AllSources()); + Source<NavigationController>(navigation_controller_)); } RepostFormWarningView::~RepostFormWarningView() { @@ -95,8 +96,9 @@ void RepostFormWarningView::Observe(NotificationType type, // a navigation controller anymore. if (window() && navigation_controller_ && (type == NotificationType::LOAD_START || - type == NotificationType::TAB_CLOSING) && - Source<NavigationController>(source).ptr() == navigation_controller_) { + type == NotificationType::TAB_CLOSING)) { + DCHECK_EQ(Source<NavigationController>(source).ptr(), + navigation_controller_); navigation_controller_ = NULL; window()->Close(); } diff --git a/chrome/browser/views/repost_form_warning_view.h b/chrome/browser/views/repost_form_warning_view.h index 40db8ac..3c8538b 100644 --- a/chrome/browser/views/repost_form_warning_view.h +++ b/chrome/browser/views/repost_form_warning_view.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_VIEWS_REPOST_FORM_WARNING_VIEW_H_ #define CHROME_BROWSER_VIEWS_REPOST_FORM_WARNING_VIEW_H_ +#include "base/gfx/native_widget_types.h" #include "chrome/common/notification_registrar.h" #include "views/window/dialog_delegate.h" @@ -17,8 +18,9 @@ class Window; class RepostFormWarningView : public views::DialogDelegate, public NotificationObserver { public: - // Use RunRepostFormWarningDialog (declared in repost_form_warning.h) to use. - RepostFormWarningView(NavigationController* navigation_controller); + // Use BrowserWindow::ShowRepostFormWarningDialog to use. + RepostFormWarningView(gfx::NativeWindow parent_window, + NavigationController* navigation_controller); virtual ~RepostFormWarningView(); // views::DialogDelegate Methods: |