summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-10 23:58:21 +0000
committerpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-10 23:58:21 +0000
commit73f5b3628564ad8162a3901cb672264eb71ef970 (patch)
tree452cbca17c78f945a3e9358a46cc9ff24b5901db
parentb160d6dc73b9ce92827f81517d9b155006a4e422 (diff)
downloadchromium_src-73f5b3628564ad8162a3901cb672264eb71ef970.zip
chromium_src-73f5b3628564ad8162a3901cb672264eb71ef970.tar.gz
chromium_src-73f5b3628564ad8162a3901cb672264eb71ef970.tar.bz2
Fix a bug when exiting Mac Chrome with in progress downloads.
If the user has closed all browser windows and then tries to exit with downloads in progress, Mac Chrome would just quit. This CL handles the case of exiting without any windows open. BUG=15899 (http://crbug.com/15899) TEST=Start a download, close all windows then try to exit. Chrome will now prompt the user with an exit confirm dialog. Review URL: http://codereview.chromium.org/164273 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22973 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/app_controller_mac.mm140
1 files changed, 75 insertions, 65 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 0752215..0cdee36 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -43,6 +43,7 @@
- (void)openFiles:(NSAppleEventDescriptor*)event
withReply:(NSAppleEventDescriptor*)reply;
- (void)windowLayeringDidChange:(NSNotification*)inNotification;
+- (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount;
- (BOOL)shouldQuitWithInProgressDownloads;
@end
@@ -247,80 +248,89 @@
[self openPendingURLs];
}
-// Check all browsers for in progress downloads, and if we find any, prompt the
+// Helper function for populating and displaying the in progress downloads at
+// exit alert panel.
+- (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount {
+ NSString* descriptionText = nil;
+ NSString* waitTitle = nil;
+ NSString* exitTitle = nil;
+
+ // Set the dialog text based on whether or not there are multiple downloads.
+ if (downloadCount == 1) {
+ // Dialog text.
+ descriptionText =
+ base::SysWideToNSString(
+ l10n_util::GetString(IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_TITLE));
+
+ // Cancel download and exit button text.
+ exitTitle =
+ base::SysWideToNSString(
+ l10n_util::GetString(
+ IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL));
+
+ // Wait for download button text.
+ waitTitle =
+ 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,
+ downloadCount));
+
+ // Cancel downloads and exit button text.
+ exitTitle =
+ base::SysWideToNSString(
+ l10n_util::GetString(
+ IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_OK_BUTTON_LABEL));
+
+ // Wait for downloads button text.
+ waitTitle =
+ base::SysWideToNSString(
+ l10n_util::GetString(
+ IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL));
+ }
+
+ // 'waitButton' is the default choice.
+ int choice = NSRunAlertPanel(nil, descriptionText, waitTitle, exitTitle, nil);
+ return choice == NSAlertDefaultReturn ? YES : NO;
+}
+
+// Check all profiles 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;
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ if (!profile_manager)
+ return YES;
+ ProfileManager::const_iterator it = profile_manager->begin();
+ for (; it != profile_manager->end(); ++it) {
+ Profile* profile = *it;
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));
- }
+ if (download_manager && download_manager->in_progress_count() > 0) {
+ int downloadCount = download_manager->in_progress_count();
+ if ([self userWillWaitForInProgressDownloads:downloadCount]) {
+ // Create a new browser window (if necessary) and navigate to the
+ // downloads page if the user chooses to wait.
+ Browser* browser = BrowserList::FindBrowserWithProfile(profile);
+ if (!browser) {
+ browser = Browser::Create(profile);
+ browser->window()->Show();
+ }
+ DCHECK(browser);
+ browser->ShowDownloadsTab();
+ return NO;
+ }
- // '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;
+ // User wants to exit.
+ return YES;
}
- break;
}
- // Okay to exit.
+ // No profiles or active downloads found, okay to exit.
return YES;
}