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/gtk/download/download_item_gtk.h" | 5 #include "chrome/browser/ui/gtk/download/download_item_gtk.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 switch (download->GetState()) { | 328 switch (download->GetState()) { |
329 case DownloadItem::REMOVING: | 329 case DownloadItem::REMOVING: |
330 parent_shelf_->RemoveDownloadItem(this); // This will delete us! | 330 parent_shelf_->RemoveDownloadItem(this); // This will delete us! |
331 return; | 331 return; |
332 case DownloadItem::CANCELLED: | 332 case DownloadItem::CANCELLED: |
333 StopDownloadProgress(); | 333 StopDownloadProgress(); |
334 gtk_widget_queue_draw(progress_area_.get()); | 334 gtk_widget_queue_draw(progress_area_.get()); |
335 break; | 335 break; |
336 case DownloadItem::INTERRUPTED: | 336 case DownloadItem::INTERRUPTED: |
337 StopDownloadProgress(); | 337 StopDownloadProgress(); |
| 338 UpdateTooltip(); |
338 | 339 |
339 complete_animation_.Show(); | 340 complete_animation_.Show(); |
340 break; | 341 break; |
341 case DownloadItem::COMPLETE: | 342 case DownloadItem::COMPLETE: |
342 // GetAutoOpened() may change after the download's initial transition to | 343 // GetAutoOpened() may change after the download's initial transition to |
343 // COMPLETE, so we check it before the idemopotency shield below. | 344 // COMPLETE, so we check it before the idemopotency shield below. |
344 if (download->GetAutoOpened()) { | 345 if (download->GetAutoOpened()) { |
345 parent_shelf_->RemoveDownloadItem(this); // This will delete us! | 346 parent_shelf_->RemoveDownloadItem(this); // This will delete us! |
346 return; | 347 return; |
347 } | 348 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 IconLoader::SMALL, &icon_consumer_, | 470 IconLoader::SMALL, &icon_consumer_, |
470 base::Bind(&DownloadItemGtk::OnLoadSmallIconComplete, | 471 base::Bind(&DownloadItemGtk::OnLoadSmallIconComplete, |
471 base::Unretained(this))); | 472 base::Unretained(this))); |
472 im->LoadIcon(icon_filepath_, | 473 im->LoadIcon(icon_filepath_, |
473 IconLoader::LARGE, &icon_consumer_, | 474 IconLoader::LARGE, &icon_consumer_, |
474 base::Bind(&DownloadItemGtk::OnLoadLargeIconComplete, | 475 base::Bind(&DownloadItemGtk::OnLoadLargeIconComplete, |
475 base::Unretained(this))); | 476 base::Unretained(this))); |
476 } | 477 } |
477 | 478 |
478 void DownloadItemGtk::UpdateTooltip() { | 479 void DownloadItemGtk::UpdateTooltip() { |
479 string16 elided_filename = ui::ElideFilename( | 480 string16 tooltip_text = |
480 get_download()->GetFileNameToReportUser(), | 481 download_model_->GetTooltipText(gfx::Font(), kTooltipMaxWidth); |
481 gfx::Font(), kTooltipMaxWidth); | 482 gtk_widget_set_tooltip_text(body_.get(), UTF16ToUTF8(tooltip_text).c_str()); |
482 gtk_widget_set_tooltip_text(body_.get(), | |
483 UTF16ToUTF8(elided_filename).c_str()); | |
484 } | 483 } |
485 | 484 |
486 void DownloadItemGtk::UpdateNameLabel() { | 485 void DownloadItemGtk::UpdateNameLabel() { |
487 // TODO(estade): This is at best an educated guess, since we don't actually | 486 // TODO(estade): This is at best an educated guess, since we don't actually |
488 // use gfx::Font() to draw the text. This is why we need to add so | 487 // use gfx::Font() to draw the text. This is why we need to add so |
489 // much padding when we set the size request. We need to either use gfx::Font | 488 // much padding when we set the size request. We need to either use gfx::Font |
490 // or somehow extend TextElider. | 489 // or somehow extend TextElider. |
491 gfx::Font font = gfx::Font(); | 490 gfx::Font font = gfx::Font(); |
492 string16 filename; | 491 string16 filename; |
493 if (!disabled_while_opening_) { | 492 if (!disabled_while_opening_) { |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 get_download()->DangerousDownloadValidated(); | 917 get_download()->DangerousDownloadValidated(); |
919 } | 918 } |
920 | 919 |
921 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { | 920 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { |
922 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 921 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
923 base::Time::Now() - creation_time_); | 922 base::Time::Now() - creation_time_); |
924 if (get_download()->IsPartialDownload()) | 923 if (get_download()->IsPartialDownload()) |
925 get_download()->Cancel(true); | 924 get_download()->Cancel(true); |
926 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 925 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
927 } | 926 } |
OLD | NEW |