Index: chrome/browser/ui/gtk/download/download_item_gtk.cc |
diff --git a/chrome/browser/ui/gtk/download/download_item_gtk.cc b/chrome/browser/ui/gtk/download/download_item_gtk.cc |
index 7bef1e8206c971878af87f1bec8dbf2a96c8b4cf..ff07fa8a10677754e3b77c5ccc96c739ed7bb0b7 100644 |
--- a/chrome/browser/ui/gtk/download/download_item_gtk.cc |
+++ b/chrome/browser/ui/gtk/download/download_item_gtk.cc |
@@ -62,6 +62,9 @@ const int kMinDownloadItemWidth = download_util::kSmallProgressIconSize; |
// New download item animation speed in milliseconds. |
const int kNewItemAnimationDurationMs = 800; |
+// Dangerous download prompt transition animation speed in milliseconds. |
+const int kDangerPromptAnimationDurationMs = 800; |
+ |
// How long the 'download complete/interrupted' animation should last for. |
const int kCompleteAnimationDurationMs = 2500; |
@@ -184,76 +187,13 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf, |
new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs); |
gtk_widget_show_all(hbox_.get()); |
- if (IsDangerous()) { |
- // Hide the download item components for now. |
- gtk_widget_set_no_show_all(body_.get(), TRUE); |
- gtk_widget_set_no_show_all(menu_button_, TRUE); |
- gtk_widget_hide(body_.get()); |
- gtk_widget_hide(menu_button_); |
- |
- // Create an hbox to hold it all. |
- dangerous_hbox_.Own(gtk_hbox_new(FALSE, kDangerousElementPadding)); |
- |
- // Add padding at the beginning and end. The hbox will add padding between |
- // the empty labels and the other elements. |
- GtkWidget* empty_label_a = gtk_label_new(NULL); |
- GtkWidget* empty_label_b = gtk_label_new(NULL); |
- gtk_box_pack_start(GTK_BOX(dangerous_hbox_.get()), empty_label_a, |
- FALSE, FALSE, 0); |
- gtk_box_pack_end(GTK_BOX(dangerous_hbox_.get()), empty_label_b, |
- FALSE, FALSE, 0); |
- |
- // Create the warning icon. |
- dangerous_image_ = gtk_image_new(); |
- gtk_box_pack_start(GTK_BOX(dangerous_hbox_.get()), dangerous_image_, |
- FALSE, FALSE, 0); |
- |
- dangerous_label_ = gtk_label_new(NULL); |
- // We pass TRUE, TRUE so that the label will condense to less than its |
- // request when the animation is going on. |
- gtk_box_pack_start(GTK_BOX(dangerous_hbox_.get()), dangerous_label_, |
- TRUE, TRUE, 0); |
- |
- // Create the nevermind button. |
- GtkWidget* dangerous_decline = gtk_button_new_with_label( |
- l10n_util::GetStringUTF8(IDS_DISCARD_DOWNLOAD).c_str()); |
- g_signal_connect(dangerous_decline, "clicked", |
- G_CALLBACK(OnDangerousDeclineThunk), this); |
- gtk_util::CenterWidgetInHBox(dangerous_hbox_.get(), dangerous_decline, |
- false, 0); |
- |
- // Create the ok button. |
- GtkWidget* dangerous_accept = gtk_button_new_with_label( |
- l10n_util::GetStringUTF8( |
- ChromeDownloadManagerDelegate::IsExtensionDownload( |
- download_model->download()) ? |
- IDS_CONTINUE_EXTENSION_DOWNLOAD : |
- IDS_CONFIRM_DOWNLOAD).c_str()); |
- g_signal_connect(dangerous_accept, "clicked", |
- G_CALLBACK(OnDangerousAcceptThunk), this); |
- gtk_util::CenterWidgetInHBox(dangerous_hbox_.get(), dangerous_accept, false, |
- 0); |
- |
- // Put it in an alignment so that padding will be added on the left and |
- // right. |
- dangerous_prompt_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); |
- gtk_alignment_set_padding(GTK_ALIGNMENT(dangerous_prompt_), |
- 0, 0, kDangerousElementPadding, kDangerousElementPadding); |
- gtk_container_add(GTK_CONTAINER(dangerous_prompt_), dangerous_hbox_.get()); |
- gtk_box_pack_start(GTK_BOX(hbox_.get()), dangerous_prompt_, FALSE, FALSE, |
- 0); |
- gtk_widget_set_app_paintable(dangerous_prompt_, TRUE); |
- gtk_widget_set_redraw_on_allocate(dangerous_prompt_, TRUE); |
- g_signal_connect(dangerous_prompt_, "expose-event", |
- G_CALLBACK(OnDangerousPromptExposeThunk), this); |
- gtk_widget_show_all(dangerous_prompt_); |
- } |
+ if (IsDangerous()) |
+ ShowDangerPrompt(); |
registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
content::Source<ThemeService>(theme_service_)); |
theme_service_->InitThemesFor(this); |
- // Set the initial width of the widget to be animated. |
if (IsDangerous()) { |
gtk_widget_set_size_request(dangerous_hbox_.get(), |
dangerous_hbox_start_width_, -1); |
@@ -304,6 +244,15 @@ void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) { |
// We may free some shelf space for showing more download items. |
parent_shelf_->MaybeShowMoreDownloadItems(); |
+ } else if (dangerous_prompt_ == NULL && IsDangerous()) { |
+ ShowDangerPrompt(); |
+ gtk_widget_set_size_request(dangerous_hbox_.get(), kBodyWidth, -1); |
+ // Complete the new_item_animation_, so we don't race each other. |
+ new_item_animation_->Reset(1); |
+ danger_prompt_animation_.reset(new ui::SlideAnimation(this)); |
+ danger_prompt_animation_->SetSlideDuration( |
+ kDangerPromptAnimationDurationMs); |
+ danger_prompt_animation_->Show(); |
} |
if (download->GetUserVerifiedFilePath() != icon_filepath_) { |
@@ -364,6 +313,13 @@ void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) { |
void DownloadItemGtk::AnimationProgressed(const ui::Animation* animation) { |
if (animation == &complete_animation_) { |
gtk_widget_queue_draw(progress_area_.get()); |
+ } else if (danger_prompt_animation_.get() && |
+ animation == danger_prompt_animation_.get()) { |
+ int progress = static_cast<int>((dangerous_hbox_full_width_ - |
+ kBodyWidth) * |
+ animation->GetCurrentValue()); |
+ int showing_width = kBodyWidth + progress; |
+ gtk_widget_set_size_request(dangerous_hbox_.get(), showing_width, -1); |
} else { |
DCHECK(animation == new_item_animation_.get()); |
if (IsDangerous()) { |
@@ -558,16 +514,17 @@ void DownloadItemGtk::UpdateDangerWarning() { |
// We create |dangerous_warning| as a wide string so we can more easily |
// calculate its length in characters. |
string16 dangerous_warning; |
+ DownloadStateInfo::DangerType danger_type = get_download()->GetDangerType(); |
// The dangerous download label text is different for different cases. |
- if (get_download()->GetDangerType() == DownloadStateInfo::DANGEROUS_URL) { |
+ if (danger_type == DownloadStateInfo::DANGEROUS_URL || |
+ danger_type == DownloadStateInfo::DANGEROUS_CONTENT) { |
// Safebrowsing shows the download URL leads to malicious file. |
dangerous_warning = |
l10n_util::GetStringUTF16(IDS_PROMPT_UNSAFE_DOWNLOAD_URL); |
Randy Smith (Not in Mondays)
2011/11/21 01:38:13
Noe': Do we want the prompts to be the same for co
|
} else { |
// It's a dangerous file type (e.g.: an executable). |
- DCHECK(get_download()->GetDangerType() == |
- DownloadStateInfo::DANGEROUS_FILE); |
+ DCHECK(danger_type == DownloadStateInfo::DANGEROUS_FILE); |
if (ChromeDownloadManagerDelegate::IsExtensionDownload(get_download())) { |
dangerous_warning = |
l10n_util::GetStringUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); |
@@ -615,9 +572,11 @@ void DownloadItemGtk::UpdateDangerWarning() { |
} |
void DownloadItemGtk::UpdateDangerIcon() { |
+ DownloadStateInfo::DangerType danger_type = get_download()->GetDangerType(); |
if (theme_service_->UsingNativeTheme()) { |
const char* stock = |
- get_download()->GetDangerType() == DownloadStateInfo::DANGEROUS_URL ? |
+ (danger_type == DownloadStateInfo::DANGEROUS_URL || |
+ danger_type == DownloadStateInfo::DANGEROUS_CONTENT) ? |
GTK_STOCK_DIALOG_ERROR : GTK_STOCK_DIALOG_WARNING; |
gtk_image_set_from_stock( |
GTK_IMAGE(dangerous_image_), stock, GTK_ICON_SIZE_SMALL_TOOLBAR); |
@@ -625,13 +584,82 @@ void DownloadItemGtk::UpdateDangerIcon() { |
// Set the warning icon. |
ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
int pixbuf_id = |
- get_download()->GetDangerType() == DownloadStateInfo::DANGEROUS_URL ? |
+ (danger_type == DownloadStateInfo::DANGEROUS_URL || |
+ danger_type == DownloadStateInfo::DANGEROUS_CONTENT) ? |
IDR_SAFEBROWSING_WARNING : IDR_WARNING; |
GdkPixbuf* download_pixbuf = rb.GetNativeImageNamed(pixbuf_id); |
gtk_image_set_from_pixbuf(GTK_IMAGE(dangerous_image_), download_pixbuf); |
} |
} |
+void DownloadItemGtk::ShowDangerPrompt() { |
+ if (dangerous_prompt_) |
+ return; |
+ |
+ // Hide the download item components for now. |
+ gtk_widget_set_no_show_all(body_.get(), TRUE); |
+ gtk_widget_set_no_show_all(menu_button_, TRUE); |
+ gtk_widget_hide(body_.get()); |
+ gtk_widget_hide(menu_button_); |
+ |
+ // Create an hbox to hold it all. |
+ dangerous_hbox_.Own(gtk_hbox_new(FALSE, kDangerousElementPadding)); |
+ |
+ // Add padding at the beginning and end. The hbox will add padding between |
+ // the empty labels and the other elements. |
+ GtkWidget* empty_label_a = gtk_label_new(NULL); |
+ GtkWidget* empty_label_b = gtk_label_new(NULL); |
+ gtk_box_pack_start(GTK_BOX(dangerous_hbox_.get()), empty_label_a, |
+ FALSE, FALSE, 0); |
+ gtk_box_pack_end(GTK_BOX(dangerous_hbox_.get()), empty_label_b, |
+ FALSE, FALSE, 0); |
+ |
+ // Create the warning icon. |
+ dangerous_image_ = gtk_image_new(); |
+ gtk_box_pack_start(GTK_BOX(dangerous_hbox_.get()), dangerous_image_, |
+ FALSE, FALSE, 0); |
+ |
+ dangerous_label_ = gtk_label_new(NULL); |
+ // We pass TRUE, TRUE so that the label will condense to less than its |
+ // request when the animation is going on. |
+ gtk_box_pack_start(GTK_BOX(dangerous_hbox_.get()), dangerous_label_, |
+ TRUE, TRUE, 0); |
+ |
+ // Create the nevermind button. |
+ GtkWidget* dangerous_decline = gtk_button_new_with_label( |
+ l10n_util::GetStringUTF8(IDS_DISCARD_DOWNLOAD).c_str()); |
+ g_signal_connect(dangerous_decline, "clicked", |
+ G_CALLBACK(OnDangerousDeclineThunk), this); |
+ gtk_util::CenterWidgetInHBox(dangerous_hbox_.get(), dangerous_decline, |
+ false, 0); |
+ |
+ // Create the ok button. |
+ GtkWidget* dangerous_accept = gtk_button_new_with_label( |
+ l10n_util::GetStringUTF8( |
+ ChromeDownloadManagerDelegate::IsExtensionDownload( |
+ download_model_->download()) ? |
+ IDS_CONTINUE_EXTENSION_DOWNLOAD : |
+ IDS_CONFIRM_DOWNLOAD).c_str()); |
+ g_signal_connect(dangerous_accept, "clicked", |
+ G_CALLBACK(OnDangerousAcceptThunk), this); |
+ gtk_util::CenterWidgetInHBox(dangerous_hbox_.get(), dangerous_accept, false, |
+ 0); |
+ |
+ // Put it in an alignment so that padding will be added on the left and right. |
+ dangerous_prompt_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); |
+ gtk_alignment_set_padding( |
+ GTK_ALIGNMENT(dangerous_prompt_), |
+ 0, 0, kDangerousElementPadding, kDangerousElementPadding); |
+ gtk_container_add(GTK_CONTAINER(dangerous_prompt_), dangerous_hbox_.get()); |
+ gtk_box_pack_start(GTK_BOX(hbox_.get()), dangerous_prompt_, FALSE, FALSE, 0); |
+ gtk_widget_set_app_paintable(dangerous_prompt_, TRUE); |
+ gtk_widget_set_redraw_on_allocate(dangerous_prompt_, TRUE); |
+ g_signal_connect(dangerous_prompt_, "expose-event", |
+ G_CALLBACK(OnDangerousPromptExposeThunk), this); |
+ gtk_widget_show_all(dangerous_prompt_); |
+ UpdateDangerWarning(); |
+} |
+ |
// static |
void DownloadItemGtk::InitNineBoxes() { |
if (body_nine_box_normal_) |