| 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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 499 |
| 503 bool is_off_the_record = item_->GetBrowserContext() && | 500 bool is_off_the_record = item_->GetBrowserContext() && |
| 504 item_->GetBrowserContext()->IsOffTheRecord(); | 501 item_->GetBrowserContext()->IsOffTheRecord(); |
| 505 switch (item_->GetState()) { | 502 switch (item_->GetState()) { |
| 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 // TODO(estade): vectorize. | 506 // TODO(estade): vectorize. |
| 510 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_INCOGNITO); | 507 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_INCOGNITO); |
| 511 } else { | 508 } else { |
| 512 #if defined(OS_MACOSX) | |
| 513 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_DOWNLOADING); | |
| 514 #else | |
| 515 SetNotificationVectorIcon(gfx::VectorIconId::FILE_DOWNLOAD, | 509 SetNotificationVectorIcon(gfx::VectorIconId::FILE_DOWNLOAD, |
| 516 gfx::kGoogleBlue); | 510 gfx::kGoogleBlue); |
| 517 #endif | |
| 518 } | 511 } |
| 519 break; | 512 break; |
| 520 | 513 |
| 521 case content::DownloadItem::INTERRUPTED: | 514 case content::DownloadItem::INTERRUPTED: |
| 522 #if defined(OS_MACOSX) | 515 #if defined(OS_MACOSX) |
| 523 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_ERROR); | 516 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_ERROR); |
| 524 #else | 517 #else |
| 525 SetNotificationVectorIcon(gfx::VectorIconId::ERROR_CIRCLE, | 518 SetNotificationVectorIcon(gfx::VectorIconId::ERROR_CIRCLE, |
| 526 gfx::kErrorRed); | 519 gfx::kErrorRed); |
| 527 #endif | 520 #endif |
| (...skipping 22 matching lines...) Expand all Loading... |
| 550 } | 543 } |
| 551 | 544 |
| 552 void DownloadItemNotification::SetNotificationIcon(int resource_id) { | 545 void DownloadItemNotification::SetNotificationIcon(int resource_id) { |
| 553 if (image_resource_id_ == resource_id) | 546 if (image_resource_id_ == resource_id) |
| 554 return; | 547 return; |
| 555 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 548 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 556 image_resource_id_ = resource_id; | 549 image_resource_id_ = resource_id; |
| 557 notification_->set_icon(bundle.GetImageNamed(image_resource_id_)); | 550 notification_->set_icon(bundle.GetImageNamed(image_resource_id_)); |
| 558 } | 551 } |
| 559 | 552 |
| 560 #if !defined(OS_MACOSX) | |
| 561 void DownloadItemNotification::SetNotificationVectorIcon(gfx::VectorIconId id, | 553 void DownloadItemNotification::SetNotificationVectorIcon(gfx::VectorIconId id, |
| 562 SkColor color) { | 554 SkColor color) { |
| 563 if (vector_icon_params_ == std::make_pair(id, color)) | 555 if (vector_icon_params_ == std::make_pair(id, color)) |
| 564 return; | 556 return; |
| 565 vector_icon_params_ = std::make_pair(id, color); | 557 vector_icon_params_ = std::make_pair(id, color); |
| 566 image_resource_id_ = 0; | 558 image_resource_id_ = 0; |
| 567 notification_->set_icon(gfx::Image(gfx::CreateVectorIcon(id, 40, color))); | 559 notification_->set_icon(gfx::Image(gfx::CreateVectorIcon(id, 40, color))); |
| 568 } | 560 } |
| 569 #endif | |
| 570 | 561 |
| 571 void DownloadItemNotification::OnImageLoaded(const std::string& image_data) { | 562 void DownloadItemNotification::OnImageLoaded(const std::string& image_data) { |
| 572 if (image_data.empty()) | 563 if (image_data.empty()) |
| 573 return; | 564 return; |
| 574 | 565 |
| 575 // TODO(yoshiki): Set option to reduce the image size to supress memory usage. | 566 // TODO(yoshiki): Set option to reduce the image size to supress memory usage. |
| 576 ImageDecoder::Start(this, image_data); | 567 ImageDecoder::Start(this, image_data); |
| 577 } | 568 } |
| 578 | 569 |
| 579 void DownloadItemNotification::OnImageDecoded(const SkBitmap& decoded_bitmap) { | 570 void DownloadItemNotification::OnImageDecoded(const SkBitmap& decoded_bitmap) { |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 profile_id); | 886 profile_id); |
| 896 | 887 |
| 897 message_center::NotificationList::Notifications visible_notifications = | 888 message_center::NotificationList::Notifications visible_notifications = |
| 898 g_browser_process->message_center()->GetVisibleNotifications(); | 889 g_browser_process->message_center()->GetVisibleNotifications(); |
| 899 for (const auto& notification : visible_notifications) { | 890 for (const auto& notification : visible_notifications) { |
| 900 if (notification->id() == notification_id_in_message_center) | 891 if (notification->id() == notification_id_in_message_center) |
| 901 return true; | 892 return true; |
| 902 } | 893 } |
| 903 return false; | 894 return false; |
| 904 } | 895 } |
| OLD | NEW |