1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import <Cocoa/Cocoa.h>
7 #include "base/memory/scoped_ptr.h"
8 #include "base/time/time.h"
10 @
class ChromeUILocalizer
;
11 @
class DownloadItemCell
;
12 @
class DownloadItemButton
;
13 class DownloadItemMac
;
14 class DownloadItemModel
;
15 class DownloadShelfContextMenuMac
;
16 @
class DownloadShelfController
;
17 @
class GTMWidthBasedTweaker
;
24 namespace extensions
{
25 class ExperienceSamplingEvent
;
36 // A controller class that manages one download item.
38 // The view hierarchy is as follows:
40 // DownloadItemController
42 // | A container that is showing one of its child views (progressView_ or
43 // | dangerousDownloadView_) depending on whether the download is safe or not.
45 // +-- progressView_ (instance of DownloadItemButton)
47 // | +-- cell_ (instance of DownloadItemCell)
49 // +-- dangerousDownloadView_
51 // | Contains the dangerous download warning. Dependong on whether the
52 // | download is dangerous (e.g. dangerous due to type of file), or
53 // | malicious (e.g. downloaded from a known malware site) only one of
54 // | dangerousButtonTweaker_ or maliciousButtonTweaker_ will be visible at
57 // +-- dangerousDownloadLabel_
61 // +-- dangerousButtonTweaker_
63 // | Contains the 'Discard'/'Save' buttons for a dangerous download. This
64 // | is a GTMWidthBasedTweaker that adjusts the width based on the text of
67 // +-- maliciousButtonTweaker_
69 // Contains the 'Discard' button and the drop down context menu button.
70 // This is a GTMWidthBasedTweaker that adjusts the width based on the
71 // text of the 'Discard' button.
73 @interface DownloadItemController
: NSViewController
{
75 IBOutlet DownloadItemButton
* progressView_
;
76 IBOutlet DownloadItemCell
* cell_
;
78 // This is shown instead of progressView_ for dangerous downloads.
79 IBOutlet NSView
* dangerousDownloadView_
;
80 IBOutlet NSTextField
* dangerousDownloadLabel_
;
81 IBOutlet NSButton
* dangerousDownloadConfirmButton_
;
83 // Needed to find out how much the tweakers changed sizes to update the other
85 IBOutlet GTMWidthBasedTweaker
* dangerousButtonTweaker_
;
86 IBOutlet GTMWidthBasedTweaker
* maliciousButtonTweaker_
;
88 // Because the confirm text and button for dangerous downloads are determined
89 // at runtime, an outlet to the localizer is needed to construct the layout
90 // tweaker in awakeFromNib in order to adjust the UI after all strings are
92 IBOutlet ChromeUILocalizer
* localizer_
;
94 IBOutlet NSImageView
* image_
;
96 scoped_ptr
<DownloadItemMac
> bridge_
;
97 scoped_ptr
<DownloadShelfContextMenuMac
> menuBridge_
;
99 // Weak pointer to the shelf that owns us.
100 DownloadShelfController
* shelf_
;
102 // The time at which this view was created.
103 base::Time creationTime_
;
105 // Default font list to use for text metrics.
106 scoped_ptr
<gfx::FontList
> font_list_
;
108 // The state of this item.
109 enum DownloadItemState
{
114 // ExperienceSampling: This tracks dangerous/malicious downloads warning UI
115 // and the user's decisions about it.
116 scoped_ptr
<extensions::ExperienceSamplingEvent
> sampling_event_
;
119 // Initialize controller for |downloadItem|.
120 - (id
)initWithDownload
:(content::DownloadItem
*)downloadItem
121 shelf
:(DownloadShelfController
*)shelf
122 navigator
:(content::PageNavigator
*)navigator
;
124 // Updates the UI and menu state from |downloadModel|.
125 - (void)setStateFromDownload
:(DownloadItemModel
*)downloadModel
;
127 // Remove ourself from the download UI.
130 // Update item's visibility depending on if the item is still completely
131 // contained in its parent.
132 - (void)updateVisibility
:(id
)sender
;
134 // Called after a download is opened.
135 - (void)downloadWasOpened
;
137 // Asynchronous icon loading callback.
138 - (void)setIcon
:(NSImage
*)icon
;
140 // Download item button clicked
141 - (IBAction
)handleButtonClick
:(id
)sender
;
143 // Returns the size this item wants to have.
144 - (NSSize
)preferredSize
;
146 // Returns the DownloadItem model object belonging to this item.
147 - (content::DownloadItem
*)download
;
149 // Returns the MenuModel for the download item context menu. The returned
150 // MenuModel is owned by the DownloadItemController and will be valid until the
151 // DownloadItemController is destroyed.
152 - (ui::MenuModel
*)contextMenuModel
;
154 // Updates the tooltip with the download's path.
155 - (void)updateToolTip
;
157 // Handling of dangerous downloads
158 - (void)clearDangerousMode
;
159 - (BOOL
)isDangerousMode
;
160 - (IBAction
)saveDownload
:(id
)sender
;
161 - (IBAction
)discardDownload
:(id
)sender
;
162 - (IBAction
)dismissMaliciousDownload
:(id
)sender
;
163 - (IBAction
)showContextMenu
:(id
)sender
;