| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // downloaded item. | 75 // downloaded item. |
| 76 static const int kDisabledOnOpenDuration = 3000; | 76 static const int kDisabledOnOpenDuration = 3000; |
| 77 | 77 |
| 78 // Darken light-on-dark download status text by 20% before drawing, thus | 78 // Darken light-on-dark download status text by 20% before drawing, thus |
| 79 // creating a "muted" version of title text for both dark-on-light and | 79 // creating a "muted" version of title text for both dark-on-light and |
| 80 // light-on-dark themes. | 80 // light-on-dark themes. |
| 81 static const double kDownloadItemLuminanceMod = 0.8; | 81 static const double kDownloadItemLuminanceMod = 0.8; |
| 82 | 82 |
| 83 using content::DownloadItem; | 83 using content::DownloadItem; |
| 84 | 84 |
| 85 DownloadItemView::DownloadItemView(DownloadItem* download, | 85 DownloadItemView::DownloadItemView(DownloadItem* download_item, |
| 86 DownloadShelfView* parent, | 86 DownloadShelfView* parent) |
| 87 DownloadItemModel* model) | |
| 88 : warning_icon_(NULL), | 87 : warning_icon_(NULL), |
| 89 download_(download), | |
| 90 shelf_(parent), | 88 shelf_(parent), |
| 91 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), | 89 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), |
| 92 body_state_(NORMAL), | 90 body_state_(NORMAL), |
| 93 drop_down_state_(NORMAL), | 91 drop_down_state_(NORMAL), |
| 94 mode_(NORMAL_MODE), | 92 mode_(NORMAL_MODE), |
| 95 progress_angle_(download_util::kStartAngleDegrees), | 93 progress_angle_(download_util::kStartAngleDegrees), |
| 96 drop_down_pressed_(false), | 94 drop_down_pressed_(false), |
| 97 dragging_(false), | 95 dragging_(false), |
| 98 starting_drag_(false), | 96 starting_drag_(false), |
| 99 model_(model), | 97 model_(download_item), |
| 100 save_button_(NULL), | 98 save_button_(NULL), |
| 101 discard_button_(NULL), | 99 discard_button_(NULL), |
| 102 dangerous_download_label_(NULL), | 100 dangerous_download_label_(NULL), |
| 103 dangerous_download_label_sized_(false), | 101 dangerous_download_label_sized_(false), |
| 104 disabled_while_opening_(false), | 102 disabled_while_opening_(false), |
| 105 creation_time_(base::Time::Now()), | 103 creation_time_(base::Time::Now()), |
| 106 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 104 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 107 DCHECK(download_); | 105 DCHECK(download()); |
| 108 download_->AddObserver(this); | 106 download()->AddObserver(this); |
| 109 set_context_menu_controller(this); | 107 set_context_menu_controller(this); |
| 110 | 108 |
| 111 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 109 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 112 | 110 |
| 113 BodyImageSet normal_body_image_set = { | 111 BodyImageSet normal_body_image_set = { |
| 114 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP), | 112 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP), |
| 115 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE), | 113 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE), |
| 116 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM), | 114 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM), |
| 117 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP), | 115 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP), |
| 118 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE), | 116 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE), |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 if (download_util::kSmallProgressIconSize > box_height_) | 195 if (download_util::kSmallProgressIconSize > box_height_) |
| 198 box_y_ = (download_util::kSmallProgressIconSize - box_height_) / 2; | 196 box_y_ = (download_util::kSmallProgressIconSize - box_height_) / 2; |
| 199 else | 197 else |
| 200 box_y_ = 0; | 198 box_y_ = 0; |
| 201 | 199 |
| 202 body_hover_animation_.reset(new ui::SlideAnimation(this)); | 200 body_hover_animation_.reset(new ui::SlideAnimation(this)); |
| 203 drop_hover_animation_.reset(new ui::SlideAnimation(this)); | 201 drop_hover_animation_.reset(new ui::SlideAnimation(this)); |
| 204 | 202 |
| 205 set_accessibility_focusable(true); | 203 set_accessibility_focusable(true); |
| 206 | 204 |
| 207 OnDownloadUpdated(download_); | 205 OnDownloadUpdated(download()); |
| 208 UpdateDropDownButtonPosition(); | 206 UpdateDropDownButtonPosition(); |
| 209 } | 207 } |
| 210 | 208 |
| 211 DownloadItemView::~DownloadItemView() { | 209 DownloadItemView::~DownloadItemView() { |
| 212 StopDownloadProgress(); | 210 StopDownloadProgress(); |
| 213 download_->RemoveObserver(this); | 211 download()->RemoveObserver(this); |
| 214 } | 212 } |
| 215 | 213 |
| 216 // Progress animation handlers. | 214 // Progress animation handlers. |
| 217 | 215 |
| 218 void DownloadItemView::UpdateDownloadProgress() { | 216 void DownloadItemView::UpdateDownloadProgress() { |
| 219 progress_angle_ = (progress_angle_ + | 217 progress_angle_ = (progress_angle_ + |
| 220 download_util::kUnknownIncrementDegrees) % | 218 download_util::kUnknownIncrementDegrees) % |
| 221 download_util::kMaxDegrees; | 219 download_util::kMaxDegrees; |
| 222 SchedulePaint(); | 220 SchedulePaint(); |
| 223 } | 221 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 236 | 234 |
| 237 void DownloadItemView::OnExtractIconComplete(gfx::Image* icon_bitmap) { | 235 void DownloadItemView::OnExtractIconComplete(gfx::Image* icon_bitmap) { |
| 238 if (icon_bitmap) | 236 if (icon_bitmap) |
| 239 shelf_->SchedulePaint(); | 237 shelf_->SchedulePaint(); |
| 240 } | 238 } |
| 241 | 239 |
| 242 // DownloadObserver interface. | 240 // DownloadObserver interface. |
| 243 | 241 |
| 244 // Update the progress graphic on the icon and our text status label | 242 // Update the progress graphic on the icon and our text status label |
| 245 // to reflect our current bytes downloaded, time remaining. | 243 // to reflect our current bytes downloaded, time remaining. |
| 246 void DownloadItemView::OnDownloadUpdated(DownloadItem* download) { | 244 void DownloadItemView::OnDownloadUpdated(DownloadItem* download_item) { |
| 247 DCHECK_EQ(download_, download); | 245 DCHECK_EQ(download(), download_item); |
| 248 | 246 |
| 249 if (IsShowingWarningDialog() && !model_->IsDangerous()) { | 247 if (IsShowingWarningDialog() && !model_.IsDangerous()) { |
| 250 // We have been approved. | 248 // We have been approved. |
| 251 ClearWarningDialog(); | 249 ClearWarningDialog(); |
| 252 } else if (!IsShowingWarningDialog() && model_->IsDangerous()) { | 250 } else if (!IsShowingWarningDialog() && model_.IsDangerous()) { |
| 253 ShowWarningDialog(); | 251 ShowWarningDialog(); |
| 254 // Force the shelf to layout again as our size has changed. | 252 // Force the shelf to layout again as our size has changed. |
| 255 shelf_->Layout(); | 253 shelf_->Layout(); |
| 256 SchedulePaint(); | 254 SchedulePaint(); |
| 257 } else { | 255 } else { |
| 258 string16 status_text = model_->GetStatusText(); | 256 string16 status_text = model_.GetStatusText(); |
| 259 switch (download_->GetState()) { | 257 switch (download()->GetState()) { |
| 260 case DownloadItem::IN_PROGRESS: | 258 case DownloadItem::IN_PROGRESS: |
| 261 download_->IsPaused() ? | 259 download()->IsPaused() ? |
| 262 StopDownloadProgress() : StartDownloadProgress(); | 260 StopDownloadProgress() : StartDownloadProgress(); |
| 263 LoadIconIfItemPathChanged(); | 261 LoadIconIfItemPathChanged(); |
| 264 break; | 262 break; |
| 265 case DownloadItem::INTERRUPTED: | 263 case DownloadItem::INTERRUPTED: |
| 266 StopDownloadProgress(); | 264 StopDownloadProgress(); |
| 267 complete_animation_.reset(new ui::SlideAnimation(this)); | 265 complete_animation_.reset(new ui::SlideAnimation(this)); |
| 268 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs); | 266 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs); |
| 269 complete_animation_->SetTweenType(ui::Tween::LINEAR); | 267 complete_animation_->SetTweenType(ui::Tween::LINEAR); |
| 270 complete_animation_->Show(); | 268 complete_animation_->Show(); |
| 271 SchedulePaint(); | 269 SchedulePaint(); |
| 272 LoadIcon(); | 270 LoadIcon(); |
| 273 break; | 271 break; |
| 274 case DownloadItem::COMPLETE: | 272 case DownloadItem::COMPLETE: |
| 275 if (download_->GetAutoOpened()) { | 273 if (download()->GetAutoOpened()) { |
| 276 shelf_->RemoveDownloadView(this); // This will delete us! | 274 shelf_->RemoveDownloadView(this); // This will delete us! |
| 277 return; | 275 return; |
| 278 } | 276 } |
| 279 StopDownloadProgress(); | 277 StopDownloadProgress(); |
| 280 complete_animation_.reset(new ui::SlideAnimation(this)); | 278 complete_animation_.reset(new ui::SlideAnimation(this)); |
| 281 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); | 279 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); |
| 282 complete_animation_->SetTweenType(ui::Tween::LINEAR); | 280 complete_animation_->SetTweenType(ui::Tween::LINEAR); |
| 283 complete_animation_->Show(); | 281 complete_animation_->Show(); |
| 284 SchedulePaint(); | 282 SchedulePaint(); |
| 285 LoadIcon(); | 283 LoadIcon(); |
| 286 break; | 284 break; |
| 287 case DownloadItem::CANCELLED: | 285 case DownloadItem::CANCELLED: |
| 288 StopDownloadProgress(); | 286 StopDownloadProgress(); |
| 289 LoadIcon(); | 287 LoadIcon(); |
| 290 break; | 288 break; |
| 291 default: | 289 default: |
| 292 NOTREACHED(); | 290 NOTREACHED(); |
| 293 } | 291 } |
| 294 status_text_ = status_text; | 292 status_text_ = status_text; |
| 295 } | 293 } |
| 296 | 294 |
| 297 string16 new_tip = model_->GetTooltipText(font_, kTooltipMaxWidth); | 295 string16 new_tip = model_.GetTooltipText(font_, kTooltipMaxWidth); |
| 298 if (new_tip != tooltip_text_) { | 296 if (new_tip != tooltip_text_) { |
| 299 tooltip_text_ = new_tip; | 297 tooltip_text_ = new_tip; |
| 300 TooltipTextChanged(); | 298 TooltipTextChanged(); |
| 301 } | 299 } |
| 302 | 300 |
| 303 UpdateAccessibleName(); | 301 UpdateAccessibleName(); |
| 304 | 302 |
| 305 // We use the parent's (DownloadShelfView's) SchedulePaint, since there | 303 // We use the parent's (DownloadShelfView's) SchedulePaint, since there |
| 306 // are spaces between each DownloadItemView that the parent is responsible | 304 // are spaces between each DownloadItemView that the parent is responsible |
| 307 // for painting. | 305 // for painting. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 bool DownloadItemView::OnMouseDragged(const ui::MouseEvent& event) { | 397 bool DownloadItemView::OnMouseDragged(const ui::MouseEvent& event) { |
| 400 // Mouse should not activate us in dangerous mode. | 398 // Mouse should not activate us in dangerous mode. |
| 401 if (IsShowingWarningDialog()) | 399 if (IsShowingWarningDialog()) |
| 402 return true; | 400 return true; |
| 403 | 401 |
| 404 if (!starting_drag_) { | 402 if (!starting_drag_) { |
| 405 starting_drag_ = true; | 403 starting_drag_ = true; |
| 406 drag_start_point_ = event.location(); | 404 drag_start_point_ = event.location(); |
| 407 } | 405 } |
| 408 if (dragging_) { | 406 if (dragging_) { |
| 409 if (download_->IsComplete()) { | 407 if (download()->IsComplete()) { |
| 410 IconManager* im = g_browser_process->icon_manager(); | 408 IconManager* im = g_browser_process->icon_manager(); |
| 411 gfx::Image* icon = im->LookupIcon(download_->GetUserVerifiedFilePath(), | 409 gfx::Image* icon = im->LookupIcon(download()->GetUserVerifiedFilePath(), |
| 412 IconLoader::SMALL); | 410 IconLoader::SMALL); |
| 413 if (icon) { | 411 if (icon) { |
| 414 views::Widget* widget = GetWidget(); | 412 views::Widget* widget = GetWidget(); |
| 415 download_util::DragDownload(download_, icon, | 413 download_util::DragDownload(download(), icon, |
| 416 widget ? widget->GetNativeView() : NULL); | 414 widget ? widget->GetNativeView() : NULL); |
| 417 } | 415 } |
| 418 } | 416 } |
| 419 } else if (ExceededDragThreshold(event.location() - drag_start_point_)) { | 417 } else if (ExceededDragThreshold(event.location() - drag_start_point_)) { |
| 420 dragging_ = true; | 418 dragging_ = true; |
| 421 } | 419 } |
| 422 return true; | 420 return true; |
| 423 } | 421 } |
| 424 | 422 |
| 425 void DownloadItemView::OnMouseReleased(const ui::MouseEvent& event) { | 423 void DownloadItemView::OnMouseReleased(const ui::MouseEvent& event) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 } | 475 } |
| 478 | 476 |
| 479 tooltip->assign(tooltip_text_); | 477 tooltip->assign(tooltip_text_); |
| 480 | 478 |
| 481 return true; | 479 return true; |
| 482 } | 480 } |
| 483 | 481 |
| 484 void DownloadItemView::GetAccessibleState(ui::AccessibleViewState* state) { | 482 void DownloadItemView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 485 state->name = accessible_name_; | 483 state->name = accessible_name_; |
| 486 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 484 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 487 if (model_->IsDangerous()) { | 485 if (model_.IsDangerous()) { |
| 488 state->state = ui::AccessibilityTypes::STATE_UNAVAILABLE; | 486 state->state = ui::AccessibilityTypes::STATE_UNAVAILABLE; |
| 489 } else { | 487 } else { |
| 490 state->state = ui::AccessibilityTypes::STATE_HASPOPUP; | 488 state->state = ui::AccessibilityTypes::STATE_HASPOPUP; |
| 491 } | 489 } |
| 492 } | 490 } |
| 493 | 491 |
| 494 void DownloadItemView::OnThemeChanged() { | 492 void DownloadItemView::OnThemeChanged() { |
| 495 UpdateColorsFromTheme(); | 493 UpdateColorsFromTheme(); |
| 496 } | 494 } |
| 497 | 495 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 518 gfx::Point local_point = point; | 516 gfx::Point local_point = point; |
| 519 ConvertPointFromScreen(this, &local_point); | 517 ConvertPointFromScreen(this, &local_point); |
| 520 ShowContextMenuImpl(local_point, true); | 518 ShowContextMenuImpl(local_point, true); |
| 521 } | 519 } |
| 522 | 520 |
| 523 void DownloadItemView::ButtonPressed( | 521 void DownloadItemView::ButtonPressed( |
| 524 views::Button* sender, const ui::Event& event) { | 522 views::Button* sender, const ui::Event& event) { |
| 525 if (sender == discard_button_) { | 523 if (sender == discard_button_) { |
| 526 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 524 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
| 527 base::Time::Now() - creation_time_); | 525 base::Time::Now() - creation_time_); |
| 528 if (download_->IsPartialDownload()) | 526 if (download()->IsPartialDownload()) |
| 529 download_->Cancel(true); | 527 download()->Cancel(true); |
| 530 download_->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 528 download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 531 // WARNING: we are deleted at this point. Don't access 'this'. | 529 // WARNING: we are deleted at this point. Don't access 'this'. |
| 532 } else if (save_button_ && sender == save_button_) { | 530 } else if (save_button_ && sender == save_button_) { |
| 533 // The user has confirmed a dangerous download. We'd record how quickly the | 531 // The user has confirmed a dangerous download. We'd record how quickly the |
| 534 // user did this to detect whether we're being clickjacked. | 532 // user did this to detect whether we're being clickjacked. |
| 535 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", | 533 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", |
| 536 base::Time::Now() - creation_time_); | 534 base::Time::Now() - creation_time_); |
| 537 // This will change the state and notify us. | 535 // This will change the state and notify us. |
| 538 download_->DangerousDownloadValidated(); | 536 download()->DangerousDownloadValidated(); |
| 539 } | 537 } |
| 540 } | 538 } |
| 541 | 539 |
| 542 void DownloadItemView::AnimationProgressed(const ui::Animation* animation) { | 540 void DownloadItemView::AnimationProgressed(const ui::Animation* animation) { |
| 543 // We don't care if what animation (body button/drop button/complete), | 541 // We don't care if what animation (body button/drop button/complete), |
| 544 // is calling back, as they all have to go through the same paint call. | 542 // is calling back, as they all have to go through the same paint call. |
| 545 SchedulePaint(); | 543 SchedulePaint(); |
| 546 } | 544 } |
| 547 | 545 |
| 548 // The DownloadItemView can be in three major modes (NORMAL_MODE, DANGEROUS_MODE | 546 // The DownloadItemView can be in three major modes (NORMAL_MODE, DANGEROUS_MODE |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 // Consequently, the x-axis of following canvas->DrawXXX() method should be | 733 // Consequently, the x-axis of following canvas->DrawXXX() method should be |
| 736 // mirrored so the text and images are down in the right positions. | 734 // mirrored so the text and images are down in the right positions. |
| 737 canvas->Restore(); | 735 canvas->Restore(); |
| 738 | 736 |
| 739 // Print the text, left aligned and always print the file extension. | 737 // Print the text, left aligned and always print the file extension. |
| 740 // Last value of x was the end of the right image, just before the button. | 738 // Last value of x was the end of the right image, just before the button. |
| 741 // Note that in dangerous mode we use a label (as the text is multi-line). | 739 // Note that in dangerous mode we use a label (as the text is multi-line). |
| 742 if (!IsShowingWarningDialog()) { | 740 if (!IsShowingWarningDialog()) { |
| 743 string16 filename; | 741 string16 filename; |
| 744 if (!disabled_while_opening_) { | 742 if (!disabled_while_opening_) { |
| 745 filename = ui::ElideFilename(download_->GetFileNameToReportUser(), | 743 filename = ui::ElideFilename(download()->GetFileNameToReportUser(), |
| 746 font_, kTextWidth); | 744 font_, kTextWidth); |
| 747 } else { | 745 } else { |
| 748 // First, Calculate the download status opening string width. | 746 // First, Calculate the download status opening string width. |
| 749 string16 status_string = | 747 string16 status_string = |
| 750 l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, string16()); | 748 l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, string16()); |
| 751 int status_string_width = font_.GetStringWidth(status_string); | 749 int status_string_width = font_.GetStringWidth(status_string); |
| 752 // Then, elide the file name. | 750 // Then, elide the file name. |
| 753 string16 filename_string = | 751 string16 filename_string = |
| 754 ui::ElideFilename(download_->GetFileNameToReportUser(), font_, | 752 ui::ElideFilename(download()->GetFileNameToReportUser(), font_, |
| 755 kTextWidth - status_string_width); | 753 kTextWidth - status_string_width); |
| 756 // Last, concat the whole string. | 754 // Last, concat the whole string. |
| 757 filename = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, | 755 filename = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, |
| 758 filename_string); | 756 filename_string); |
| 759 } | 757 } |
| 760 | 758 |
| 761 int mirrored_x = GetMirroredXWithWidthInView( | 759 int mirrored_x = GetMirroredXWithWidthInView( |
| 762 download_util::kSmallProgressIconSize, kTextWidth); | 760 download_util::kSmallProgressIconSize, kTextWidth); |
| 763 SkColor file_name_color = GetThemeProvider()->GetColor( | 761 SkColor file_name_color = GetThemeProvider()->GetColor( |
| 764 ThemeService::COLOR_BOOKMARK_TEXT); | 762 ThemeService::COLOR_BOOKMARK_TEXT); |
| 765 int y = | 763 int y = |
| 766 box_y_ + (status_text_.empty() ? | 764 box_y_ + (status_text_.empty() ? |
| 767 ((box_height_ - font_.GetHeight()) / 2) : kVerticalPadding); | 765 ((box_height_ - font_.GetHeight()) / 2) : kVerticalPadding); |
| 768 | 766 |
| 769 // Draw the file's name. | 767 // Draw the file's name. |
| 770 canvas->DrawStringInt(filename, font_, | 768 canvas->DrawStringInt(filename, font_, |
| 771 enabled() ? file_name_color | 769 enabled() ? file_name_color |
| 772 : kFileNameDisabledColor, | 770 : kFileNameDisabledColor, |
| 773 mirrored_x, y, kTextWidth, font_.GetHeight()); | 771 mirrored_x, y, kTextWidth, font_.GetHeight()); |
| 774 } | 772 } |
| 775 | 773 |
| 776 // Load the icon. | 774 // Load the icon. |
| 777 IconManager* im = g_browser_process->icon_manager(); | 775 IconManager* im = g_browser_process->icon_manager(); |
| 778 gfx::Image* image = im->LookupIcon(download_->GetUserVerifiedFilePath(), | 776 gfx::Image* image = im->LookupIcon(download()->GetUserVerifiedFilePath(), |
| 779 IconLoader::SMALL); | 777 IconLoader::SMALL); |
| 780 const gfx::ImageSkia* icon = NULL; | 778 const gfx::ImageSkia* icon = NULL; |
| 781 if (IsShowingWarningDialog()) | 779 if (IsShowingWarningDialog()) |
| 782 icon = warning_icon_; | 780 icon = warning_icon_; |
| 783 else if (image) | 781 else if (image) |
| 784 icon = image->ToImageSkia(); | 782 icon = image->ToImageSkia(); |
| 785 | 783 |
| 786 // We count on the fact that the icon manager will cache the icons and if one | 784 // We count on the fact that the icon manager will cache the icons and if one |
| 787 // is available, it will be cached here. We *don't* want to request the icon | 785 // is available, it will be cached here. We *don't* want to request the icon |
| 788 // to be loaded here, since this will also get called if the icon can't be | 786 // to be loaded here, since this will also get called if the icon can't be |
| 789 // loaded, in which case LookupIcon will always be NULL. The loading will be | 787 // loaded, in which case LookupIcon will always be NULL. The loading will be |
| 790 // triggered only when we think the status might change. | 788 // triggered only when we think the status might change. |
| 791 if (icon) { | 789 if (icon) { |
| 792 if (!IsShowingWarningDialog()) { | 790 if (!IsShowingWarningDialog()) { |
| 793 if (download_->IsInProgress()) { | 791 if (download()->IsInProgress()) { |
| 794 download_util::PaintDownloadProgress(canvas, this, 0, 0, | 792 download_util::PaintDownloadProgress(canvas, this, 0, 0, |
| 795 progress_angle_, | 793 progress_angle_, |
| 796 model_->PercentComplete(), | 794 model_.PercentComplete(), |
| 797 download_util::SMALL); | 795 download_util::SMALL); |
| 798 } else if (download_->IsComplete() && | 796 } else if (download()->IsComplete() && |
| 799 complete_animation_.get() && | 797 complete_animation_.get() && |
| 800 complete_animation_->is_animating()) { | 798 complete_animation_->is_animating()) { |
| 801 if (download_->IsInterrupted()) { | 799 if (download()->IsInterrupted()) { |
| 802 download_util::PaintDownloadInterrupted(canvas, this, 0, 0, | 800 download_util::PaintDownloadInterrupted(canvas, this, 0, 0, |
| 803 complete_animation_->GetCurrentValue(), | 801 complete_animation_->GetCurrentValue(), |
| 804 download_util::SMALL); | 802 download_util::SMALL); |
| 805 } else { | 803 } else { |
| 806 download_util::PaintDownloadComplete(canvas, this, 0, 0, | 804 download_util::PaintDownloadComplete(canvas, this, 0, 0, |
| 807 complete_animation_->GetCurrentValue(), | 805 complete_animation_->GetCurrentValue(), |
| 808 download_util::SMALL); | 806 download_util::SMALL); |
| 809 } | 807 } |
| 810 } | 808 } |
| 811 } | 809 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 831 } | 829 } |
| 832 } | 830 } |
| 833 } | 831 } |
| 834 | 832 |
| 835 void DownloadItemView::OpenDownload() { | 833 void DownloadItemView::OpenDownload() { |
| 836 DCHECK(!IsShowingWarningDialog()); | 834 DCHECK(!IsShowingWarningDialog()); |
| 837 // We're interested in how long it takes users to open downloads. If they | 835 // We're interested in how long it takes users to open downloads. If they |
| 838 // open downloads super quickly, we should be concerned about clickjacking. | 836 // open downloads super quickly, we should be concerned about clickjacking. |
| 839 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", | 837 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", |
| 840 base::Time::Now() - creation_time_); | 838 base::Time::Now() - creation_time_); |
| 841 download_->OpenDownload(); | 839 download()->OpenDownload(); |
| 842 UpdateAccessibleName(); | 840 UpdateAccessibleName(); |
| 843 } | 841 } |
| 844 | 842 |
| 845 void DownloadItemView::LoadIcon() { | 843 void DownloadItemView::LoadIcon() { |
| 846 IconManager* im = g_browser_process->icon_manager(); | 844 IconManager* im = g_browser_process->icon_manager(); |
| 847 last_download_item_path_ = download_->GetUserVerifiedFilePath(); | 845 last_download_item_path_ = download()->GetUserVerifiedFilePath(); |
| 848 im->LoadIcon(last_download_item_path_, | 846 im->LoadIcon(last_download_item_path_, |
| 849 IconLoader::SMALL, | 847 IconLoader::SMALL, |
| 850 base::Bind(&DownloadItemView::OnExtractIconComplete, | 848 base::Bind(&DownloadItemView::OnExtractIconComplete, |
| 851 base::Unretained(this)), | 849 base::Unretained(this)), |
| 852 &cancelable_task_tracker_); | 850 &cancelable_task_tracker_); |
| 853 } | 851 } |
| 854 | 852 |
| 855 void DownloadItemView::LoadIconIfItemPathChanged() { | 853 void DownloadItemView::LoadIconIfItemPathChanged() { |
| 856 FilePath current_download_path = download_->GetUserVerifiedFilePath(); | 854 FilePath current_download_path = download()->GetUserVerifiedFilePath(); |
| 857 if (last_download_item_path_ == current_download_path) | 855 if (last_download_item_path_ == current_download_path) |
| 858 return; | 856 return; |
| 859 | 857 |
| 860 LoadIcon(); | 858 LoadIcon(); |
| 861 } | 859 } |
| 862 | 860 |
| 863 void DownloadItemView::UpdateColorsFromTheme() { | 861 void DownloadItemView::UpdateColorsFromTheme() { |
| 864 if (dangerous_download_label_ && GetThemeProvider()) { | 862 if (dangerous_download_label_ && GetThemeProvider()) { |
| 865 dangerous_download_label_->SetEnabledColor( | 863 dangerous_download_label_->SetEnabledColor( |
| 866 GetThemeProvider()->GetColor(ThemeService::COLOR_BOOKMARK_TEXT)); | 864 GetThemeProvider()->GetColor(ThemeService::COLOR_BOOKMARK_TEXT)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 895 // below, it runs an inner message loop that might cause us to be deleted. | 893 // below, it runs an inner message loop that might cause us to be deleted. |
| 896 // Posting a task with a WeakPtr lets us safely handle the button release. | 894 // Posting a task with a WeakPtr lets us safely handle the button release. |
| 897 MessageLoop::current()->PostNonNestableTask( | 895 MessageLoop::current()->PostNonNestableTask( |
| 898 FROM_HERE, | 896 FROM_HERE, |
| 899 base::Bind(&DownloadItemView::ReleaseDropDown, | 897 base::Bind(&DownloadItemView::ReleaseDropDown, |
| 900 weak_ptr_factory_.GetWeakPtr())); | 898 weak_ptr_factory_.GetWeakPtr())); |
| 901 views::View::ConvertPointToScreen(this, &point); | 899 views::View::ConvertPointToScreen(this, &point); |
| 902 | 900 |
| 903 if (!context_menu_.get()) { | 901 if (!context_menu_.get()) { |
| 904 context_menu_.reset( | 902 context_menu_.reset( |
| 905 new DownloadShelfContextMenuView(model_.get(), | 903 new DownloadShelfContextMenuView(download(), shelf_->GetNavigator())); |
| 906 shelf_->GetNavigator())); | |
| 907 } | 904 } |
| 908 context_menu_->Run(GetWidget()->GetTopLevelWidget(), | 905 context_menu_->Run(GetWidget()->GetTopLevelWidget(), |
| 909 gfx::Rect(point, size)); | 906 gfx::Rect(point, size)); |
| 910 // We could be deleted now. | 907 // We could be deleted now. |
| 911 } | 908 } |
| 912 | 909 |
| 913 void DownloadItemView::HandlePressEvent(const ui::LocatedEvent& event, | 910 void DownloadItemView::HandlePressEvent(const ui::LocatedEvent& event, |
| 914 bool active_event) { | 911 bool active_event) { |
| 915 // The event should not activate us in dangerous mode. | 912 // The event should not activate us in dangerous mode. |
| 916 if (mode_ == DANGEROUS_MODE) | 913 if (mode_ == DANGEROUS_MODE) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 AnimateStateTransition(body_state_, new_body_state, | 990 AnimateStateTransition(body_state_, new_body_state, |
| 994 body_hover_animation_.get()); | 991 body_hover_animation_.get()); |
| 995 AnimateStateTransition(drop_down_state_, new_drop_state, | 992 AnimateStateTransition(drop_down_state_, new_drop_state, |
| 996 drop_hover_animation_.get()); | 993 drop_hover_animation_.get()); |
| 997 body_state_ = new_body_state; | 994 body_state_ = new_body_state; |
| 998 drop_down_state_ = new_drop_state; | 995 drop_down_state_ = new_drop_state; |
| 999 SchedulePaint(); | 996 SchedulePaint(); |
| 1000 } | 997 } |
| 1001 | 998 |
| 1002 void DownloadItemView::ClearWarningDialog() { | 999 void DownloadItemView::ClearWarningDialog() { |
| 1003 DCHECK(download_->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED && | 1000 DCHECK(download()->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED); |
| 1004 (mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE)); | 1001 DCHECK(mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE); |
| 1005 | 1002 |
| 1006 mode_ = NORMAL_MODE; | 1003 mode_ = NORMAL_MODE; |
| 1007 body_state_ = NORMAL; | 1004 body_state_ = NORMAL; |
| 1008 drop_down_state_ = NORMAL; | 1005 drop_down_state_ = NORMAL; |
| 1009 | 1006 |
| 1010 // Remove the views used by the warning dialog. | 1007 // Remove the views used by the warning dialog. |
| 1011 if (save_button_) { | 1008 if (save_button_) { |
| 1012 RemoveChildView(save_button_); | 1009 RemoveChildView(save_button_); |
| 1013 delete save_button_; | 1010 delete save_button_; |
| 1014 save_button_ = NULL; | 1011 save_button_ = NULL; |
| 1015 } | 1012 } |
| 1016 RemoveChildView(discard_button_); | 1013 RemoveChildView(discard_button_); |
| 1017 delete discard_button_; | 1014 delete discard_button_; |
| 1018 discard_button_ = NULL; | 1015 discard_button_ = NULL; |
| 1019 RemoveChildView(dangerous_download_label_); | 1016 RemoveChildView(dangerous_download_label_); |
| 1020 delete dangerous_download_label_; | 1017 delete dangerous_download_label_; |
| 1021 dangerous_download_label_ = NULL; | 1018 dangerous_download_label_ = NULL; |
| 1022 dangerous_download_label_sized_ = false; | 1019 dangerous_download_label_sized_ = false; |
| 1023 cached_button_size_.SetSize(0,0); | 1020 cached_button_size_.SetSize(0,0); |
| 1024 | 1021 |
| 1025 // Set the accessible name back to the status and filename instead of the | 1022 // Set the accessible name back to the status and filename instead of the |
| 1026 // download warning. | 1023 // download warning. |
| 1027 UpdateAccessibleName(); | 1024 UpdateAccessibleName(); |
| 1028 UpdateDropDownButtonPosition(); | 1025 UpdateDropDownButtonPosition(); |
| 1029 | 1026 |
| 1030 // We need to load the icon now that the download_ has the real path. | 1027 // We need to load the icon now that the download has the real path. |
| 1031 LoadIcon(); | 1028 LoadIcon(); |
| 1032 | 1029 |
| 1033 // Force the shelf to layout again as our size has changed. | 1030 // Force the shelf to layout again as our size has changed. |
| 1034 shelf_->Layout(); | 1031 shelf_->Layout(); |
| 1035 shelf_->SchedulePaint(); | 1032 shelf_->SchedulePaint(); |
| 1036 | 1033 |
| 1037 TooltipTextChanged(); | 1034 TooltipTextChanged(); |
| 1038 } | 1035 } |
| 1039 | 1036 |
| 1040 void DownloadItemView::ShowWarningDialog() { | 1037 void DownloadItemView::ShowWarningDialog() { |
| 1041 DCHECK(mode_ != DANGEROUS_MODE && mode_ != MALICIOUS_MODE); | 1038 DCHECK(mode_ != DANGEROUS_MODE && mode_ != MALICIOUS_MODE); |
| 1042 mode_ = ((model_->IsMalicious()) ? MALICIOUS_MODE : DANGEROUS_MODE); | 1039 mode_ = ((model_.IsMalicious()) ? MALICIOUS_MODE : DANGEROUS_MODE); |
| 1043 | 1040 |
| 1044 body_state_ = NORMAL; | 1041 body_state_ = NORMAL; |
| 1045 drop_down_state_ = NORMAL; | 1042 drop_down_state_ = NORMAL; |
| 1046 if (mode_ == DANGEROUS_MODE) { | 1043 if (mode_ == DANGEROUS_MODE) { |
| 1047 save_button_ = new views::NativeTextButton( | 1044 save_button_ = new views::NativeTextButton( |
| 1048 this, model_->GetWarningConfirmButtonText()); | 1045 this, model_.GetWarningConfirmButtonText()); |
| 1049 save_button_->set_ignore_minimum_size(true); | 1046 save_button_->set_ignore_minimum_size(true); |
| 1050 AddChildView(save_button_); | 1047 AddChildView(save_button_); |
| 1051 } | 1048 } |
| 1052 discard_button_ = new views::NativeTextButton( | 1049 discard_button_ = new views::NativeTextButton( |
| 1053 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); | 1050 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); |
| 1054 discard_button_->set_ignore_minimum_size(true); | 1051 discard_button_->set_ignore_minimum_size(true); |
| 1055 AddChildView(discard_button_); | 1052 AddChildView(discard_button_); |
| 1056 | 1053 |
| 1057 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1054 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 1058 // The dangerous download label text and icon are different under | 1055 // The dangerous download label text and icon are different under |
| 1059 // different cases. | 1056 // different cases. |
| 1060 if (mode_ == MALICIOUS_MODE) { | 1057 if (mode_ == MALICIOUS_MODE) { |
| 1061 warning_icon_ = rb.GetImageSkiaNamed(IDR_SAFEBROWSING_WARNING); | 1058 warning_icon_ = rb.GetImageSkiaNamed(IDR_SAFEBROWSING_WARNING); |
| 1062 } else { | 1059 } else { |
| 1063 // The download file has dangerous file type (e.g.: an executable). | 1060 // The download file has dangerous file type (e.g.: an executable). |
| 1064 warning_icon_ = rb.GetImageSkiaNamed(IDR_WARNING); | 1061 warning_icon_ = rb.GetImageSkiaNamed(IDR_WARNING); |
| 1065 } | 1062 } |
| 1066 string16 dangerous_label = model_->GetWarningText(font_, kTextWidth); | 1063 string16 dangerous_label = model_.GetWarningText(font_, kTextWidth); |
| 1067 dangerous_download_label_ = new views::Label(dangerous_label); | 1064 dangerous_download_label_ = new views::Label(dangerous_label); |
| 1068 dangerous_download_label_->SetMultiLine(true); | 1065 dangerous_download_label_->SetMultiLine(true); |
| 1069 dangerous_download_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1066 dangerous_download_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1070 dangerous_download_label_->SetAutoColorReadabilityEnabled(false); | 1067 dangerous_download_label_->SetAutoColorReadabilityEnabled(false); |
| 1071 AddChildView(dangerous_download_label_); | 1068 AddChildView(dangerous_download_label_); |
| 1072 SizeLabelToMinWidth(); | 1069 SizeLabelToMinWidth(); |
| 1073 UpdateDropDownButtonPosition(); | 1070 UpdateDropDownButtonPosition(); |
| 1074 TooltipTextChanged(); | 1071 TooltipTextChanged(); |
| 1075 } | 1072 } |
| 1076 | 1073 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 return true; | 1175 return true; |
| 1179 return false; | 1176 return false; |
| 1180 } | 1177 } |
| 1181 | 1178 |
| 1182 void DownloadItemView::UpdateAccessibleName() { | 1179 void DownloadItemView::UpdateAccessibleName() { |
| 1183 string16 new_name; | 1180 string16 new_name; |
| 1184 if (IsShowingWarningDialog()) { | 1181 if (IsShowingWarningDialog()) { |
| 1185 new_name = dangerous_download_label_->text(); | 1182 new_name = dangerous_download_label_->text(); |
| 1186 } else { | 1183 } else { |
| 1187 new_name = status_text_ + char16(' ') + | 1184 new_name = status_text_ + char16(' ') + |
| 1188 download_->GetFileNameToReportUser().LossyDisplayName(); | 1185 download()->GetFileNameToReportUser().LossyDisplayName(); |
| 1189 } | 1186 } |
| 1190 | 1187 |
| 1191 // If the name has changed, notify assistive technology that the name | 1188 // If the name has changed, notify assistive technology that the name |
| 1192 // has changed so they can announce it immediately. | 1189 // has changed so they can announce it immediately. |
| 1193 if (new_name != accessible_name_) { | 1190 if (new_name != accessible_name_) { |
| 1194 accessible_name_ = new_name; | 1191 accessible_name_ = new_name; |
| 1195 if (GetWidget()) { | 1192 if (GetWidget()) { |
| 1196 GetWidget()->NotifyAccessibilityEvent( | 1193 GetWidget()->NotifyAccessibilityEvent( |
| 1197 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true); | 1194 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true); |
| 1198 } | 1195 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1216 void DownloadItemView::AnimateStateTransition(State from, State to, | 1213 void DownloadItemView::AnimateStateTransition(State from, State to, |
| 1217 ui::SlideAnimation* animation) { | 1214 ui::SlideAnimation* animation) { |
| 1218 if (from == NORMAL && to == HOT) { | 1215 if (from == NORMAL && to == HOT) { |
| 1219 animation->Show(); | 1216 animation->Show(); |
| 1220 } else if (from == HOT && to == NORMAL) { | 1217 } else if (from == HOT && to == NORMAL) { |
| 1221 animation->Hide(); | 1218 animation->Hide(); |
| 1222 } else if (from != to) { | 1219 } else if (from != to) { |
| 1223 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1220 animation->Reset((to == HOT) ? 1.0 : 0.0); |
| 1224 } | 1221 } |
| 1225 } | 1222 } |
| OLD | NEW |