| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/notification/download_item_notification.h" | 5 #include "chrome/browser/download/notification/download_item_notification.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/download/download_crx_util.h" | 10 #include "chrome/browser/download/download_crx_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "content/public/browser/page_navigator.h" | 25 #include "content/public/browser/page_navigator.h" |
| 26 #include "content/public/browser/user_metrics.h" | 26 #include "content/public/browser/user_metrics.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
| 29 #include "net/base/mime_util.h" | 29 #include "net/base/mime_util.h" |
| 30 #include "third_party/skia/include/core/SkCanvas.h" | 30 #include "third_party/skia/include/core/SkCanvas.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/l10n/time_format.h" | 32 #include "ui/base/l10n/time_format.h" |
| 33 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 34 #include "ui/gfx/codec/jpeg_codec.h" | 34 #include "ui/gfx/codec/jpeg_codec.h" |
| 35 #include "ui/gfx/color_palette.h" |
| 35 #include "ui/gfx/image/image.h" | 36 #include "ui/gfx/image/image.h" |
| 37 #include "ui/gfx/paint_vector_icon.h" |
| 38 #include "ui/gfx/vector_icons_public.h" |
| 36 #include "ui/message_center/message_center.h" | 39 #include "ui/message_center/message_center.h" |
| 37 #include "ui/message_center/message_center_style.h" | 40 #include "ui/message_center/message_center_style.h" |
| 38 | 41 |
| 39 #if !defined(OS_MACOSX) | |
| 40 #include "ui/gfx/color_palette.h" | |
| 41 #include "ui/gfx/paint_vector_icon.h" | |
| 42 #include "ui/gfx/vector_icons_public.h" | |
| 43 #endif | |
| 44 | |
| 45 using base::UserMetricsAction; | 42 using base::UserMetricsAction; |
| 46 | 43 |
| 47 namespace { | 44 namespace { |
| 48 | 45 |
| 49 const char kDownloadNotificationNotifierId[] = | 46 const char kDownloadNotificationNotifierId[] = |
| 50 "chrome://downloads/notification/id-notifier"; | 47 "chrome://downloads/notification/id-notifier"; |
| 51 | 48 |
| 52 // Background color of the preview images | 49 // Background color of the preview images |
| 53 const SkColor kImageBackgroundColor = SK_ColorWHITE; | 50 const SkColor kImageBackgroundColor = SK_ColorWHITE; |
| 54 | 51 |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 case content::DownloadItem::IN_PROGRESS: | 503 case content::DownloadItem::IN_PROGRESS: |
| 507 case content::DownloadItem::COMPLETE: | 504 case content::DownloadItem::COMPLETE: |
| 508 if (is_off_the_record) { | 505 if (is_off_the_record) { |
| 509 #if defined(OS_MACOSX) | 506 #if defined(OS_MACOSX) |
| 510 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_INCOGNITO); | 507 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_INCOGNITO); |
| 511 #else | 508 #else |
| 512 SetNotificationVectorIcon(gfx::VectorIconId::FILE_DOWNLOAD_INCOGNITO, | 509 SetNotificationVectorIcon(gfx::VectorIconId::FILE_DOWNLOAD_INCOGNITO, |
| 513 gfx::kChromeIconGrey); | 510 gfx::kChromeIconGrey); |
| 514 #endif | 511 #endif |
| 515 } else { | 512 } else { |
| 516 #if defined(OS_MACOSX) | |
| 517 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_DOWNLOADING); | |
| 518 #else | |
| 519 SetNotificationVectorIcon(gfx::VectorIconId::FILE_DOWNLOAD, | 513 SetNotificationVectorIcon(gfx::VectorIconId::FILE_DOWNLOAD, |
| 520 gfx::kGoogleBlue); | 514 gfx::kGoogleBlue); |
| 521 #endif | |
| 522 } | 515 } |
| 523 break; | 516 break; |
| 524 | 517 |
| 525 case content::DownloadItem::INTERRUPTED: | 518 case content::DownloadItem::INTERRUPTED: |
| 526 #if defined(OS_MACOSX) | 519 #if defined(OS_MACOSX) |
| 527 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_ERROR); | 520 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_ERROR); |
| 528 #else | 521 #else |
| 529 SetNotificationVectorIcon(gfx::VectorIconId::ERROR_CIRCLE, | 522 SetNotificationVectorIcon(gfx::VectorIconId::ERROR_CIRCLE, |
| 530 gfx::kErrorRed); | 523 gfx::kErrorRed); |
| 531 #endif | 524 #endif |
| (...skipping 22 matching lines...) Expand all Loading... |
| 554 } | 547 } |
| 555 | 548 |
| 556 void DownloadItemNotification::SetNotificationIcon(int resource_id) { | 549 void DownloadItemNotification::SetNotificationIcon(int resource_id) { |
| 557 if (image_resource_id_ == resource_id) | 550 if (image_resource_id_ == resource_id) |
| 558 return; | 551 return; |
| 559 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 552 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 560 image_resource_id_ = resource_id; | 553 image_resource_id_ = resource_id; |
| 561 notification_->set_icon(bundle.GetImageNamed(image_resource_id_)); | 554 notification_->set_icon(bundle.GetImageNamed(image_resource_id_)); |
| 562 } | 555 } |
| 563 | 556 |
| 564 #if !defined(OS_MACOSX) | |
| 565 void DownloadItemNotification::SetNotificationVectorIcon(gfx::VectorIconId id, | 557 void DownloadItemNotification::SetNotificationVectorIcon(gfx::VectorIconId id, |
| 566 SkColor color) { | 558 SkColor color) { |
| 567 if (vector_icon_params_ == std::make_pair(id, color)) | 559 if (vector_icon_params_ == std::make_pair(id, color)) |
| 568 return; | 560 return; |
| 569 vector_icon_params_ = std::make_pair(id, color); | 561 vector_icon_params_ = std::make_pair(id, color); |
| 570 image_resource_id_ = 0; | 562 image_resource_id_ = 0; |
| 571 notification_->set_icon(gfx::Image(gfx::CreateVectorIcon(id, 40, color))); | 563 notification_->set_icon(gfx::Image(gfx::CreateVectorIcon(id, 40, color))); |
| 572 } | 564 } |
| 573 #endif | |
| 574 | 565 |
| 575 void DownloadItemNotification::OnImageLoaded(const std::string& image_data) { | 566 void DownloadItemNotification::OnImageLoaded(const std::string& image_data) { |
| 576 if (image_data.empty()) | 567 if (image_data.empty()) |
| 577 return; | 568 return; |
| 578 | 569 |
| 579 // TODO(yoshiki): Set option to reduce the image size to supress memory usage. | 570 // TODO(yoshiki): Set option to reduce the image size to supress memory usage. |
| 580 ImageDecoder::Start(this, image_data); | 571 ImageDecoder::Start(this, image_data); |
| 581 } | 572 } |
| 582 | 573 |
| 583 void DownloadItemNotification::OnImageDecoded(const SkBitmap& decoded_bitmap) { | 574 void DownloadItemNotification::OnImageDecoded(const SkBitmap& decoded_bitmap) { |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 profile_id); | 890 profile_id); |
| 900 | 891 |
| 901 message_center::NotificationList::Notifications visible_notifications = | 892 message_center::NotificationList::Notifications visible_notifications = |
| 902 g_browser_process->message_center()->GetVisibleNotifications(); | 893 g_browser_process->message_center()->GetVisibleNotifications(); |
| 903 for (const auto& notification : visible_notifications) { | 894 for (const auto& notification : visible_notifications) { |
| 904 if (notification->id() == notification_id_in_message_center) | 895 if (notification->id() == notification_id_in_message_center) |
| 905 return true; | 896 return true; |
| 906 } | 897 } |
| 907 return false; | 898 return false; |
| 908 } | 899 } |
| OLD | NEW |