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 #include "chrome/browser/download/download_danger_prompt.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/ui/views/constrained_window_views.h" | 9 #include "chrome/browser/ui/views/constrained_window_views.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 "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/download_danger_type.h" | 13 #include "content/public/browser/download_danger_type.h" |
13 #include "content/public/browser/download_item.h" | 14 #include "content/public/browser/download_item.h" |
14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/views/controls/button/label_button.h" | 17 #include "ui/views/controls/button/label_button.h" |
17 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
18 #include "ui/views/layout/grid_layout.h" | 19 #include "ui/views/layout/grid_layout.h" |
19 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
21 #include "ui/views/window/dialog_client_view.h" | 22 #include "ui/views/window/dialog_client_view.h" |
22 #include "ui/views/window/dialog_delegate.h" | 23 #include "ui/views/window/dialog_delegate.h" |
23 | 24 |
| 25 using extensions::ExperienceSamplingEvent; |
| 26 |
24 namespace { | 27 namespace { |
25 | 28 |
26 const int kMessageWidth = 320; | 29 const int kMessageWidth = 320; |
27 const int kParagraphPadding = 15; | 30 const int kParagraphPadding = 15; |
28 | 31 |
29 // Views-specific implementation of download danger prompt dialog. We use this | 32 // Views-specific implementation of download danger prompt dialog. We use this |
30 // class rather than a TabModalConfirmDialog so that we can use custom | 33 // class rather than a TabModalConfirmDialog so that we can use custom |
31 // formatting on the text in the body of the dialog. | 34 // formatting on the text in the body of the dialog. |
32 class DownloadDangerPromptViews : public DownloadDangerPrompt, | 35 class DownloadDangerPromptViews : public DownloadDangerPrompt, |
33 public content::DownloadItem::Observer, | 36 public content::DownloadItem::Observer, |
(...skipping 28 matching lines...) Expand all Loading... |
62 base::string16 GetCancelButtonTitle() const; | 65 base::string16 GetCancelButtonTitle() const; |
63 // The message lead is separated from the main text and is bolded. | 66 // The message lead is separated from the main text and is bolded. |
64 base::string16 GetMessageLead() const; | 67 base::string16 GetMessageLead() const; |
65 base::string16 GetMessageBody() const; | 68 base::string16 GetMessageBody() const; |
66 void RunDone(Action action); | 69 void RunDone(Action action); |
67 | 70 |
68 content::DownloadItem* download_; | 71 content::DownloadItem* download_; |
69 bool show_context_; | 72 bool show_context_; |
70 OnDone done_; | 73 OnDone done_; |
71 | 74 |
| 75 scoped_ptr<ExperienceSamplingEvent> sampling_event_; |
| 76 |
72 views::View* contents_view_; | 77 views::View* contents_view_; |
73 }; | 78 }; |
74 | 79 |
75 DownloadDangerPromptViews::DownloadDangerPromptViews( | 80 DownloadDangerPromptViews::DownloadDangerPromptViews( |
76 content::DownloadItem* item, | 81 content::DownloadItem* item, |
77 bool show_context, | 82 bool show_context, |
78 const OnDone& done) | 83 const OnDone& done) |
79 : download_(item), | 84 : download_(item), |
80 show_context_(show_context), | 85 show_context_(show_context), |
81 done_(done), | 86 done_(done), |
(...skipping 28 matching lines...) Expand all Loading... |
110 | 115 |
111 views::Label* message_body_label = new views::Label(GetMessageBody()); | 116 views::Label* message_body_label = new views::Label(GetMessageBody()); |
112 message_body_label->SetMultiLine(true); | 117 message_body_label->SetMultiLine(true); |
113 message_body_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 118 message_body_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
114 message_body_label->SetAllowCharacterBreak(true); | 119 message_body_label->SetAllowCharacterBreak(true); |
115 | 120 |
116 layout->StartRow(0, 0); | 121 layout->StartRow(0, 0); |
117 layout->AddView(message_body_label); | 122 layout->AddView(message_body_label); |
118 | 123 |
119 RecordOpenedDangerousConfirmDialog(download_->GetDangerType()); | 124 RecordOpenedDangerousConfirmDialog(download_->GetDangerType()); |
| 125 |
| 126 // ExperienceSampling: A malicious download warning is being shown to the |
| 127 // user, so we start a new SamplingEvent and track it. |
| 128 sampling_event_.reset(new ExperienceSamplingEvent( |
| 129 ExperienceSamplingEvent::kDownloadDangerPrompt, |
| 130 item->GetURL(), |
| 131 item->GetReferrerUrl(), |
| 132 item->GetBrowserContext())); |
120 } | 133 } |
121 | 134 |
122 // DownloadDangerPrompt methods: | 135 // DownloadDangerPrompt methods: |
123 void DownloadDangerPromptViews::InvokeActionForTesting(Action action) { | 136 void DownloadDangerPromptViews::InvokeActionForTesting(Action action) { |
124 switch (action) { | 137 switch (action) { |
125 case ACCEPT: | 138 case ACCEPT: |
126 Accept(); | 139 Accept(); |
127 break; | 140 break; |
128 | 141 |
129 case CANCEL: | 142 case CANCEL: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 176 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
164 delete this; | 177 delete this; |
165 } | 178 } |
166 | 179 |
167 ui::ModalType DownloadDangerPromptViews::GetModalType() const { | 180 ui::ModalType DownloadDangerPromptViews::GetModalType() const { |
168 return ui::MODAL_TYPE_CHILD; | 181 return ui::MODAL_TYPE_CHILD; |
169 } | 182 } |
170 | 183 |
171 bool DownloadDangerPromptViews::Cancel() { | 184 bool DownloadDangerPromptViews::Cancel() { |
172 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 185 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 186 // ExperienceSampling: User canceled the warning. |
| 187 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); |
173 RunDone(CANCEL); | 188 RunDone(CANCEL); |
174 return true; | 189 return true; |
175 } | 190 } |
176 | 191 |
177 bool DownloadDangerPromptViews::Accept() { | 192 bool DownloadDangerPromptViews::Accept() { |
178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 193 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 194 // ExperienceSampling: User proceeded through the warning. |
| 195 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); |
179 RunDone(ACCEPT); | 196 RunDone(ACCEPT); |
180 return true; | 197 return true; |
181 } | 198 } |
182 | 199 |
183 bool DownloadDangerPromptViews::Close() { | 200 bool DownloadDangerPromptViews::Close() { |
184 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 201 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 202 // ExperienceSampling: User canceled the warning. |
| 203 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); |
185 RunDone(DISMISS); | 204 RunDone(DISMISS); |
186 return true; | 205 return true; |
187 } | 206 } |
188 | 207 |
189 views::View* DownloadDangerPromptViews::GetInitiallyFocusedView() { | 208 views::View* DownloadDangerPromptViews::GetInitiallyFocusedView() { |
190 return GetDialogClientView()->cancel_button(); | 209 return GetDialogClientView()->cancel_button(); |
191 } | 210 } |
192 | 211 |
193 views::View* DownloadDangerPromptViews::GetContentsView() { | 212 views::View* DownloadDangerPromptViews::GetContentsView() { |
194 return contents_view_; | 213 return contents_view_; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 DownloadDangerPrompt* DownloadDangerPrompt::Create( | 346 DownloadDangerPrompt* DownloadDangerPrompt::Create( |
328 content::DownloadItem* item, | 347 content::DownloadItem* item, |
329 content::WebContents* web_contents, | 348 content::WebContents* web_contents, |
330 bool show_context, | 349 bool show_context, |
331 const OnDone& done) { | 350 const OnDone& done) { |
332 DownloadDangerPromptViews* download_danger_prompt = | 351 DownloadDangerPromptViews* download_danger_prompt = |
333 new DownloadDangerPromptViews(item, show_context, done); | 352 new DownloadDangerPromptViews(item, show_context, done); |
334 ShowWebModalDialogViews(download_danger_prompt, web_contents); | 353 ShowWebModalDialogViews(download_danger_prompt, web_contents); |
335 return download_danger_prompt; | 354 return download_danger_prompt; |
336 } | 355 } |
OLD | NEW |