| 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 #include "chrome/browser/download/download_danger_prompt.h" |
| 4 | 5 |
| 5 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 6 #include "chrome/browser/download/download_danger_prompt.h" | |
| 7 #include "chrome/browser/download/download_stats.h" | 7 #include "chrome/browser/download/download_stats.h" |
| 8 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" | 8 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" |
| 9 #include "chrome/grit/chromium_strings.h" | 9 #include "chrome/grit/chromium_strings.h" |
| 10 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| 11 #include "components/constrained_window/constrained_window_views.h" | 11 #include "components/constrained_window/constrained_window_views.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/download_danger_type.h" | 13 #include "content/public/browser/download_danger_type.h" |
| 14 #include "content/public/browser/download_item.h" | 14 #include "content/public/browser/download_item.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 34 // formatting on the text in the body of the dialog. | 34 // formatting on the text in the body of the dialog. |
| 35 class DownloadDangerPromptViews : public DownloadDangerPrompt, | 35 class DownloadDangerPromptViews : public DownloadDangerPrompt, |
| 36 public content::DownloadItem::Observer, | 36 public content::DownloadItem::Observer, |
| 37 public views::DialogDelegate { | 37 public views::DialogDelegate { |
| 38 public: | 38 public: |
| 39 DownloadDangerPromptViews(content::DownloadItem* item, | 39 DownloadDangerPromptViews(content::DownloadItem* item, |
| 40 bool show_context, | 40 bool show_context, |
| 41 const OnDone& done); | 41 const OnDone& done); |
| 42 | 42 |
| 43 // DownloadDangerPrompt methods: | 43 // DownloadDangerPrompt methods: |
| 44 void InvokeActionForTesting(Action action) override; | 44 std::string InvokeActionForTesting(Action action, |
| 45 const GURL& url) override; |
| 45 | 46 |
| 46 // views::DialogDelegate methods: | 47 // views::DialogDelegate methods: |
| 47 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | 48 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; |
| 48 base::string16 GetWindowTitle() const override; | 49 base::string16 GetWindowTitle() const override; |
| 49 void DeleteDelegate() override; | 50 void DeleteDelegate() override; |
| 50 ui::ModalType GetModalType() const override; | 51 ui::ModalType GetModalType() const override; |
| 51 bool Cancel() override; | 52 bool Cancel() override; |
| 52 bool Accept() override; | 53 bool Accept() override; |
| 53 bool Close() override; | 54 bool Close() override; |
| 54 views::View* GetInitiallyFocusedView() override; | 55 views::View* GetInitiallyFocusedView() override; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // ExperienceSampling: A malicious download warning is being shown to the | 126 // ExperienceSampling: A malicious download warning is being shown to the |
| 126 // user, so we start a new SamplingEvent and track it. | 127 // user, so we start a new SamplingEvent and track it. |
| 127 sampling_event_.reset(new ExperienceSamplingEvent( | 128 sampling_event_.reset(new ExperienceSamplingEvent( |
| 128 ExperienceSamplingEvent::kDownloadDangerPrompt, | 129 ExperienceSamplingEvent::kDownloadDangerPrompt, |
| 129 item->GetURL(), | 130 item->GetURL(), |
| 130 item->GetReferrerUrl(), | 131 item->GetReferrerUrl(), |
| 131 item->GetBrowserContext())); | 132 item->GetBrowserContext())); |
| 132 } | 133 } |
| 133 | 134 |
| 134 // DownloadDangerPrompt methods: | 135 // DownloadDangerPrompt methods: |
| 135 void DownloadDangerPromptViews::InvokeActionForTesting(Action action) { | 136 std::string DownloadDangerPromptViews::InvokeActionForTesting( |
| 137 Action action, const GURL& url) { |
| 136 switch (action) { | 138 switch (action) { |
| 137 case ACCEPT: | 139 case ACCEPT: |
| 138 Accept(); | 140 Accept(); |
| 139 break; | 141 break; |
| 140 | 142 |
| 141 case CANCEL: | 143 case CANCEL: |
| 142 case DISMISS: | 144 case DISMISS: |
| 143 Cancel(); | 145 Cancel(); |
| 144 break; | 146 break; |
| 145 | 147 |
| 146 default: | 148 default: |
| 147 NOTREACHED(); | 149 NOTREACHED(); |
| 148 break; | 150 break; |
| 149 } | 151 } |
| 152 |
| 153 return CreateSafeBrowsingDownloadRecoveryReport(action == ACCEPT, url); |
| 150 } | 154 } |
| 151 | 155 |
| 152 // views::DialogDelegate methods: | 156 // views::DialogDelegate methods: |
| 153 base::string16 DownloadDangerPromptViews::GetDialogButtonLabel( | 157 base::string16 DownloadDangerPromptViews::GetDialogButtonLabel( |
| 154 ui::DialogButton button) const { | 158 ui::DialogButton button) const { |
| 155 switch (button) { | 159 switch (button) { |
| 156 case ui::DIALOG_BUTTON_OK: | 160 case ui::DIALOG_BUTTON_OK: |
| 157 return GetAcceptButtonTitle(); | 161 return GetAcceptButtonTitle(); |
| 158 | 162 |
| 159 case ui::DIALOG_BUTTON_CANCEL: | 163 case ui::DIALOG_BUTTON_CANCEL: |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 NOTREACHED(); | 330 NOTREACHED(); |
| 327 return base::string16(); | 331 return base::string16(); |
| 328 } | 332 } |
| 329 | 333 |
| 330 void DownloadDangerPromptViews::RunDone(Action action) { | 334 void DownloadDangerPromptViews::RunDone(Action action) { |
| 331 // Invoking the callback can cause the download item state to change or cause | 335 // Invoking the callback can cause the download item state to change or cause |
| 332 // the window to close, and |callback| refers to a member variable. | 336 // the window to close, and |callback| refers to a member variable. |
| 333 OnDone done = done_; | 337 OnDone done = done_; |
| 334 done_.Reset(); | 338 done_.Reset(); |
| 335 if (download_ != NULL) { | 339 if (download_ != NULL) { |
| 340 if (!download_->GetURL().is_empty()) { |
| 341 std::string report = CreateSafeBrowsingDownloadRecoveryReport( |
| 342 action == DownloadDangerPrompt::ACCEPT, download_->GetURL()); |
| 343 if (!report.empty()) |
| 344 SendSerializedReport(report); |
| 345 } |
| 336 download_->RemoveObserver(this); | 346 download_->RemoveObserver(this); |
| 337 download_ = NULL; | 347 download_ = NULL; |
| 338 } | 348 } |
| 339 if (!done.is_null()) | 349 if (!done.is_null()) |
| 340 done.Run(action); | 350 done.Run(action); |
| 341 } | 351 } |
| 342 | 352 |
| 343 } // namespace | 353 } // namespace |
| 344 | 354 |
| 345 DownloadDangerPrompt* DownloadDangerPrompt::Create( | 355 DownloadDangerPrompt* DownloadDangerPrompt::Create( |
| 346 content::DownloadItem* item, | 356 content::DownloadItem* item, |
| 347 content::WebContents* web_contents, | 357 content::WebContents* web_contents, |
| 348 bool show_context, | 358 bool show_context, |
| 349 const OnDone& done) { | 359 const OnDone& done) { |
| 350 DownloadDangerPromptViews* download_danger_prompt = | 360 DownloadDangerPromptViews* download_danger_prompt = |
| 351 new DownloadDangerPromptViews(item, show_context, done); | 361 new DownloadDangerPromptViews(item, show_context, done); |
| 352 constrained_window::ShowWebModalDialogViews(download_danger_prompt, | 362 constrained_window::ShowWebModalDialogViews(download_danger_prompt, |
| 353 web_contents); | 363 web_contents); |
| 354 return download_danger_prompt; | 364 return download_danger_prompt; |
| 355 } | 365 } |
| OLD | NEW |