OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/webview/web_dialog_view.h" | 5 #include "ui/views/controls/webview/web_dialog_view.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 using content::WebUIMessageHandler; | 29 using content::WebUIMessageHandler; |
30 using ui::WebDialogDelegate; | 30 using ui::WebDialogDelegate; |
31 using ui::WebDialogUI; | 31 using ui::WebDialogUI; |
32 using ui::WebDialogWebContentsDelegate; | 32 using ui::WebDialogWebContentsDelegate; |
33 | 33 |
34 namespace views { | 34 namespace views { |
35 | 35 |
36 //////////////////////////////////////////////////////////////////////////////// | 36 //////////////////////////////////////////////////////////////////////////////// |
37 // WebDialogView, public: | 37 // WebDialogView, public: |
38 | 38 |
39 WebDialogView::WebDialogView( | 39 WebDialogView::WebDialogView(content::BrowserContext* context, |
40 content::BrowserContext* context, | 40 WebDialogDelegate* delegate, |
41 WebDialogDelegate* delegate, | 41 WebContentsHandler* handler) |
42 WebContentsHandler* handler) | 42 : ClientView(nullptr, nullptr), |
43 : ClientView(NULL, NULL), | |
44 WebDialogWebContentsDelegate(context, handler), | 43 WebDialogWebContentsDelegate(context, handler), |
45 delegate_(delegate), | 44 delegate_(delegate), |
46 web_view_(new views::WebView(context)), | 45 web_view_(new views::WebView(context)) { |
47 is_attempting_close_dialog_(false), | |
48 before_unload_fired_(false), | |
49 closed_via_webui_(false), | |
50 close_contents_called_(false) { | |
51 web_view_->set_allow_accelerators(true); | 46 web_view_->set_allow_accelerators(true); |
52 AddChildView(web_view_); | 47 AddChildView(web_view_); |
53 set_contents_view(web_view_); | 48 set_contents_view(web_view_); |
54 SetLayoutManager(new views::FillLayout); | 49 SetLayoutManager(new views::FillLayout); |
55 // Pressing the ESC key will close the dialog. | 50 // Pressing the ESC key will close the dialog. |
56 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 51 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 52 |
| 53 if (delegate_) { |
| 54 for (const auto& accelerator : delegate_->GetAccelerators()) |
| 55 AddAccelerator(accelerator); |
| 56 } |
57 } | 57 } |
58 | 58 |
59 WebDialogView::~WebDialogView() { | 59 WebDialogView::~WebDialogView() { |
60 } | 60 } |
61 | 61 |
62 content::WebContents* WebDialogView::web_contents() { | 62 content::WebContents* WebDialogView::web_contents() { |
63 return web_view_->web_contents(); | 63 return web_view_->web_contents(); |
64 } | 64 } |
65 | 65 |
66 //////////////////////////////////////////////////////////////////////////////// | 66 //////////////////////////////////////////////////////////////////////////////// |
67 // WebDialogView, views::View implementation: | 67 // WebDialogView, views::View implementation: |
68 | 68 |
69 gfx::Size WebDialogView::GetPreferredSize() const { | 69 gfx::Size WebDialogView::GetPreferredSize() const { |
70 gfx::Size out; | 70 gfx::Size out; |
71 if (delegate_) | 71 if (delegate_) |
72 delegate_->GetDialogSize(&out); | 72 delegate_->GetDialogSize(&out); |
73 return out; | 73 return out; |
74 } | 74 } |
75 | 75 |
76 gfx::Size WebDialogView::GetMinimumSize() const { | 76 gfx::Size WebDialogView::GetMinimumSize() const { |
77 gfx::Size out; | 77 gfx::Size out; |
78 if (delegate_) | 78 if (delegate_) |
79 delegate_->GetMinimumDialogSize(&out); | 79 delegate_->GetMinimumDialogSize(&out); |
80 return out; | 80 return out; |
81 } | 81 } |
82 | 82 |
83 bool WebDialogView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 83 bool WebDialogView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 84 if (delegate_ && delegate_->AcceleratorPressed(accelerator)) |
| 85 return true; |
| 86 |
84 // Pressing ESC closes the dialog. | 87 // Pressing ESC closes the dialog. |
85 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 88 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); |
86 if (GetWidget()) | 89 if (GetWidget()) |
87 GetWidget()->Close(); | 90 GetWidget()->Close(); |
88 return true; | 91 return true; |
89 } | 92 } |
90 | 93 |
91 void WebDialogView::ViewHierarchyChanged( | 94 void WebDialogView::ViewHierarchyChanged( |
92 const ViewHierarchyChangedDetails& details) { | 95 const ViewHierarchyChangedDetails& details) { |
93 if (details.is_add && GetWidget()) | 96 if (details.is_add && GetWidget()) |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 if (delegate_) { | 230 if (delegate_) { |
228 // Store the dialog content area size. | 231 // Store the dialog content area size. |
229 delegate_->StoreDialogSize(GetContentsBounds().size()); | 232 delegate_->StoreDialogSize(GetContentsBounds().size()); |
230 } | 233 } |
231 | 234 |
232 if (GetWidget()) | 235 if (GetWidget()) |
233 GetWidget()->Close(); | 236 GetWidget()->Close(); |
234 | 237 |
235 if (delegate_) { | 238 if (delegate_) { |
236 delegate_->OnDialogClosed(json_retval); | 239 delegate_->OnDialogClosed(json_retval); |
237 delegate_ = NULL; // We will not communicate further with the delegate. | 240 delegate_ = nullptr; // We will not communicate further with the delegate. |
238 } | 241 } |
239 } | 242 } |
240 | 243 |
241 void WebDialogView::OnDialogCloseFromWebUI(const std::string& json_retval) { | 244 void WebDialogView::OnDialogCloseFromWebUI(const std::string& json_retval) { |
242 closed_via_webui_ = true; | 245 closed_via_webui_ = true; |
243 dialog_close_retval_ = json_retval; | 246 dialog_close_retval_ = json_retval; |
244 if (GetWidget()) | 247 if (GetWidget()) |
245 GetWidget()->Close(); | 248 GetWidget()->Close(); |
246 } | 249 } |
247 | 250 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 close_contents_called_ = true; | 292 close_contents_called_ = true; |
290 bool close_dialog = false; | 293 bool close_dialog = false; |
291 OnCloseContents(source, &close_dialog); | 294 OnCloseContents(source, &close_dialog); |
292 if (close_dialog) | 295 if (close_dialog) |
293 OnDialogClosed(closed_via_webui_ ? dialog_close_retval_ : std::string()); | 296 OnDialogClosed(closed_via_webui_ ? dialog_close_retval_ : std::string()); |
294 } | 297 } |
295 | 298 |
296 content::WebContents* WebDialogView::OpenURLFromTab( | 299 content::WebContents* WebDialogView::OpenURLFromTab( |
297 content::WebContents* source, | 300 content::WebContents* source, |
298 const content::OpenURLParams& params) { | 301 const content::OpenURLParams& params) { |
299 content::WebContents* new_contents = NULL; | 302 content::WebContents* new_contents = nullptr; |
300 if (delegate_ && | 303 if (delegate_ && |
301 delegate_->HandleOpenURLFromTab(source, params, &new_contents)) { | 304 delegate_->HandleOpenURLFromTab(source, params, &new_contents)) { |
302 return new_contents; | 305 return new_contents; |
303 } | 306 } |
304 return WebDialogWebContentsDelegate::OpenURLFromTab(source, params); | 307 return WebDialogWebContentsDelegate::OpenURLFromTab(source, params); |
305 } | 308 } |
306 | 309 |
307 void WebDialogView::AddNewContents(content::WebContents* source, | 310 void WebDialogView::AddNewContents(content::WebContents* source, |
308 content::WebContents* new_contents, | 311 content::WebContents* new_contents, |
309 WindowOpenDisposition disposition, | 312 WindowOpenDisposition disposition, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 web_contents->SetDelegate(this); | 363 web_contents->SetDelegate(this); |
361 | 364 |
362 // Set the delegate. This must be done before loading the page. See | 365 // Set the delegate. This must be done before loading the page. See |
363 // the comment above WebDialogUI in its header file for why. | 366 // the comment above WebDialogUI in its header file for why. |
364 WebDialogUI::SetDelegate(web_contents, this); | 367 WebDialogUI::SetDelegate(web_contents, this); |
365 | 368 |
366 web_view_->LoadInitialURL(GetDialogContentURL()); | 369 web_view_->LoadInitialURL(GetDialogContentURL()); |
367 } | 370 } |
368 | 371 |
369 } // namespace views | 372 } // namespace views |
OLD | NEW |