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