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/ui/views/constrained_window_views.h" | |
9 #include "components/web_modal/web_contents_modal_dialog_host.h" | 8 #include "components/web_modal/web_contents_modal_dialog_host.h" |
10 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 9 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
11 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 10 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
12 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/download_danger_type.h" | 12 #include "content/public/browser/download_danger_type.h" |
14 #include "content/public/browser/download_item.h" | 13 #include "content/public/browser/download_item.h" |
15 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
16 #include "grit/chromium_strings.h" | 15 #include "grit/chromium_strings.h" |
17 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
18 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 | 50 |
52 // views::DialogDelegate methods: | 51 // views::DialogDelegate methods: |
53 virtual base::string16 GetDialogButtonLabel( | 52 virtual base::string16 GetDialogButtonLabel( |
54 ui::DialogButton button) const OVERRIDE; | 53 ui::DialogButton button) const OVERRIDE; |
55 virtual base::string16 GetWindowTitle() const OVERRIDE; | 54 virtual base::string16 GetWindowTitle() const OVERRIDE; |
56 virtual void DeleteDelegate() OVERRIDE; | 55 virtual void DeleteDelegate() OVERRIDE; |
57 virtual ui::ModalType GetModalType() const OVERRIDE; | 56 virtual ui::ModalType GetModalType() const OVERRIDE; |
58 virtual bool Cancel() OVERRIDE; | 57 virtual bool Cancel() OVERRIDE; |
59 virtual bool Accept() OVERRIDE; | 58 virtual bool Accept() OVERRIDE; |
60 virtual bool Close() OVERRIDE; | 59 virtual bool Close() OVERRIDE; |
61 // TODO(wittman): Remove this override once we move to the new style frame | |
62 // view on all dialogs. | |
63 virtual views::NonClientFrameView* CreateNonClientFrameView( | |
64 views::Widget* widget) OVERRIDE; | |
65 virtual views::View* GetInitiallyFocusedView() OVERRIDE; | 60 virtual views::View* GetInitiallyFocusedView() OVERRIDE; |
66 virtual views::View* GetContentsView() OVERRIDE; | 61 virtual views::View* GetContentsView() OVERRIDE; |
67 virtual views::Widget* GetWidget() OVERRIDE; | 62 virtual views::Widget* GetWidget() OVERRIDE; |
68 virtual const views::Widget* GetWidget() const OVERRIDE; | 63 virtual const views::Widget* GetWidget() const OVERRIDE; |
69 | 64 |
70 // content::DownloadItem::Observer: | 65 // content::DownloadItem::Observer: |
71 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; | 66 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; |
72 | 67 |
73 private: | 68 private: |
74 base::string16 GetAcceptButtonTitle() const; | 69 base::string16 GetAcceptButtonTitle() const; |
75 base::string16 GetCancelButtonTitle() const; | 70 base::string16 GetCancelButtonTitle() const; |
76 // The message lead is separated from the main text and is bolded. | 71 // The message lead is separated from the main text and is bolded. |
77 base::string16 GetMessageLead() const; | 72 base::string16 GetMessageLead() const; |
78 base::string16 GetMessageBody() const; | 73 base::string16 GetMessageBody() const; |
79 void RunDone(Action action); | 74 void RunDone(Action action); |
80 | 75 |
81 content::DownloadItem* download_; | 76 content::DownloadItem* download_; |
82 content::WebContents* web_contents_; | 77 content::WebContents* web_contents_; |
msw
2014/02/10 19:21:15
nit: this member (and its corresponding ctor param
Lei Zhang
2014/02/10 23:21:42
Done.
| |
83 bool show_context_; | 78 bool show_context_; |
84 OnDone done_; | 79 OnDone done_; |
85 | 80 |
86 views::View* contents_view_; | 81 views::View* contents_view_; |
87 }; | 82 }; |
88 | 83 |
89 DownloadDangerPromptViews::DownloadDangerPromptViews( | 84 DownloadDangerPromptViews::DownloadDangerPromptViews( |
90 content::DownloadItem* item, | 85 content::DownloadItem* item, |
91 content::WebContents* web_contents, | 86 content::WebContents* web_contents, |
92 bool show_context, | 87 bool show_context, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 return true; | 198 return true; |
204 } | 199 } |
205 | 200 |
206 bool DownloadDangerPromptViews::Close() { | 201 bool DownloadDangerPromptViews::Close() { |
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
208 | 203 |
209 RunDone(DISMISS); | 204 RunDone(DISMISS); |
210 return true; | 205 return true; |
211 } | 206 } |
212 | 207 |
213 // TODO(wittman): Remove this override once we move to the new style frame | |
214 // view on all dialogs. | |
215 views::NonClientFrameView* DownloadDangerPromptViews::CreateNonClientFrameView( | |
216 views::Widget* widget) { | |
217 return CreateConstrainedStyleNonClientFrameView( | |
218 widget, web_contents_->GetBrowserContext()); | |
219 } | |
220 | |
221 views::View* DownloadDangerPromptViews::GetInitiallyFocusedView() { | 208 views::View* DownloadDangerPromptViews::GetInitiallyFocusedView() { |
222 return GetDialogClientView()->cancel_button(); | 209 return GetDialogClientView()->cancel_button(); |
223 } | 210 } |
224 | 211 |
225 views::View* DownloadDangerPromptViews::GetContentsView() { | 212 views::View* DownloadDangerPromptViews::GetContentsView() { |
226 return contents_view_; | 213 return contents_view_; |
227 } | 214 } |
228 | 215 |
229 views::Widget* DownloadDangerPromptViews::GetWidget() { | 216 views::Widget* DownloadDangerPromptViews::GetWidget() { |
230 return contents_view_->GetWidget(); | 217 return contents_view_->GetWidget(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 } | 279 } |
293 | 280 |
294 base::string16 DownloadDangerPromptViews::GetMessageBody() const { | 281 base::string16 DownloadDangerPromptViews::GetMessageBody() const { |
295 if (show_context_) { | 282 if (show_context_) { |
296 switch (download_->GetDangerType()) { | 283 switch (download_->GetDangerType()) { |
297 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: { | 284 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: { |
298 return l10n_util::GetStringFUTF16( | 285 return l10n_util::GetStringFUTF16( |
299 IDS_PROMPT_DANGEROUS_DOWNLOAD, | 286 IDS_PROMPT_DANGEROUS_DOWNLOAD, |
300 download_->GetFileNameToReportUser().LossyDisplayName()); | 287 download_->GetFileNameToReportUser().LossyDisplayName()); |
301 } | 288 } |
302 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: // Fall through | 289 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: // Fall through |
303 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 290 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
304 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { | 291 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { |
305 return l10n_util::GetStringFUTF16( | 292 return l10n_util::GetStringFUTF16( |
306 IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT, | 293 IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT, |
307 download_->GetFileNameToReportUser().LossyDisplayName()); | 294 download_->GetFileNameToReportUser().LossyDisplayName()); |
308 } | 295 } |
309 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: { | 296 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: { |
310 return l10n_util::GetStringFUTF16( | 297 return l10n_util::GetStringFUTF16( |
311 IDS_PROMPT_UNCOMMON_DOWNLOAD_CONTENT, | 298 IDS_PROMPT_UNCOMMON_DOWNLOAD_CONTENT, |
312 download_->GetFileNameToReportUser().LossyDisplayName()); | 299 download_->GetFileNameToReportUser().LossyDisplayName()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 WebContentsModalDialogManagerDelegate* modal_delegate = | 356 WebContentsModalDialogManagerDelegate* modal_delegate = |
370 web_contents_modal_dialog_manager->delegate(); | 357 web_contents_modal_dialog_manager->delegate(); |
371 CHECK(modal_delegate); | 358 CHECK(modal_delegate); |
372 views::Widget* dialog = views::Widget::CreateWindowAsFramelessChild( | 359 views::Widget* dialog = views::Widget::CreateWindowAsFramelessChild( |
373 download_danger_prompt, | 360 download_danger_prompt, |
374 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | 361 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
375 web_contents_modal_dialog_manager->ShowDialog(dialog->GetNativeView()); | 362 web_contents_modal_dialog_manager->ShowDialog(dialog->GetNativeView()); |
376 | 363 |
377 return download_danger_prompt; | 364 return download_danger_prompt; |
378 } | 365 } |
OLD | NEW |