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..3404d310393016edf6cd47d1cf1c89b7347bd71b 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() { return currently_shown_; } |
mattm
2014/02/06 03:35:22
should be const method
felt
2014/02/06 23:10:22
Done.
|
+ void currently_shown(bool shown) { currently_shown_ = shown; } |
mattm
2014/02/06 03:35:22
set_currently_shown
felt
2014/02/06 23:10:22
Done.
|
+ private: |
+ bool currently_shown_; |
+}; |
+ |
DownloadItemView::DownloadItemView(DownloadItem* download_item, |
DownloadShelfView* parent) |
: warning_icon_(NULL), |
@@ -550,9 +565,47 @@ 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()) { |
+ 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)); |
+ 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 == NULL) { |
+ data = new DialogStatusData(); |
+ shelf_->browser()->profile()->SetUserData(kDialogStatusKey, data); |
+ } |
+ if (data->currently_shown() == false) { |
+ data->currently_shown(true); |
+ DownloadFeedbackDialogView::Show( |
+ shelf_->get_parent()->GetNativeWindow(), |
+ shelf_->browser()->profile(), |
+ base::Bind( |
+ &DownloadItemView::PossiblySubmitDownloadToFeedbackService, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ } else { |
+ PossiblySubmitDownloadToFeedbackService( |
+ DownloadFeedbackDialogView::kDownloadReportingDisabled); |
+ } |
+ break; |
+ |
+ case DownloadFeedbackDialogView::kDownloadReportingEnabled: |
+ case DownloadFeedbackDialogView::kDownloadReportingDisabled: |
+ PossiblySubmitDownloadToFeedbackService(pref_value); |
+ break; |
+ |
+ case DownloadFeedbackDialogView::kMaxValue: |
+ NOTREACHED(); |
+ } |
+ return; |
+ } |
download()->Remove(); |
} |
@@ -890,7 +943,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 +952,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 +962,20 @@ bool DownloadItemView::BeginDownloadFeedback() { |
#endif |
} |
+void DownloadItemView::PossiblySubmitDownloadToFeedbackService( |
+ DownloadFeedbackDialogView::DownloadReportingStatus status) { |
+ DialogStatusData* data = static_cast<DialogStatusData*>( |
+ shelf_->browser()->profile()->GetUserData(kDialogStatusKey)); |
+ DCHECK(data); |
+ data->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 +1203,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); |