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 "components/web_modal/web_contents_modal_dialog_host.h" | 8 #include "chrome/browser/ui/views/constrained_window_views.h" |
9 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
10 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | |
11 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/download_danger_type.h" | 10 #include "content/public/browser/download_danger_type.h" |
13 #include "content/public/browser/download_item.h" | 11 #include "content/public/browser/download_item.h" |
14 #include "content/public/browser/web_contents.h" | |
15 #include "grit/chromium_strings.h" | 12 #include "grit/chromium_strings.h" |
16 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
17 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/views/controls/button/label_button.h" | 16 #include "ui/views/controls/button/label_button.h" |
20 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
21 #include "ui/views/layout/grid_layout.h" | 18 #include "ui/views/layout/grid_layout.h" |
22 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
23 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
24 #include "ui/views/window/dialog_client_view.h" | 21 #include "ui/views/window/dialog_client_view.h" |
25 #include "ui/views/window/dialog_delegate.h" | 22 #include "ui/views/window/dialog_delegate.h" |
26 | 23 |
27 using content::BrowserThread; | |
28 using web_modal::WebContentsModalDialogManager; | |
29 using web_modal::WebContentsModalDialogManagerDelegate; | |
30 | |
31 namespace { | 24 namespace { |
32 | 25 |
33 const int kMessageWidth = 320; | 26 const int kMessageWidth = 320; |
34 const int kParagraphPadding = 15; | 27 const int kParagraphPadding = 15; |
35 | 28 |
36 // Views-specific implementation of download danger prompt dialog. We use this | 29 // Views-specific implementation of download danger prompt dialog. We use this |
37 // class rather than a TabModalConfirmDialog so that we can use custom | 30 // class rather than a TabModalConfirmDialog so that we can use custom |
38 // formatting on the text in the body of the dialog. | 31 // formatting on the text in the body of the dialog. |
39 class DownloadDangerPromptViews : public DownloadDangerPrompt, | 32 class DownloadDangerPromptViews : public DownloadDangerPrompt, |
40 public content::DownloadItem::Observer, | 33 public content::DownloadItem::Observer, |
41 public views::DialogDelegate { | 34 public views::DialogDelegate { |
42 public: | 35 public: |
43 DownloadDangerPromptViews(content::DownloadItem* item, | 36 DownloadDangerPromptViews(content::DownloadItem* item, |
44 content::WebContents* web_contents, | |
45 bool show_context, | 37 bool show_context, |
46 const OnDone& done); | 38 const OnDone& done); |
47 | 39 |
48 // DownloadDangerPrompt methods: | 40 // DownloadDangerPrompt methods: |
49 virtual void InvokeActionForTesting(Action action) OVERRIDE; | 41 virtual void InvokeActionForTesting(Action action) OVERRIDE; |
50 | 42 |
51 // views::DialogDelegate methods: | 43 // views::DialogDelegate methods: |
52 virtual base::string16 GetDialogButtonLabel( | 44 virtual base::string16 GetDialogButtonLabel( |
53 ui::DialogButton button) const OVERRIDE; | 45 ui::DialogButton button) const OVERRIDE; |
54 virtual base::string16 GetWindowTitle() const OVERRIDE; | 46 virtual base::string16 GetWindowTitle() const OVERRIDE; |
(...skipping 20 matching lines...) Expand all Loading... |
75 | 67 |
76 content::DownloadItem* download_; | 68 content::DownloadItem* download_; |
77 bool show_context_; | 69 bool show_context_; |
78 OnDone done_; | 70 OnDone done_; |
79 | 71 |
80 views::View* contents_view_; | 72 views::View* contents_view_; |
81 }; | 73 }; |
82 | 74 |
83 DownloadDangerPromptViews::DownloadDangerPromptViews( | 75 DownloadDangerPromptViews::DownloadDangerPromptViews( |
84 content::DownloadItem* item, | 76 content::DownloadItem* item, |
85 content::WebContents* web_contents, | |
86 bool show_context, | 77 bool show_context, |
87 const OnDone& done) | 78 const OnDone& done) |
88 : download_(item), | 79 : download_(item), |
89 show_context_(show_context), | 80 show_context_(show_context), |
90 done_(done), | 81 done_(done), |
91 contents_view_(NULL) { | 82 contents_view_(NULL) { |
92 DCHECK(!done_.is_null()); | 83 DCHECK(!done_.is_null()); |
93 download_->AddObserver(this); | 84 download_->AddObserver(this); |
94 | 85 |
95 contents_view_ = new views::View; | 86 contents_view_ = new views::View; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 ui::DialogButton button) const { | 142 ui::DialogButton button) const { |
152 switch (button) { | 143 switch (button) { |
153 case ui::DIALOG_BUTTON_OK: | 144 case ui::DIALOG_BUTTON_OK: |
154 return GetAcceptButtonTitle(); | 145 return GetAcceptButtonTitle(); |
155 | 146 |
156 case ui::DIALOG_BUTTON_CANCEL: | 147 case ui::DIALOG_BUTTON_CANCEL: |
157 return GetCancelButtonTitle(); | 148 return GetCancelButtonTitle(); |
158 | 149 |
159 default: | 150 default: |
160 return DialogDelegate::GetDialogButtonLabel(button); | 151 return DialogDelegate::GetDialogButtonLabel(button); |
161 }; | 152 } |
162 } | 153 } |
163 | 154 |
164 base::string16 DownloadDangerPromptViews::GetWindowTitle() const { | 155 base::string16 DownloadDangerPromptViews::GetWindowTitle() const { |
165 if (show_context_) | 156 if (show_context_) |
166 return l10n_util::GetStringUTF16(IDS_CONFIRM_KEEP_DANGEROUS_DOWNLOAD_TITLE); | 157 return l10n_util::GetStringUTF16(IDS_CONFIRM_KEEP_DANGEROUS_DOWNLOAD_TITLE); |
167 else | 158 else |
168 return l10n_util::GetStringUTF16(IDS_RESTORE_KEEP_DANGEROUS_DOWNLOAD_TITLE); | 159 return l10n_util::GetStringUTF16(IDS_RESTORE_KEEP_DANGEROUS_DOWNLOAD_TITLE); |
169 } | 160 } |
170 | 161 |
171 void DownloadDangerPromptViews::DeleteDelegate() { | 162 void DownloadDangerPromptViews::DeleteDelegate() { |
172 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 163 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
173 | |
174 delete this; | 164 delete this; |
175 } | 165 } |
176 | 166 |
177 ui::ModalType DownloadDangerPromptViews::GetModalType() const { | 167 ui::ModalType DownloadDangerPromptViews::GetModalType() const { |
178 #if defined(USE_ASH) | |
179 return ui::MODAL_TYPE_CHILD; | 168 return ui::MODAL_TYPE_CHILD; |
180 #else | |
181 return views::WidgetDelegate::GetModalType(); | |
182 #endif | |
183 } | 169 } |
184 | 170 |
185 bool DownloadDangerPromptViews::Cancel() { | 171 bool DownloadDangerPromptViews::Cancel() { |
186 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 172 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
187 | |
188 RunDone(CANCEL); | 173 RunDone(CANCEL); |
189 return true; | 174 return true; |
190 } | 175 } |
191 | 176 |
192 bool DownloadDangerPromptViews::Accept() { | 177 bool DownloadDangerPromptViews::Accept() { |
193 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
194 | |
195 RunDone(ACCEPT); | 179 RunDone(ACCEPT); |
196 return true; | 180 return true; |
197 } | 181 } |
198 | 182 |
199 bool DownloadDangerPromptViews::Close() { | 183 bool DownloadDangerPromptViews::Close() { |
200 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 184 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
201 | |
202 RunDone(DISMISS); | 185 RunDone(DISMISS); |
203 return true; | 186 return true; |
204 } | 187 } |
205 | 188 |
206 views::View* DownloadDangerPromptViews::GetInitiallyFocusedView() { | 189 views::View* DownloadDangerPromptViews::GetInitiallyFocusedView() { |
207 return GetDialogClientView()->cancel_button(); | 190 return GetDialogClientView()->cancel_button(); |
208 } | 191 } |
209 | 192 |
210 views::View* DownloadDangerPromptViews::GetContentsView() { | 193 views::View* DownloadDangerPromptViews::GetContentsView() { |
211 return contents_view_; | 194 return contents_view_; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 } | 323 } |
341 | 324 |
342 } // namespace | 325 } // namespace |
343 | 326 |
344 DownloadDangerPrompt* DownloadDangerPrompt::Create( | 327 DownloadDangerPrompt* DownloadDangerPrompt::Create( |
345 content::DownloadItem* item, | 328 content::DownloadItem* item, |
346 content::WebContents* web_contents, | 329 content::WebContents* web_contents, |
347 bool show_context, | 330 bool show_context, |
348 const OnDone& done) { | 331 const OnDone& done) { |
349 DownloadDangerPromptViews* download_danger_prompt = | 332 DownloadDangerPromptViews* download_danger_prompt = |
350 new DownloadDangerPromptViews(item, web_contents, show_context, done); | 333 new DownloadDangerPromptViews(item, show_context, done); |
351 | 334 ShowWebModalDialogViews(download_danger_prompt, web_contents); |
352 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | |
353 WebContentsModalDialogManager::FromWebContents(web_contents); | |
354 WebContentsModalDialogManagerDelegate* modal_delegate = | |
355 web_contents_modal_dialog_manager->delegate(); | |
356 CHECK(modal_delegate); | |
357 views::Widget* dialog = views::Widget::CreateWindowAsFramelessChild( | |
358 download_danger_prompt, | |
359 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | |
360 web_contents_modal_dialog_manager->ShowModalDialog( | |
361 dialog->GetNativeView()); | |
362 | |
363 return download_danger_prompt; | 335 return download_danger_prompt; |
364 } | 336 } |
OLD | NEW |