OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h" | 5 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/supports_user_data.h" | 8 #include "base/supports_user_data.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/views/constrained_window_views.h" | 10 #include "chrome/browser/ui/views/constrained_window_views.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 private: | 26 private: |
27 bool currently_shown_; | 27 bool currently_shown_; |
28 }; | 28 }; |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 // static | 32 // static |
33 void DownloadFeedbackDialogView::Show( | 33 void DownloadFeedbackDialogView::Show( |
34 gfx::NativeWindow parent_window, | 34 gfx::NativeWindow parent_window, |
35 Profile* profile, | 35 Profile* profile, |
36 const base::Callback<void(DownloadReportingStatus)>& callback) { | 36 const base::Callback<void(bool)>& callback) { |
37 // This dialog should only be shown if it hasn't been shown before. | 37 // This dialog should only be shown if it hasn't been shown before. |
38 DCHECK(profile->GetPrefs()->GetInteger( | 38 DCHECK(!profile->GetPrefs()->HasPrefPath( |
39 prefs::kSafeBrowsingDownloadReportingEnabled) == kDialogNotYetShown); | 39 prefs::kSafeBrowsingDownloadFeedbackEnabled)); |
40 | 40 |
41 // Only one dialog should be shown at a time, so check to see if another one | 41 // Only one dialog should be shown at a time, so check to see if another one |
42 // is open. If another one is open, treat this parallel call as if reporting | 42 // is open. If another one is open, treat this parallel call as if reporting |
43 // is disabled (to be conservative). | 43 // is disabled (to be conservative). |
44 DialogStatusData* data = | 44 DialogStatusData* data = |
45 static_cast<DialogStatusData*>(profile->GetUserData(kDialogStatusKey)); | 45 static_cast<DialogStatusData*>(profile->GetUserData(kDialogStatusKey)); |
46 if (data == NULL) { | 46 if (data == NULL) { |
47 data = new DialogStatusData(); | 47 data = new DialogStatusData(); |
48 profile->SetUserData(kDialogStatusKey, data); | 48 profile->SetUserData(kDialogStatusKey, data); |
49 } | 49 } |
50 if (data->currently_shown() == false) { | 50 if (data->currently_shown() == false) { |
51 data->set_currently_shown(true); | 51 data->set_currently_shown(true); |
52 DownloadFeedbackDialogView* window = | 52 DownloadFeedbackDialogView* window = |
53 new DownloadFeedbackDialogView(profile, callback); | 53 new DownloadFeedbackDialogView(profile, callback); |
54 CreateBrowserModalDialogViews(window, parent_window)->Show(); | 54 CreateBrowserModalDialogViews(window, parent_window)->Show(); |
55 } else { | 55 } else { |
56 callback.Run(kDownloadReportingDisabled); | 56 callback.Run(false /* disabled */); |
Peter Kasting
2014/02/13 22:17:52
Nit: Don't add these sorts of parameter-explaining
felt
2014/02/14 00:21:49
Done, added typedef for the callback.
| |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 void DownloadFeedbackDialogView::ReleaseDialogStatusHold() { | 60 void DownloadFeedbackDialogView::ReleaseDialogStatusHold() { |
61 DialogStatusData* data = | 61 DialogStatusData* data = |
62 static_cast<DialogStatusData*>(profile_->GetUserData(kDialogStatusKey)); | 62 static_cast<DialogStatusData*>(profile_->GetUserData(kDialogStatusKey)); |
63 DCHECK(data); | 63 DCHECK(data); |
64 data->set_currently_shown(false); | 64 data->set_currently_shown(false); |
65 } | 65 } |
66 | 66 |
67 DownloadFeedbackDialogView::DownloadFeedbackDialogView( | 67 DownloadFeedbackDialogView::DownloadFeedbackDialogView( |
68 Profile* profile, | 68 Profile* profile, |
69 const base::Callback<void(DownloadReportingStatus)>& callback) | 69 const base::Callback<void(bool)>& callback) |
70 : profile_(profile), | 70 : profile_(profile), |
71 callback_(callback), | 71 callback_(callback), |
72 explanation_box_view_(new views::MessageBoxView( | 72 explanation_box_view_(new views::MessageBoxView( |
73 views::MessageBoxView::InitParams(l10n_util::GetStringUTF16( | 73 views::MessageBoxView::InitParams(l10n_util::GetStringUTF16( |
74 IDS_FEEDBACK_SERVICE_DIALOG_EXPLANATION)))), | 74 IDS_FEEDBACK_SERVICE_DIALOG_EXPLANATION)))), |
75 title_text_(l10n_util::GetStringUTF16(IDS_FEEDBACK_SERVICE_DIALOG_TITLE)), | 75 title_text_(l10n_util::GetStringUTF16(IDS_FEEDBACK_SERVICE_DIALOG_TITLE)), |
76 ok_button_text_(l10n_util::GetStringUTF16( | 76 ok_button_text_(l10n_util::GetStringUTF16( |
77 IDS_FEEDBACK_SERVICE_DIALOG_OK_BUTTON_LABEL)), | 77 IDS_FEEDBACK_SERVICE_DIALOG_OK_BUTTON_LABEL)), |
78 cancel_button_text_(l10n_util::GetStringUTF16( | 78 cancel_button_text_(l10n_util::GetStringUTF16( |
79 IDS_FEEDBACK_SERVICE_DIALOG_CANCEL_BUTTON_LABEL)) { | 79 IDS_FEEDBACK_SERVICE_DIALOG_CANCEL_BUTTON_LABEL)) { |
80 } | 80 } |
81 | 81 |
82 DownloadFeedbackDialogView::~DownloadFeedbackDialogView() {} | 82 DownloadFeedbackDialogView::~DownloadFeedbackDialogView() {} |
83 | 83 |
84 int DownloadFeedbackDialogView::GetDefaultDialogButton() const { | 84 int DownloadFeedbackDialogView::GetDefaultDialogButton() const { |
85 return ui::DIALOG_BUTTON_CANCEL; | 85 return ui::DIALOG_BUTTON_CANCEL; |
86 } | 86 } |
87 | 87 |
88 base::string16 DownloadFeedbackDialogView::GetDialogButtonLabel( | 88 base::string16 DownloadFeedbackDialogView::GetDialogButtonLabel( |
89 ui::DialogButton button) const { | 89 ui::DialogButton button) const { |
90 return (button == ui::DIALOG_BUTTON_OK) ? | 90 return (button == ui::DIALOG_BUTTON_OK) ? |
91 ok_button_text_ : cancel_button_text_; | 91 ok_button_text_ : cancel_button_text_; |
92 } | 92 } |
93 | 93 |
94 bool DownloadFeedbackDialogView::Cancel() { | 94 bool DownloadFeedbackDialogView::Cancel() { |
95 profile_->GetPrefs()->SetInteger( | 95 profile_->GetPrefs()->SetBoolean(prefs::kSafeBrowsingDownloadFeedbackEnabled, |
96 prefs::kSafeBrowsingDownloadReportingEnabled, kDownloadReportingDisabled); | 96 false); |
97 ReleaseDialogStatusHold(); | 97 ReleaseDialogStatusHold(); |
98 callback_.Run(kDownloadReportingDisabled); | 98 callback_.Run(false /* disabled */); |
99 return true; | 99 return true; |
Peter Kasting
2014/02/13 22:17:52
Nit: Because the bodies of these two functions are
felt
2014/02/14 00:21:49
Done. Also merged ReleaseDialogStatusHold into the
| |
100 } | 100 } |
101 | 101 |
102 bool DownloadFeedbackDialogView::Accept() { | 102 bool DownloadFeedbackDialogView::Accept() { |
103 profile_->GetPrefs()->SetInteger( | 103 profile_->GetPrefs()->SetBoolean(prefs::kSafeBrowsingDownloadFeedbackEnabled, |
104 prefs::kSafeBrowsingDownloadReportingEnabled, kDownloadReportingEnabled); | 104 true); |
105 ReleaseDialogStatusHold(); | 105 ReleaseDialogStatusHold(); |
106 callback_.Run(kDownloadReportingEnabled); | 106 callback_.Run(true /* enabled */); |
107 return true; | 107 return true; |
108 } | 108 } |
109 | 109 |
110 ui::ModalType DownloadFeedbackDialogView::GetModalType() const { | 110 ui::ModalType DownloadFeedbackDialogView::GetModalType() const { |
111 return ui::MODAL_TYPE_WINDOW; | 111 return ui::MODAL_TYPE_WINDOW; |
112 } | 112 } |
113 | 113 |
114 base::string16 DownloadFeedbackDialogView::GetWindowTitle() const { | 114 base::string16 DownloadFeedbackDialogView::GetWindowTitle() const { |
115 return title_text_; | 115 return title_text_; |
116 } | 116 } |
117 | 117 |
118 void DownloadFeedbackDialogView::DeleteDelegate() { | 118 void DownloadFeedbackDialogView::DeleteDelegate() { |
119 delete this; | 119 delete this; |
120 } | 120 } |
121 | 121 |
122 views::Widget* DownloadFeedbackDialogView::GetWidget() { | 122 views::Widget* DownloadFeedbackDialogView::GetWidget() { |
123 return explanation_box_view_->GetWidget(); | 123 return explanation_box_view_->GetWidget(); |
124 } | 124 } |
125 | 125 |
126 const views::Widget* DownloadFeedbackDialogView::GetWidget() const { | 126 const views::Widget* DownloadFeedbackDialogView::GetWidget() const { |
127 return explanation_box_view_->GetWidget(); | 127 return explanation_box_view_->GetWidget(); |
128 } | 128 } |
129 | 129 |
130 views::View* DownloadFeedbackDialogView::GetContentsView() { | 130 views::View* DownloadFeedbackDialogView::GetContentsView() { |
131 return explanation_box_view_; | 131 return explanation_box_view_; |
132 } | 132 } |
OLD | NEW |