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 #include "chrome/browser/download/download_danger_prompt.h" | |
|
msw
2015/11/17 01:17:38
nit: add a blank line above this.
Jialiu Lin
2015/11/17 02:05:50
Done.
| |
| 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, const GURL& url) override; |
| 45 | 45 |
| 46 // views::DialogDelegate methods: | 46 // views::DialogDelegate methods: |
| 47 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | 47 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; |
| 48 base::string16 GetWindowTitle() const override; | 48 base::string16 GetWindowTitle() const override; |
| 49 void DeleteDelegate() override; | 49 void DeleteDelegate() override; |
| 50 ui::ModalType GetModalType() const override; | 50 ui::ModalType GetModalType() const override; |
| 51 bool Cancel() override; | 51 bool Cancel() override; |
| 52 bool Accept() override; | 52 bool Accept() override; |
| 53 bool Close() override; | 53 bool Close() override; |
| 54 views::View* GetInitiallyFocusedView() override; | 54 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 | 125 // ExperienceSampling: A malicious download warning is being shown to the |
| 126 // user, so we start a new SamplingEvent and track it. | 126 // user, so we start a new SamplingEvent and track it. |
| 127 sampling_event_.reset(new ExperienceSamplingEvent( | 127 sampling_event_.reset(new ExperienceSamplingEvent( |
| 128 ExperienceSamplingEvent::kDownloadDangerPrompt, | 128 ExperienceSamplingEvent::kDownloadDangerPrompt, |
| 129 item->GetURL(), | 129 item->GetURL(), |
| 130 item->GetReferrerUrl(), | 130 item->GetReferrerUrl(), |
| 131 item->GetBrowserContext())); | 131 item->GetBrowserContext())); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // DownloadDangerPrompt methods: | 134 // DownloadDangerPrompt methods: |
| 135 void DownloadDangerPromptViews::InvokeActionForTesting(Action action) { | 135 std::string DownloadDangerPromptViews::InvokeActionForTesting(Action action, |
| 136 const GURL& url) { | |
| 136 switch (action) { | 137 switch (action) { |
| 137 case ACCEPT: | 138 case ACCEPT: |
| 138 Accept(); | 139 Accept(); |
| 139 break; | 140 break; |
| 140 | 141 |
| 141 case CANCEL: | 142 case CANCEL: |
| 142 case DISMISS: | 143 case DISMISS: |
| 143 Cancel(); | 144 Cancel(); |
| 144 break; | 145 break; |
| 145 | 146 |
| 146 default: | 147 default: |
| 147 NOTREACHED(); | 148 NOTREACHED(); |
| 148 break; | 149 break; |
| 149 } | 150 } |
| 151 | |
| 152 return CreateSafeBrowsingDownloadRecoveryReport(action == ACCEPT, url); | |
| 150 } | 153 } |
| 151 | 154 |
| 152 // views::DialogDelegate methods: | 155 // views::DialogDelegate methods: |
| 153 base::string16 DownloadDangerPromptViews::GetDialogButtonLabel( | 156 base::string16 DownloadDangerPromptViews::GetDialogButtonLabel( |
| 154 ui::DialogButton button) const { | 157 ui::DialogButton button) const { |
| 155 switch (button) { | 158 switch (button) { |
| 156 case ui::DIALOG_BUTTON_OK: | 159 case ui::DIALOG_BUTTON_OK: |
| 157 return GetAcceptButtonTitle(); | 160 return GetAcceptButtonTitle(); |
| 158 | 161 |
| 159 case ui::DIALOG_BUTTON_CANCEL: | 162 case ui::DIALOG_BUTTON_CANCEL: |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 NOTREACHED(); | 329 NOTREACHED(); |
| 327 return base::string16(); | 330 return base::string16(); |
| 328 } | 331 } |
| 329 | 332 |
| 330 void DownloadDangerPromptViews::RunDone(Action action) { | 333 void DownloadDangerPromptViews::RunDone(Action action) { |
| 331 // Invoking the callback can cause the download item state to change or cause | 334 // 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. | 335 // the window to close, and |callback| refers to a member variable. |
| 333 OnDone done = done_; | 336 OnDone done = done_; |
| 334 done_.Reset(); | 337 done_.Reset(); |
| 335 if (download_ != NULL) { | 338 if (download_ != NULL) { |
| 339 if (!download_->GetURL().is_empty()) { | |
| 340 std::string report = CreateSafeBrowsingDownloadRecoveryReport( | |
| 341 action == DownloadDangerPrompt::ACCEPT, download_->GetURL()); | |
| 342 if (!report.empty()) | |
| 343 SendSerializedReport(report); | |
| 344 } | |
| 336 download_->RemoveObserver(this); | 345 download_->RemoveObserver(this); |
| 337 download_ = NULL; | 346 download_ = NULL; |
| 338 } | 347 } |
| 339 if (!done.is_null()) | 348 if (!done.is_null()) |
| 340 done.Run(action); | 349 done.Run(action); |
| 341 } | 350 } |
| 342 | 351 |
| 343 } // namespace | 352 } // namespace |
| 344 | 353 |
| 345 DownloadDangerPrompt* DownloadDangerPrompt::Create( | 354 DownloadDangerPrompt* DownloadDangerPrompt::Create( |
| 346 content::DownloadItem* item, | 355 content::DownloadItem* item, |
| 347 content::WebContents* web_contents, | 356 content::WebContents* web_contents, |
| 348 bool show_context, | 357 bool show_context, |
| 349 const OnDone& done) { | 358 const OnDone& done) { |
| 350 DownloadDangerPromptViews* download_danger_prompt = | 359 DownloadDangerPromptViews* download_danger_prompt = |
| 351 new DownloadDangerPromptViews(item, show_context, done); | 360 new DownloadDangerPromptViews(item, show_context, done); |
| 352 constrained_window::ShowWebModalDialogViews(download_danger_prompt, | 361 constrained_window::ShowWebModalDialogViews(download_danger_prompt, |
| 353 web_contents); | 362 web_contents); |
| 354 return download_danger_prompt; | 363 return download_danger_prompt; |
| 355 } | 364 } |
| OLD | NEW |