#include "base/i18n/break_iterator.h"
#include "base/i18n/rtl.h"
#include "base/metrics/histogram.h"
+#include "base/prefs/pref_service.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.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/profiles/profile.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 "chrome/browser/ui/views/frame/browser_view.h"
#include "content/public/browser/download_danger_type.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
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()) {
+ if (!shelf_->browser()->profile()->GetPrefs()->HasPrefPath(
+ prefs::kSafeBrowsingDownloadFeedbackEnabled)) {
+ // Show dialog, because the dialog hasn't been shown before.
+ DownloadFeedbackDialogView::Show(
+ shelf_->get_parent()->GetNativeWindow(),
+ shelf_->browser()->profile(),
+ base::Bind(
+ &DownloadItemView::PossiblySubmitDownloadToFeedbackService,
+ weak_ptr_factory_.GetWeakPtr()));
+ } else {
+ PossiblySubmitDownloadToFeedbackService(
+ shelf_->browser()->profile()->GetPrefs()->GetBoolean(
+ prefs::kSafeBrowsingDownloadFeedbackEnabled));
+ }
+ return;
+ }
download()->Remove();
}
UpdateAccessibleName();
}
-bool DownloadItemView::BeginDownloadFeedback() {
+bool DownloadItemView::SubmitDownloadToFeedbackService() {
#if defined(FULL_SAFE_BROWSING)
SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service();
if (!sb_service)
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'.
#endif
}
+void DownloadItemView::PossiblySubmitDownloadToFeedbackService(bool enabled) {
+ if (!enabled || !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();
}
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);