diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-27 21:13:42 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-27 21:13:42 +0000 |
commit | 848364347bff182dbf8a0c2f22ed3ed5d65bca4e (patch) | |
tree | e79de6d570b32c486996e580d49c1a63209338b0 /chrome/browser/cocoa | |
parent | 80b7f1a8bfd97d4d8b268329932efba1d4f49567 (diff) | |
download | chromium_src-848364347bff182dbf8a0c2f22ed3ed5d65bca4e.zip chromium_src-848364347bff182dbf8a0c2f22ed3ed5d65bca4e.tar.gz chromium_src-848364347bff182dbf8a0c2f22ed3ed5d65bca4e.tar.bz2 |
Remove completed downloads from shelf when the shelf closes.
BUG=15712
TEST=Download a few things, close shelf, download something else, note initial few things are no longer on the shelf.
Special cases:
* Dangerous downloads still awaiting affirmation should never be removed, no matter if they are completed or not.
* Cancelled downloads should be removed.
* In-progress downloads should not be removed.
Review URL: http://codereview.chromium.org/173186
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24663 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/download_item_controller.h | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_item_controller.mm | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_shelf_controller.mm | 23 |
3 files changed, 31 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/download_item_controller.h b/chrome/browser/cocoa/download_item_controller.h index dd8d4e2c..c34c557 100644 --- a/chrome/browser/cocoa/download_item_controller.h +++ b/chrome/browser/cocoa/download_item_controller.h @@ -9,6 +9,7 @@ class BaseDownloadItemModel; @class DownloadItemCell; +class DownloadItem; class DownloadItemMac; class DownloadShelfContextMenuMac; @class DownloadShelfController; @@ -68,6 +69,9 @@ class DownloadShelfContextMenuMac; // Returns the size this item wants to have. - (NSSize)preferredSize; +// Returns the DownloadItem model object belonging to this item. +- (DownloadItem*)download; + // Handling of dangerous downloads - (void)clearDangerousMode; - (BOOL)isDangerousMode; diff --git a/chrome/browser/cocoa/download_item_controller.mm b/chrome/browser/cocoa/download_item_controller.mm index fd40a6a..7058a2a 100644 --- a/chrome/browser/cocoa/download_item_controller.mm +++ b/chrome/browser/cocoa/download_item_controller.mm @@ -137,6 +137,10 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { return [dangerousDownloadView_ frame].size; } +- (DownloadItem*)download { + return bridge_->download_model()->download(); +} + - (void)clearDangerousMode { [self setState:kNormal]; } diff --git a/chrome/browser/cocoa/download_shelf_controller.mm b/chrome/browser/cocoa/download_shelf_controller.mm index c9448d6..73b2af5 100644 --- a/chrome/browser/cocoa/download_shelf_controller.mm +++ b/chrome/browser/cocoa/download_shelf_controller.mm @@ -13,6 +13,7 @@ #include "chrome/browser/cocoa/download_item_controller.h" #include "chrome/browser/cocoa/download_shelf_mac.h" #import "chrome/browser/cocoa/download_shelf_view.h" +#include "chrome/browser/download/download_manager.h" #include "grit/generated_resources.h" namespace { @@ -34,6 +35,7 @@ const NSTimeInterval kDownloadItemOpenDuration = 0.8; - (void)showDownloadShelf:(BOOL)enable; - (void)resizeDownloadLinkToFit; - (void)layoutItems:(BOOL)skipFirst; +- (void)closed; @end @@ -178,6 +180,10 @@ const NSTimeInterval kDownloadItemOpenDuration = 0.8; bridge_->Close(); else [self showDownloadShelf:NO]; + + // TODO(port): When closing the shelf is animated, call this only after the + // animation has ended: + [self closed]; } - (float)height { @@ -254,4 +260,21 @@ const NSTimeInterval kDownloadItemOpenDuration = 0.8; [self layoutItems:YES]; } +- (void)closed { + NSUInteger i = 0; + while (i < [downloadItemControllers_.get() count]) { + DownloadItemController* itemController = [downloadItemControllers_.get() + objectAtIndex:i]; + bool isTransferDone = + [itemController download]->state() == DownloadItem::COMPLETE || + [itemController download]->state() == DownloadItem::CANCELLED; + if (isTransferDone && + [itemController download]->safety_state() != DownloadItem::DANGEROUS) { + [self remove:itemController]; + } else { + ++i; + } + } +} + @end |