Skip to content
Snippets Groups Projects
Commit 72f53f99 authored by thakis@chromium.org's avatar thakis@chromium.org
Browse files

[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
parent a7355951
No related branches found
No related tags found
No related merge requests found
......@@ -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() {
......
// 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_
// 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);
}
}
......@@ -1177,6 +1177,8 @@
'browser/cocoa/preferences_window_controller.mm',
'browser/cocoa/rwhvm_editcommand_helper.h',
'browser/cocoa/rwhvm_editcommand_helper.mm',
'browser/cocoa/repost_form_warning_mac.h',
'browser/cocoa/repost_form_warning_mac.mm',
'browser/cocoa/restart_browser.h',
'browser/cocoa/restart_browser.mm',
'browser/cocoa/sad_tab_view.h',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment