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

Side by Side Diff: chrome/browser/ui/views/download/download_danger_prompt_views.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 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"
11 #include "chrome/grit/generated_resources.h" 11 #include "chrome/grit/generated_resources.h"
12 #include "components/constrained_window/constrained_window_views.h" 12 #include "components/constrained_window/constrained_window_views.h"
13 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/download_danger_type.h" 15 #include "content/public/browser/download_danger_type.h"
16 #include "content/public/browser/download_item.h" 16 #include "content/public/browser/download_item.h"
17 #include "grit/components_strings.h" 17 #include "grit/components_strings.h"
18 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/views/controls/button/label_button.h" 20 #include "ui/views/controls/button/label_button.h"
21 #include "ui/views/controls/label.h" 21 #include "ui/views/controls/label.h"
22 #include "ui/views/layout/grid_layout.h" 22 #include "ui/views/layout/grid_layout.h"
23 #include "ui/views/view.h" 23 #include "ui/views/view.h"
24 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
25 #include "ui/views/window/dialog_client_view.h" 25 #include "ui/views/window/dialog_client_view.h"
26 #include "ui/views/window/dialog_delegate.h" 26 #include "ui/views/window/dialog_delegate.h"
27 #include "url/gurl.h" 27 #include "url/gurl.h"
28 28
29 using extensions::ExperienceSamplingEvent; 29 using extensions::ExperienceSamplingEvent;
30 using safe_browsing::ClientSafeBrowsingReportRequest;
30 31
31 namespace { 32 namespace {
32 33
33 const int kMessageWidth = 320; 34 const int kMessageWidth = 320;
34 const int kParagraphPadding = 15; 35 const int kParagraphPadding = 15;
35 36
36 // Views-specific implementation of download danger prompt dialog. We use this 37 // Views-specific implementation of download danger prompt dialog. We use this
37 // class rather than a TabModalConfirmDialog so that we can use custom 38 // class rather than a TabModalConfirmDialog so that we can use custom
38 // formatting on the text in the body of the dialog. 39 // formatting on the text in the body of the dialog.
39 class DownloadDangerPromptViews : public DownloadDangerPrompt, 40 class DownloadDangerPromptViews : public DownloadDangerPrompt,
(...skipping 24 matching lines...) Expand all
64 65
65 private: 66 private:
66 base::string16 GetAcceptButtonTitle() const; 67 base::string16 GetAcceptButtonTitle() const;
67 base::string16 GetCancelButtonTitle() const; 68 base::string16 GetCancelButtonTitle() const;
68 // The message lead is separated from the main text and is bolded. 69 // The message lead is separated from the main text and is bolded.
69 base::string16 GetMessageLead() const; 70 base::string16 GetMessageLead() const;
70 base::string16 GetMessageBody() const; 71 base::string16 GetMessageBody() const;
71 void RunDone(Action action); 72 void RunDone(Action action);
72 73
73 content::DownloadItem* download_; 74 content::DownloadItem* download_;
75 // If show_context_ is true, this is a download confirmation dialog by
76 // download API, otherwise it is download recovery dialog from a regular
77 // download.
74 bool show_context_; 78 bool show_context_;
75 OnDone done_; 79 OnDone done_;
76 80
77 std::unique_ptr<ExperienceSamplingEvent> sampling_event_; 81 std::unique_ptr<ExperienceSamplingEvent> sampling_event_;
78 82
79 views::View* contents_view_; 83 views::View* contents_view_;
80 }; 84 };
81 85
82 DownloadDangerPromptViews::DownloadDangerPromptViews( 86 DownloadDangerPromptViews::DownloadDangerPromptViews(
83 content::DownloadItem* item, 87 content::DownloadItem* item,
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 NOTREACHED(); 327 NOTREACHED();
324 return base::string16(); 328 return base::string16();
325 } 329 }
326 330
327 void DownloadDangerPromptViews::RunDone(Action action) { 331 void DownloadDangerPromptViews::RunDone(Action action) {
328 // Invoking the callback can cause the download item state to change or cause 332 // Invoking the callback can cause the download item state to change or cause
329 // the window to close, and |callback| refers to a member variable. 333 // the window to close, and |callback| refers to a member variable.
330 OnDone done = done_; 334 OnDone done = done_;
331 done_.Reset(); 335 done_.Reset();
332 if (download_ != NULL) { 336 if (download_ != NULL) {
333 // If this download is no longer dangerous, or is already canceled or 337 // If this download is no longer dangerous, is already canceled or
334 // completed, don't send any report. 338 // completed, don't send any report.
335 if (download_->IsDangerous() && !download_->IsDone()) { 339 if (download_->IsDangerous() && !download_->IsDone()) {
336 const bool accept = action == DownloadDangerPrompt::ACCEPT; 340 const bool accept = action == DownloadDangerPrompt::ACCEPT;
337 RecordDownloadDangerPrompt(accept, *download_); 341 RecordDownloadDangerPrompt(accept, *download_);
338 if (!download_->GetURL().is_empty() && 342 if (!download_->GetURL().is_empty() &&
339 !download_->GetBrowserContext()->IsOffTheRecord()) { 343 !download_->GetBrowserContext()->IsOffTheRecord()) {
340 SendSafeBrowsingDownloadRecoveryReport(accept, *download_); 344 ClientSafeBrowsingReportRequest::ReportType report_type
345 = show_context_ ?
346 ClientSafeBrowsingReportRequest::DANGEROUS_DOWNLOAD_BY_API :
347 ClientSafeBrowsingReportRequest::DANGEROUS_DOWNLOAD_RECOVERY;
348 SendSafeBrowsingDownloadReport(report_type, accept, *download_);
341 } 349 }
342 } 350 }
343 download_->RemoveObserver(this); 351 download_->RemoveObserver(this);
344 download_ = NULL; 352 download_ = NULL;
345 } 353 }
346 if (!done.is_null()) 354 if (!done.is_null())
347 done.Run(action); 355 done.Run(action);
348 } 356 }
349 357
350 } // namespace 358 } // namespace
351 359
352 DownloadDangerPrompt* DownloadDangerPrompt::Create( 360 DownloadDangerPrompt* DownloadDangerPrompt::Create(
353 content::DownloadItem* item, 361 content::DownloadItem* item,
354 content::WebContents* web_contents, 362 content::WebContents* web_contents,
355 bool show_context, 363 bool show_context,
356 const OnDone& done) { 364 const OnDone& done) {
357 DownloadDangerPromptViews* download_danger_prompt = 365 DownloadDangerPromptViews* download_danger_prompt =
358 new DownloadDangerPromptViews(item, show_context, done); 366 new DownloadDangerPromptViews(item, show_context, done);
359 constrained_window::ShowWebModalDialogViews(download_danger_prompt, 367 constrained_window::ShowWebModalDialogViews(download_danger_prompt,
360 web_contents); 368 web_contents);
361 return download_danger_prompt; 369 return download_danger_prompt;
362 } 370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698