Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h" | |
| 6 | |
| 7 #include "chrome/browser/prefs/pref_service_syncable.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | |
| 9 #include "chrome/browser/ui/views/constrained_window_views.h" | |
| 10 #include "grit/generated_resources.h" | |
| 11 #include "ui/base/l10n/l10n_util.h" | |
| 12 #include "ui/views/controls/message_box_view.h" | |
| 13 #include "ui/views/widget/widget.h" | |
| 14 | |
| 15 // static | |
| 16 void DownloadFeedbackDialogView::Show( | |
| 17 gfx::NativeWindow parent_window, | |
| 18 Profile* profile, | |
| 19 const base::Callback<void(bool)>& callback) { | |
| 20 // Enforce the constraint that this dialog should only be shown if it hasn't | |
| 21 // been shown before. Uses USER_DISABLED as a safe default. | |
|
mattm
2014/01/27 08:03:33
So it's intentional that if the browser is closed
felt
2014/01/27 20:06:59
hmmm. I guess that would be bad. my concern was th
| |
| 22 DCHECK(profile->GetPrefs()-> | |
| 23 GetInteger(prefs::kSafeBrowsingDownloadReportingEnabled) == kNeverShown); | |
| 24 profile->GetPrefs()-> | |
| 25 SetInteger(prefs::kSafeBrowsingDownloadReportingEnabled, kUserDisabled); | |
| 26 DownloadFeedbackDialogView* window = new DownloadFeedbackDialogView( | |
| 27 profile, callback); | |
| 28 CreateBrowserModalDialogViews(window, parent_window)->Show(); | |
| 29 } | |
| 30 | |
| 31 DownloadFeedbackDialogView::DownloadFeedbackDialogView( | |
| 32 Profile* profile, | |
| 33 const base::Callback<void(bool)>& callback) | |
| 34 : profile_(profile), | |
| 35 callback_(callback), | |
| 36 explanation_box_view_(NULL) { | |
| 37 title_text_ = l10n_util::GetStringUTF16(IDS_FEEDBACK_SERVICE_DIALOG_TITLE); | |
| 38 base::string16 explanation_text = l10n_util::GetStringUTF16( | |
| 39 IDS_FEEDBACK_SERVICE_DIALOG_EXPLANATION); | |
| 40 explanation_box_view_ = new views::MessageBoxView( | |
| 41 views::MessageBoxView::InitParams(explanation_text)); | |
| 42 ok_button_text_ = | |
| 43 l10n_util::GetStringUTF16(IDS_FEEDBACK_SERVICE_DIALOG_OK_BUTTON_LABEL); | |
| 44 cancel_button_text_ = l10n_util::GetStringUTF16( | |
| 45 IDS_FEEDBACK_SERVICE_DIALOG_CANCEL_BUTTON_LABEL); | |
| 46 } | |
| 47 | |
| 48 DownloadFeedbackDialogView::~DownloadFeedbackDialogView() {} | |
| 49 | |
| 50 int DownloadFeedbackDialogView::GetDefaultDialogButton() const { | |
| 51 return ui::DIALOG_BUTTON_CANCEL; | |
| 52 } | |
| 53 | |
| 54 base::string16 DownloadFeedbackDialogView::GetDialogButtonLabel( | |
| 55 ui::DialogButton button) const { | |
| 56 return (button == ui::DIALOG_BUTTON_OK) ? | |
| 57 ok_button_text_ : cancel_button_text_; | |
| 58 } | |
| 59 | |
| 60 bool DownloadFeedbackDialogView::Cancel() { | |
| 61 callback_.Run(false); | |
| 62 return true; | |
| 63 } | |
| 64 | |
| 65 bool DownloadFeedbackDialogView::Accept() { | |
| 66 profile_->GetPrefs()-> | |
| 67 SetInteger(prefs::kSafeBrowsingDownloadReportingEnabled, kUserEnabled); | |
| 68 callback_.Run(true); | |
| 69 return true; | |
| 70 } | |
| 71 | |
| 72 ui::ModalType DownloadFeedbackDialogView::GetModalType() const { | |
| 73 return ui::MODAL_TYPE_SYSTEM; | |
| 74 } | |
| 75 | |
| 76 base::string16 DownloadFeedbackDialogView::GetWindowTitle() const { | |
| 77 return title_text_; | |
| 78 } | |
| 79 | |
| 80 void DownloadFeedbackDialogView::DeleteDelegate() { | |
| 81 delete this; | |
| 82 } | |
| 83 | |
| 84 views::Widget* DownloadFeedbackDialogView::GetWidget() { | |
| 85 return explanation_box_view_->GetWidget(); | |
| 86 } | |
| 87 | |
| 88 const views::Widget* DownloadFeedbackDialogView::GetWidget() const { | |
| 89 return explanation_box_view_->GetWidget(); | |
| 90 } | |
| 91 | |
| 92 views::View* DownloadFeedbackDialogView::GetContentsView() { | |
| 93 return explanation_box_view_; | |
| 94 } | |
| OLD | NEW |