Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1174)

Unified Diff: chrome/browser/ui/views/download/download_feedback_dialog_view.cc

Issue 147593002: Implement new dangerous download reporting dialog for UNCOMMON_DOWNLOAD, in Views (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/download/download_feedback_dialog_view.cc
diff --git a/chrome/browser/ui/views/download/download_feedback_dialog_view.cc b/chrome/browser/ui/views/download/download_feedback_dialog_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..38f62133cd893102fbcd27e15dc98635ba19ebbe
--- /dev/null
+++ b/chrome/browser/ui/views/download/download_feedback_dialog_view.cc
@@ -0,0 +1,94 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/download/download_feedback_dialog_view.h"
+
+#include "chrome/browser/prefs/pref_service_syncable.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/views/constrained_window_views.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/views/controls/message_box_view.h"
+#include "ui/views/widget/widget.h"
+
+// static
+void DownloadFeedbackDialogView::Show(
+ gfx::NativeWindow parent_window,
+ Profile* profile,
+ const base::Callback<void(bool)>& callback) {
+ // Enforce the constraint that this dialog should only be shown if it hasn't
Peter Kasting 2014/02/04 21:56:33 Nit: DCHECKs don't really "enforce" anything, so I
felt 2014/02/04 23:37:22 Done.
+ // been shown before.
+ DCHECK(profile->GetPrefs()->
+ GetInteger(prefs::kSafeBrowsingDownloadReportingEnabled) == kNeverShown);
+ DownloadFeedbackDialogView* window = new DownloadFeedbackDialogView(
Peter Kasting 2014/02/04 21:56:33 Nit: Breaking after '=' instead of '(' seems a lit
felt 2014/02/04 23:37:22 Done.
+ profile, callback);
+ CreateBrowserModalDialogViews(window, parent_window)->Show();
+}
+
+DownloadFeedbackDialogView::DownloadFeedbackDialogView(
+ Profile* profile,
+ const base::Callback<void(bool)>& callback)
+ : profile_(profile),
+ callback_(callback),
+ explanation_box_view_(NULL) {
+ title_text_ = l10n_util::GetStringUTF16(IDS_FEEDBACK_SERVICE_DIALOG_TITLE);
Peter Kasting 2014/02/04 21:56:33 Nit: All these strings can be set in the initializ
felt 2014/02/04 23:37:22 Done.
+ base::string16 explanation_text = l10n_util::GetStringUTF16(
Peter Kasting 2014/02/04 21:56:33 Nit: You can just inline this into the next statem
felt 2014/02/04 23:37:22 Done.
+ IDS_FEEDBACK_SERVICE_DIALOG_EXPLANATION);
+ explanation_box_view_ = new views::MessageBoxView(
+ views::MessageBoxView::InitParams(explanation_text));
+ ok_button_text_ =
+ l10n_util::GetStringUTF16(IDS_FEEDBACK_SERVICE_DIALOG_OK_BUTTON_LABEL);
+ cancel_button_text_ = l10n_util::GetStringUTF16(
+ IDS_FEEDBACK_SERVICE_DIALOG_CANCEL_BUTTON_LABEL);
+}
+
+DownloadFeedbackDialogView::~DownloadFeedbackDialogView() {}
+
+int DownloadFeedbackDialogView::GetDefaultDialogButton() const {
+ return ui::DIALOG_BUTTON_CANCEL;
+}
+
+base::string16 DownloadFeedbackDialogView::GetDialogButtonLabel(
+ ui::DialogButton button) const {
+ return (button == ui::DIALOG_BUTTON_OK) ?
+ ok_button_text_ : cancel_button_text_;
+}
+
+bool DownloadFeedbackDialogView::Cancel() {
+ profile_->GetPrefs()->
+ SetInteger(prefs::kSafeBrowsingDownloadReportingEnabled, kUserDisabled);
+ callback_.Run(false);
+ return true;
+}
+
+bool DownloadFeedbackDialogView::Accept() {
+ profile_->GetPrefs()->
+ SetInteger(prefs::kSafeBrowsingDownloadReportingEnabled, kUserEnabled);
+ callback_.Run(true);
+ return true;
+}
+
+ui::ModalType DownloadFeedbackDialogView::GetModalType() const {
+ return ui::MODAL_TYPE_SYSTEM;
Peter Kasting 2014/02/04 21:56:33 Why does this need to be system-modal?
felt 2014/02/04 23:37:22 I was copying how similar dialogs seem to work. I
Peter Kasting 2014/02/05 00:07:36 In general, we want to be as non-modal as possible
felt 2014/02/05 02:08:53 This dialog doesn't pertain to any specific tab. I
Peter Kasting 2014/02/05 02:10:54 I think that's MODAL_TYPE_WINDOW? sky might know
felt 2014/02/05 18:41:32 sky agrees it should be MODAL_TYPE_WINDOW, so done
+}
+
+base::string16 DownloadFeedbackDialogView::GetWindowTitle() const {
+ return title_text_;
+}
+
+void DownloadFeedbackDialogView::DeleteDelegate() {
+ delete this;
+}
+
+views::Widget* DownloadFeedbackDialogView::GetWidget() {
+ return explanation_box_view_->GetWidget();
+}
+
+const views::Widget* DownloadFeedbackDialogView::GetWidget() const {
+ return explanation_box_view_->GetWidget();
+}
+
+views::View* DownloadFeedbackDialogView::GetContentsView() {
+ return explanation_box_view_;
+}

Powered by Google App Engine
This is Rietveld 408576698