summaryrefslogtreecommitdiffstats
path: root/chrome/browser/repost_form_warning_controller.cc
diff options
context:
space:
mode:
authorbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-09 11:59:02 +0000
committerbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-09 11:59:02 +0000
commit965bb0937dc924fbabe69a350c427aa3d84f76ab (patch)
treece6e1ebfa7f64a97467e2b1555cfd26462676d86 /chrome/browser/repost_form_warning_controller.cc
parente14c72d324f6eddfc0f1b1d462ea7e897da5fc1c (diff)
downloadchromium_src-965bb0937dc924fbabe69a350c427aa3d84f76ab.zip
chromium_src-965bb0937dc924fbabe69a350c427aa3d84f76ab.tar.gz
chromium_src-965bb0937dc924fbabe69a350c427aa3d84f76ab.tar.bz2
Refactor common, platform-independent code for the repost form warning dialog on all platforms into a delegate.
The platform-dependent ConstrainedWindow{Gtk,Mac,Win} classes each have their own platform-dependent |ConstrainedWindowDelegate| to inherit from, so instead of a common superclass they now have a RepostFormWarningDelegate. Also, change the RELOADING notification to REPOST_WARNING_SHOWN to avoid trying to close the dialog while it's already in the process of being closed. BUG=none TEST=RepostFormWarningTest.* Review URL: http://codereview.chromium.org/1520023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44074 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/repost_form_warning_controller.cc')
-rw-r--r--chrome/browser/repost_form_warning_controller.cc66
1 files changed, 66 insertions, 0 deletions
diff --git a/chrome/browser/repost_form_warning_controller.cc b/chrome/browser/repost_form_warning_controller.cc
new file mode 100644
index 0000000..7b38c4c
--- /dev/null
+++ b/chrome/browser/repost_form_warning_controller.cc
@@ -0,0 +1,66 @@
+// Copyright (c) 2010 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/repost_form_warning_controller.h"
+
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/notification_service.h"
+
+RepostFormWarningController::RepostFormWarningController(
+ TabContents* tab_contents)
+ : tab_contents_(tab_contents),
+ window_(NULL) {
+ NavigationController* controller = &tab_contents->controller();
+ registrar_.Add(this, NotificationType::LOAD_START,
+ Source<NavigationController>(controller));
+ registrar_.Add(this, NotificationType::TAB_CLOSING,
+ Source<NavigationController>(controller));
+ registrar_.Add(this, NotificationType::REPOST_WARNING_SHOWN,
+ Source<NavigationController>(controller));
+}
+
+RepostFormWarningController::~RepostFormWarningController() {
+}
+
+void RepostFormWarningController::Show(
+ ConstrainedWindowDelegate* window_delegate) {
+ window_ = tab_contents_->CreateConstrainedDialog(window_delegate);
+}
+
+void RepostFormWarningController::Cancel() {
+ if (tab_contents_) {
+ tab_contents_->controller().CancelPendingReload();
+ CloseDialog();
+ }
+}
+
+void RepostFormWarningController::Continue() {
+ if (tab_contents_) {
+ tab_contents_->controller().ContinuePendingReload();
+ // If we reload the page, the dialog will be closed anyway.
+ }
+}
+
+void RepostFormWarningController::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 ((type == NotificationType::LOAD_START ||
+ type == NotificationType::TAB_CLOSING ||
+ type == NotificationType::REPOST_WARNING_SHOWN)) {
+ DCHECK_EQ(Source<NavigationController>(source).ptr(),
+ &tab_contents_->controller());
+ Cancel();
+ }
+}
+
+void RepostFormWarningController::CloseDialog() {
+ tab_contents_ = NULL;
+ if (window_) {
+ window_->CloseConstrainedWindow();
+ }
+ delete this;
+}