summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-30 01:32:30 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-30 01:32:30 +0000
commit72f53f9945ce253a40b7f7ff441290b49d756836 (patch)
tree51cf1354b50577c8d0409502caefee74ec85e48d /chrome/browser/cocoa
parenta73559511d314072bcf16a0341c5126dd4012bc0 (diff)
downloadchromium_src-72f53f9945ce253a40b7f7ff441290b49d756836.zip
chromium_src-72f53f9945ce253a40b7f7ff441290b49d756836.tar.gz
chromium_src-72f53f9945ce253a40b7f7ff441290b49d756836.tar.bz2
[Mac] Implement form resubmission warning dialog
Surprisingly, this is not a tab-modal sheet on linux and windows, so it's window-modal on os x as well for now. BUG=23526 TEST=Go to http://www.cs.unc.edu/~jbs/resources/perl/perl-cgi/programs/form1-POST.html , click "Do it!", hit reload. Window sheet should come up. Hitting cancel should cancel the navigation (and hitting reload again should bring up sheet again). Hitting "Resend" should trigger reload. Review URL: http://codereview.chromium.org/327009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30547 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/browser_window_cocoa.mm3
-rw-r--r--chrome/browser/cocoa/repost_form_warning_mac.h57
-rw-r--r--chrome/browser/cocoa/repost_form_warning_mac.mm93
3 files changed, 152 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm
index f48746e..f16c524 100644
--- a/chrome/browser/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/cocoa/browser_window_cocoa.mm
@@ -14,6 +14,7 @@
#import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h"
#import "chrome/browser/cocoa/nsmenuitem_additions.h"
#include "chrome/browser/cocoa/page_info_window_mac.h"
+#include "chrome/browser/cocoa/repost_form_warning_mac.h"
#include "chrome/browser/cocoa/status_bubble_mac.h"
#include "chrome/browser/cocoa/task_manager_mac.h"
#import "chrome/browser/cocoa/theme_install_bubble_view.h"
@@ -276,7 +277,7 @@ void BrowserWindowCocoa::ShowNewProfileDialog() {
void BrowserWindowCocoa::ShowRepostFormWarningDialog(
TabContents* tab_contents) {
- NOTIMPLEMENTED();
+ new RepostFormWarningMac(GetNativeHandle(), &tab_contents->controller());
}
void BrowserWindowCocoa::ShowHistoryTooNewDialog() {
diff --git a/chrome/browser/cocoa/repost_form_warning_mac.h b/chrome/browser/cocoa/repost_form_warning_mac.h
new file mode 100644
index 0000000..d55beeb
--- /dev/null
+++ b/chrome/browser/cocoa/repost_form_warning_mac.h
@@ -0,0 +1,57 @@
+// 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_COCOA_REPOST_FORM_WARNING_MAC_H_
+#define CHROME_BROWSER_COCOA_REPOST_FORM_WARNING_MAC_H_
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/scoped_nsobject.h"
+#include "chrome/common/notification_registrar.h"
+
+class NavigationController;
+class RepostFormWarningMac;
+
+@interface RepostDelegate : NSObject {
+ RepostFormWarningMac* warning_; // weak, owns us.
+}
+- (id)initWithWarning:(RepostFormWarningMac*)warning;
+- (void)alertDidEnd:(NSAlert*)alert
+ returnCode:(int)returnCode
+ contextInfo:(void*)contextInfo;
+@end
+
+class RepostFormWarningMac : public NotificationObserver {
+ public:
+ RepostFormWarningMac(NSWindow* parent,
+ NavigationController* navigation_controller);
+ virtual ~RepostFormWarningMac();
+
+ void Confirm();
+ void Cancel();
+
+ 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);
+
+ // Close the sheet. This will only be done once, even if Destroy is called
+ // multiple times (eg, from both Confirm and Observe.)
+ void Destroy();
+
+ NotificationRegistrar registrar_;
+
+ // Navigation controller, used to continue the reload.
+ NavigationController* navigation_controller_;
+
+ scoped_nsobject<NSAlert> alert_;
+
+ scoped_nsobject<RepostDelegate> delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(RepostFormWarningMac);
+};
+
+#endif // CHROME_BROWSER_COCOA_REPOST_FORM_WARNING_MAC_H_
diff --git a/chrome/browser/cocoa/repost_form_warning_mac.mm b/chrome/browser/cocoa/repost_form_warning_mac.mm
new file mode 100644
index 0000000..ab63cee
--- /dev/null
+++ b/chrome/browser/cocoa/repost_form_warning_mac.mm
@@ -0,0 +1,93 @@
+// 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/cocoa/repost_form_warning_mac.h"
+
+#include "app/l10n_util_mac.h"
+#include "base/message_loop.h"
+#include "chrome/browser/tab_contents/navigation_controller.h"
+#include "chrome/common/notification_service.h"
+#include "grit/generated_resources.h"
+
+@implementation RepostDelegate
+- (id)initWithWarning:(RepostFormWarningMac*)warning {
+ if ((self = [super init])) {
+ warning_ = warning;
+ }
+ return self;
+}
+
+- (void)alertDidEnd:(NSAlert*)alert
+ returnCode:(int)returnCode
+ contextInfo:(void*)contextInfo {
+ if (returnCode == NSAlertFirstButtonReturn)
+ warning_->Confirm();
+ else
+ warning_->Cancel();
+}
+@end
+
+RepostFormWarningMac::RepostFormWarningMac(
+ NSWindow* parent,
+ NavigationController* navigation_controller)
+ : navigation_controller_(navigation_controller),
+ alert_([[NSAlert alloc] init]),
+ delegate_([[RepostDelegate alloc] initWithWarning:this]) {
+ [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_HTTP_POST_WARNING_CANCEL)];
+
+ [alert_ beginSheetModalForWindow:parent
+ modalDelegate:delegate_.get()
+ didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
+ contextInfo:nil];
+
+ registrar_.Add(this, NotificationType::LOAD_START,
+ Source<NavigationController>(navigation_controller_));
+ registrar_.Add(this, NotificationType::TAB_CLOSING,
+ Source<NavigationController>(navigation_controller_));
+}
+
+RepostFormWarningMac::~RepostFormWarningMac() {
+}
+
+void RepostFormWarningMac::Confirm() {
+ Destroy();
+ if (navigation_controller_)
+ navigation_controller_->Reload(false);
+}
+
+void RepostFormWarningMac::Cancel() {
+ Destroy();
+}
+
+void RepostFormWarningMac::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 (alert_ && navigation_controller_ &&
+ (type == NotificationType::LOAD_START ||
+ type == NotificationType::TAB_CLOSING)) {
+ DCHECK_EQ(Source<NavigationController>(source).ptr(),
+ navigation_controller_);
+ navigation_controller_ = NULL;
+
+ // This will call |Cancel()|.
+ [NSApp endSheet:[alert_ window] returnCode:NSAlertSecondButtonReturn];
+ }
+}
+
+void RepostFormWarningMac::Destroy() {
+ if (alert_) {
+ alert_.reset(NULL);
+ MessageLoop::current()->DeleteSoon(FROM_HERE, this);
+ }
+}