Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(652)

Side by Side Diff: chrome/browser/cocoa/repost_form_warning_mac.mm

Issue 327009: [Mac] Implement form resubmission warning dialog (Closed)
Patch Set: rebase tot Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/cocoa/repost_form_warning_mac.h"
6
7 #include "app/l10n_util_mac.h"
8 #include "base/message_loop.h"
9 #include "chrome/browser/tab_contents/navigation_controller.h"
10 #include "chrome/common/notification_service.h"
11 #include "grit/generated_resources.h"
12
13 @implementation RepostDelegate
14 - (id)initWithWarning:(RepostFormWarningMac*)warning {
15 if ((self = [super init])) {
16 warning_ = warning;
17 }
18 return self;
19 }
20
21 - (void)alertDidEnd:(NSAlert*)alert
22 returnCode:(int)returnCode
23 contextInfo:(void*)contextInfo {
24 if (returnCode == NSAlertFirstButtonReturn)
25 warning_->Confirm();
26 else
27 warning_->Cancel();
28 }
29 @end
30
31 RepostFormWarningMac::RepostFormWarningMac(
32 NSWindow* parent,
33 NavigationController* navigation_controller)
34 : navigation_controller_(navigation_controller),
35 alert_([[NSAlert alloc] init]),
36 delegate_([[RepostDelegate alloc] initWithWarning:this]) {
37 [alert_ setMessageText:
38 l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING_TITLE)];
39 [alert_ setInformativeText:
40 l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING)];
41 [alert_ addButtonWithTitle:
42 l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING_RESEND)];
43 [alert_ addButtonWithTitle:
44 l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING_CANCEL)];
45
46 [alert_ beginSheetModalForWindow:parent
47 modalDelegate:delegate_.get()
48 didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
49 contextInfo:nil];
50
51 registrar_.Add(this, NotificationType::LOAD_START,
52 Source<NavigationController>(navigation_controller_));
53 registrar_.Add(this, NotificationType::TAB_CLOSING,
54 Source<NavigationController>(navigation_controller_));
55 }
56
57 RepostFormWarningMac::~RepostFormWarningMac() {
58 }
59
60 void RepostFormWarningMac::Confirm() {
61 Destroy();
62 if (navigation_controller_)
63 navigation_controller_->Reload(false);
64 }
65
66 void RepostFormWarningMac::Cancel() {
67 Destroy();
68 }
69
70 void RepostFormWarningMac::Observe(NotificationType type,
71 const NotificationSource& source,
72 const NotificationDetails& details) {
73 // Close the dialog if we load a page (because reloading might not apply to
74 // the same page anymore) or if the tab is closed, because then we won't have
75 // a navigation controller anymore.
76 if (alert_ && navigation_controller_ &&
77 (type == NotificationType::LOAD_START ||
78 type == NotificationType::TAB_CLOSING)) {
79 DCHECK_EQ(Source<NavigationController>(source).ptr(),
80 navigation_controller_);
81 navigation_controller_ = NULL;
82
83 // This will call |Cancel()|.
84 [NSApp endSheet:[alert_ window] returnCode:NSAlertSecondButtonReturn];
85 }
86 }
87
88 void RepostFormWarningMac::Destroy() {
89 if (alert_) {
90 alert_.reset(NULL);
91 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
92 }
93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698