| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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/download_request_dialog_delegate_mac.h" | 5 #include "chrome/browser/cocoa/download_request_dialog_delegate_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "app/l10n_util_mac.h" | 9 #include "app/l10n_util_mac.h" |
| 10 #include "app/message_box_flags.h" | 10 #include "app/message_box_flags.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 return self; | 30 return self; |
| 31 } | 31 } |
| 32 - (void)alertDidEnd:(NSAlert *)alert | 32 - (void)alertDidEnd:(NSAlert *)alert |
| 33 returnCode:(int)returnCode | 33 returnCode:(int)returnCode |
| 34 contextInfo:(void *)contextInfo { | 34 contextInfo:(void *)contextInfo { |
| 35 target_->SheetDidEnd(returnCode); | 35 target_->SheetDidEnd(returnCode); |
| 36 } | 36 } |
| 37 @end | 37 @end |
| 38 | 38 |
| 39 | 39 |
| 40 // Return value passed to the end-sheet routine to indicate that the sheet was |
| 41 // ended by |DeleteDelegate()|. This just needs to be some value never used by |
| 42 // Apple as a return value for the sheet. |
| 43 static int kClosedByDelegate = 658042027; |
| 44 |
| 40 // static | 45 // static |
| 41 DownloadRequestDialogDelegate* DownloadRequestDialogDelegate::Create( | 46 DownloadRequestDialogDelegate* DownloadRequestDialogDelegate::Create( |
| 42 TabContents* tab, | 47 TabContents* tab, |
| 43 DownloadRequestManager::TabDownloadState* host) { | 48 DownloadRequestManager::TabDownloadState* host) { |
| 49 if (!tab->CanCreateConstrainedDialog()) |
| 50 return NULL; |
| 51 |
| 44 return new DownloadRequestDialogDelegateMac(tab, host); | 52 return new DownloadRequestDialogDelegateMac(tab, host); |
| 45 } | 53 } |
| 46 | 54 |
| 47 DownloadRequestDialogDelegateMac::DownloadRequestDialogDelegateMac( | 55 DownloadRequestDialogDelegateMac::DownloadRequestDialogDelegateMac( |
| 48 TabContents* tab, | 56 TabContents* tab, |
| 49 DownloadRequestManager::TabDownloadState* host) | 57 DownloadRequestManager::TabDownloadState* host) |
| 50 : DownloadRequestDialogDelegate(host), | 58 : DownloadRequestDialogDelegate(host), |
| 51 ConstrainedWindowMacDelegateSystemSheet( | 59 ConstrainedWindowMacDelegateSystemSheet( |
| 52 [[[SheetCallback alloc] initWithTarget:this] autorelease], | 60 [[[SheetCallback alloc] initWithTarget:this] autorelease], |
| 53 @selector(alertDidEnd:returnCode:contextInfo:)), | 61 @selector(alertDidEnd:returnCode:contextInfo:)), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 74 window_ = tab->CreateConstrainedDialog(this); | 82 window_ = tab->CreateConstrainedDialog(this); |
| 75 } | 83 } |
| 76 | 84 |
| 77 void DownloadRequestDialogDelegateMac::CloseWindow() { | 85 void DownloadRequestDialogDelegateMac::CloseWindow() { |
| 78 window_->CloseConstrainedWindow(); | 86 window_->CloseConstrainedWindow(); |
| 79 } | 87 } |
| 80 | 88 |
| 81 void DownloadRequestDialogDelegateMac::DeleteDelegate() { | 89 void DownloadRequestDialogDelegateMac::DeleteDelegate() { |
| 82 if (is_sheet_open()) { | 90 if (is_sheet_open()) { |
| 83 // Close sheet if it's still open. | 91 // Close sheet if it's still open. |
| 84 [NSApp endSheet:[(NSAlert*)sheet() window]]; // calls SheetDidEnd(). | 92 [NSApp endSheet:[(NSAlert*)sheet() window] |
| 93 returnCode:kClosedByDelegate]; // Calls SheetDidEnd(). |
| 85 DCHECK(responded_); | 94 DCHECK(responded_); |
| 86 } | 95 } |
| 87 if (!responded_) { | 96 if (!responded_) { |
| 88 // Happens if the sheet was never visible. | 97 // Happens if the sheet was never visible. |
| 89 responded_ = true; | 98 responded_ = true; |
| 90 DoCancel(); | 99 DoCancel(); |
| 91 } | 100 } |
| 92 DCHECK(!host_); | 101 DCHECK(!host_); |
| 93 delete this; | 102 delete this; |
| 94 } | 103 } |
| 95 | 104 |
| 96 void DownloadRequestDialogDelegateMac::SheetDidEnd(int returnCode) { | 105 void DownloadRequestDialogDelegateMac::SheetDidEnd(int returnCode) { |
| 97 DCHECK(!responded_); | 106 DCHECK(!responded_); |
| 107 responded_ = true; |
| 98 if (returnCode == NSAlertFirstButtonReturn) { | 108 if (returnCode == NSAlertFirstButtonReturn) { |
| 99 DoAccept(); | 109 DoAccept(); |
| 100 } else { | 110 } else { |
| 101 DoCancel(); | 111 DoCancel(); |
| 112 |
| 113 // If this ended in a "normal" way, i.e., the user pressing one of the |
| 114 // buttons, we still have to clean up the window (and the delegate). If, on |
| 115 // the other hand, the window was ended by |CloseConstrainedWindow()| (which |
| 116 // caused this routine to be called), then we *must* not try to do that |
| 117 // again. |
| 118 if (returnCode != kClosedByDelegate) |
| 119 CloseWindow(); |
| 102 } | 120 } |
| 103 responded_ = true; | |
| 104 } | 121 } |
| OLD | NEW |