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 "base/supports_user_data.h" | |
8 #include "chrome/browser/prefs/pref_service_syncable.h" | |
mattm
2014/02/07 11:21:04
this one too?
felt
2014/02/07 15:39:54
Done.
| |
9 #include "chrome/browser/profiles/profile.h" | |
10 #include "chrome/browser/ui/views/constrained_window_views.h" | |
11 #include "grit/generated_resources.h" | |
12 #include "ui/base/l10n/l10n_util.h" | |
13 #include "ui/views/controls/message_box_view.h" | |
14 #include "ui/views/widget/widget.h" | |
15 | |
16 namespace { | |
17 | |
18 const void* kDialogStatusKey = &kDialogStatusKey; | |
19 | |
20 class DialogStatusData : public base::SupportsUserData::Data { | |
21 public: | |
22 DialogStatusData() : currently_shown_(false) {} | |
23 virtual ~DialogStatusData() {} | |
24 bool currently_shown() const { return currently_shown_; } | |
25 void set_currently_shown(bool shown) { currently_shown_ = shown; } | |
26 private: | |
27 bool currently_shown_; | |
28 }; | |
29 | |
30 } // namespace | |
31 | |
32 // static | |
33 void DownloadFeedbackDialogView::Show( | |
34 gfx::NativeWindow parent_window, | |
35 Profile* profile, | |
36 const base::Callback<void(DownloadReportingStatus)>& callback) { | |
37 // This dialog should only be shown if it hasn't been shown before. | |
38 DCHECK(profile->GetPrefs()->GetInteger( | |
39 prefs::kSafeBrowsingDownloadReportingEnabled) == kDialogNotYetShown); | |
40 | |
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 | |
43 // is disabled (to be conservative). | |
44 DialogStatusData* data = | |
45 static_cast<DialogStatusData*>(profile->GetUserData(kDialogStatusKey)); | |
46 if (data == NULL) { | |
47 data = new DialogStatusData(); | |
48 profile->SetUserData(kDialogStatusKey, data); | |
49 } | |
50 if (data->currently_shown() == false) { | |
51 data->set_currently_shown(true); | |
52 DownloadFeedbackDialogView* window = | |
53 new DownloadFeedbackDialogView(profile, callback); | |
54 CreateBrowserModalDialogViews(window, parent_window)->Show(); | |
55 } else { | |
56 callback.Run(kDownloadReportingDisabled); | |
57 } | |
58 } | |
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( | |
68 Profile* profile, | |
69 const base::Callback<void(DownloadReportingStatus)>& callback) | |
70 : profile_(profile), | |
71 callback_(callback), | |
72 explanation_box_view_(new views::MessageBoxView( | |
73 views::MessageBoxView::InitParams(l10n_util::GetStringUTF16( | |
74 IDS_FEEDBACK_SERVICE_DIALOG_EXPLANATION)))), | |
75 title_text_(l10n_util::GetStringUTF16(IDS_FEEDBACK_SERVICE_DIALOG_TITLE)), | |
76 ok_button_text_(l10n_util::GetStringUTF16( | |
77 IDS_FEEDBACK_SERVICE_DIALOG_OK_BUTTON_LABEL)), | |
78 cancel_button_text_(l10n_util::GetStringUTF16( | |
79 IDS_FEEDBACK_SERVICE_DIALOG_CANCEL_BUTTON_LABEL)) { | |
80 } | |
81 | |
82 DownloadFeedbackDialogView::~DownloadFeedbackDialogView() {} | |
83 | |
84 int DownloadFeedbackDialogView::GetDefaultDialogButton() const { | |
85 return ui::DIALOG_BUTTON_CANCEL; | |
86 } | |
87 | |
88 base::string16 DownloadFeedbackDialogView::GetDialogButtonLabel( | |
89 ui::DialogButton button) const { | |
90 return (button == ui::DIALOG_BUTTON_OK) ? | |
91 ok_button_text_ : cancel_button_text_; | |
92 } | |
93 | |
94 bool DownloadFeedbackDialogView::Cancel() { | |
95 profile_->GetPrefs()->SetInteger( | |
96 prefs::kSafeBrowsingDownloadReportingEnabled, kDownloadReportingDisabled); | |
97 ReleaseDialogStatusHold(); | |
98 callback_.Run(kDownloadReportingDisabled); | |
99 return true; | |
100 } | |
101 | |
102 bool DownloadFeedbackDialogView::Accept() { | |
103 profile_->GetPrefs()->SetInteger( | |
104 prefs::kSafeBrowsingDownloadReportingEnabled, kDownloadReportingEnabled); | |
105 ReleaseDialogStatusHold(); | |
106 callback_.Run(kDownloadReportingEnabled); | |
107 return true; | |
108 } | |
109 | |
110 ui::ModalType DownloadFeedbackDialogView::GetModalType() const { | |
111 return ui::MODAL_TYPE_WINDOW; | |
112 } | |
113 | |
114 base::string16 DownloadFeedbackDialogView::GetWindowTitle() const { | |
115 return title_text_; | |
116 } | |
117 | |
118 void DownloadFeedbackDialogView::DeleteDelegate() { | |
119 delete this; | |
120 } | |
121 | |
122 views::Widget* DownloadFeedbackDialogView::GetWidget() { | |
123 return explanation_box_view_->GetWidget(); | |
124 } | |
125 | |
126 const views::Widget* DownloadFeedbackDialogView::GetWidget() const { | |
127 return explanation_box_view_->GetWidget(); | |
128 } | |
129 | |
130 views::View* DownloadFeedbackDialogView::GetContentsView() { | |
131 return explanation_box_view_; | |
132 } | |
OLD | NEW |