diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-28 22:47:11 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-28 22:47:11 +0000 |
commit | 0bb17f3457fc494b9711ce6580571c1bc7dacf57 (patch) | |
tree | f5ce47ae31942fce886a45d36ede9b5de357c14e /chrome | |
parent | 02525bc37fe1722c8b38af1d6087bf286e075bf9 (diff) | |
download | chromium_src-0bb17f3457fc494b9711ce6580571c1bc7dacf57.zip chromium_src-0bb17f3457fc494b9711ce6580571c1bc7dacf57.tar.gz chromium_src-0bb17f3457fc494b9711ce6580571c1bc7dacf57.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@24826 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
20 files changed, 179 insertions, 59 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 4acd94b..3486a62 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -2059,6 +2059,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 63ccb0a..d0f403a 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -527,6 +527,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 a1dbe76..2532d4b 100644 --- a/chrome/browser/browser_window.h +++ b/chrome/browser/browser_window.h @@ -15,6 +15,7 @@ class FindBar; class GURL; class HtmlDialogUIDelegate; class LocationBar; +class NavigationController; class Profile; class StatusBubble; class TabContents; @@ -187,6 +188,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 1635602..0eb7693 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.h +++ b/chrome/browser/cocoa/browser_window_cocoa.h @@ -71,6 +71,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 13ff5bb..7d8a202 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -246,6 +246,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 9c295ac..d3df442 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" @@ -1024,6 +1025,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 d186aa5..c21a9ed 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -102,6 +102,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/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 6dc9adf..f9a627b 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -35,6 +35,7 @@ #include "chrome/browser/views/frame/browser_frame.h" #include "chrome/browser/views/fullscreen_exit_bubble.h" #include "chrome/browser/views/infobars/infobar_container.h" +#include "chrome/browser/views/repost_form_warning_view.h" #include "chrome/browser/views/status_bubble_views.h" #include "chrome/browser/views/tab_contents/tab_contents_container.h" #include "chrome/browser/views/tabs/browser_tab_strip.h" @@ -929,6 +930,10 @@ void BrowserView::ShowNewProfileDialog() { browser::ShowNewProfileDialog(); } +void BrowserView::ShowRepostFormWarningDialog(TabContents* tab_contents) { + new RepostFormWarningView(GetNativeHandle(), &tab_contents->controller()); +} + 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 d978c51..e59c8aa 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -243,6 +243,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..074850d7 100644 --- a/chrome/browser/views/repost_form_warning_view.cc +++ b/chrome/browser/views/repost_form_warning_view.cc @@ -14,14 +14,8 @@ #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); -} - RepostFormWarningView::RepostFormWarningView( + gfx::NativeWindow parent_window, NavigationController* navigation_controller) : navigation_controller_(navigation_controller), message_box_view_(NULL) { @@ -29,19 +23,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 +82,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: diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 62b1aa9..0e08bea 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1302,6 +1302,8 @@ 'browser/gtk/page_info_window_gtk.cc', 'browser/gtk/process_singleton_dialog.cc', 'browser/gtk/process_singleton_dialog.h', + 'browser/gtk/repost_form_warning_gtk.cc', + 'browser/gtk/repost_form_warning_gtk.h', 'browser/gtk/sad_tab_gtk.cc', 'browser/gtk/sad_tab_gtk.h', 'browser/gtk/slide_animator_gtk.cc', @@ -1790,7 +1792,6 @@ 'browser/tab_contents/render_view_host_delegate_helper.h', 'browser/tab_contents/render_view_host_manager.cc', 'browser/tab_contents/render_view_host_manager.h', - 'browser/tab_contents/repost_form_warning.h', 'browser/tab_contents/security_style.h', 'browser/tab_contents/tab_contents.cc', 'browser/tab_contents/tab_contents.h', diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc index 162a6ab..78e4085 100644 --- a/chrome/common/temp_scaffolding_stubs.cc +++ b/chrome/common/temp_scaffolding_stubs.cc @@ -210,13 +210,6 @@ bool RLZTracker::RecordProductEvent(Product product, AccessPoint point, //-------------------------------------------------------------------------- -void RunRepostFormWarningDialog(NavigationController*) { - // http://code.google.com/p/chromium/issues/detail?id=19761 - NOTIMPLEMENTED(); -} - -//-------------------------------------------------------------------------- - MemoryDetails::MemoryDetails() { NOTIMPLEMENTED(); } diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h index 47e0e86..0ccab4e 100644 --- a/chrome/common/temp_scaffolding_stubs.h +++ b/chrome/common/temp_scaffolding_stubs.h @@ -148,12 +148,6 @@ class DockInfo { //--------------------------------------------------------------------------- // These stubs are for TabContents -class RepostFormWarningDialog { - public: - static void RunRepostFormWarningDialog(NavigationController*) { } - virtual ~RepostFormWarningDialog() { } -}; - class BaseDragSource { }; diff --git a/chrome/test/test_browser_window.h b/chrome/test/test_browser_window.h index a7a06db..45394cf 100644 --- a/chrome/test/test_browser_window.h +++ b/chrome/test/test_browser_window.h @@ -69,6 +69,7 @@ class TestBrowserWindow : 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) {} |