Commit ec6816b0 authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

Include origin in background fetch desktop download notifications

The origin will be displayed in the status section of the notification.
Very long origins will be elided to display the eTLD+1.

Screenshots:
https://lh3.googleusercontent.com/-eFfCFlWJf3Y/W7NlhkLY07I/AAAAAAAABMw/_RhaEe6jlnM1X-xXfsIoZ7uyJOnfd6JngCL0BGAYYCw/h48/desktoporigin1.png
https://lh3.googleusercontent.com/-TiCAYHS9hfg/W7Nlep2HgkI/AAAAAAAABMk/cG6uFKK8sBcc8P-cmy9HtqEZHTp_2S2hgCL0BGAYYCw/h50/desktoporiginevil.png

Bug: 774612
Change-Id: Iacd874b5fd03f3e6e37c204e9df9e4cbaba67435
Reviewed-on: https://chromium-review.googlesource.com/1256943Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596262}
parent 095a273a
......@@ -461,6 +461,14 @@ GURL DownloadUIModel::GetURL() const {
return GURL();
}
GURL DownloadUIModel::GetOriginalURL() const {
return GURL();
}
bool DownloadUIModel::ShouldPromoteOrigin() const {
return false;
}
#if !defined(OS_ANDROID)
bool DownloadUIModel::IsCommandEnabled(
const DownloadCommands* download_commands,
......
......@@ -278,6 +278,13 @@ class DownloadUIModel {
// |FailState::NO_FAILURE| if there is no previous failure reason.
virtual offline_items_collection::FailState GetLastFailState() const;
// Returns the URL of the orginiating request.
virtual GURL GetOriginalURL() const;
// Whether the Origin should be clearly displayed in the notification for
// security reasons.
virtual bool ShouldPromoteOrigin() const;
#if !defined(OS_ANDROID)
// Methods related to DownloadCommands.
// Returns whether the given download command is enabled for this download.
......
......@@ -236,6 +236,15 @@ FailState OfflineItemModel::GetLastFailState() const {
return offline_item_ ? offline_item_->fail_state : FailState::USER_CANCELED;
}
GURL OfflineItemModel::GetOriginalURL() const {
return offline_item_ ? offline_item_->original_url : GURL();
}
bool OfflineItemModel::ShouldPromoteOrigin() const {
// TODO(crbug.com/774612): Add a field in OfflineItem to make this decision.
return true;
}
#if !defined(OS_ANDROID)
bool OfflineItemModel::IsCommandEnabled(
const DownloadCommands* download_commands,
......
......@@ -57,6 +57,8 @@ class OfflineItemModel : public DownloadUIModel,
GURL GetURL() const override;
bool ShouldRemoveFromShelfWhenComplete() const override;
offline_items_collection::FailState GetLastFailState() const override;
GURL GetOriginalURL() const override;
bool ShouldPromoteOrigin() const override;
#if !defined(OS_ANDROID)
bool IsCommandEnabled(const DownloadCommands* download_commands,
......
......@@ -21,6 +21,7 @@
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
......@@ -40,6 +41,7 @@
#include "components/download/public/common/download_danger_type.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "components/url_formatter/elide_url.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/download_item_utils.h"
#include "third_party/icu/source/common/unicode/uchar.h"
......@@ -236,7 +238,7 @@ void DownloadItemView::OnDownloadUpdated() {
if (IsShowingWarningDialog() != model_->IsDangerous()) {
ToggleWarningDialog();
} else {
status_text_ = model_->GetStatusText();
status_text_ = GetStatusText();
switch (model_->GetState()) {
case DownloadItem::IN_PROGRESS:
// No need to send accessible alert for "paused", as the button ends
......@@ -1167,3 +1169,20 @@ SkColor DownloadItemView::GetTextColor() const {
SkColor DownloadItemView::GetDimmedTextColor() const {
return SkColorSetA(GetTextColor(), 0xC7);
}
base::string16 DownloadItemView::GetStatusText() const {
if (!model_->ShouldPromoteOrigin() ||
model_->GetOriginalURL().GetOrigin().is_empty()) {
// Use the default status text.
return model_->GetStatusText();
}
#if !defined(OS_ANDROID)
return url_formatter::ElideUrl(model_->GetOriginalURL().GetOrigin(),
status_font_list_, kTextWidth,
gfx::Typesetter::BROWSER);
#else
NOTREACHED();
return base::string16();
#endif
}
......@@ -309,6 +309,9 @@ class DownloadItemView : public views::InkDropHostView,
// Returns a slightly dimmed version of the base text color.
SkColor GetDimmedTextColor() const;
// Returns the status text to show in the notification.
base::string16 GetStatusText() const;
// The download shelf that owns us.
DownloadShelfView* shelf_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment