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 UserDecisionCallback& 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); |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 void DownloadFeedbackDialogView::ReleaseDialogStatusHold() { | |
61 DialogStatusData* data = | |
62 static_cast<DialogStatusData*>(profile_->GetUserData(kDialogStatusKey)); | |
63 DCHECK(data); | |
64 data->set_currently_shown(false); | |
65 } | |
66 | |
67 DownloadFeedbackDialogView::DownloadFeedbackDialogView( | 60 DownloadFeedbackDialogView::DownloadFeedbackDialogView( |
68 Profile* profile, | 61 Profile* profile, |
69 const base::Callback<void(DownloadReportingStatus)>& callback) | 62 const UserDecisionCallback& callback) |
70 : profile_(profile), | 63 : profile_(profile), |
71 callback_(callback), | 64 callback_(callback), |
72 explanation_box_view_(new views::MessageBoxView( | 65 explanation_box_view_(new views::MessageBoxView( |
73 views::MessageBoxView::InitParams(l10n_util::GetStringUTF16( | 66 views::MessageBoxView::InitParams(l10n_util::GetStringUTF16( |
74 IDS_FEEDBACK_SERVICE_DIALOG_EXPLANATION)))), | 67 IDS_FEEDBACK_SERVICE_DIALOG_EXPLANATION)))), |
75 title_text_(l10n_util::GetStringUTF16(IDS_FEEDBACK_SERVICE_DIALOG_TITLE)), | 68 title_text_(l10n_util::GetStringUTF16(IDS_FEEDBACK_SERVICE_DIALOG_TITLE)), |
76 ok_button_text_(l10n_util::GetStringUTF16( | 69 ok_button_text_(l10n_util::GetStringUTF16( |
77 IDS_FEEDBACK_SERVICE_DIALOG_OK_BUTTON_LABEL)), | 70 IDS_FEEDBACK_SERVICE_DIALOG_OK_BUTTON_LABEL)), |
78 cancel_button_text_(l10n_util::GetStringUTF16( | 71 cancel_button_text_(l10n_util::GetStringUTF16( |
79 IDS_FEEDBACK_SERVICE_DIALOG_CANCEL_BUTTON_LABEL)) { | 72 IDS_FEEDBACK_SERVICE_DIALOG_CANCEL_BUTTON_LABEL)) { |
80 } | 73 } |
81 | 74 |
82 DownloadFeedbackDialogView::~DownloadFeedbackDialogView() {} | 75 DownloadFeedbackDialogView::~DownloadFeedbackDialogView() {} |
83 | 76 |
84 int DownloadFeedbackDialogView::GetDefaultDialogButton() const { | 77 int DownloadFeedbackDialogView::GetDefaultDialogButton() const { |
85 return ui::DIALOG_BUTTON_CANCEL; | 78 return ui::DIALOG_BUTTON_CANCEL; |
86 } | 79 } |
87 | 80 |
88 base::string16 DownloadFeedbackDialogView::GetDialogButtonLabel( | 81 base::string16 DownloadFeedbackDialogView::GetDialogButtonLabel( |
89 ui::DialogButton button) const { | 82 ui::DialogButton button) const { |
90 return (button == ui::DIALOG_BUTTON_OK) ? | 83 return (button == ui::DIALOG_BUTTON_OK) ? |
91 ok_button_text_ : cancel_button_text_; | 84 ok_button_text_ : cancel_button_text_; |
92 } | 85 } |
93 | 86 |
94 bool DownloadFeedbackDialogView::Cancel() { | 87 bool DownloadFeedbackDialogView::OnButtonClicked(bool accepted) { |
95 profile_->GetPrefs()->SetInteger( | 88 profile_->GetPrefs()->SetBoolean(prefs::kSafeBrowsingDownloadFeedbackEnabled, |
96 prefs::kSafeBrowsingDownloadReportingEnabled, kDownloadReportingDisabled); | 89 accepted); |
97 ReleaseDialogStatusHold(); | 90 DialogStatusData* data = |
98 callback_.Run(kDownloadReportingDisabled); | 91 static_cast<DialogStatusData*>(profile_->GetUserData(kDialogStatusKey)); |
| 92 DCHECK(data); |
| 93 data->set_currently_shown(false); |
| 94 |
| 95 callback_.Run(accepted); |
99 return true; | 96 return true; |
100 } | 97 } |
101 | 98 |
| 99 bool DownloadFeedbackDialogView::Cancel() { |
| 100 return OnButtonClicked(false); |
| 101 } |
| 102 |
102 bool DownloadFeedbackDialogView::Accept() { | 103 bool DownloadFeedbackDialogView::Accept() { |
103 profile_->GetPrefs()->SetInteger( | 104 return OnButtonClicked(true); |
104 prefs::kSafeBrowsingDownloadReportingEnabled, kDownloadReportingEnabled); | |
105 ReleaseDialogStatusHold(); | |
106 callback_.Run(kDownloadReportingEnabled); | |
107 return true; | |
108 } | 105 } |
109 | 106 |
110 ui::ModalType DownloadFeedbackDialogView::GetModalType() const { | 107 ui::ModalType DownloadFeedbackDialogView::GetModalType() const { |
111 return ui::MODAL_TYPE_WINDOW; | 108 return ui::MODAL_TYPE_WINDOW; |
112 } | 109 } |
113 | 110 |
114 base::string16 DownloadFeedbackDialogView::GetWindowTitle() const { | 111 base::string16 DownloadFeedbackDialogView::GetWindowTitle() const { |
115 return title_text_; | 112 return title_text_; |
116 } | 113 } |
117 | 114 |
118 void DownloadFeedbackDialogView::DeleteDelegate() { | 115 void DownloadFeedbackDialogView::DeleteDelegate() { |
119 delete this; | 116 delete this; |
120 } | 117 } |
121 | 118 |
122 views::Widget* DownloadFeedbackDialogView::GetWidget() { | 119 views::Widget* DownloadFeedbackDialogView::GetWidget() { |
123 return explanation_box_view_->GetWidget(); | 120 return explanation_box_view_->GetWidget(); |
124 } | 121 } |
125 | 122 |
126 const views::Widget* DownloadFeedbackDialogView::GetWidget() const { | 123 const views::Widget* DownloadFeedbackDialogView::GetWidget() const { |
127 return explanation_box_view_->GetWidget(); | 124 return explanation_box_view_->GetWidget(); |
128 } | 125 } |
129 | 126 |
130 views::View* DownloadFeedbackDialogView::GetContentsView() { | 127 views::View* DownloadFeedbackDialogView::GetContentsView() { |
131 return explanation_box_view_; | 128 return explanation_box_view_; |
132 } | 129 } |
OLD | NEW |