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

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

Issue 969003: Make repost form warning tab-modal on Mac. (Closed)
Patch Set: Remove an unnecessary line. Created 10 years, 9 months 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
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/cocoa/repost_form_warning_mac.h" 5 #include "chrome/browser/cocoa/repost_form_warning_mac.h"
6 6
7 #include "app/l10n_util_mac.h" 7 #include "app/l10n_util_mac.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chrome/browser/tab_contents/navigation_controller.h" 9 #include "chrome/browser/tab_contents/navigation_controller.h"
10 #include "chrome/common/notification_service.h" 10 #include "chrome/common/notification_service.h"
(...skipping 23 matching lines...) Expand all
34 contextInfo:(void*)contextInfo { 34 contextInfo:(void*)contextInfo {
35 if (returnCode == NSAlertFirstButtonReturn) 35 if (returnCode == NSAlertFirstButtonReturn)
36 warning_->Confirm(); 36 warning_->Confirm();
37 else 37 else
38 warning_->Cancel(); 38 warning_->Cancel();
39 } 39 }
40 @end 40 @end
41 41
42 RepostFormWarningMac::RepostFormWarningMac( 42 RepostFormWarningMac::RepostFormWarningMac(
43 NSWindow* parent, 43 NSWindow* parent,
44 NavigationController* navigation_controller) 44 TabContents* tab_contents)
45 : navigation_controller_(navigation_controller), 45 : ConstrainedWindowMacDelegateSystemSheet(
46 alert_([[NSAlert alloc] init]), 46 [[[RepostDelegate alloc] initWithWarning:this] autorelease],
47 delegate_([[RepostDelegate alloc] initWithWarning:this]) { 47 @selector(alertDidEnd:returnCode:contextInfo:)),
48 [alert_ setMessageText: 48 navigation_controller_(&tab_contents->controller()) {
49 scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]);
50 [alert setMessageText:
49 l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING_TITLE)]; 51 l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING_TITLE)];
50 [alert_ setInformativeText: 52 [alert setInformativeText:
51 l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING)]; 53 l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING)];
52 [alert_ addButtonWithTitle: 54 [alert addButtonWithTitle:
53 l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING_RESEND)]; 55 l10n_util::GetNSStringWithFixup(IDS_HTTP_POST_WARNING_RESEND)];
54 [alert_ addButtonWithTitle: 56 [alert addButtonWithTitle:
55 l10n_util::GetNSStringWithFixup(IDS_CANCEL)]; 57 l10n_util::GetNSStringWithFixup(IDS_CANCEL)];
56 58
57 [alert_ beginSheetModalForWindow:parent 59 set_sheet(alert);
58 modalDelegate:delegate_.get()
59 didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
60 contextInfo:nil];
61 60
62 registrar_.Add(this, NotificationType::LOAD_START, 61 registrar_.Add(this, NotificationType::LOAD_START,
63 Source<NavigationController>(navigation_controller_)); 62 Source<NavigationController>(navigation_controller_));
64 registrar_.Add(this, NotificationType::TAB_CLOSING, 63 registrar_.Add(this, NotificationType::TAB_CLOSING,
65 Source<NavigationController>(navigation_controller_)); 64 Source<NavigationController>(navigation_controller_));
65 registrar_.Add(this, NotificationType::RELOADING,
66 Source<NavigationController>(navigation_controller_));
67 window_ = tab_contents->CreateConstrainedDialog(this);
66 } 68 }
67 69
68 RepostFormWarningMac::~RepostFormWarningMac() { 70 RepostFormWarningMac::~RepostFormWarningMac() {
69 } 71 }
70 72
73 void RepostFormWarningMac::DeleteDelegate() {
74 window_ = NULL;
75 Dismiss();
76 delete this;
77 }
78
71 void RepostFormWarningMac::Confirm() { 79 void RepostFormWarningMac::Confirm() {
80 if (navigation_controller_) {
81 navigation_controller_->ContinuePendingReload();
82 }
72 Destroy(); 83 Destroy();
73 if (navigation_controller_)
74 navigation_controller_->Reload(false);
75 } 84 }
76 85
77 void RepostFormWarningMac::Cancel() { 86 void RepostFormWarningMac::Cancel() {
87 if (navigation_controller_) {
88 navigation_controller_->CancelPendingReload();
89 }
78 Destroy(); 90 Destroy();
79 } 91 }
80 92
93 void RepostFormWarningMac::Dismiss() {
94 if (sheet() && is_sheet_open()) {
95 // This will call |Cancel()|.
96 [NSApp endSheet:[(NSAlert*)sheet() window]
97 returnCode:NSAlertSecondButtonReturn];
98 }
99 }
100
81 void RepostFormWarningMac::Observe(NotificationType type, 101 void RepostFormWarningMac::Observe(NotificationType type,
82 const NotificationSource& source, 102 const NotificationSource& source,
83 const NotificationDetails& details) { 103 const NotificationDetails& details) {
84 // Close the dialog if we load a page (because reloading might not apply to 104 // Close the dialog if we load a page (because reloading might not apply to
85 // the same page anymore) or if the tab is closed, because then we won't have 105 // the same page anymore) or if the tab is closed, because then we won't have
86 // a navigation controller anymore. 106 // a navigation controller anymore.
87 if (alert_ && navigation_controller_ && 107 if ((type == NotificationType::LOAD_START ||
88 (type == NotificationType::LOAD_START || 108 type == NotificationType::TAB_CLOSING ||
89 type == NotificationType::TAB_CLOSING)) { 109 type == NotificationType::RELOADING)) {
90 DCHECK_EQ(Source<NavigationController>(source).ptr(), 110 DCHECK_EQ(Source<NavigationController>(source).ptr(),
91 navigation_controller_); 111 navigation_controller_);
92 navigation_controller_ = NULL; 112 Dismiss();
93
94 // This will call |Cancel()|.
95 [NSApp endSheet:[alert_ window] returnCode:NSAlertSecondButtonReturn];
96 } 113 }
97 } 114 }
98 115
99 void RepostFormWarningMac::Destroy() { 116 void RepostFormWarningMac::Destroy() {
100 if (alert_) { 117 navigation_controller_ = NULL;
101 alert_.reset(NULL); 118 if (sheet()) {
102 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 119 set_sheet(nil);
120 }
121 if (window_) {
122 window_->CloseConstrainedWindow();
103 } 123 }
104 } 124 }
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/repost_form_warning_mac.h ('k') | chrome/browser/cocoa/toolbar_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698