OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/webui/constrained_html_ui_delegate_impl.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/property_bag.h" | |
10 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/browser/ui/constrained_window.h" | |
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
13 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" | |
14 #include "chrome/browser/ui/webui/html_dialog_ui.h" | |
15 #include "content/public/browser/web_contents.h" | |
16 | |
17 using content::WebContents; | |
18 | |
19 ConstrainedHtmlUIDelegateImpl::ConstrainedHtmlUIDelegateImpl( | |
20 Profile* profile, | |
21 HtmlDialogUIDelegate* delegate, | |
22 HtmlDialogTabContentsDelegate* tab_delegate) | |
23 : HtmlDialogTabContentsDelegate(profile), | |
24 html_delegate_(delegate), | |
25 window_(NULL), | |
26 closed_via_webui_(false), | |
27 release_tab_on_close_(false) { | |
28 CHECK(delegate); | |
29 WebContents* web_contents = | |
30 WebContents::Create(profile, NULL, MSG_ROUTING_NONE, NULL, NULL); | |
31 tab_.reset(new TabContentsWrapper(web_contents)); | |
32 if (tab_delegate) { | |
33 override_tab_delegate_.reset(tab_delegate); | |
34 web_contents->SetDelegate(tab_delegate); | |
35 } else { | |
36 web_contents->SetDelegate(this); | |
37 } | |
38 // Set |this| as a property so the ConstrainedHtmlUI can retrieve it. | |
39 ConstrainedHtmlUI::GetPropertyAccessor().SetProperty( | |
40 web_contents->GetPropertyBag(), this); | |
41 | |
42 web_contents->GetController().LoadURL(delegate->GetDialogContentURL(), | |
43 content::Referrer(), | |
44 content::PAGE_TRANSITION_START_PAGE, | |
45 std::string()); | |
46 } | |
47 | |
48 ConstrainedHtmlUIDelegateImpl::~ConstrainedHtmlUIDelegateImpl() { | |
49 if (release_tab_on_close_) | |
50 ignore_result(tab_.release()); | |
51 } | |
52 | |
53 const HtmlDialogUIDelegate* | |
54 ConstrainedHtmlUIDelegateImpl::GetHtmlDialogUIDelegate() const { | |
55 return html_delegate_; | |
56 } | |
57 | |
58 HtmlDialogUIDelegate* | |
59 ConstrainedHtmlUIDelegateImpl::GetHtmlDialogUIDelegate() { | |
60 return html_delegate_; | |
61 } | |
62 | |
63 void ConstrainedHtmlUIDelegateImpl::OnDialogCloseFromWebUI() { | |
64 closed_via_webui_ = true; | |
65 window_->CloseConstrainedWindow(); | |
66 } | |
67 | |
68 void ConstrainedHtmlUIDelegateImpl::set_window(ConstrainedWindow* window) { | |
69 window_ = window; | |
70 } | |
71 | |
72 void ConstrainedHtmlUIDelegateImpl::set_override_tab_delegate( | |
73 HtmlDialogTabContentsDelegate* override_tab_delegate) { | |
74 override_tab_delegate_.reset(override_tab_delegate); | |
75 } | |
76 | |
77 bool ConstrainedHtmlUIDelegateImpl::closed_via_webui() const { | |
78 return closed_via_webui_; | |
79 } | |
80 | |
81 void ConstrainedHtmlUIDelegateImpl::ReleaseTabContentsOnDialogClose() { | |
82 release_tab_on_close_ = true; | |
83 } | |
84 | |
85 ConstrainedWindow* ConstrainedHtmlUIDelegateImpl::window() { | |
86 return window_; | |
87 } | |
88 | |
89 TabContentsWrapper* ConstrainedHtmlUIDelegateImpl::tab() { | |
90 return tab_.get(); | |
91 } | |
92 | |
93 void ConstrainedHtmlUIDelegateImpl::HandleKeyboardEvent( | |
94 const NativeWebKeyboardEvent& event) { | |
95 } | |
OLD | NEW |