OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/webui/constrained_html_ui.h" | 5 #include "chrome/browser/ui/webui/constrained_html_ui.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
10 #include "chrome/browser/ui/views/constrained_window_views.h" | 10 #include "chrome/browser/ui/views/constrained_window_views.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 public views::WidgetDelegate, | 21 public views::WidgetDelegate, |
22 public HtmlDialogTabContentsDelegate { | 22 public HtmlDialogTabContentsDelegate { |
23 public: | 23 public: |
24 ConstrainedHtmlDelegateViews(Profile* profile, | 24 ConstrainedHtmlDelegateViews(Profile* profile, |
25 HtmlDialogUIDelegate* delegate); | 25 HtmlDialogUIDelegate* delegate); |
26 ~ConstrainedHtmlDelegateViews(); | 26 ~ConstrainedHtmlDelegateViews(); |
27 | 27 |
28 // ConstrainedHtmlUIDelegate interface. | 28 // ConstrainedHtmlUIDelegate interface. |
29 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE; | 29 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE; |
30 virtual void OnDialogCloseFromWebUI() OVERRIDE; | 30 virtual void OnDialogCloseFromWebUI() OVERRIDE; |
| 31 virtual void ReleaseTabContentsOnDialogClose() OVERRIDE; |
| 32 virtual ConstrainedWindow* window() OVERRIDE { return window_; } |
| 33 virtual TabContentsWrapper* tab() OVERRIDE { |
| 34 return html_tab_contents_.get(); |
| 35 } |
31 | 36 |
32 // views::WidgetDelegate interface. | 37 // views::WidgetDelegate interface. |
33 virtual bool CanResize() const OVERRIDE { return true; } | 38 virtual bool CanResize() const OVERRIDE { return true; } |
34 virtual views::View* GetContentsView() OVERRIDE { | 39 virtual views::View* GetContentsView() OVERRIDE { |
35 return this; | 40 return this; |
36 } | 41 } |
37 virtual void WindowClosing() OVERRIDE { | 42 virtual void WindowClosing() OVERRIDE { |
38 if (!closed_via_webui_) | 43 if (!closed_via_webui_) |
39 html_delegate_->OnDialogClosed(""); | 44 html_delegate_->OnDialogClosed(""); |
40 } | 45 } |
(...skipping 16 matching lines...) Expand all Loading... |
57 gfx::Size size; | 62 gfx::Size size; |
58 html_delegate_->GetDialogSize(&size); | 63 html_delegate_->GetDialogSize(&size); |
59 return size; | 64 return size; |
60 } | 65 } |
61 | 66 |
62 virtual void ViewHierarchyChanged(bool is_add, | 67 virtual void ViewHierarchyChanged(bool is_add, |
63 views::View* parent, | 68 views::View* parent, |
64 views::View* child) OVERRIDE { | 69 views::View* child) OVERRIDE { |
65 TabContentsContainer::ViewHierarchyChanged(is_add, parent, child); | 70 TabContentsContainer::ViewHierarchyChanged(is_add, parent, child); |
66 if (is_add && child == this) { | 71 if (is_add && child == this) { |
67 ChangeTabContents(&html_tab_contents_); | 72 ChangeTabContents(html_tab_contents_->tab_contents()); |
68 } | 73 } |
69 } | 74 } |
70 | 75 |
71 void set_window(ConstrainedWindow* window) { | 76 void set_window(ConstrainedWindow* window) { |
72 window_ = window; | 77 window_ = window; |
73 } | 78 } |
74 | 79 |
75 private: | 80 private: |
76 TabContents html_tab_contents_; | 81 scoped_ptr<TabContentsWrapper> html_tab_contents_; |
77 | 82 |
78 HtmlDialogUIDelegate* html_delegate_; | 83 HtmlDialogUIDelegate* html_delegate_; |
79 | 84 |
80 // The constrained window that owns |this|. Saved so we can close it later. | 85 // The constrained window that owns |this|. Saved so we can close it later. |
81 ConstrainedWindow* window_; | 86 ConstrainedWindow* window_; |
82 | 87 |
83 // Was the dialog closed from WebUI (in which case |html_delegate_|'s | 88 // Was the dialog closed from WebUI (in which case |html_delegate_|'s |
84 // OnDialogClosed() method has already been called)? | 89 // OnDialogClosed() method has already been called)? |
85 bool closed_via_webui_; | 90 bool closed_via_webui_; |
| 91 |
| 92 // If true, release |tab_| on close instead of destroying it. |
| 93 bool release_tab_on_close_; |
86 }; | 94 }; |
87 | 95 |
88 ConstrainedHtmlDelegateViews::ConstrainedHtmlDelegateViews( | 96 ConstrainedHtmlDelegateViews::ConstrainedHtmlDelegateViews( |
89 Profile* profile, | 97 Profile* profile, |
90 HtmlDialogUIDelegate* delegate) | 98 HtmlDialogUIDelegate* delegate) |
91 : HtmlDialogTabContentsDelegate(profile), | 99 : HtmlDialogTabContentsDelegate(profile), |
92 html_tab_contents_(profile, NULL, MSG_ROUTING_NONE, NULL, NULL), | |
93 html_delegate_(delegate), | 100 html_delegate_(delegate), |
94 window_(NULL), | 101 window_(NULL), |
95 closed_via_webui_(false) { | 102 closed_via_webui_(false), |
| 103 release_tab_on_close_(false) { |
96 CHECK(delegate); | 104 CHECK(delegate); |
97 html_tab_contents_.set_delegate(this); | 105 TabContents* tab_contents = |
| 106 new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, NULL); |
| 107 html_tab_contents_.reset(new TabContentsWrapper(tab_contents)); |
| 108 tab_contents->set_delegate(this); |
98 | 109 |
99 // Set |this| as a property so the ConstrainedHtmlUI can retrieve it. | 110 // Set |this| as a property so the ConstrainedHtmlUI can retrieve it. |
100 ConstrainedHtmlUI::GetPropertyAccessor().SetProperty( | 111 ConstrainedHtmlUI::GetPropertyAccessor().SetProperty( |
101 html_tab_contents_.property_bag(), this); | 112 html_tab_contents_->tab_contents()->property_bag(), this); |
102 html_tab_contents_.controller().LoadURL( | 113 tab_contents->controller().LoadURL(delegate->GetDialogContentURL(), |
103 delegate->GetDialogContentURL(), | 114 GURL(), |
104 GURL(), | 115 content::PAGE_TRANSITION_START_PAGE, |
105 content::PAGE_TRANSITION_START_PAGE, | 116 std::string()); |
106 std::string()); | |
107 } | 117 } |
108 | 118 |
109 ConstrainedHtmlDelegateViews::~ConstrainedHtmlDelegateViews() { | 119 ConstrainedHtmlDelegateViews::~ConstrainedHtmlDelegateViews() { |
| 120 if (release_tab_on_close_) |
| 121 ignore_result(html_tab_contents_.release()); |
110 } | 122 } |
111 | 123 |
112 HtmlDialogUIDelegate* ConstrainedHtmlDelegateViews::GetHtmlDialogUIDelegate() { | 124 HtmlDialogUIDelegate* ConstrainedHtmlDelegateViews::GetHtmlDialogUIDelegate() { |
113 return html_delegate_; | 125 return html_delegate_; |
114 } | 126 } |
115 | 127 |
116 void ConstrainedHtmlDelegateViews::OnDialogCloseFromWebUI() { | 128 void ConstrainedHtmlDelegateViews::OnDialogCloseFromWebUI() { |
117 closed_via_webui_ = true; | 129 closed_via_webui_ = true; |
118 window_->CloseConstrainedWindow(); | 130 window_->CloseConstrainedWindow(); |
119 } | 131 } |
120 | 132 |
| 133 void ConstrainedHtmlDelegateViews::ReleaseTabContentsOnDialogClose() { |
| 134 release_tab_on_close_ = true; |
| 135 } |
| 136 |
121 // static | 137 // static |
122 ConstrainedWindow* ConstrainedHtmlUI::CreateConstrainedHtmlDialog( | 138 ConstrainedHtmlUIDelegate* ConstrainedHtmlUI::CreateConstrainedHtmlDialog( |
123 Profile* profile, | 139 Profile* profile, |
124 HtmlDialogUIDelegate* delegate, | 140 HtmlDialogUIDelegate* delegate, |
125 TabContentsWrapper* container) { | 141 TabContentsWrapper* container) { |
126 ConstrainedHtmlDelegateViews* constrained_delegate = | 142 ConstrainedHtmlDelegateViews* constrained_delegate = |
127 new ConstrainedHtmlDelegateViews(profile, delegate); | 143 new ConstrainedHtmlDelegateViews(profile, delegate); |
128 ConstrainedWindow* constrained_window = | 144 ConstrainedWindow* constrained_window = |
129 new ConstrainedWindowViews(container, constrained_delegate); | 145 new ConstrainedWindowViews(container, constrained_delegate); |
130 constrained_delegate->set_window(constrained_window); | 146 constrained_delegate->set_window(constrained_window); |
131 return constrained_window; | 147 return constrained_delegate; |
132 } | 148 } |
OLD | NEW |