| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 ExperienceSamplingEvent::kDownloadDangerPrompt, | 131 ExperienceSamplingEvent::kDownloadDangerPrompt, |
| 133 item->GetURL(), | 132 item->GetURL(), |
| 134 item->GetReferrerUrl(), | 133 item->GetReferrerUrl(), |
| 135 item->GetBrowserContext())); | 134 item->GetBrowserContext())); |
| 136 } | 135 } |
| 137 | 136 |
| 138 // DownloadDangerPrompt methods: | 137 // DownloadDangerPrompt methods: |
| 139 void DownloadDangerPromptViews::InvokeActionForTesting(Action action) { | 138 void DownloadDangerPromptViews::InvokeActionForTesting(Action action) { |
| 140 switch (action) { | 139 switch (action) { |
| 141 case ACCEPT: | 140 case ACCEPT: |
| 141 // This inversion is intentional. |
| 142 Cancel(); |
| 143 break; |
| 144 |
| 145 case DISMISS: |
| 146 Close(); |
| 147 break; |
| 148 |
| 149 case CANCEL: |
| 142 Accept(); | 150 Accept(); |
| 143 break; | 151 break; |
| 144 | 152 |
| 145 case CANCEL: | |
| 146 case DISMISS: | |
| 147 Cancel(); | |
| 148 break; | |
| 149 | |
| 150 default: | 153 default: |
| 151 NOTREACHED(); | 154 NOTREACHED(); |
| 152 break; | 155 break; |
| 153 } | 156 } |
| 154 } | 157 } |
| 155 | 158 |
| 156 // views::DialogDelegate methods: | 159 // views::DialogDelegate methods: |
| 157 base::string16 DownloadDangerPromptViews::GetDialogButtonLabel( | 160 base::string16 DownloadDangerPromptViews::GetDialogButtonLabel( |
| 158 ui::DialogButton button) const { | 161 ui::DialogButton button) const { |
| 159 switch (button) { | 162 switch (button) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 177 | 180 |
| 178 void DownloadDangerPromptViews::DeleteDelegate() { | 181 void DownloadDangerPromptViews::DeleteDelegate() { |
| 179 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 182 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 180 delete this; | 183 delete this; |
| 181 } | 184 } |
| 182 | 185 |
| 183 ui::ModalType DownloadDangerPromptViews::GetModalType() const { | 186 ui::ModalType DownloadDangerPromptViews::GetModalType() const { |
| 184 return ui::MODAL_TYPE_CHILD; | 187 return ui::MODAL_TYPE_CHILD; |
| 185 } | 188 } |
| 186 | 189 |
| 190 bool DownloadDangerPromptViews::Accept() { |
| 191 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 192 // ExperienceSampling: User did not proceed down the dangerous path. |
| 193 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); |
| 194 // Note that the presentational concept of "Accept/Cancel" is inverted from |
| 195 // the model's concept of ACCEPT/CANCEL. In the UI, the safe path is "Accept" |
| 196 // and the dangerous path is "Cancel". |
| 197 RunDone(CANCEL); |
| 198 return true; |
| 199 } |
| 200 |
| 187 bool DownloadDangerPromptViews::Cancel() { | 201 bool DownloadDangerPromptViews::Cancel() { |
| 188 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 202 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 189 // ExperienceSampling: User canceled the warning. | 203 // 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); | 204 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); |
| 199 RunDone(ACCEPT); | 205 RunDone(ACCEPT); |
| 200 return true; | 206 return true; |
| 201 } | 207 } |
| 202 | 208 |
| 203 bool DownloadDangerPromptViews::Close() { | 209 bool DownloadDangerPromptViews::Close() { |
| 204 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 210 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 205 // ExperienceSampling: User canceled the warning. | 211 // ExperienceSampling: User did not proceed down the dangerous path. |
| 206 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); | 212 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); |
| 207 RunDone(DISMISS); | 213 RunDone(DISMISS); |
| 208 return true; | 214 return true; |
| 209 } | 215 } |
| 210 | 216 |
| 211 views::View* DownloadDangerPromptViews::GetInitiallyFocusedView() { | |
| 212 return GetDialogClientView()->cancel_button(); | |
| 213 } | |
| 214 | |
| 215 views::View* DownloadDangerPromptViews::GetContentsView() { | 217 views::View* DownloadDangerPromptViews::GetContentsView() { |
| 216 return contents_view_; | 218 return contents_view_; |
| 217 } | 219 } |
| 218 | 220 |
| 219 views::Widget* DownloadDangerPromptViews::GetWidget() { | 221 views::Widget* DownloadDangerPromptViews::GetWidget() { |
| 220 return contents_view_->GetWidget(); | 222 return contents_view_->GetWidget(); |
| 221 } | 223 } |
| 222 | 224 |
| 223 const views::Widget* DownloadDangerPromptViews::GetWidget() const { | 225 const views::Widget* DownloadDangerPromptViews::GetWidget() const { |
| 224 return contents_view_->GetWidget(); | 226 return contents_view_->GetWidget(); |
| 225 } | 227 } |
| 226 | 228 |
| 227 // content::DownloadItem::Observer: | 229 // content::DownloadItem::Observer: |
| 228 void DownloadDangerPromptViews::OnDownloadUpdated( | 230 void DownloadDangerPromptViews::OnDownloadUpdated( |
| 229 content::DownloadItem* download) { | 231 content::DownloadItem* download) { |
| 230 // If the download is nolonger dangerous (accepted externally) or the download | 232 // 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 | 233 // is in a terminal state, then the download danger prompt is no longer |
| 232 // necessary. | 234 // necessary. |
| 233 if (!download_->IsDangerous() || download_->IsDone()) { | 235 if (!download_->IsDangerous() || download_->IsDone()) { |
| 234 RunDone(DISMISS); | 236 RunDone(DISMISS); |
| 235 Cancel(); | 237 Cancel(); |
| 236 } | 238 } |
| 237 } | 239 } |
| 238 | 240 |
| 239 base::string16 DownloadDangerPromptViews::GetAcceptButtonTitle() const { | 241 base::string16 DownloadDangerPromptViews::GetAcceptButtonTitle() const { |
| 242 // "Be safe". |
| 243 return l10n_util::GetStringUTF16(IDS_CONFIRM_CANCEL_AGAIN_MALICIOUS); |
| 244 } |
| 245 |
| 246 base::string16 DownloadDangerPromptViews::GetCancelButtonTitle() const { |
| 240 if (show_context_) | 247 if (show_context_) |
| 241 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD); | 248 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD); |
| 242 switch (download_->GetDangerType()) { | 249 switch (download_->GetDangerType()) { |
| 243 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | 250 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
| 244 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 251 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
| 245 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { | 252 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { |
| 246 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD_AGAIN_MALICIOUS); | 253 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD_AGAIN_MALICIOUS); |
| 247 } | 254 } |
| 248 default: | 255 default: |
| 249 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD_AGAIN); | 256 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD_AGAIN); |
| 250 } | 257 } |
| 251 } | 258 } |
| 252 | 259 |
| 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 { | 260 base::string16 DownloadDangerPromptViews::GetMessageLead() const { |
| 268 if (!show_context_) { | 261 if (!show_context_) { |
| 269 switch (download_->GetDangerType()) { | 262 switch (download_->GetDangerType()) { |
| 270 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | 263 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
| 271 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 264 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
| 272 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: | 265 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
| 273 return l10n_util::GetStringUTF16( | 266 return l10n_util::GetStringUTF16( |
| 274 IDS_PROMPT_CONFIRM_KEEP_MALICIOUS_DOWNLOAD_LEAD); | 267 IDS_PROMPT_CONFIRM_KEEP_MALICIOUS_DOWNLOAD_LEAD); |
| 275 | 268 |
| 276 default: | 269 default: |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 content::DownloadItem* item, | 349 content::DownloadItem* item, |
| 357 content::WebContents* web_contents, | 350 content::WebContents* web_contents, |
| 358 bool show_context, | 351 bool show_context, |
| 359 const OnDone& done) { | 352 const OnDone& done) { |
| 360 DownloadDangerPromptViews* download_danger_prompt = | 353 DownloadDangerPromptViews* download_danger_prompt = |
| 361 new DownloadDangerPromptViews(item, show_context, done); | 354 new DownloadDangerPromptViews(item, show_context, done); |
| 362 constrained_window::ShowWebModalDialogViews(download_danger_prompt, | 355 constrained_window::ShowWebModalDialogViews(download_danger_prompt, |
| 363 web_contents); | 356 web_contents); |
| 364 return download_danger_prompt; | 357 return download_danger_prompt; |
| 365 } | 358 } |
| OLD | NEW |