Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/download/download_danger_prompt.h" | 5 #include "chrome/browser/download/download_danger_prompt.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "chrome/browser/download/download_stats.h" | 8 #include "chrome/browser/download/download_stats.h" |
| 9 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" | 9 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" |
| 10 #include "chrome/grit/chromium_strings.h" | 10 #include "chrome/grit/chromium_strings.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 void InvokeActionForTesting(Action action) override; | 48 void InvokeActionForTesting(Action action) override; |
| 49 | 49 |
| 50 // views::DialogDelegate methods: | 50 // views::DialogDelegate methods: |
| 51 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | 51 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; |
| 52 base::string16 GetWindowTitle() const override; | 52 base::string16 GetWindowTitle() const override; |
| 53 void DeleteDelegate() override; | 53 void DeleteDelegate() override; |
| 54 ui::ModalType GetModalType() const override; | 54 ui::ModalType GetModalType() const override; |
| 55 bool Cancel() override; | 55 bool Cancel() override; |
| 56 bool Accept() override; | 56 bool Accept() override; |
| 57 bool Close() override; | 57 bool Close() override; |
| 58 views::View* GetInitiallyFocusedView() override; | |
| 59 views::View* GetContentsView() override; | 58 views::View* GetContentsView() override; |
| 60 views::Widget* GetWidget() override; | 59 views::Widget* GetWidget() override; |
| 61 const views::Widget* GetWidget() const override; | 60 const views::Widget* GetWidget() const override; |
| 62 | 61 |
| 63 // content::DownloadItem::Observer: | 62 // content::DownloadItem::Observer: |
| 64 void OnDownloadUpdated(content::DownloadItem* download) override; | 63 void OnDownloadUpdated(content::DownloadItem* download) override; |
| 65 | 64 |
| 66 private: | 65 private: |
| 67 base::string16 GetAcceptButtonTitle() const; | 66 base::string16 GetAcceptButtonTitle() const; |
| 68 base::string16 GetCancelButtonTitle() const; | 67 base::string16 GetCancelButtonTitle() const; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 | 176 |
| 178 void DownloadDangerPromptViews::DeleteDelegate() { | 177 void DownloadDangerPromptViews::DeleteDelegate() { |
| 179 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 180 delete this; | 179 delete this; |
| 181 } | 180 } |
| 182 | 181 |
| 183 ui::ModalType DownloadDangerPromptViews::GetModalType() const { | 182 ui::ModalType DownloadDangerPromptViews::GetModalType() const { |
| 184 return ui::MODAL_TYPE_CHILD; | 183 return ui::MODAL_TYPE_CHILD; |
| 185 } | 184 } |
| 186 | 185 |
| 186 bool DownloadDangerPromptViews::Accept() { | |
|
Mike Wittman
2016/02/08 17:52:21
nit: declaration order has this below Cancel()
Evan Stade
2016/02/08 19:12:57
Done.
| |
| 187 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 188 // ExperienceSampling: User did not proceed down the dangerous path. | |
| 189 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); | |
| 190 // Note that the presentational concept of "Accept/Cancel" is inverted from | |
| 191 // the model's concept of ACCEPT/CANCEL. In the UI, the safe path is "Accept" | |
| 192 // and the dangerous path is "Cancel". | |
| 193 RunDone(CANCEL); | |
| 194 return true; | |
| 195 } | |
| 196 | |
| 187 bool DownloadDangerPromptViews::Cancel() { | 197 bool DownloadDangerPromptViews::Cancel() { |
| 188 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 198 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 189 // ExperienceSampling: User canceled the warning. | 199 // ExperienceSampling: User proceeded down the dangerous path. |
| 190 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); | |
| 191 RunDone(CANCEL); | |
| 192 return true; | |
| 193 } | |
| 194 | |
| 195 bool DownloadDangerPromptViews::Accept() { | |
| 196 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 197 // ExperienceSampling: User proceeded through the warning. | |
| 198 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); | 200 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); |
| 199 RunDone(ACCEPT); | 201 RunDone(ACCEPT); |
| 200 return true; | 202 return true; |
| 201 } | 203 } |
| 202 | 204 |
| 203 bool DownloadDangerPromptViews::Close() { | 205 bool DownloadDangerPromptViews::Close() { |
| 204 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 206 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 205 // ExperienceSampling: User canceled the warning. | 207 // ExperienceSampling: User did not proceed down the dangerous path. |
| 206 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); | 208 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); |
| 207 RunDone(DISMISS); | 209 RunDone(DISMISS); |
| 208 return true; | 210 return true; |
| 209 } | 211 } |
| 210 | 212 |
| 211 views::View* DownloadDangerPromptViews::GetInitiallyFocusedView() { | |
| 212 return GetDialogClientView()->cancel_button(); | |
| 213 } | |
| 214 | |
| 215 views::View* DownloadDangerPromptViews::GetContentsView() { | 213 views::View* DownloadDangerPromptViews::GetContentsView() { |
| 216 return contents_view_; | 214 return contents_view_; |
| 217 } | 215 } |
| 218 | 216 |
| 219 views::Widget* DownloadDangerPromptViews::GetWidget() { | 217 views::Widget* DownloadDangerPromptViews::GetWidget() { |
| 220 return contents_view_->GetWidget(); | 218 return contents_view_->GetWidget(); |
| 221 } | 219 } |
| 222 | 220 |
| 223 const views::Widget* DownloadDangerPromptViews::GetWidget() const { | 221 const views::Widget* DownloadDangerPromptViews::GetWidget() const { |
| 224 return contents_view_->GetWidget(); | 222 return contents_view_->GetWidget(); |
| 225 } | 223 } |
| 226 | 224 |
| 227 // content::DownloadItem::Observer: | 225 // content::DownloadItem::Observer: |
| 228 void DownloadDangerPromptViews::OnDownloadUpdated( | 226 void DownloadDangerPromptViews::OnDownloadUpdated( |
| 229 content::DownloadItem* download) { | 227 content::DownloadItem* download) { |
| 230 // If the download is nolonger dangerous (accepted externally) or the download | 228 // If the download is nolonger dangerous (accepted externally) or the download |
| 231 // is in a terminal state, then the download danger prompt is no longer | 229 // is in a terminal state, then the download danger prompt is no longer |
| 232 // necessary. | 230 // necessary. |
| 233 if (!download_->IsDangerous() || download_->IsDone()) { | 231 if (!download_->IsDangerous() || download_->IsDone()) { |
| 234 RunDone(DISMISS); | 232 RunDone(DISMISS); |
| 235 Cancel(); | 233 Cancel(); |
| 236 } | 234 } |
| 237 } | 235 } |
| 238 | 236 |
| 239 base::string16 DownloadDangerPromptViews::GetAcceptButtonTitle() const { | 237 base::string16 DownloadDangerPromptViews::GetAcceptButtonTitle() const { |
| 238 // "Be safe". | |
| 239 return l10n_util::GetStringUTF16(IDS_CONFIRM_CANCEL_AGAIN_MALICIOUS); | |
| 240 } | |
| 241 | |
| 242 base::string16 DownloadDangerPromptViews::GetCancelButtonTitle() const { | |
| 240 if (show_context_) | 243 if (show_context_) |
| 241 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD); | 244 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD); |
| 242 switch (download_->GetDangerType()) { | 245 switch (download_->GetDangerType()) { |
| 243 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | 246 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
| 244 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 247 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
| 245 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { | 248 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { |
| 246 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD_AGAIN_MALICIOUS); | 249 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD_AGAIN_MALICIOUS); |
| 247 } | 250 } |
| 248 default: | 251 default: |
| 249 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD_AGAIN); | 252 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD_AGAIN); |
| 250 } | 253 } |
| 251 } | 254 } |
| 252 | 255 |
| 253 base::string16 DownloadDangerPromptViews::GetCancelButtonTitle() const { | |
| 254 if (show_context_) | |
| 255 return l10n_util::GetStringUTF16(IDS_CANCEL); | |
| 256 switch (download_->GetDangerType()) { | |
| 257 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | |
| 258 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | |
| 259 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { | |
| 260 return l10n_util::GetStringUTF16(IDS_CONFIRM_CANCEL_AGAIN_MALICIOUS); | |
| 261 } | |
| 262 default: | |
| 263 return l10n_util::GetStringUTF16(IDS_CANCEL); | |
| 264 } | |
| 265 } | |
| 266 | |
| 267 base::string16 DownloadDangerPromptViews::GetMessageLead() const { | 256 base::string16 DownloadDangerPromptViews::GetMessageLead() const { |
| 268 if (!show_context_) { | 257 if (!show_context_) { |
| 269 switch (download_->GetDangerType()) { | 258 switch (download_->GetDangerType()) { |
| 270 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | 259 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
| 271 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 260 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
| 272 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: | 261 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
| 273 return l10n_util::GetStringUTF16( | 262 return l10n_util::GetStringUTF16( |
| 274 IDS_PROMPT_CONFIRM_KEEP_MALICIOUS_DOWNLOAD_LEAD); | 263 IDS_PROMPT_CONFIRM_KEEP_MALICIOUS_DOWNLOAD_LEAD); |
| 275 | 264 |
| 276 default: | 265 default: |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 content::DownloadItem* item, | 345 content::DownloadItem* item, |
| 357 content::WebContents* web_contents, | 346 content::WebContents* web_contents, |
| 358 bool show_context, | 347 bool show_context, |
| 359 const OnDone& done) { | 348 const OnDone& done) { |
| 360 DownloadDangerPromptViews* download_danger_prompt = | 349 DownloadDangerPromptViews* download_danger_prompt = |
| 361 new DownloadDangerPromptViews(item, show_context, done); | 350 new DownloadDangerPromptViews(item, show_context, done); |
| 362 constrained_window::ShowWebModalDialogViews(download_danger_prompt, | 351 constrained_window::ShowWebModalDialogViews(download_danger_prompt, |
| 363 web_contents); | 352 web_contents); |
| 364 return download_danger_prompt; | 353 return download_danger_prompt; |
| 365 } | 354 } |
| OLD | NEW |