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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 | |
|
msw
2015/11/13 19:01:28
Remove this blank line or just put download_danger
Jialiu Lin
2015/11/13 23:47:01
oops, sorry
| |
| 6 #include "chrome/browser/download/download_danger_prompt.h" | 7 #include "chrome/browser/download/download_danger_prompt.h" |
| 7 #include "chrome/browser/download/download_stats.h" | 8 #include "chrome/browser/download/download_stats.h" |
| 8 #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" |
| 9 #include "chrome/grit/chromium_strings.h" | 10 #include "chrome/grit/chromium_strings.h" |
| 10 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 11 #include "components/constrained_window/constrained_window_views.h" | 12 #include "components/constrained_window/constrained_window_views.h" |
| 12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/download_danger_type.h" | 14 #include "content/public/browser/download_danger_type.h" |
| 14 #include "content/public/browser/download_item.h" | 15 #include "content/public/browser/download_item.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 34 // formatting on the text in the body of the dialog. | 35 // formatting on the text in the body of the dialog. |
| 35 class DownloadDangerPromptViews : public DownloadDangerPrompt, | 36 class DownloadDangerPromptViews : public DownloadDangerPrompt, |
| 36 public content::DownloadItem::Observer, | 37 public content::DownloadItem::Observer, |
| 37 public views::DialogDelegate { | 38 public views::DialogDelegate { |
| 38 public: | 39 public: |
| 39 DownloadDangerPromptViews(content::DownloadItem* item, | 40 DownloadDangerPromptViews(content::DownloadItem* item, |
| 40 bool show_context, | 41 bool show_context, |
| 41 const OnDone& done); | 42 const OnDone& done); |
| 42 | 43 |
| 43 // DownloadDangerPrompt methods: | 44 // DownloadDangerPrompt methods: |
| 44 void InvokeActionForTesting(Action action) override; | 45 std::string InvokeActionForTesting(Action action, |
| 46 const GURL& testing_url) override; | |
|
msw
2015/11/13 19:01:28
nit: use |url| here and below to match the base cl
Jialiu Lin
2015/11/13 23:47:01
Done.
| |
| 45 | 47 |
| 46 // views::DialogDelegate methods: | 48 // views::DialogDelegate methods: |
| 47 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | 49 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; |
| 48 base::string16 GetWindowTitle() const override; | 50 base::string16 GetWindowTitle() const override; |
| 49 void DeleteDelegate() override; | 51 void DeleteDelegate() override; |
| 50 ui::ModalType GetModalType() const override; | 52 ui::ModalType GetModalType() const override; |
| 51 bool Cancel() override; | 53 bool Cancel() override; |
| 52 bool Accept() override; | 54 bool Accept() override; |
| 53 bool Close() override; | 55 bool Close() override; |
| 54 views::View* GetInitiallyFocusedView() override; | 56 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 | 127 // ExperienceSampling: A malicious download warning is being shown to the |
| 126 // user, so we start a new SamplingEvent and track it. | 128 // user, so we start a new SamplingEvent and track it. |
| 127 sampling_event_.reset(new ExperienceSamplingEvent( | 129 sampling_event_.reset(new ExperienceSamplingEvent( |
| 128 ExperienceSamplingEvent::kDownloadDangerPrompt, | 130 ExperienceSamplingEvent::kDownloadDangerPrompt, |
| 129 item->GetURL(), | 131 item->GetURL(), |
| 130 item->GetReferrerUrl(), | 132 item->GetReferrerUrl(), |
| 131 item->GetBrowserContext())); | 133 item->GetBrowserContext())); |
| 132 } | 134 } |
| 133 | 135 |
| 134 // DownloadDangerPrompt methods: | 136 // DownloadDangerPrompt methods: |
| 135 void DownloadDangerPromptViews::InvokeActionForTesting(Action action) { | 137 std::string DownloadDangerPromptViews::InvokeActionForTesting( |
|
msw
2015/11/13 19:01:28
This looks like a near-copy of DownloadDangerPromp
Jialiu Lin
2015/11/13 23:47:00
They looks like the same, however, the Accept() in
msw
2015/11/17 01:17:37
This is troubling... someone more familiar here sh
msw
2015/11/17 18:54:40
My approval is gated on someone familiar with this
Jialiu Lin
2015/11/17 19:13:53
asanka (already in reviewer list) would be the exp
| |
| 138 Action action, | |
| 139 const GURL& testing_url) { | |
| 136 switch (action) { | 140 switch (action) { |
| 137 case ACCEPT: | 141 case ACCEPT: |
| 138 Accept(); | 142 Accept(); |
| 139 break; | 143 break; |
| 140 | 144 |
| 141 case CANCEL: | 145 case CANCEL: |
| 142 case DISMISS: | 146 case DISMISS: |
| 143 Cancel(); | 147 Cancel(); |
| 144 break; | 148 break; |
| 145 | 149 |
| 146 default: | 150 default: |
| 147 NOTREACHED(); | 151 NOTREACHED(); |
| 148 break; | 152 break; |
| 149 } | 153 } |
| 154 | |
| 155 return CreateSafeBrowsingDownloadRecoveryReport(action == ACCEPT, | |
| 156 testing_url); | |
| 150 } | 157 } |
| 151 | 158 |
| 152 // views::DialogDelegate methods: | 159 // views::DialogDelegate methods: |
| 153 base::string16 DownloadDangerPromptViews::GetDialogButtonLabel( | 160 base::string16 DownloadDangerPromptViews::GetDialogButtonLabel( |
| 154 ui::DialogButton button) const { | 161 ui::DialogButton button) const { |
| 155 switch (button) { | 162 switch (button) { |
| 156 case ui::DIALOG_BUTTON_OK: | 163 case ui::DIALOG_BUTTON_OK: |
| 157 return GetAcceptButtonTitle(); | 164 return GetAcceptButtonTitle(); |
| 158 | 165 |
| 159 case ui::DIALOG_BUTTON_CANCEL: | 166 case ui::DIALOG_BUTTON_CANCEL: |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 default: { | 327 default: { |
| 321 return l10n_util::GetStringUTF16( | 328 return l10n_util::GetStringUTF16( |
| 322 IDS_PROMPT_CONFIRM_KEEP_DANGEROUS_DOWNLOAD); | 329 IDS_PROMPT_CONFIRM_KEEP_DANGEROUS_DOWNLOAD); |
| 323 } | 330 } |
| 324 } | 331 } |
| 325 } | 332 } |
| 326 NOTREACHED(); | 333 NOTREACHED(); |
| 327 return base::string16(); | 334 return base::string16(); |
| 328 } | 335 } |
| 329 | 336 |
| 330 void DownloadDangerPromptViews::RunDone(Action action) { | 337 void DownloadDangerPromptViews::RunDone(Action action) { |
|
msw
2015/11/13 19:01:28
Why does this have the same exact impl as Download
Jialiu Lin
2015/11/13 23:47:01
Very hard to move this function to parent class, u
| |
| 331 // Invoking the callback can cause the download item state to change or cause | 338 // 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. | 339 // the window to close, and |callback| refers to a member variable. |
| 333 OnDone done = done_; | 340 OnDone done = done_; |
| 334 done_.Reset(); | 341 done_.Reset(); |
| 335 if (download_ != NULL) { | 342 if (download_ != NULL) { |
| 343 if (download_->GetURL() != GURL::EmptyGURL()) { | |
|
msw
2015/11/13 19:01:28
nit: use GURL::is_empty()
Jialiu Lin
2015/11/13 23:47:00
Done.
| |
| 344 std::string report = CreateSafeBrowsingDownloadRecoveryReport( | |
| 345 action == DownloadDangerPrompt::ACCEPT, download_->GetURL()); | |
| 346 if (!report.empty()) | |
| 347 SendSerializedReport(report); | |
| 348 } | |
| 336 download_->RemoveObserver(this); | 349 download_->RemoveObserver(this); |
| 337 download_ = NULL; | 350 download_ = NULL; |
| 338 } | 351 } |
| 339 if (!done.is_null()) | 352 if (!done.is_null()) |
| 340 done.Run(action); | 353 done.Run(action); |
| 341 } | 354 } |
| 342 | 355 |
| 343 } // namespace | 356 } // namespace |
| 344 | 357 |
| 345 DownloadDangerPrompt* DownloadDangerPrompt::Create( | 358 DownloadDangerPrompt* DownloadDangerPrompt::Create( |
| 346 content::DownloadItem* item, | 359 content::DownloadItem* item, |
| 347 content::WebContents* web_contents, | 360 content::WebContents* web_contents, |
| 348 bool show_context, | 361 bool show_context, |
| 349 const OnDone& done) { | 362 const OnDone& done) { |
| 350 DownloadDangerPromptViews* download_danger_prompt = | 363 DownloadDangerPromptViews* download_danger_prompt = |
| 351 new DownloadDangerPromptViews(item, show_context, done); | 364 new DownloadDangerPromptViews(item, show_context, done); |
| 352 constrained_window::ShowWebModalDialogViews(download_danger_prompt, | 365 constrained_window::ShowWebModalDialogViews(download_danger_prompt, |
| 353 web_contents); | 366 web_contents); |
| 354 return download_danger_prompt; | 367 return download_danger_prompt; |
| 355 } | 368 } |
| OLD | NEW |