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

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: Use ui::ElideText() 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 DCHECK(IsDangerous());
119 switch (download_->GetDangerType()) {
120 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL:
121 return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL);
122
123 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE:
124 if (ChromeDownloadManagerDelegate::IsExtensionDownload(download_)) {
125 return l10n_util::GetStringUTF16(
126 IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION);
127 } else {
128 return l10n_util::GetStringFUTF16(
129 IDS_PROMPT_DANGEROUS_DOWNLOAD,
130 ui::ElideFilename(download_->GetFileNameToReportUser(),
131 font, base_width));
132 }
133
134 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT:
135 return l10n_util::GetStringFUTF16(
136 IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT,
137 ui::ElideFilename(download_->GetFileNameToReportUser(),
138 font, base_width));
139
140 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS:
141 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT:
142 case content::DOWNLOAD_DANGER_TYPE_MAX:
143 NOTREACHED();
144 }
145 return string16();
146 }
147
148 bool DownloadItemModel::IsMalicious() {
149 if (!IsDangerous())
150 return false;
151 switch (download_->GetDangerType()) {
152 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL:
153 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT:
154 return true;
155
156 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS:
157 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT:
158 case content::DOWNLOAD_DANGER_TYPE_MAX:
159 // We shouldn't get any of these due to the IsDangerous() test above.
160 NOTREACHED();
161 // Fallthrough.
162 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE:
163 return false;
164 }
165 NOTREACHED();
166 return false;
167 }
168
169 bool DownloadItemModel::IsDangerous() {
170 return download_->GetSafetyState() == DownloadItem::DANGEROUS;
171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698