File: download_item_controller.h

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (165 lines) | stat: -rw-r--r-- 5,033 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <Cocoa/Cocoa.h>

#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"

@class ChromeUILocalizer;
@class DownloadItemCell;
@class DownloadItemButton;
class DownloadItemMac;
class DownloadItemModel;
class DownloadShelfContextMenuMac;
@class DownloadShelfController;
@class GTMWidthBasedTweaker;

namespace content {
class DownloadItem;
class PageNavigator;
}

namespace extensions {
class ExperienceSamplingEvent;
}

namespace gfx {
class FontList;
}

namespace ui {
class MenuModel;
}

// A controller class that manages one download item.
//
// The view hierarchy is as follows:
//
// DownloadItemController
//  |
//  |  A container that is showing one of its child views (progressView_ or
//  |  dangerousDownloadView_) depending on whether the download is safe or not.
//  |
//  +-- progressView_ (instance of DownloadItemButton)
//  |   |
//  |   +-- cell_ (instance of DownloadItemCell)
//  |
//  +-- dangerousDownloadView_
//      |
//      |  Contains the dangerous download warning. Dependong on whether the
//      |  download is dangerous (e.g. dangerous due to type of file), or
//      |  malicious (e.g. downloaded from a known malware site) only one of
//      |  dangerousButtonTweaker_ or maliciousButtonTweaker_ will be visible at
//      |  one time.
//      |
//      +-- dangerousDownloadLabel_
//      |
//      +-- image_
//      |
//      +-- dangerousButtonTweaker_
//      |
//      |  Contains the 'Discard'/'Save' buttons for a dangerous download. This
//      |  is a GTMWidthBasedTweaker that adjusts the width based on the text of
//      |  buttons.
//      |
//      +-- maliciousButtonTweaker_
//
//         Contains the 'Discard' button and the drop down context menu button.
//         This is a GTMWidthBasedTweaker that adjusts the width based on the
//         text of the 'Discard' button.
//
@interface DownloadItemController : NSViewController {
 @private
  IBOutlet DownloadItemButton* progressView_;
  IBOutlet DownloadItemCell* cell_;

  // This is shown instead of progressView_ for dangerous downloads.
  IBOutlet NSView* dangerousDownloadView_;
  IBOutlet NSTextField* dangerousDownloadLabel_;
  IBOutlet NSButton* dangerousDownloadConfirmButton_;

  // Needed to find out how much the tweakers changed sizes to update the other
  // views.
  IBOutlet GTMWidthBasedTweaker* dangerousButtonTweaker_;
  IBOutlet GTMWidthBasedTweaker* maliciousButtonTweaker_;

  // Because the confirm text and button for dangerous downloads are determined
  // at runtime, an outlet to the localizer is needed to construct the layout
  // tweaker in awakeFromNib in order to adjust the UI after all strings are
  // determined.
  IBOutlet ChromeUILocalizer* localizer_;

  IBOutlet NSImageView* image_;

  scoped_ptr<DownloadItemMac> bridge_;
  scoped_ptr<DownloadShelfContextMenuMac> menuBridge_;

  // Weak pointer to the shelf that owns us.
  DownloadShelfController* shelf_;

  // The time at which this view was created.
  base::Time creationTime_;

  // Default font list to use for text metrics.
  scoped_ptr<gfx::FontList> font_list_;

  // The state of this item.
  enum DownloadItemState {
    kNormal,
    kDangerous
  } state_;

  // ExperienceSampling: This tracks dangerous/malicious downloads warning UI
  // and the user's decisions about it.
  scoped_ptr<extensions::ExperienceSamplingEvent> sampling_event_;
};

// Initialize controller for |downloadItem|.
- (id)initWithDownload:(content::DownloadItem*)downloadItem
                 shelf:(DownloadShelfController*)shelf
             navigator:(content::PageNavigator*)navigator;

// Updates the UI and menu state from |downloadModel|.
- (void)setStateFromDownload:(DownloadItemModel*)downloadModel;

// Remove ourself from the download UI.
- (void)remove;

// Update item's visibility depending on if the item is still completely
// contained in its parent.
- (void)updateVisibility:(id)sender;

// Called after a download is opened.
- (void)downloadWasOpened;

// Asynchronous icon loading callback.
- (void)setIcon:(NSImage*)icon;

// Download item button clicked
- (IBAction)handleButtonClick:(id)sender;

// Returns the size this item wants to have.
- (NSSize)preferredSize;

// Returns the DownloadItem model object belonging to this item.
- (content::DownloadItem*)download;

// Returns the MenuModel for the download item context menu. The returned
// MenuModel is owned by the DownloadItemController and will be valid until the
// DownloadItemController is destroyed.
- (ui::MenuModel*)contextMenuModel;

// Updates the tooltip with the download's path.
- (void)updateToolTip;

// Handling of dangerous downloads
- (void)clearDangerousMode;
- (BOOL)isDangerousMode;
- (IBAction)saveDownload:(id)sender;
- (IBAction)discardDownload:(id)sender;
- (IBAction)dismissMaliciousDownload:(id)sender;
- (IBAction)showContextMenu:(id)sender;

@end