summaryrefslogtreecommitdiffstats
path: root/chrome/browser/app_controller_mac.mm
diff options
context:
space:
mode:
authorpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-03 23:21:41 +0000
committerpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-03 23:21:41 +0000
commit09729a552e7fdba21a70c132a1e4a21068a2d851 (patch)
tree0b753552be0f407000ccf87b3fcfb783d2890203 /chrome/browser/app_controller_mac.mm
parentff1f61b9ac199e5927e6539624d14e1f032db773 (diff)
downloadchromium_src-09729a552e7fdba21a70c132a1e4a21068a2d851.zip
chromium_src-09729a552e7fdba21a70c132a1e4a21068a2d851.tar.gz
chromium_src-09729a552e7fdba21a70c132a1e4a21068a2d851.tar.bz2
Implement the quit dialog on Mac displayed when the user has in progress
Downloads. BUG=15899 TEST=A dialog asking the user if they want to quit when there are downloads in progress will be displayed when the user tries to exit under that condition. Review URL: http://codereview.chromium.org/159424 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22341 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/app_controller_mac.mm')
-rw-r--r--chrome/browser/app_controller_mac.mm87
1 files changed, 87 insertions, 0 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 08882bc..0752215 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -4,7 +4,9 @@
#import "chrome/browser/app_controller_mac.h"
+#include "app/l10n_util.h"
#include "base/command_line.h"
+#include "base/mac_util.h"
#include "base/message_loop.h"
#include "base/sys_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
@@ -23,11 +25,13 @@
#import "chrome/browser/cocoa/tab_strip_controller.h"
#import "chrome/browser/cocoa/tab_window_controller.h"
#include "chrome/browser/command_updater.h"
+#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
#include "chrome/browser/profile_manager.h"
#include "chrome/common/temp_scaffolding_stubs.h"
+#include "grit/generated_resources.h"
#import "xib_localizers/main_menu_localizer.h"
@interface AppController(PRIVATE)
@@ -39,6 +43,7 @@
- (void)openFiles:(NSAppleEventDescriptor*)event
withReply:(NSAppleEventDescriptor*)reply;
- (void)windowLayeringDidChange:(NSNotification*)inNotification;
+- (BOOL)shouldQuitWithInProgressDownloads;
@end
@implementation AppController
@@ -242,6 +247,83 @@
[self openPendingURLs];
}
+// Check all browsers for in progress downloads, and if we find any, prompt the
+// user to see if we should continue to exit (and thus cancel the downloads), or
+// if we should wait.
+- (BOOL)shouldQuitWithInProgressDownloads {
+ BrowserList::const_iterator it = BrowserList::begin();
+ for (; it != BrowserList::end(); ++it) {
+ Browser* browser = *it;
+ Profile* profile = browser->profile();
+ if (!profile)
+ continue;
+
+ DownloadManager* download_manager = profile->GetDownloadManager();
+ if (!download_manager || download_manager->in_progress_count() == 0)
+ continue;
+
+ // There are downloads in progress so run the dialog asking if we should
+ // exit. There can be multiple windows (i.e. browsers) open, but we don't
+ // want to prompt for each one. Use the first browser with downloads in
+ // progress.
+ NSString* descriptionText = nil;
+ NSString* waitButton = nil;
+ NSString* exitButton = nil;
+
+ // Set the dialog text based on whether or not there are multiple downloads.
+ if (download_manager->in_progress_count() == 1) {
+ // Dialog text.
+ descriptionText =
+ base::SysWideToNSString(
+ l10n_util::GetString(IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_TITLE));
+
+ // Cancel downloads and exit button text.
+ exitButton =
+ base::SysWideToNSString(
+ l10n_util::GetString(
+ IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL));
+
+ // Wait for downloads button text.
+ waitButton =
+ base::SysWideToNSString(
+ l10n_util::GetString(
+ IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL));
+ } else {
+ // Dialog text.
+ descriptionText =
+ base::SysWideToNSString(
+ l10n_util::GetStringF(IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_TITLE,
+ download_manager->in_progress_count()));
+
+ // Cancel downloads and exit button text.
+ exitButton =
+ base::SysWideToNSString(
+ l10n_util::GetString(
+ IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_OK_BUTTON_LABEL));
+
+ // Wait for downloads button text.
+ waitButton =
+ base::SysWideToNSString(
+ l10n_util::GetString(
+ IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL));
+ }
+
+ // 'waitButton' is the default choice.
+ int choice = NSRunAlertPanel(nil, descriptionText,
+ waitButton, exitButton, nil);
+ if (choice == NSAlertDefaultReturn) {
+ // We're not going to exit, so show the user the download page so they can
+ // see the in progress downloads.
+ browser->ShowDownloadsTab();
+ return NO;
+ }
+ break;
+ }
+
+ // Okay to exit.
+ return YES;
+}
+
// We can't use the standard terminate: method because it will abruptly exit
// the app and leave things on the stack in an unfinalized state. We need to
// post a quit message to our run loop so the stack can gracefully unwind.
@@ -254,6 +336,11 @@
// handle it. If it says to continue, post the quit message, otherwise
// go back to normal.
+ // Check for in-progress downloads, and prompt the user if they really want to
+ // quit (and thus cancel the downloads).
+ if (![self shouldQuitWithInProgressDownloads])
+ return;
+
NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
[em removeEventHandlerForEventClass:kInternetEventClass
andEventID:kAEGetURL];