OLD | NEW |
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/ui/views/download/download_item_view.h" | 5 #include "chrome/browser/ui/views/download/download_item_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // TODO(paulg): These may need to be adjusted when download progress | 42 // TODO(paulg): These may need to be adjusted when download progress |
43 // animation is added, and also possibly to take into account | 43 // animation is added, and also possibly to take into account |
44 // different screen resolutions. | 44 // different screen resolutions. |
45 static const int kTextWidth = 140; // Pixels | 45 static const int kTextWidth = 140; // Pixels |
46 static const int kDangerousTextWidth = 200; // Pixels | 46 static const int kDangerousTextWidth = 200; // Pixels |
47 static const int kHorizontalTextPadding = 2; // Pixels | 47 static const int kHorizontalTextPadding = 2; // Pixels |
48 static const int kVerticalPadding = 3; // Pixels | 48 static const int kVerticalPadding = 3; // Pixels |
49 static const int kVerticalTextSpacer = 2; // Pixels | 49 static const int kVerticalTextSpacer = 2; // Pixels |
50 static const int kVerticalTextPadding = 2; // Pixels | 50 static const int kVerticalTextPadding = 2; // Pixels |
51 | 51 |
52 // The maximum number of characters we show in a file name when displaying the | |
53 // dangerous download message. | |
54 static const int kFileNameMaxLength = 20; | |
55 | |
56 // We add some padding before the left image so that the progress animation icon | 52 // We add some padding before the left image so that the progress animation icon |
57 // hides the corners of the left image. | 53 // hides the corners of the left image. |
58 static const int kLeftPadding = 0; // Pixels. | 54 static const int kLeftPadding = 0; // Pixels. |
59 | 55 |
60 // The space between the Save and Discard buttons when prompting for a dangerous | 56 // The space between the Save and Discard buttons when prompting for a dangerous |
61 // download. | 57 // download. |
62 static const int kButtonPadding = 5; // Pixels. | 58 static const int kButtonPadding = 5; // Pixels. |
63 | 59 |
64 // The space on the left and right side of the dangerous download label. | 60 // The space on the left and right side of the dangerous download label. |
65 static const int kLabelPadding = 4; // Pixels. | 61 static const int kLabelPadding = 4; // Pixels. |
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 LoadIcon(); | 993 LoadIcon(); |
998 tooltip_text_ = download_->GetFileNameToReportUser().LossyDisplayName(); | 994 tooltip_text_ = download_->GetFileNameToReportUser().LossyDisplayName(); |
999 | 995 |
1000 // Force the shelf to layout again as our size has changed. | 996 // Force the shelf to layout again as our size has changed. |
1001 parent_->Layout(); | 997 parent_->Layout(); |
1002 parent_->SchedulePaint(); | 998 parent_->SchedulePaint(); |
1003 } | 999 } |
1004 | 1000 |
1005 void DownloadItemView::ShowWarningDialog() { | 1001 void DownloadItemView::ShowWarningDialog() { |
1006 DCHECK(mode_ != DANGEROUS_MODE && mode_ != MALICIOUS_MODE); | 1002 DCHECK(mode_ != DANGEROUS_MODE && mode_ != MALICIOUS_MODE); |
1007 if (download_->GetDangerType() == | 1003 mode_ = ((model_->IsMalicious()) ? MALICIOUS_MODE : DANGEROUS_MODE); |
1008 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || | 1004 |
1009 download_->GetDangerType() == | |
1010 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT) { | |
1011 mode_ = MALICIOUS_MODE; | |
1012 } else { | |
1013 DCHECK(download_->GetDangerType() == | |
1014 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); | |
1015 mode_ = DANGEROUS_MODE; | |
1016 } | |
1017 body_state_ = NORMAL; | 1005 body_state_ = NORMAL; |
1018 drop_down_state_ = NORMAL; | 1006 drop_down_state_ = NORMAL; |
1019 tooltip_text_.clear(); | 1007 tooltip_text_.clear(); |
1020 if (mode_ == DANGEROUS_MODE) { | 1008 if (mode_ == DANGEROUS_MODE) { |
1021 save_button_ = new views::NativeTextButton(this, | 1009 save_button_ = new views::NativeTextButton(this, |
1022 l10n_util::GetStringUTF16( | 1010 l10n_util::GetStringUTF16( |
1023 ChromeDownloadManagerDelegate::IsExtensionDownload(download_) ? | 1011 ChromeDownloadManagerDelegate::IsExtensionDownload(download_) ? |
1024 IDS_CONTINUE_EXTENSION_DOWNLOAD : IDS_CONFIRM_DOWNLOAD)); | 1012 IDS_CONTINUE_EXTENSION_DOWNLOAD : IDS_CONFIRM_DOWNLOAD)); |
1025 save_button_->set_ignore_minimum_size(true); | 1013 save_button_->set_ignore_minimum_size(true); |
1026 AddChildView(save_button_); | 1014 AddChildView(save_button_); |
1027 } | 1015 } |
1028 discard_button_ = new views::NativeTextButton( | 1016 discard_button_ = new views::NativeTextButton( |
1029 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); | 1017 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); |
1030 discard_button_->set_ignore_minimum_size(true); | 1018 discard_button_->set_ignore_minimum_size(true); |
1031 AddChildView(discard_button_); | 1019 AddChildView(discard_button_); |
1032 | 1020 |
1033 // Ensure the file name is not too long. | |
1034 | |
1035 // Extract the file extension (if any). | |
1036 FilePath filename(download_->GetTargetName()); | |
1037 #if defined(OS_POSIX) | |
1038 string16 extension = WideToUTF16(base::SysNativeMBToWide( | |
1039 filename.Extension())); | |
1040 #else | |
1041 string16 extension = filename.Extension(); | |
1042 #endif | |
1043 | |
1044 // Remove leading '.' | |
1045 if (extension.length() > 0) | |
1046 extension = extension.substr(1); | |
1047 #if defined(OS_POSIX) | |
1048 string16 rootname = WideToUTF16(base::SysNativeMBToWide( | |
1049 filename.RemoveExtension().value())); | |
1050 #else | |
1051 string16 rootname = filename.RemoveExtension().value(); | |
1052 #endif | |
1053 | |
1054 // Elide giant extensions (this shouldn't currently be hit, but might | |
1055 // in future, should we ever notice unsafe giant extensions). | |
1056 if (extension.length() > kFileNameMaxLength / 2) | |
1057 ui::ElideString(extension, kFileNameMaxLength / 2, &extension); | |
1058 | |
1059 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1021 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1060 // The dangerous download label text and icon are different | 1022 // The dangerous download label text and icon are different under |
1061 // under different cases. | 1023 // different cases. |
1062 if (mode_ == MALICIOUS_MODE) { | 1024 if (mode_ == MALICIOUS_MODE) { |
1063 warning_icon_ = rb.GetBitmapNamed(IDR_SAFEBROWSING_WARNING); | 1025 warning_icon_ = rb.GetBitmapNamed(IDR_SAFEBROWSING_WARNING); |
1064 } else { | 1026 } else { |
1065 DCHECK(download_->GetDangerType() == | |
1066 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); | |
1067 // The download file has dangerous file type (e.g.: an executable). | 1027 // The download file has dangerous file type (e.g.: an executable). |
1068 warning_icon_ = rb.GetBitmapNamed(IDR_WARNING); | 1028 warning_icon_ = rb.GetBitmapNamed(IDR_WARNING); |
1069 } | 1029 } |
1070 string16 dangerous_label; | 1030 string16 dangerous_label = model_->GetWarningText(font_, kTextWidth); |
1071 if (download_->GetDangerType() == | |
1072 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL) { | |
1073 // Safebrowsing shows the download URL or content leads to malicious file. | |
1074 dangerous_label = l10n_util::GetStringUTF16( | |
1075 IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); | |
1076 } else if (download_->GetDangerType() == | |
1077 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE && | |
1078 ChromeDownloadManagerDelegate::IsExtensionDownload(download_)) { | |
1079 dangerous_label = | |
1080 l10n_util::GetStringUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); | |
1081 } else { | |
1082 // The download file has dangerous file type (e.g.: an executable) or the | |
1083 // file content is known to be malicious. | |
1084 DCHECK(download_->GetDangerType() == | |
1085 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || | |
1086 download_->GetDangerType() == | |
1087 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT); | |
1088 ui::ElideString(rootname, | |
1089 kFileNameMaxLength - extension.length(), | |
1090 &rootname); | |
1091 string16 filename = rootname + ASCIIToUTF16(".") + extension; | |
1092 filename = base::i18n::GetDisplayStringInLTRDirectionality(filename); | |
1093 dangerous_label = l10n_util::GetStringFUTF16( | |
1094 download_->GetDangerType() == | |
1095 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE ? | |
1096 IDS_PROMPT_DANGEROUS_DOWNLOAD : | |
1097 IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT, | |
1098 filename); | |
1099 } | |
1100 | |
1101 dangerous_download_label_ = new views::Label(dangerous_label); | 1031 dangerous_download_label_ = new views::Label(dangerous_label); |
1102 dangerous_download_label_->SetMultiLine(true); | 1032 dangerous_download_label_->SetMultiLine(true); |
1103 dangerous_download_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 1033 dangerous_download_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
1104 dangerous_download_label_->SetAutoColorReadabilityEnabled(false); | 1034 dangerous_download_label_->SetAutoColorReadabilityEnabled(false); |
1105 AddChildView(dangerous_download_label_); | 1035 AddChildView(dangerous_download_label_); |
1106 SizeLabelToMinWidth(); | 1036 SizeLabelToMinWidth(); |
1107 UpdateDropDownButtonPosition(); | 1037 UpdateDropDownButtonPosition(); |
1108 } | 1038 } |
1109 | 1039 |
1110 gfx::Size DownloadItemView::GetButtonSize() { | 1040 gfx::Size DownloadItemView::GetButtonSize() { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 // Drop down button is glued to the left of the download shelf. | 1168 // Drop down button is glued to the left of the download shelf. |
1239 drop_down_x_left_ = 0; | 1169 drop_down_x_left_ = 0; |
1240 drop_down_x_right_ = normal_drop_down_image_set_.top->width(); | 1170 drop_down_x_right_ = normal_drop_down_image_set_.top->width(); |
1241 } else { | 1171 } else { |
1242 // Drop down button is glued to the right of the download shelf. | 1172 // Drop down button is glued to the right of the download shelf. |
1243 drop_down_x_left_ = | 1173 drop_down_x_left_ = |
1244 size.width() - normal_drop_down_image_set_.top->width(); | 1174 size.width() - normal_drop_down_image_set_.top->width(); |
1245 drop_down_x_right_ = size.width(); | 1175 drop_down_x_right_ = size.width(); |
1246 } | 1176 } |
1247 } | 1177 } |
OLD | NEW |