| Index: chrome/browser/ui/views/download/download_item_view.cc
|
| diff --git a/chrome/browser/ui/views/download/download_item_view.cc b/chrome/browser/ui/views/download/download_item_view.cc
|
| index 65f6495f0b3f12fd4d7b9f051b7fa4f7844a8ecb..7b0bddd4fb1f410f6516e759ebee625b0e4e5d48 100644
|
| --- a/chrome/browser/ui/views/download/download_item_view.cc
|
| +++ b/chrome/browser/ui/views/download/download_item_view.cc
|
| @@ -17,15 +17,18 @@
|
| #include "base/strings/stringprintf.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "base/supports_user_data.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/download/chrome_download_manager_delegate.h"
|
| #include "chrome/browser/download/download_item_model.h"
|
| #include "chrome/browser/download/download_stats.h"
|
| #include "chrome/browser/download/drag_download_item.h"
|
| +#include "chrome/browser/prefs/pref_service_syncable.h"
|
| #include "chrome/browser/safe_browsing/download_feedback_service.h"
|
| #include "chrome/browser/safe_browsing/download_protection_service.h"
|
| #include "chrome/browser/safe_browsing/safe_browsing_service.h"
|
| #include "chrome/browser/themes/theme_properties.h"
|
| +#include "chrome/browser/ui/views/download/download_feedback_dialog_view.h"
|
| #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h"
|
| #include "chrome/browser/ui/views/download/download_shelf_view.h"
|
| #include "content/public/browser/download_danger_type.h"
|
| @@ -88,6 +91,18 @@ static const double kDownloadItemLuminanceMod = 0.8;
|
|
|
| using content::DownloadItem;
|
|
|
| +const void* kDialogStatusKey = &kDialogStatusKey;
|
| +
|
| +class DialogStatusData : public base::SupportsUserData::Data {
|
| + public:
|
| + DialogStatusData() : currently_shown_(false) {}
|
| + virtual ~DialogStatusData() {}
|
| + bool currently_shown() const { return currently_shown_; }
|
| + void set_currently_shown(bool shown) { currently_shown_ = shown; }
|
| + private:
|
| + bool currently_shown_;
|
| +};
|
| +
|
| DownloadItemView::DownloadItemView(DownloadItem* download_item,
|
| DownloadShelfView* parent)
|
| : warning_icon_(NULL),
|
| @@ -550,9 +565,49 @@ void DownloadItemView::ButtonPressed(views::Button* sender,
|
| shelf_->RemoveDownloadView(this);
|
| return;
|
| }
|
| - if (model_.ShouldAllowDownloadFeedback() && BeginDownloadFeedback())
|
| - return;
|
| UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration);
|
| + if (model_.ShouldAllowDownloadFeedback() &&
|
| + !shelf_->browser()->profile()->IsOffTheRecord()) {
|
| + DownloadFeedbackDialogView::DownloadReportingStatus pref_value =
|
| + static_cast<DownloadFeedbackDialogView::DownloadReportingStatus>(
|
| + shelf_->browser()->profile()->GetPrefs()->GetInteger(
|
| + prefs::kSafeBrowsingDownloadReportingEnabled));
|
| + DialogStatusData* data = static_cast<DialogStatusData*>(
|
| + shelf_->browser()->profile()->GetUserData(kDialogStatusKey));
|
| + if (data == NULL) {
|
| + data = new DialogStatusData();
|
| + shelf_->browser()->profile()->SetUserData(kDialogStatusKey, data);
|
| + }
|
| + switch (pref_value) {
|
| + case DownloadFeedbackDialogView::kDialogNotYetShown:
|
| + // Need to check if the dialog is already displayed for this profile.
|
| + // If it is, default to discarding the file and don't generate a second
|
| + // instance of the dialog.
|
| + if (data->currently_shown() == false) {
|
| + data->set_currently_shown(true);
|
| + DownloadFeedbackDialogView::Show(
|
| + shelf_->get_parent()->GetNativeWindow(),
|
| + shelf_->browser()->profile(),
|
| + base::Bind(
|
| + &DownloadItemView::PossiblySubmitDownloadToFeedbackService,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| + } else {
|
| + PossiblySubmitDownloadToFeedbackService(
|
| + DownloadFeedbackDialogView::kDialogDecisionPending);
|
| + }
|
| + break;
|
| +
|
| + case DownloadFeedbackDialogView::kDownloadReportingEnabled:
|
| + case DownloadFeedbackDialogView::kDownloadReportingDisabled:
|
| + PossiblySubmitDownloadToFeedbackService(pref_value);
|
| + break;
|
| +
|
| + case DownloadFeedbackDialogView::kDialogDecisionPending:
|
| + case DownloadFeedbackDialogView::kMaxValue:
|
| + NOTREACHED();
|
| + }
|
| + return;
|
| + }
|
| download()->Remove();
|
| }
|
|
|
| @@ -890,7 +945,7 @@ void DownloadItemView::OpenDownload() {
|
| UpdateAccessibleName();
|
| }
|
|
|
| -bool DownloadItemView::BeginDownloadFeedback() {
|
| +bool DownloadItemView::SubmitDownloadToFeedbackService() {
|
| #if defined(FULL_SAFE_BROWSING)
|
| SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service();
|
| if (!sb_service)
|
| @@ -899,11 +954,6 @@ bool DownloadItemView::BeginDownloadFeedback() {
|
| sb_service->download_protection_service();
|
| if (!download_protection_service)
|
| return false;
|
| - base::TimeDelta warning_duration = base::TimeDelta();
|
| - if (!time_download_warning_shown_.is_null())
|
| - warning_duration = base::Time::Now() - time_download_warning_shown_;
|
| - UMA_HISTOGRAM_LONG_TIMES("clickjacking.report_and_discard_download",
|
| - warning_duration);
|
| download_protection_service->feedback_service()->BeginFeedbackForDownload(
|
| download());
|
| // WARNING: we are deleted at this point. Don't access 'this'.
|
| @@ -914,6 +964,22 @@ bool DownloadItemView::BeginDownloadFeedback() {
|
| #endif
|
| }
|
|
|
| +void DownloadItemView::PossiblySubmitDownloadToFeedbackService(
|
| + DownloadFeedbackDialogView::DownloadReportingStatus status) {
|
| + if (status != DownloadFeedbackDialogView::kDialogDecisionPending) {
|
| + DialogStatusData* data = static_cast<DialogStatusData*>(
|
| + shelf_->browser()->profile()->GetUserData(kDialogStatusKey));
|
| + DCHECK(data);
|
| + data->set_currently_shown(false);
|
| + }
|
| +
|
| + if (status != DownloadFeedbackDialogView::kDownloadReportingEnabled ||
|
| + !SubmitDownloadToFeedbackService()) {
|
| + download()->Remove();
|
| + }
|
| + // WARNING: 'this' is deleted at this point. Don't access 'this'.
|
| +}
|
| +
|
| void DownloadItemView::LoadIcon() {
|
| IconManager* im = g_browser_process->icon_manager();
|
| last_download_item_path_ = download()->GetTargetFilePath();
|
| @@ -1141,8 +1207,6 @@ void DownloadItemView::ShowWarningDialog() {
|
| }
|
| int discard_button_message = model_.IsMalicious() ?
|
| IDS_DISMISS_DOWNLOAD : IDS_DISCARD_DOWNLOAD;
|
| - if (!model_.IsMalicious() && model_.ShouldAllowDownloadFeedback())
|
| - discard_button_message = IDS_REPORT_AND_DISCARD_DOWNLOAD;
|
| discard_button_ = new views::LabelButton(
|
| this, l10n_util::GetStringUTF16(discard_button_message));
|
| discard_button_->SetStyle(views::Button::STYLE_BUTTON);
|
|
|