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 | |
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.
| |
21 // been shown before. | |
22 DCHECK(profile->GetPrefs()-> | |
23 GetInteger(prefs::kSafeBrowsingDownloadReportingEnabled) == kNeverShown); | |
24 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.
| |
25 profile, callback); | |
26 CreateBrowserModalDialogViews(window, parent_window)->Show(); | |
27 } | |
28 | |
29 DownloadFeedbackDialogView::DownloadFeedbackDialogView( | |
30 Profile* profile, | |
31 const base::Callback<void(bool)>& callback) | |
32 : profile_(profile), | |
33 callback_(callback), | |
34 explanation_box_view_(NULL) { | |
35 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.
| |
36 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.
| |
37 IDS_FEEDBACK_SERVICE_DIALOG_EXPLANATION); | |
38 explanation_box_view_ = new views::MessageBoxView( | |
39 views::MessageBoxView::InitParams(explanation_text)); | |
40 ok_button_text_ = | |
41 l10n_util::GetStringUTF16(IDS_FEEDBACK_SERVICE_DIALOG_OK_BUTTON_LABEL); | |
42 cancel_button_text_ = l10n_util::GetStringUTF16( | |
43 IDS_FEEDBACK_SERVICE_DIALOG_CANCEL_BUTTON_LABEL); | |
44 } | |
45 | |
46 DownloadFeedbackDialogView::~DownloadFeedbackDialogView() {} | |
47 | |
48 int DownloadFeedbackDialogView::GetDefaultDialogButton() const { | |
49 return ui::DIALOG_BUTTON_CANCEL; | |
50 } | |
51 | |
52 base::string16 DownloadFeedbackDialogView::GetDialogButtonLabel( | |
53 ui::DialogButton button) const { | |
54 return (button == ui::DIALOG_BUTTON_OK) ? | |
55 ok_button_text_ : cancel_button_text_; | |
56 } | |
57 | |
58 bool DownloadFeedbackDialogView::Cancel() { | |
59 profile_->GetPrefs()-> | |
60 SetInteger(prefs::kSafeBrowsingDownloadReportingEnabled, kUserDisabled); | |
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; | |
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
| |
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 |