| Index: chrome/browser/cocoa/download_request_dialog_delegate_mac.mm
|
| diff --git a/chrome/browser/cocoa/download_request_dialog_delegate_mac.mm b/chrome/browser/cocoa/download_request_dialog_delegate_mac.mm
|
| index 4f5e29acba60df6e6c48806ec11d005edfdf6fd4..bb9e846a89ee5c3afedb1002560452e42abcdb1f 100644
|
| --- a/chrome/browser/cocoa/download_request_dialog_delegate_mac.mm
|
| +++ b/chrome/browser/cocoa/download_request_dialog_delegate_mac.mm
|
| @@ -37,10 +37,18 @@
|
| @end
|
|
|
|
|
| +// Return value passed to the end-sheet routine to indicate that the sheet was
|
| +// ended by |DeleteDelegate()|. This just needs to be some value never used by
|
| +// Apple as a return value for the sheet.
|
| +static int kClosedByDelegate = 658042027;
|
| +
|
| // static
|
| DownloadRequestDialogDelegate* DownloadRequestDialogDelegate::Create(
|
| TabContents* tab,
|
| DownloadRequestManager::TabDownloadState* host) {
|
| + if (!tab->CanCreateConstrainedDialog())
|
| + return NULL;
|
| +
|
| return new DownloadRequestDialogDelegateMac(tab, host);
|
| }
|
|
|
| @@ -81,7 +89,8 @@ void DownloadRequestDialogDelegateMac::CloseWindow() {
|
| void DownloadRequestDialogDelegateMac::DeleteDelegate() {
|
| if (is_sheet_open()) {
|
| // Close sheet if it's still open.
|
| - [NSApp endSheet:[(NSAlert*)sheet() window]]; // calls SheetDidEnd().
|
| + [NSApp endSheet:[(NSAlert*)sheet() window]
|
| + returnCode:kClosedByDelegate]; // Calls SheetDidEnd().
|
| DCHECK(responded_);
|
| }
|
| if (!responded_) {
|
| @@ -95,10 +104,18 @@ void DownloadRequestDialogDelegateMac::DeleteDelegate() {
|
|
|
| void DownloadRequestDialogDelegateMac::SheetDidEnd(int returnCode) {
|
| DCHECK(!responded_);
|
| + responded_ = true;
|
| if (returnCode == NSAlertFirstButtonReturn) {
|
| DoAccept();
|
| } else {
|
| DoCancel();
|
| +
|
| + // If this ended in a "normal" way, i.e., the user pressing one of the
|
| + // buttons, we still have to clean up the window (and the delegate). If, on
|
| + // the other hand, the window was ended by |CloseConstrainedWindow()| (which
|
| + // caused this routine to be called), then we *must* not try to do that
|
| + // again.
|
| + if (returnCode != kClosedByDelegate)
|
| + CloseWindow();
|
| }
|
| - responded_ = true;
|
| }
|
|
|