Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1806)

Side by Side Diff: chrome/browser/ui/cocoa/download/download_danger_prompt_impl.cc

Issue 2029903002: Add token field to ClientSafeBrowsingReportReqeust (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: re-write using GetUserData/SetUserData Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/download/download_stats.h" 9 #include "chrome/browser/download/download_stats.h"
10 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" 10 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h"
11 #include "chrome/browser/safe_browsing/download_protection_service.h"
11 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" 12 #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
12 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" 13 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
13 #include "chrome/grit/chromium_strings.h" 14 #include "chrome/grit/chromium_strings.h"
14 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
15 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/download_danger_type.h" 17 #include "content/public/browser/download_danger_type.h"
17 #include "content/public/browser/download_item.h" 18 #include "content/public/browser/download_item.h"
18 #include "grit/components_strings.h" 19 #include "grit/components_strings.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 using extensions::ExperienceSamplingEvent; 23 using extensions::ExperienceSamplingEvent;
24 using safe_browsing::ClientSafeBrowsingReportRequest;
23 25
24 namespace { 26 namespace {
25 27
26 // TODO(wittman): Create a native web contents modal dialog implementation of 28 // TODO(wittman): Create a native web contents modal dialog implementation of
27 // this dialog for non-Views platforms, to support bold formatting of the 29 // this dialog for non-Views platforms, to support bold formatting of the
28 // message lead. 30 // message lead.
29 31
30 // Implements DownloadDangerPrompt using a TabModalConfirmDialog. 32 // Implements DownloadDangerPrompt using a TabModalConfirmDialog.
31 class DownloadDangerPromptImpl : public DownloadDangerPrompt, 33 class DownloadDangerPromptImpl : public DownloadDangerPrompt,
32 public content::DownloadItem::Observer, 34 public content::DownloadItem::Observer,
(...skipping 17 matching lines...) Expand all
50 base::string16 GetDialogMessage() override; 52 base::string16 GetDialogMessage() override;
51 base::string16 GetAcceptButtonTitle() override; 53 base::string16 GetAcceptButtonTitle() override;
52 base::string16 GetCancelButtonTitle() override; 54 base::string16 GetCancelButtonTitle() override;
53 void OnAccepted() override; 55 void OnAccepted() override;
54 void OnCanceled() override; 56 void OnCanceled() override;
55 void OnClosed() override; 57 void OnClosed() override;
56 58
57 void RunDone(Action action); 59 void RunDone(Action action);
58 60
59 content::DownloadItem* download_; 61 content::DownloadItem* download_;
62 // If show_context_ is true, this is a download confirmation dialog by
63 // download API, otherwise it is download recovery dialog from a regular
64 // download.
60 bool show_context_; 65 bool show_context_;
61 OnDone done_; 66 OnDone done_;
62 67
63 std::unique_ptr<ExperienceSamplingEvent> sampling_event_; 68 std::unique_ptr<ExperienceSamplingEvent> sampling_event_;
64 69
65 DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptImpl); 70 DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptImpl);
66 }; 71 };
67 72
68 DownloadDangerPromptImpl::DownloadDangerPromptImpl( 73 DownloadDangerPromptImpl::DownloadDangerPromptImpl(
69 content::DownloadItem* download, 74 content::DownloadItem* download,
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 OnDone done = done_; 248 OnDone done = done_;
244 done_.Reset(); 249 done_.Reset();
245 if (download_ != NULL) { 250 if (download_ != NULL) {
246 // If this download is no longer dangerous, or is already canceled or 251 // If this download is no longer dangerous, or is already canceled or
247 // completed, don't send any report. 252 // completed, don't send any report.
248 if (download_->IsDangerous() && !download_->IsDone()) { 253 if (download_->IsDangerous() && !download_->IsDone()) {
249 const bool accept = action == DownloadDangerPrompt::ACCEPT; 254 const bool accept = action == DownloadDangerPrompt::ACCEPT;
250 RecordDownloadDangerPrompt(accept, *download_); 255 RecordDownloadDangerPrompt(accept, *download_);
251 if (!download_->GetURL().is_empty() && 256 if (!download_->GetURL().is_empty() &&
252 !download_->GetBrowserContext()->IsOffTheRecord()) { 257 !download_->GetBrowserContext()->IsOffTheRecord()) {
253 SendSafeBrowsingDownloadRecoveryReport(accept, *download_); 258 ClientSafeBrowsingReportRequest::ReportType report_type
259 = show_context_ ?
260 ClientSafeBrowsingReportRequest::DANGEROUS_DOWNLOAD_BY_API :
261 ClientSafeBrowsingReportRequest::DANGEROUS_DOWNLOAD_RECOVERY;
262 SendSafeBrowsingDownloadReport(report_type, accept, *download_);
254 } 263 }
255 } 264 }
256 download_->RemoveObserver(this); 265 download_->RemoveObserver(this);
257 download_ = NULL; 266 download_ = NULL;
258 } 267 }
259 if (!done.is_null()) 268 if (!done.is_null())
260 done.Run(action); 269 done.Run(action);
261 } 270 }
262 271
263 } // namespace 272 } // namespace
264 273
265 // static 274 // static
266 DownloadDangerPrompt* DownloadDangerPrompt::Create( 275 DownloadDangerPrompt* DownloadDangerPrompt::Create(
267 content::DownloadItem* item, 276 content::DownloadItem* item,
268 content::WebContents* web_contents, 277 content::WebContents* web_contents,
269 bool show_context, 278 bool show_context,
270 const OnDone& done) { 279 const OnDone& done) {
271 DownloadDangerPromptImpl* prompt = 280 DownloadDangerPromptImpl* prompt =
272 new DownloadDangerPromptImpl(item, web_contents, show_context, done); 281 new DownloadDangerPromptImpl(item, web_contents, show_context, done);
273 // |prompt| will be deleted when the dialog is done. 282 // |prompt| will be deleted when the dialog is done.
274 TabModalConfirmDialog::Create(prompt, web_contents); 283 TabModalConfirmDialog::Create(prompt, web_contents);
275 return prompt; 284 return prompt;
276 } 285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698