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_; | |
83 bool show_context_; | 77 bool show_context_; |
84 OnDone done_; | 78 OnDone done_; |
85 | 79 |
86 views::View* contents_view_; | 80 views::View* contents_view_; |
87 }; | 81 }; |
88 | 82 |
89 DownloadDangerPromptViews::DownloadDangerPromptViews( | 83 DownloadDangerPromptViews::DownloadDangerPromptViews( |
90 content::DownloadItem* item, | 84 content::DownloadItem* item, |
91 content::WebContents* web_contents, | 85 content::WebContents* web_contents, |
92 bool show_context, | 86 bool show_context, |
93 const OnDone& done) | 87 const OnDone& done) |
94 : download_(item), | 88 : download_(item), |
95 web_contents_(web_contents), | |
96 show_context_(show_context), | 89 show_context_(show_context), |
97 done_(done), | 90 done_(done), |
98 contents_view_(NULL) { | 91 contents_view_(NULL) { |
99 DCHECK(!done_.is_null()); | 92 DCHECK(!done_.is_null()); |
100 download_->AddObserver(this); | 93 download_->AddObserver(this); |
101 | 94 |
102 contents_view_ = new views::View; | 95 contents_view_ = new views::View; |
103 | 96 |
104 views::GridLayout* layout = views::GridLayout::CreatePanel(contents_view_); | 97 views::GridLayout* layout = views::GridLayout::CreatePanel(contents_view_); |
105 contents_view_->SetLayoutManager(layout); | 98 contents_view_->SetLayoutManager(layout); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 return true; | 196 return true; |
204 } | 197 } |
205 | 198 |
206 bool DownloadDangerPromptViews::Close() { | 199 bool DownloadDangerPromptViews::Close() { |
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
208 | 201 |
209 RunDone(DISMISS); | 202 RunDone(DISMISS); |
210 return true; | 203 return true; |
211 } | 204 } |
212 | 205 |
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() { | 206 views::View* DownloadDangerPromptViews::GetInitiallyFocusedView() { |
222 return GetDialogClientView()->cancel_button(); | 207 return GetDialogClientView()->cancel_button(); |
223 } | 208 } |
224 | 209 |
225 views::View* DownloadDangerPromptViews::GetContentsView() { | 210 views::View* DownloadDangerPromptViews::GetContentsView() { |
226 return contents_view_; | 211 return contents_view_; |
227 } | 212 } |
228 | 213 |
229 views::Widget* DownloadDangerPromptViews::GetWidget() { | 214 views::Widget* DownloadDangerPromptViews::GetWidget() { |
230 return contents_view_->GetWidget(); | 215 return contents_view_->GetWidget(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 277 } |
293 | 278 |
294 base::string16 DownloadDangerPromptViews::GetMessageBody() const { | 279 base::string16 DownloadDangerPromptViews::GetMessageBody() const { |
295 if (show_context_) { | 280 if (show_context_) { |
296 switch (download_->GetDangerType()) { | 281 switch (download_->GetDangerType()) { |
297 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: { | 282 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: { |
298 return l10n_util::GetStringFUTF16( | 283 return l10n_util::GetStringFUTF16( |
299 IDS_PROMPT_DANGEROUS_DOWNLOAD, | 284 IDS_PROMPT_DANGEROUS_DOWNLOAD, |
300 download_->GetFileNameToReportUser().LossyDisplayName()); | 285 download_->GetFileNameToReportUser().LossyDisplayName()); |
301 } | 286 } |
302 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: // Fall through | 287 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: // Fall through |
303 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 288 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
304 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { | 289 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { |
305 return l10n_util::GetStringFUTF16( | 290 return l10n_util::GetStringFUTF16( |
306 IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT, | 291 IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT, |
307 download_->GetFileNameToReportUser().LossyDisplayName()); | 292 download_->GetFileNameToReportUser().LossyDisplayName()); |
308 } | 293 } |
309 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: { | 294 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: { |
310 return l10n_util::GetStringFUTF16( | 295 return l10n_util::GetStringFUTF16( |
311 IDS_PROMPT_UNCOMMON_DOWNLOAD_CONTENT, | 296 IDS_PROMPT_UNCOMMON_DOWNLOAD_CONTENT, |
312 download_->GetFileNameToReportUser().LossyDisplayName()); | 297 download_->GetFileNameToReportUser().LossyDisplayName()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 WebContentsModalDialogManagerDelegate* modal_delegate = | 354 WebContentsModalDialogManagerDelegate* modal_delegate = |
370 web_contents_modal_dialog_manager->delegate(); | 355 web_contents_modal_dialog_manager->delegate(); |
371 CHECK(modal_delegate); | 356 CHECK(modal_delegate); |
372 views::Widget* dialog = views::Widget::CreateWindowAsFramelessChild( | 357 views::Widget* dialog = views::Widget::CreateWindowAsFramelessChild( |
373 download_danger_prompt, | 358 download_danger_prompt, |
374 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | 359 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
375 web_contents_modal_dialog_manager->ShowDialog(dialog->GetNativeView()); | 360 web_contents_modal_dialog_manager->ShowDialog(dialog->GetNativeView()); |
376 | 361 |
377 return download_danger_prompt; | 362 return download_danger_prompt; |
378 } | 363 } |
OLD | NEW |