Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(622)

Side by Side Diff: chrome/browser/download/download_item_model.cc

Issue 9569011: Refactor dangerous download warning text generation into DownloadItemModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update copyright headers Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/download/download_item_model.h" 5 #include "chrome/browser/download/download_item_model.h"
6 6
7 #include "base/i18n/number_formatting.h" 7 #include "base/i18n/number_formatting.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/sys_string_conversions.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/download/chrome_download_manager_delegate.h" 12 #include "chrome/browser/download/chrome_download_manager_delegate.h"
12 #include "chrome/common/time_format.h" 13 #include "chrome/common/time_format.h"
14 #include "content/public/browser/download_danger_type.h"
13 #include "content/public/browser/download_item.h" 15 #include "content/public/browser/download_item.h"
14 #include "grit/chromium_strings.h" 16 #include "grit/chromium_strings.h"
15 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/text/bytes_formatting.h" 19 #include "ui/base/text/bytes_formatting.h"
20 #include "ui/base/text/text_elider.h"
18 21
19 using base::TimeDelta; 22 using base::TimeDelta;
20 using content::DownloadItem; 23 using content::DownloadItem;
21 24
22 // ----------------------------------------------------------------------------- 25 // -----------------------------------------------------------------------------
23 // DownloadItemModel 26 // DownloadItemModel
24 27
25 DownloadItemModel::DownloadItemModel(DownloadItem* download) 28 DownloadItemModel::DownloadItemModel(DownloadItem* download)
26 : BaseDownloadItemModel(download) { 29 : BaseDownloadItemModel(download) {
27 } 30 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 status_text = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_INTERRUPTED, 105 status_text = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_INTERRUPTED,
103 simple_size, 106 simple_size,
104 simple_total); 107 simple_total);
105 break; 108 break;
106 default: 109 default:
107 NOTREACHED(); 110 NOTREACHED();
108 } 111 }
109 112
110 return status_text; 113 return status_text;
111 } 114 }
115
116 string16 DownloadItemModel::GetWarningText(const gfx::Font& font,
117 int base_width) {
118 // Should only be called if IsDangerous().
119 DCHECK(IsDangerous());
120 switch (download_->GetDangerType()) {
121 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL:
122 return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL);
123
124 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE:
125 if (ChromeDownloadManagerDelegate::IsExtensionDownload(download_)) {
126 return l10n_util::GetStringUTF16(
127 IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION);
128 } else {
129 return l10n_util::GetStringFUTF16(
130 IDS_PROMPT_DANGEROUS_DOWNLOAD,
131 ui::ElideFilename(download_->GetFileNameToReportUser(),
132 font, base_width));
133 }
134
135 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT:
136 return l10n_util::GetStringFUTF16(
137 IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT,
138 ui::ElideFilename(download_->GetFileNameToReportUser(),
139 font, base_width));
140
141 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS:
142 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT:
143 case content::DOWNLOAD_DANGER_TYPE_MAX:
144 NOTREACHED();
145 }
146 return string16();
147 }
148
149 string16 DownloadItemModel::GetWarningConfirmButtonText() {
150 // Should only be called if IsDangerous()
151 DCHECK(IsDangerous());
152 if (download_->GetDangerType() ==
153 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE &&
154 ChromeDownloadManagerDelegate::IsExtensionDownload(download_)) {
155 return l10n_util::GetStringUTF16(IDS_CONTINUE_EXTENSION_DOWNLOAD);
156 } else {
157 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD);
158 }
159 }
160
161 bool DownloadItemModel::IsMalicious() {
162 if (!IsDangerous())
163 return false;
164 switch (download_->GetDangerType()) {
165 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL:
166 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT:
167 return true;
168
169 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS:
170 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT:
171 case content::DOWNLOAD_DANGER_TYPE_MAX:
172 // We shouldn't get any of these due to the IsDangerous() test above.
173 NOTREACHED();
174 // Fallthrough.
175 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE:
176 return false;
177 }
178 NOTREACHED();
179 return false;
180 }
181
182 bool DownloadItemModel::IsDangerous() {
183 return download_->GetSafetyState() == DownloadItem::DANGEROUS;
184 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_item_model.h ('k') | chrome/browser/download/download_shelf_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698